feat: Adds a control to set the Secondary Y-axis bounds in Mixed charts (#23917)

Co-authored-by: Evan Rusackas <evan@preset.io>
This commit is contained in:
Michael S. Molina
2023-05-05 10:11:54 -03:00
committed by GitHub
parent f3f5d926c1
commit b4371f68b7
2 changed files with 28 additions and 5 deletions

View File

@@ -367,11 +367,11 @@ const config: ControlPanelConfig = {
name: 'y_axis_bounds',
config: {
type: 'BoundsControl',
label: t('Y Axis Bounds'),
label: t('Primary y-axis Bounds'),
renderTrigger: true,
default: yAxisBounds,
description: t(
'Bounds for the Y-axis. When left empty, the bounds are ' +
'Bounds for the primary Y-axis. When left empty, the bounds are ' +
'dynamically defined based on the min/max of the data. Note that ' +
"this feature will only expand the axis range. It won't " +
"narrow the data's extent.",
@@ -400,6 +400,23 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'y_axis_bounds_secondary',
config: {
type: 'BoundsControl',
label: t('Secondary y-axis Bounds'),
renderTrigger: true,
default: yAxisBounds,
description: t(
`Bounds for the secondary Y-axis. Only works when Independent Y-axis
bounds are enabled. When left empty, the bounds are dynamically defined
based on the min/max of the data. Note that this feature will only expand
the axis range. It won't narrow the data's extent.`,
),
},
},
],
[
{
name: `y_axis_format_secondary`,

View File

@@ -139,6 +139,7 @@ export default function transformProps(
yAxisFormatSecondary,
xAxisTimeFormat,
yAxisBounds,
yAxisBoundsSecondary,
yAxisIndex,
yAxisIndexB,
yAxisTitleSecondary,
@@ -285,10 +286,13 @@ export default function transformProps(
// yAxisBounds need to be parsed to replace incompatible values with undefined
let [min, max] = (yAxisBounds || []).map(parseYAxisBound);
let [minSecondary, maxSecondary] = (yAxisBoundsSecondary || []).map(
parseYAxisBound,
);
const maxLabelFormatter = getOverMaxHiddenFormatter({ max, formatter });
const maxLabelFormatterSecondary = getOverMaxHiddenFormatter({
max,
max: maxSecondary,
formatter: formatterSecondary,
});
@@ -348,6 +352,8 @@ export default function transformProps(
if (contributionMode === 'row' && stack) {
if (min === undefined) min = 0;
if (max === undefined) max = 1;
if (minSecondary === undefined) minSecondary = 0;
if (maxSecondary === undefined) maxSecondary = 1;
}
const tooltipFormatter =
@@ -415,8 +421,8 @@ export default function transformProps(
{
...defaultYAxis,
type: logAxisSecondary ? 'log' : 'value',
min,
max,
min: minSecondary,
max: maxSecondary,
minorTick: { show: true },
splitLine: { show: false },
minorSplitLine: { show: minorSplitLine },