Explorar el Código

feat: allow clipping yAxis range

pull/347/head
Shivam Mishra hace 4 años
committed by GitHub
padre
commit
b7f20aab15
Se han modificado 2 ficheros con 11 adiciones y 2 borrados
  1. +2
    -1
      src/js/charts/AxisChart.js
  2. +9
    -1
      src/js/utils/intervals.js

+ 2
- 1
src/js/charts/AxisChart.js Ver fichero

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

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

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


+ 9
- 1
src/js/utils/intervals.js Ver fichero

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

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

// Calculates best-fit y intervals from given values
@@ -82,6 +82,14 @@ export function calcChartIntervals(values, withMinimum = false) {
let maxValue = Math.max(...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
let exponent = 0, intervals = []; // eslint-disable-line no-unused-vars



Cargando…
Cancelar
Guardar