From f33309601201776c9f724e46badadaeef4663358 Mon Sep 17 00:00:00 2001 From: Arjun Choudhary Date: Wed, 27 Sep 2023 16:08:01 +0530 Subject: [PATCH] feat: experimental! allow overrriding yAxisLabels --- src/js/charts/AxisChart.js | 4 ++-- src/js/charts/BaseChart.js | 2 ++ src/js/utils/intervals.js | 10 +++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/js/charts/AxisChart.js b/src/js/charts/AxisChart.js index 6bcb05a3..cea84b85 100644 --- a/src/js/charts/AxisChart.js +++ b/src/js/charts/AxisChart.js @@ -147,7 +147,7 @@ export default class AxisChart extends BaseChart { // if we have an object we have multiple yAxisParameters. if (dataValues instanceof Array) { - yPts = calcChartIntervals(dataValues, withMinimum); + yPts = calcChartIntervals(dataValues, withMinimum, this.config.overrideCeiling, this.config.overrideFloor); scaleMultiplier = this.height / getValueRange(yPts); intervalHeight = getIntervalSize(yPts) * scaleMultiplier; zeroLine = this.height - getZeroIndex(yPts) * intervalHeight; @@ -170,7 +170,7 @@ export default class AxisChart extends BaseChart { yAxisAlignment = yAxisConfigObject.position ? yAxisConfigObject.position : "left"; - yPts = calcChartIntervals(dataValue, withMinimum); + yPts = calcChartIntervals(dataValue, withMinimum, this.config.overrideCeiling, this.config.overrideFloor); scaleMultiplier = this.height / getValueRange(yPts); intervalHeight = getIntervalSize(yPts) * scaleMultiplier; zeroLine = this.height - getZeroIndex(yPts) * intervalHeight; diff --git a/src/js/charts/BaseChart.js b/src/js/charts/BaseChart.js index 545ae7f3..e54d68bc 100644 --- a/src/js/charts/BaseChart.js +++ b/src/js/charts/BaseChart.js @@ -56,6 +56,8 @@ export default class BaseChart { : 1, isNavigable: options.isNavigable || 0, animate: 0, + overrideCeiling: options.overrideCeiling || false, + overrideFloor: options.overrideFloor || false, truncateLegends: typeof options.truncateLegends !== "undefined" ? options.truncateLegends diff --git a/src/js/utils/intervals.js b/src/js/utils/intervals.js index 21cd6041..e3bbab5d 100644 --- a/src/js/utils/intervals.js +++ b/src/js/utils/intervals.js @@ -81,7 +81,7 @@ function getChartIntervals(maxValue, minValue = 0) { return intervals; } -export function calcChartIntervals(values, withMinimum = false) { +export function calcChartIntervals(values, withMinimum = true, overrideCeiling=false, overrideFloor=false) { //*** Where the magic happens *** // Calculates best-fit y intervals from given values @@ -90,6 +90,14 @@ export function calcChartIntervals(values, withMinimum = false) { let maxValue = Math.max(...values); let minValue = Math.min(...values); + if (overrideCeiling) { + maxValue = overrideCeiling + } + + if (overrideFloor) { + minValue = overrideFloor + } + // Exponent to be used for pretty print let exponent = 0, intervals = []; // eslint-disable-line no-unused-vars