@@ -193,6 +193,8 @@ const IMAGE_SERIES_ID_PREFIX: string = "image:";
193193const IMAGE_PIN_SIZE: number = 20 ;
194194/** Color of the pin of an annotated image */
195195const ANNOTATED_IMAGE_COLOR: string = " #FF0000" ;
196+ /** ECharts id of the series drawing the clicked data point in black, see buildSelectedPointSeries() */
197+ const SELECTED_POINT_SERIES_ID: string = " selectedPoint" ;
196198
197199/**
198200 * Events grouped by the ECharts id of the series drawing them, in the order of the series data. Used to find the
@@ -227,11 +229,6 @@ const isFullscreen: Ref<boolean> = ref<boolean>(false);
227229const selectedPoint: Ref <DataVisuPoint | undefined > = ref <DataVisuPoint | undefined >(undefined );
228230/** Clicked event pin, its details are displayed under the graphic */
229231const selectedEvent: Ref <DataVisuEvent | undefined > = ref <DataVisuEvent | undefined >(undefined );
230- /**
231- * ECharts position of the point drawn in black. ECharts only unselects the previous point of the same series, the
232- * previous point of another series is unselected by onChartClicked().
233- */
234- let selectedSymbol: { seriesId: string , dataIndex: number } | undefined ;
235232
236233/** Right-clicked data point, its menu is displayed while it is defined */
237234const rightClickMenuPoint: Ref <DataVisuPoint | undefined > = ref <DataVisuPoint | undefined >(undefined );
@@ -286,6 +283,9 @@ onBeforeUnmount(() => {
286283
287284watch (() => props .highlightedImageUri , highlightImagePins );
288285
286+ // The clicked point is drawn in black, see buildSelectedPointSeries()
287+ watch (selectedPoint , () => chart ?.setOption ({series: [buildSelectedPointSeries ()]}));
288+
289289// The tooltip is drawn above everything: it is hidden while the menu of a data point is open
290290watch (rightClickMenuPoint , (point : DataVisuPoint | undefined ) => {
291291 if (point ) {
@@ -333,17 +333,8 @@ function onChartClicked(params: ECElementEvent): void {
333333 }
334334 const dataPoint: DataVisuPoint | undefined = dataSeriesById .get (params .seriesId )?.points [params .dataIndex ];
335335 if (dataPoint ) {
336- if (selectedSymbol ?.seriesId === params .seriesId && selectedSymbol .dataIndex === params .dataIndex ) {
337- // Clicking the selected point again unselects it (ECharts does it for its color), and hides its details
338- selectedSymbol = undefined ;
339- selectedPoint .value = undefined ;
340- return ;
341- }
342- if (selectedSymbol && selectedSymbol .seriesId !== params .seriesId ) {
343- chart ?.dispatchAction ({type: " unselect" , seriesId: selectedSymbol .seriesId , dataIndex: selectedSymbol .dataIndex });
344- }
345- selectedSymbol = {seriesId: params .seriesId , dataIndex: params .dataIndex };
346- selectedPoint .value = dataPoint ;
336+ // Clicking the selected point again hides its details
337+ selectedPoint .value = dataPoint === selectedPoint .value ? undefined : dataPoint ;
347338 selectedEvent .value = undefined ;
348339 return ;
349340 }
@@ -573,7 +564,7 @@ function buildBaseOption(yAxisNames: string[], zoomRange?: ZoomRange): DataVisuO
573564 /** Horizontal background lines: only drawn by the first axis, otherwise the two axes' lines overlap */
574565 splitLine: {show: index === 0 }
575566 })),
576- series: [... buildSeries (), ... buildImageSeries (), ... buildEventSeries ()]
567+ series: [... buildSeries (), ... buildImageSeries (), ... buildEventSeries (), buildSelectedPointSeries () ]
577568 };
578569}
579570
@@ -608,9 +599,6 @@ function buildSeries(): Array<ScatterSeriesOption | LineSeriesOption> {
608599 * focus "series" fades out every other series, so the hovered point's series stands out.
609600 */
610601 emphasis: {focus: " series" as const },
611- /** A clicked point is selected and drawn in black, until another point is clicked, see onChartClicked() */
612- selectedMode: " single" as const ,
613- select: {itemStyle: {color: " #000" }},
614602 };
615603
616604 if (lineMode .value ) {
@@ -635,6 +623,33 @@ function buildSeries(): Array<ScatterSeriesOption | LineSeriesOption> {
635623 });
636624}
637625
626+ /**
627+ * The clicked data point (selectedPoint), drawn in black on top of its series. A separate series, as the style of a
628+ * single point is ignored by the optimised rendering of big scatter series (large: true). Empty when no point is
629+ * selected.
630+ */
631+ function buildSelectedPointSeries(): ScatterSeriesOption {
632+ const point: DataVisuPoint | undefined = selectedPoint .value ;
633+ const serie: DataVisuSerie | undefined = point
634+ ? Array .from (dataSeriesById .values ()).find ((s : DataVisuSerie ) => s .points .includes (point ))
635+ : undefined ;
636+ return {
637+ type: " scatter" ,
638+ id: SELECTED_POINT_SERIES_ID ,
639+ /** Same name as its data series: the legend shows them as one entry, and hides them together */
640+ name: serie ?.name ,
641+ yAxisIndex: serie ?.yAxisIndex ?? 0 ,
642+ data: point && serie ? [[point .timestamp , point .value ]] : [],
643+ color: " #000" ,
644+ symbol: serie ?.symbol ?? " circle" ,
645+ symbolSize: 6 ,
646+ /** Drawn above the data series */
647+ z: 3 ,
648+ /** Not clickable nor hoverable: the mouse goes through it to the data point below, see onChartClicked() */
649+ silent: true
650+ };
651+ }
652+
638653/**
639654 * One series of image pins per data series having images, so they can be hidden from the legend. Each pin is on
640655 * top of the point measured from the image, on the same Y axis as its data series. Always drawn as independent
@@ -820,7 +835,6 @@ function render(): void {
820835 isZoomed .value = false ;
821836 selectedPoint .value = undefined ;
822837 selectedEvent .value = undefined ;
823- selectedSymbol = undefined ;
824838 enableDragZoom ();
825839 layoutEventPins (chart );
826840}
@@ -911,6 +925,8 @@ function downloadImage(): void {
911925 selected: currentLegend [0 ]?.selected
912926 }
913927 });
928+ // The clicked point is not drawn in black in the image
929+ exportChart .setOption ({series: [{id: SELECTED_POINT_SERIES_ID , data: []}]});
914930 layoutEventPins (exportChart );
915931
916932 const link: HTMLAnchorElement = document .createElement (" a" );
0 commit comments