diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/DistBar/controlPanel.ts b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/DistBar/controlPanel.ts index f780b04c02f9..43cf59d60e47 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/DistBar/controlPanel.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/DistBar/controlPanel.ts @@ -28,6 +28,8 @@ import { barStacked, reduceXTicks, yAxisLabel, + yAxisShowMinmax, + yAxisBounds, } from '../NVD3Controls'; const config: ControlPanelConfig = { @@ -79,6 +81,8 @@ const config: ControlPanelConfig = { ['y_axis_format'], [yAxisLabel], [showControls, null], + [yAxisShowMinmax], + [yAxisBounds], ], }, { diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/DualLine/controlPanel.ts b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/DualLine/controlPanel.ts index a3aaa406a886..78f33e57c98d 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/DualLine/controlPanel.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/DualLine/controlPanel.ts @@ -18,7 +18,15 @@ */ import { t } from '@superset-ui/core'; import { ControlPanelConfig, sections } from '@superset-ui/chart-controls'; -import { xAxisFormat, yAxis2Format, showLegend } from '../NVD3Controls'; +import { + xAxisFormat, + yAxis2Format, + showLegend, + yAxisBounds, + yAxisShowMinmax, + yAxis2Bounds, + yAxis2ShowMinmax, +} from '../NVD3Controls'; const config: ControlPanelConfig = { controlPanelSections: [ @@ -31,12 +39,12 @@ const config: ControlPanelConfig = { { label: t('Y Axis 1'), expanded: true, - controlSetRows: [['metric', 'y_axis_format']], + controlSetRows: [['metric', 'y_axis_format'], [yAxisShowMinmax], [yAxisBounds]], }, { label: t('Y Axis 2'), expanded: true, - controlSetRows: [['metric_2', yAxis2Format]], + controlSetRows: [['metric_2', yAxis2Format], [yAxis2ShowMinmax], [yAxis2Bounds]], }, { label: t('Query'), diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/LineMulti/controlPanel.ts b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/LineMulti/controlPanel.ts index d9763b36a6a0..f6b9c7d8cb5b 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/LineMulti/controlPanel.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/LineMulti/controlPanel.ts @@ -29,6 +29,10 @@ import { xAxisShowMinmax, showMarkers, yAxis2Format, + yAxisShowMinmax, + yAxisBounds, + yAxis2ShowMinmax, + yAxis2Bounds, } from '../NVD3Controls'; export type Result = { @@ -110,6 +114,8 @@ const config: ControlPanelConfig = { }, ], ['y_axis_format'], + [yAxisShowMinmax], + [yAxisBounds], ], }, { @@ -142,6 +148,8 @@ const config: ControlPanelConfig = { }, ], [yAxis2Format], + [yAxis2ShowMinmax], + [yAxis2Bounds], ], }, { diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/NVD3Controls.tsx b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/NVD3Controls.tsx index fbc5703823cf..e43b224c602d 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/NVD3Controls.tsx +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/NVD3Controls.tsx @@ -93,6 +93,17 @@ export const yAxisShowMinmax: CustomControlItem = { }, }; +export const yAxis2ShowMinmax: CustomControlItem = { + name: 'y_axis_2_showminmax', + config: { + type: 'CheckboxControl', + label: t('Y 2 bounds'), + renderTrigger: true, + default: false, + description: t('Whether to display the min and max values of the Y-axis'), + }, +}; + export const lineInterpolation: CustomControlItem = { name: 'line_interpolation', config: { @@ -232,6 +243,22 @@ export const yAxisBounds: CustomControlItem = { }, }; +export const yAxis2Bounds: CustomControlItem = { + name: 'y_axis_2_bounds', + config: { + type: 'BoundsControl', + label: t('Y Axis 2 Bounds'), + renderTrigger: true, + default: [null, null], + description: t( + 'Bounds for the 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.", + ), + }, +}; + export const xAxisShowMinmax: CustomControlItem = { name: 'x_axis_showminmax', config: { diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/NVD3Vis.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/NVD3Vis.js index e4993020baef..cba128868d59 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/NVD3Vis.js +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/NVD3Vis.js @@ -297,8 +297,10 @@ function nvd3Vis(element, props) { yAxisFormat, yAxis2Format, yAxisBounds, + yAxis2Bounds, yAxisLabel, yAxisShowMinMax = false, + yAxis2ShowMinMax = false, yField, yIsLogScale, } = props; @@ -615,7 +617,7 @@ function nvd3Vis(element, props) { setAxisShowMaxMin(chart.xAxis, xAxisShowMinMax); setAxisShowMaxMin(chart.x2Axis, xAxisShowMinMax); setAxisShowMaxMin(chart.yAxis, yAxisShowMinMax); - setAxisShowMaxMin(chart.y2Axis, yAxisShowMinMax); + setAxisShowMaxMin(chart.y2Axis, yAxis2ShowMinMax || yAxisShowMinMax); if (vizType === 'time_pivot') { if (baseColor) { @@ -764,6 +766,9 @@ function nvd3Vis(element, props) { chart.yAxis1.tickValues(ticks1); chart.yAxis2.tickValues(ticks2); } + + chart.yDomain1([yAxisBounds[0] || ticks1[0], yAxisBounds[1] || ticks1[ticks1.length - 1]]); + chart.yDomain2([yAxis2Bounds[0] || ticks2[0], yAxis2Bounds[1] || ticks2[ticks2.length - 1]]); } if (showMarkers) { diff --git a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/transformProps.js b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/transformProps.js index 695f2353c116..09631a399553 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/transformProps.js +++ b/superset-frontend/temporary_superset_ui/superset-ui/plugins/legacy-preset-chart-nvd3/src/transformProps.js @@ -78,8 +78,10 @@ export default function transformProps(chartProps) { xTicksLayout, y, yAxisBounds, + yAxis2Bounds, yAxisLabel, yAxisShowminmax, + yAxis2Showminmax, yLogScale, } = formData; @@ -173,8 +175,10 @@ export default function transformProps(chartProps) { yAxisFormat, yAxis2Format, yAxisBounds, + yAxis2Bounds, yAxisLabel, yAxisShowMinMax: yAxisShowminmax, + yAxis2ShowMinMax: yAxis2Showminmax, yField: y, yIsLogScale: yLogScale, };