Skip to content

Commit

Permalink
feat: experimental! allow overrriding yAxisLabels
Browse files Browse the repository at this point in the history
  • Loading branch information
uhrjun committed Sep 27, 2023
1 parent 3a16d6c commit f333096
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/js/charts/AxisChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/js/charts/BaseChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/js/utils/intervals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f333096

Please sign in to comment.