feat: allow clipping yAxis range
This commit is contained in:
parent
7c9cf65385
commit
b7f20aab15
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user