@@ -287,6 +287,34 @@ export class LineChartService {
287287 }
288288 } ;
289289
290+ const calculateLegendDimensions = ( ) : void => {
291+ let maximumLabelWidth : number = 1 ;
292+ const labels = Object . keys ( this . legendDataMap ) ;
293+
294+ d3Select ( 'g#time-series-chart-legend' )
295+ . append ( 'g' )
296+ . attr ( 'id' , 'renderToCalculateMaxWidth' )
297+ . selectAll ( '.renderToCalculateMaxWidth' )
298+ . data ( labels )
299+ . enter ( )
300+ . append ( 'text' )
301+ . attr ( 'class' , 'legend-text' )
302+ . text ( datum => this . legendDataMap [ datum ] . text )
303+ . each ( ( datum , index , groups ) => {
304+ Array . from ( groups ) . forEach ( ( text ) => {
305+ if ( text ) {
306+ maximumLabelWidth = Math . max ( maximumLabelWidth , text . getBoundingClientRect ( ) . width )
307+ }
308+ } ) ;
309+ } ) ;
310+
311+ d3Select ( 'g#renderToCalculateMaxWidth' ) . remove ( ) ;
312+
313+ this . _legendGroupColumnWidth = maximumLabelWidth + ChartCommons . COLOR_PREVIEW_SIZE + 30 ;
314+ this . _legendGroupColumns = Math . floor ( this . _width / this . _legendGroupColumnWidth ) ;
315+ this . _legendGroupHeight = Math . ceil ( labels . length / this . _legendGroupColumns ) * ChartCommons . LABEL_HEIGHT + 30 ;
316+ } ;
317+
290318 return ( incomingData : EventResultDataDTO ) => {
291319 if ( incomingData . series . length == 0 ) {
292320 return ;
@@ -298,7 +326,7 @@ export class LineChartService {
298326 const chart : D3Selection < D3BaseType , { } , D3ContainerElement , { } > = d3Select ( 'g#time-series-chart-drawing-area' ) ;
299327 const xScale : D3ScaleTime < number , number > = this . lineChartScaleService . getXScale ( data , this . _width ) ;
300328 const yScale : D3ScaleLinear < number , number > = this . lineChartScaleService . getYScale ( data , this . _height ) ;
301- this . calculateLegendDimensions ( ) ;
329+ calculateLegendDimensions ( ) ;
302330 d3Select ( 'svg#time-series-chart' ) . transition ( ) . duration ( 500 ) . attr ( 'height' , this . _height + this . _legendGroupHeight + this . _margin . top + this . _margin . bottom ) ;
303331 d3Select ( '.x-axis' ) . transition ( ) . call ( this . updateXAxis , xScale ) ;
304332 d3Select ( '.y-axis' ) . transition ( ) . call ( this . updateYAxis , yScale , this . _width ) ;
@@ -510,34 +538,6 @@ export class LineChartService {
510538 d3Select ( svgElement . nativeElement ) . transition ( ) . duration ( 50 ) . style ( 'opacity' , 1.0 ) ;
511539 }
512540
513- private calculateLegendDimensions ( ) : void {
514- let maximumLabelWidth : number = 1 ;
515- const labels = Object . keys ( this . legendDataMap ) ;
516-
517- d3Select ( 'g#time-series-chart-legend' )
518- . append ( 'g' )
519- . attr ( 'id' , 'renderToCalculateMaxWidth' )
520- . selectAll ( '.renderToCalculateMaxWidth' )
521- . data ( labels )
522- . enter ( )
523- . append ( 'text' )
524- . attr ( 'class' , 'legend-text' )
525- . text ( datum => this . legendDataMap [ datum ] . text )
526- . each ( ( datum , index , groups ) => {
527- Array . from ( groups ) . forEach ( ( text ) => {
528- if ( text ) {
529- maximumLabelWidth = Math . max ( maximumLabelWidth , text . getBoundingClientRect ( ) . width )
530- }
531- } ) ;
532- } ) ;
533-
534- d3Select ( 'g#renderToCalculateMaxWidth' ) . remove ( ) ;
535-
536- this . _legendGroupColumnWidth = maximumLabelWidth + ChartCommons . COLOR_PREVIEW_SIZE + 30 ;
537- this . _legendGroupColumns = Math . floor ( this . _width / this . _legendGroupColumnWidth ) ;
538- this . _legendGroupHeight = Math . ceil ( labels . length / this . _legendGroupColumns ) * ChartCommons . LABEL_HEIGHT + 30 ;
539- }
540-
541541 /**
542542 * Print the x-axis on the graph
543543 */
@@ -745,7 +745,7 @@ export class LineChartService {
745745 return ;
746746 }
747747
748- this . _chartContentContainer
748+ const singleDotsContainerSelection = this . _chartContentContainer
749749 . append ( 'g' )
750750 . attr ( 'class' , 'single-dots' )
751751 . selectAll ( )
@@ -754,14 +754,23 @@ export class LineChartService {
754754 . append ( 'g' )
755755 . attr ( 'class' , s => 'single-dot-' + s . key )
756756 . style ( 'fill' , d => getColorScheme ( ) [ data . length - d . index - 1 ] )
757+ . style ( 'opacity' , '0' ) ;
758+ singleDotsContainerSelection
757759 . selectAll ( )
760+ . filter ( ( d : TimeSeries ) => this . legendDataMap [ d . key ] . show )
758761 . data ( ( s : TimeSeries ) => s . values )
759762 . enter ( )
760763 . append ( 'circle' )
761764 . attr ( 'r' , this . DOT_RADIUS )
762765 . attr ( 'cx' , ( dot : TimeSeriesPoint ) => xScale ( dot . date ) )
763766 . attr ( 'cy' , ( dot : TimeSeriesPoint ) => yScale ( dot . value ) )
764767 . style ( 'pointer-events' , 'visible' ) ;
768+ singleDotsContainerSelection
769+ . transition ( )
770+ . duration ( 500 )
771+ . style ( 'opacity' , ( timeSeries : TimeSeries ) => {
772+ return ( this . legendDataMap [ timeSeries . key ] . show ) ? '1' : '0.1' ;
773+ } ) ;
765774 } ;
766775
767776 const addDataPointsToChart = ( timeSeries : TimeSeries [ ] , xScale : D3ScaleTime < number , number > , yScale : D3ScaleLinear < number , number > ) : void => {
@@ -782,7 +791,11 @@ export class LineChartService {
782791 return getColorScheme ( ) [ nodes . length - index - 1 ] ;
783792 } )
784793 . each ( ( d : TimeSeries , i : number , e ) => {
785- const key = d . key ;
794+ // Do not render dots from not active lines
795+ if ( ! this . legendDataMap [ d . key ] . show ) {
796+ return ;
797+ }
798+
786799 const dotsGroupSelection = d3Select ( e [ i ] ) ;
787800 const minDate = xScale . domain ( ) [ 0 ] ;
788801 const maxDate = xScale . domain ( ) [ 1 ] ;
@@ -793,7 +806,7 @@ export class LineChartService {
793806 } )
794807 . enter ( )
795808 . append ( 'circle' )
796- . attr ( 'class' , ( dot : TimeSeriesPoint ) => 'dot dot-' + key + ' dot-x-' + xScale ( dot . date ) . toString ( ) . replace ( '.' , '_' ) )
809+ . attr ( 'class' , ( dot : TimeSeriesPoint ) => 'dot dot-' + d . key + ' dot-x-' + xScale ( dot . date ) . toString ( ) . replace ( '.' , '_' ) )
797810 . attr ( 'visibility' , 'hidden' )
798811 . attr ( 'r' , this . DOT_RADIUS )
799812 . attr ( 'cx' , ( dot : TimeSeriesPoint ) => xScale ( dot . date ) )
0 commit comments