Skip to content

Commit

Permalink
TimeSeriesWidget: fix echarts props update, to keep state of control …
Browse files Browse the repository at this point in the history
…when clicking (#865)
  • Loading branch information
zbigg committed Apr 22, 2024
1 parent 520d255 commit 1a8d8e2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Not released

- TimeSeriesWidget: fix echarts props update, to keep state of control when clicking [#865](https://github.com/CartoDB/carto-react/pull/865)
- TimeSeriesWidget: support removing series in mounted widget [#863](https://github.com/CartoDB/carto-react/pull/863)

## 3.0.0
Expand All @@ -12,6 +13,10 @@

## 2.5

### 2.5.3 (2024-04-18)

- TimeSeriesWidget: support removing series in mounted widget [#863](https://github.com/CartoDB/carto-react/pull/863)

### 2.5.2 (2024-04-10)

- configurable timeseries y axis [#861](https://github.com/CartoDB/carto-react/pull/861)
Expand Down
14 changes: 14 additions & 0 deletions packages/react-ui/src/custom-components/echarts-for-react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ export default class ReactEcharts extends _ReactEcharts {
}
}

updateEChartsOption() {
const { option, lazyUpdate, showLoading, loadingOption = null } = this.props;
const echartInstance = this.getEchartsInstance();

echartInstance.setOption(option, { replaceMerge: ['series'], lazyUpdate });

if (showLoading) {
echartInstance.showLoading(loadingOption);
} else {
echartInstance.hideLoading();
}
return echartInstance;
}

offEvents(instance, events) {
if (!events) return;
// loop and off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export default function TimeSeriesChart({
: theme.palette.action.disabledBackground;

return {
id: String(i),
name,
markLine: i === 0 ? markLine : undefined,
markArea: i === 0 ? markArea : undefined,
Expand Down Expand Up @@ -293,7 +294,6 @@ export default function TimeSeriesChart({
return (
<ReactEcharts
option={options}
notMerge
onEvents={onEvents}
onChartReady={onChartReady}
style={{ height }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { findItemIndexByTime } from '../utils/utilities';
const events = {};
let initialTimeWindow = null;

// we identify series by their index and stringify it
const seriesFinder = { seriesId: '0' };

export default function useTimeSeriesInteractivity({
echartsInstance,
data,
Expand All @@ -28,7 +31,7 @@ export default function useTimeSeriesInteractivity({
const updateTimelineByCoordinate = useCallback(
(params) => {
if (echartsInstance) {
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [
const [x] = echartsInstance.convertFromPixel(seriesFinder, [
params.offsetX,
params.offsetY
]);
Expand Down Expand Up @@ -87,7 +90,7 @@ export default function useTimeSeriesInteractivity({

// Move markArea
if (timeWindow.length === 2) {
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [
const [x] = echartsInstance.convertFromPixel(seriesFinder, [
params.offsetX,
params.offsetY
]);
Expand All @@ -101,7 +104,7 @@ export default function useTimeSeriesInteractivity({

if (echartsInstance) {
setIsMarkAreaSelected(true);
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [
const [x] = echartsInstance.convertFromPixel(seriesFinder, [
params.offsetX,
params.offsetY
]);
Expand All @@ -125,7 +128,7 @@ export default function useTimeSeriesInteractivity({
}

if (isMarkAreaSelected && echartsInstance) {
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [
const [x] = echartsInstance.convertFromPixel(seriesFinder, [
params.offsetX,
params.offsetY
]);
Expand Down Expand Up @@ -164,7 +167,7 @@ export default function useTimeSeriesInteractivity({
}

if (isMarkAreaMoving && echartsInstance) {
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [
const [x] = echartsInstance.convertFromPixel(seriesFinder, [
params.offsetX,
params.offsetY
]);
Expand Down

0 comments on commit 1a8d8e2

Please sign in to comment.