-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TimeSeriesWidget: fix echarts props update, to keep state of control when clicking #865
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,6 +197,7 @@ export default function TimeSeriesChart({ | |
: theme.palette.action.disabledBackground; | ||
|
||
return { | ||
id: name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ensures that echarts keeps track of series when we update data. |
||
name, | ||
markLine: i === 0 ? markLine : undefined, | ||
markArea: i === 0 ? markArea : undefined, | ||
|
@@ -293,7 +294,6 @@ export default function TimeSeriesChart({ | |
return ( | ||
<ReactEcharts | ||
option={options} | ||
notMerge | ||
onEvents={onEvents} | ||
onChartReady={onChartReady} | ||
style={{ height }} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,18 +25,26 @@ export default function useTimeSeriesInteractivity({ | |
|
||
const updateCursor = useCallback((cursor) => zr?.setCursorStyle(cursor), [zr]); | ||
|
||
const firstCategory = data?.[0]?.category; | ||
const seriesFinder = useMemo(() => { | ||
if (firstCategory) { | ||
return { seriesId: firstCategory }; | ||
} | ||
return { seriesIndex: 0 }; | ||
}, [firstCategory]); | ||
|
||
const updateTimelineByCoordinate = useCallback( | ||
(params) => { | ||
if (echartsInstance) { | ||
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [ | ||
const [x] = echartsInstance.convertFromPixel(seriesFinder, [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we remove series from beginnning (by filtering sql by param), internal echarts array looks this: [undefined, undefined, something, something ] So |
||
params.offsetX, | ||
params.offsetY | ||
]); | ||
const itemIndex = findItemIndexByTime(x, data); | ||
setTimeWindow(itemIndex !== undefined ? [data[itemIndex].name] : []); | ||
} | ||
}, | ||
[data, echartsInstance, setTimeWindow] | ||
[data, echartsInstance, setTimeWindow, seriesFinder] | ||
); | ||
|
||
// Echarts events | ||
|
@@ -87,7 +95,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 | ||
]); | ||
|
@@ -101,7 +109,7 @@ export default function useTimeSeriesInteractivity({ | |
|
||
if (echartsInstance) { | ||
setIsMarkAreaSelected(true); | ||
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [ | ||
const [x] = echartsInstance.convertFromPixel(seriesFinder, [ | ||
params.offsetX, | ||
params.offsetY | ||
]); | ||
|
@@ -111,7 +119,7 @@ export default function useTimeSeriesInteractivity({ | |
} | ||
|
||
return addEventWithCleanUp(zr, 'mousedown', mouseDownEvent); | ||
}, [zr, echartsInstance, timeWindow, updateCursor, filterable]); | ||
}, [zr, echartsInstance, timeWindow, updateCursor, filterable, seriesFinder]); | ||
|
||
useEffect(() => { | ||
function mouseMoveEvent(params) { | ||
|
@@ -125,7 +133,7 @@ export default function useTimeSeriesInteractivity({ | |
} | ||
|
||
if (isMarkAreaSelected && echartsInstance) { | ||
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [ | ||
const [x] = echartsInstance.convertFromPixel(seriesFinder, [ | ||
params.offsetX, | ||
params.offsetY | ||
]); | ||
|
@@ -145,7 +153,8 @@ export default function useTimeSeriesInteractivity({ | |
isMarkLineSelected, | ||
setTimeWindow, | ||
updateCursor, | ||
updateTimelineByCoordinate | ||
updateTimelineByCoordinate, | ||
seriesFinder | ||
]); | ||
|
||
useEffect(() => { | ||
|
@@ -164,7 +173,7 @@ export default function useTimeSeriesInteractivity({ | |
} | ||
|
||
if (isMarkAreaMoving && echartsInstance) { | ||
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [ | ||
const [x] = echartsInstance.convertFromPixel(seriesFinder, [ | ||
params.offsetX, | ||
params.offsetY | ||
]); | ||
|
@@ -187,7 +196,8 @@ export default function useTimeSeriesInteractivity({ | |
oldMarkAreaPosition, | ||
setTimeWindow, | ||
timeWindow, | ||
updateCursor | ||
updateCursor, | ||
seriesFinder | ||
]); | ||
|
||
useEffect(() => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ensures that merges
series
objects as list identified byid