@@ -75,7 +75,7 @@ export class CFDRenderer extends UIControlsRenderer {
7575 if ( this . eventBus && Array . isArray ( mouseChartsEvents ) ) {
7676 mouseChartsEvents . forEach ( ( chart ) => {
7777 this . eventBus ?. addEventListener ( `${ chart } -mousemove` , ( event ) => this . #handleMouseEvent( event , `${ chart } -mousemove` ) ) ;
78- this . eventBus ?. addEventListener ( `${ chart } -mouseleave` , ( ) => this . hideTooltipAndMovingLine ( ) ) ;
78+ this . eventBus ?. addEventListener ( `${ chart } -mouseleave` , ( ) => this . hideTooltip ( ) ) ;
7979 } ) ;
8080 }
8181 }
@@ -432,15 +432,14 @@ export class CFDRenderer extends UIControlsRenderer {
432432 /**
433433 * Shows the tooltip and the moving line at a specific position
434434 * @param {Object } event - The event object containing details: coordinates for the tooltip and line.
435- * @private
436435 */
437- #showTooltipAndMovingLine ( event ) {
438- ! this . tooltip && this . #createTooltipAndMovingLine ( event . lineX , event . lineY ) ;
436+ showTooltip ( event ) {
437+ ! this . tooltip && this . createTooltip ( event . lineX , event . lineY ) ;
439438 let { tooltipWidth, tooltipTop } = this . computeTooltipWidthAndTop ( event ) ;
440439
441- this . #clearTooltipAndMovingLine ( event . lineX , event . lineY ) ;
442- this . # positionTooltip( event . tooltipLeft , tooltipTop , tooltipWidth ) ;
443- this . # populateTooltip( event ) ;
440+ this . clearTooltipContent ( event . lineX , event . lineY ) ;
441+ this . positionTooltip ( event . tooltipLeft , tooltipTop , tooltipWidth ) ;
442+ this . populateTooltip ( event ) ;
444443 }
445444
446445 computeTooltipWidthAndTop ( event ) {
@@ -482,19 +481,30 @@ export class CFDRenderer extends UIControlsRenderer {
482481 /**
483482 * Hides the tooltip and the moving line on the chart.
484483 */
485- hideTooltipAndMovingLine ( ) {
484+ hideTooltip ( ) {
486485 if ( this . tooltip ) {
487486 this . tooltip . transition ( ) . duration ( 100 ) . style ( 'opacity' , 0 ) . style ( 'pointer-events' , 'none' ) ;
488487 this . cfdLine . transition ( ) . duration ( 100 ) . style ( 'display' , 'none' ) ;
489488 this . #removeMetricsLines( ) ;
490489 }
491490 }
492491
492+ cleanupTooltip ( ) {
493+ this . hideTooltip ( ) ;
494+ if ( this . tooltip ) {
495+ this . tooltip . remove ( ) ;
496+ this . tooltip = null ;
497+ }
498+ if ( this . cfdLine ) {
499+ this . cfdLine . remove ( ) ;
500+ this . cfdLine = null ;
501+ }
502+ }
503+
493504 /**
494505 * Creates a tooltip and a moving line for the chart used for the metrics and observation logging.
495- * @private
496506 */
497- #createTooltipAndMovingLine ( x , y ) {
507+ createTooltip ( x , y ) {
498508 this . tooltip = d3 . select ( 'body' ) . append ( 'div' ) . attr ( 'class' , styles . chartTooltip ) . attr ( 'id' , 'c-tooltip' ) . style ( 'opacity' , 0 ) ;
499509 this . cfdLine = this . chartArea
500510 ?. append ( 'line' )
@@ -509,22 +519,28 @@ export class CFDRenderer extends UIControlsRenderer {
509519
510520 /**
511521 * Positions the tooltip on the page.
512- * @private
513522 * @param {number } left - The left position for the tooltip.
514523 * @param {number } top - The top position for the tooltip.
515524 * @param {number } width - The width for the tooltip.
516525 */
517- # positionTooltip( left , top , width ) {
526+ positionTooltip ( left , top , width ) {
518527 this . tooltip ?. transition ( ) . duration ( 100 ) . style ( 'opacity' , 0.9 ) . style ( 'pointer-events' , 'auto' ) ;
519528 this . tooltip ?. style ( 'left' , left - width + 'px' ) . style ( 'top' , top + 'px' ) ;
520529 }
521530
531+ /**
532+ * Clears the content of the tooltip and the moving line.
533+ */
534+ clearTooltipContent ( x , y ) {
535+ this . cfdLine ?. attr ( 'stroke' , 'black' ) . attr ( 'y1' , 0 ) . attr ( 'y2' , y ) . attr ( 'x1' , x ) . attr ( 'x2' , x ) . style ( 'display' , null ) ;
536+ this . tooltip ?. selectAll ( '*' ) . remove ( ) ;
537+ }
538+
522539 /**
523540 * Populates the tooltip's content with event data: data, metrics and observation body
524- * @private
525541 * @param {Object } event - The event data for the tooltip.
526542 */
527- # populateTooltip( event ) {
543+ populateTooltip ( event ) {
528544 this . tooltip ?. append ( 'p' ) . text ( formatDateToLocalString ( event . date ) ) . attr ( 'class' , styles . tooltipDate ) ;
529545
530546 const gridContainer = this . tooltip ?. append ( 'div' ) . attr ( 'class' , styles . tooltipGrid ) ;
@@ -566,15 +582,6 @@ export class CFDRenderer extends UIControlsRenderer {
566582 }
567583 }
568584
569- /**
570- * Clears the content of the tooltip and the moving line.
571- * @private
572- */
573- #clearTooltipAndMovingLine( x , y ) {
574- this . cfdLine ?. attr ( 'stroke' , 'black' ) . attr ( 'y1' , 0 ) . attr ( 'y2' , y ) . attr ( 'x1' , x ) . attr ( 'x2' , x ) . style ( 'display' , null ) ;
575- this . tooltip ?. selectAll ( '*' ) . remove ( ) ;
576- }
577-
578585 //endregion
579586
580587 //region Metrics
@@ -632,7 +639,7 @@ export class CFDRenderer extends UIControlsRenderer {
632639 observationBody : observation ?. body ,
633640 observationId : observation ?. id ,
634641 } ;
635- this . #showTooltipAndMovingLine ( data ) ;
642+ this . showTooltip ( data ) ;
636643 eventName . includes ( 'click' ) && this . eventBus ?. emitEvents ( eventName , data ) ;
637644 }
638645 }
@@ -642,7 +649,7 @@ export class CFDRenderer extends UIControlsRenderer {
642649 * @private
643650 */
644651 #setupMouseLeaveHandler( ) {
645- this . chartArea ?. on ( 'mouseleave' , ( ) => this . hideTooltipAndMovingLine ( ) ) ;
652+ this . chartArea ?. on ( 'mouseleave' , ( ) => this . hideTooltip ( ) ) ;
646653 }
647654
648655 /**
0 commit comments