luizotavio32 commented on code in PR #44810:
URL: https://github.com/apache/superset/pull/44810#discussion_r4139942161
##########
superset-frontend/plugins/plugin-chart-echarts/src/components/Echart.tsx:
##########
@@ -289,12 +290,59 @@ function Echart(
const notMerge = !isDashboardRefreshing;
chartRef.current?.dispatchAction({ type: 'hideTip' });
+ // setOption(notMerge:true) replaces the dataZoom config, dropping any
+ // range the user has engaged. Preserve it across the call.
+ const previousZoom = notMerge
+ ? (
+ chartRef.current?.getOption() as {
+ dataZoom?: DataZoomComponentOption[];
+ }
+ )?.dataZoom
+ : undefined;
chartRef.current?.setOption(themedEchartOptions, {
notMerge,
replaceMerge: notMerge ? undefined : ['series'],
// lazyUpdate defers render, causing tooltip crashes on stale shapes
(#39247)
lazyUpdate: false,
});
+ if (previousZoom?.length) {
+ // Skip restore when the new option reshapes dataZoom (different count
+ // means index-based restore could land on the wrong component).
+ const newZoom = (
+ chartRef.current?.getOption() as {
+ dataZoom?: DataZoomComponentOption[];
+ }
+ )?.dataZoom;
+ if (newZoom?.length === previousZoom.length) {
+ const batch = previousZoom
+ .map((dz, dataZoomIndex) => ({
+ dataZoomIndex,
+ start: dz.start,
+ end: dz.end,
+ startValue: dz.startValue,
+ endValue: dz.endValue,
+ }))
+ .filter(b => {
+ const hasAny =
+ b.start !== undefined ||
+ b.end !== undefined ||
+ b.startValue !== undefined ||
+ b.endValue !== undefined;
+ if (!hasAny) return false;
+ // Default full-range zoom is functionally identical to the
+ // fresh state setOption already produces — skip the dispatch.
+ const isDefaultRange =
+ b.start === 0 &&
+ b.end === 100 &&
+ b.startValue === undefined &&
+ b.endValue === undefined;
+ return !isDefaultRange;
+ });
Review Comment:
Not an issue in practice: no chart config can carry an intentional zoom
range. Every zoomable ECharts chart (Timeseries, Mixed Timeseries, Gantt)
always emits the fixed default `start: 0, end: 100` from
`TIMESERIES_CONSTANTS`, and there is no Explore control for the range. So an
incoming `echartOptions` never has a deliberate range to override; the only
non-default range is the one the user dragged, which is exactly what this
restores. Nothing in Superset subscribes to `datazoom` events either, so the
restore dispatch has no side effects.
This is a straight backport of #40173 and master has the identical logic, so
any change there belongs in a separate PR against master.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]