Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export default function transformProps(
yAxisFormatSecondary,
xAxisTimeFormat,
yAxisBounds,
yAxisBoundsSecondary,
yAxisIndex,
yAxisIndexB,
yAxisTitleSecondary,
Expand Down Expand Up @@ -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,
});

Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 },
Expand Down