Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

feat: allow setting custom y axis range, even if points are outside of the range (#67533)

Jakub Chodorowicz7247ffca2dd8
diff --git a/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_Line_Custom_Y_Axis_Range_Equals_Extents.png b/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_Line_Custom_Y_Axis_Range_Equals_Extents.png
index 3d30809f13e..1aef0eb73d6 100644
Binary files a/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_Line_Custom_Y_Axis_Range_Equals_Extents.png and b/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_Line_Custom_Y_Axis_Range_Equals_Extents.png differ
diff --git a/frontend/src/metabase/static-viz/components/WaterfallChart/stories-data/null-x-axis-value.json b/frontend/src/metabase/static-viz/components/WaterfallChart/stories-data/null-x-axis-value.json
index c93596b5d14..e271615370a 100644
--- a/frontend/src/metabase/static-viz/components/WaterfallChart/stories-data/null-x-axis-value.json
+++ b/frontend/src/metabase/static-viz/components/WaterfallChart/stories-data/null-x-axis-value.json
@@ -11,7 +11,7 @@
"visualization_settings": {
"graph.y_axis.title_text": "Custom Y label",
"graph.show_values": true,
- "graph.y_axis.max": 100,
+ "graph.y_axis.max": 150,
"graph.series_order_dimension": null,
"graph.x_axis.axis_enabled": "rotate-45",
"graph.metrics": ["Y"],
diff --git a/frontend/src/metabase/visualizations/echarts/cartesian/option/axis.ts b/frontend/src/metabase/visualizations/echarts/cartesian/option/axis.ts
index e3927d12b28..584cccd8539 100644
--- a/frontend/src/metabase/visualizations/echarts/cartesian/option/axis.ts
+++ b/frontend/src/metabase/visualizations/echarts/cartesian/option/axis.ts
@@ -5,7 +5,6 @@ import { parseNumberValue } from "metabase/lib/number";
import { CHART_STYLE } from "metabase/visualizations/echarts/cartesian/constants/style";
import type {
BaseCartesianChartModel,
- Extent,
NumericAxisScaleTransforms,
NumericXAxisModel,
TimeSeriesXAxisModel,
@@ -30,15 +29,12 @@ export const getAxisNameGap = (ticksWidth: number): number => {
};
const getCustomAxisRange = (
- axisExtent: Extent,
customMin: number | null,
customMax: number | null,
isNormalized: boolean | undefined,
) => {
- const [extentMin, extentMax] = axisExtent;
-
// If this is a normalized range, respect custom min & max
- // This also accomodates non-normalized custom min & max values
+ // This also accommodates non-normalized custom min & max values
// Allows users to supply e.g. 10 for 10% min as opposed to 0.1
if (isNormalized) {
return {
@@ -47,14 +43,7 @@ const getCustomAxisRange = (
};
}
- // if min/max are not specified or within series extents return `undefined`
- // so that ECharts compute a rounded range automatically
- const finalMin =
- customMin != null && customMin < extentMin ? customMin : undefined;
- const finalMax =
- customMax != null && customMax > extentMax ? customMax : undefined;
-
- return { min: finalMin, max: finalMax };
+ return { min: customMin, max: customMax };
};
export const getYAxisRange = (
@@ -72,12 +61,7 @@ export const getYAxisRange = (
yAxisScaleTransforms,
);
- return getCustomAxisRange(
- axisModel.extent,
- customMin,
- customMax,
- axisModel.isNormalized,
- );
+ return getCustomAxisRange(customMin, customMax, axisModel.isNormalized);
};
export const getAxisNameDefaultOption = (