Просмотр исходного кода

feat: allow clipping yAxis range

pull/347/head
Shivam Mishra 4 лет назад
committed by GitHub
Родитель
Сommit
b7f20aab15
2 измененных файлов: 11 добавлений и 2 удалений
  1. +2
    -1
      src/js/charts/AxisChart.js
  2. +9
    -1
      src/js/utils/intervals.js

+ 2
- 1
src/js/charts/AxisChart.js Просмотреть файл

@@ -40,6 +40,7 @@ export default class AxisChart extends BaseChart {
this.config.yAxisMode = options.axisOptions.yAxisMode || 'span'; this.config.yAxisMode = options.axisOptions.yAxisMode || 'span';
this.config.xIsSeries = options.axisOptions.xIsSeries || 0; this.config.xIsSeries = options.axisOptions.xIsSeries || 0;
this.config.shortenYAxisNumbers = options.axisOptions.shortenYAxisNumbers || 0; this.config.shortenYAxisNumbers = options.axisOptions.shortenYAxisNumbers || 0;
this.config.yAxisRange = options.axisOptions.yAxisRange || {},


this.config.formatTooltipX = options.tooltipOptions.formatTooltipX; this.config.formatTooltipX = options.tooltipOptions.formatTooltipX;
this.config.formatTooltipY = options.tooltipOptions.formatTooltipY; this.config.formatTooltipY = options.tooltipOptions.formatTooltipY;
@@ -86,7 +87,7 @@ export default class AxisChart extends BaseChart {
} }


calcYAxisParameters(dataValues, withMinimum = 'false') { calcYAxisParameters(dataValues, withMinimum = 'false') {
const yPts = calcChartIntervals(dataValues, withMinimum);
const yPts = calcChartIntervals(dataValues, withMinimum, this.config.yAxisRange);
const scaleMultiplier = this.height / getValueRange(yPts); const scaleMultiplier = this.height / getValueRange(yPts);
const intervalHeight = getIntervalSize(yPts) * scaleMultiplier; const intervalHeight = getIntervalSize(yPts) * scaleMultiplier;
const zeroLine = this.height - (getZeroIndex(yPts) * intervalHeight); const zeroLine = this.height - (getZeroIndex(yPts) * intervalHeight);


+ 9
- 1
src/js/utils/intervals.js Просмотреть файл

@@ -73,7 +73,7 @@ function getChartIntervals(maxValue, minValue = 0) {
return intervals; return intervals;
} }


export function calcChartIntervals(values, withMinimum = false) {
export function calcChartIntervals(values, withMinimum = false, range = {}) {
//*** Where the magic happens *** //*** Where the magic happens ***


// Calculates best-fit y intervals from given values // Calculates best-fit y intervals from given values
@@ -82,6 +82,14 @@ export function calcChartIntervals(values, withMinimum = false) {
let maxValue = Math.max(...values); let maxValue = Math.max(...values);
let minValue = Math.min(...values); let minValue = Math.min(...values);


if (range.max) {
maxValue = maxValue > range.max ? maxValue : range.max;
}
if (range.min) {
minValue = minValue < range.min ? minValue : range.end;
}

// Exponent to be used for pretty print // Exponent to be used for pretty print
let exponent = 0, intervals = []; // eslint-disable-line no-unused-vars let exponent = 0, intervals = []; // eslint-disable-line no-unused-vars




Загрузка…
Отмена
Сохранить