feat: allow clipping yAxis range

This commit is contained in:
Shivam Mishra 2021-05-07 08:34:50 +00:00 committed by GitHub
parent 7c9cf65385
commit b7f20aab15
2 changed files with 11 additions and 2 deletions

View File

@ -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);

View File

@ -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