@@ -91,6 +91,11 @@ export class WebstatusGChart extends LitElement {
9191 } )
9292 hasMax = true ;
9393
94+ // Selected data points on the chart.
95+ // If the chart ever re-draws due to resize or the encompassing component
96+ // re-drawing, we need to manually set the current selection.
97+ currentSelection : google . visualization . ChartSelection [ ] | undefined ;
98+
9499 @property ( { state : true , type : Object } )
95100 dataTable :
96101 | google . visualization . DataTable
@@ -129,13 +134,18 @@ export class WebstatusGChart extends LitElement {
129134
130135 private _resizeObserver : ResizeObserver | undefined ;
131136
137+ draw ( ) {
138+ if ( this . chartWrapper ) {
139+ this . chartWrapper . draw ( ) ;
140+ this . chartWrapper ?. getChart ( ) ?. setSelection ( this . currentSelection ) ;
141+ }
142+ }
143+
132144 firstUpdated ( ) {
133145 // 1. Create the ResizeObserver
134146 this . _resizeObserver = new ResizeObserver ( ( ) => {
135147 // 2. Redraw the chart when a resize occurs
136- if ( this . chartWrapper ) {
137- this . chartWrapper . draw ( ) ;
138- }
148+ this . draw ( ) ;
139149 } ) ;
140150
141151 // 3. Start observing the chart container element
@@ -298,13 +308,17 @@ export class WebstatusGChart extends LitElement {
298308 ) ;
299309 this . _chartClickListenerAdded = true ; // Set the flag after adding the listener
300310 }
301- this . chartWrapper . draw ( ) ;
311+ this . draw ( ) ;
302312 }
303313 }
304314 private _handleChartClick ( ) {
305315 const selection = this . chartWrapper ?. getChart ( ) ?. getSelection ( ) ;
306- if ( selection === undefined ) return ;
316+ if ( selection === undefined ) {
317+ this . currentSelection = undefined ;
318+ return ;
319+ }
307320 if ( selection . length > 0 ) {
321+ this . currentSelection = selection ;
308322 // TODO: For now only look at the first selection since we only configure for one selection at a time.
309323 const item = selection [ 0 ] ;
310324 const row = item . row ;
@@ -332,6 +346,7 @@ export class WebstatusGChart extends LitElement {
332346 this . dispatchEvent ( chartClickEvent ) ;
333347 }
334348 } else if ( selection . length === 0 ) {
349+ this . currentSelection = [ ] ;
335350 const chartDeselectEvent : ChartDeselectPointEvent = new CustomEvent (
336351 'point-deselected' ,
337352 { detail : undefined } ,
0 commit comments