Commit 9e46d49
authored
Fix echart zoom reset on data update by using
### Motivation
Fixes #5819.
Updating echart data (e.g. appending points via a timer) always resets
interactive state like dataZoom slider positions. This is because
`this.chart.options` is not a valid ECharts API — it's always
`undefined` — so the `notMerge` flag evaluates to `true` on every
update, causing a full replacement of chart state instead of a merge.
MRE:
```py
chart = ui.echart({
'xAxis': {},
'yAxis': {},
'dataZoom': [{'type': 'slider', 'yAxisIndex': 0}],
'series': [{'type': 'line', 'data': []}],
})
ui.timer(1, lambda: chart.options['series'][0]['data'].append(len(chart.options['series'][0]['data'])))
```
### Implementation
Replace `this.chart.options?.series?.length` with
`this.chart.getOption()?.series?.length` in `echart.js`.
[`getOption()`](https://echarts.apache.org/en/api.html#echartsInstance.getOption)
is the correct ECharts API to retrieve the current chart configuration.
This way `notMerge` is only `true` when the number of series actually
changes (requiring a clean replacement), and `false` for normal data
updates (preserving zoom, slider positions, and other interactive
state).
### Progress
- [x] I chose a meaningful title that completes the sentence: "If
applied, this PR will..."
- [x] The implementation is complete.
- [x] This is not a security issue.
- [x] Pytests are not necessary (would be pretty hard).
- [x] Documentation is not necessary.getOption() API (#5822)1 parent f3b8033 commit 9e46d49
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
0 commit comments