11import { ComponentRef , Injector } from '@angular/core' ;
22import { Color , Dictionary , DynamicComponentService } from '@hypertrace/common' ;
33import { ContainerElement , EnterElement , select , Selection } from 'd3-selection' ;
4- import { groupBy , isNil } from 'lodash-es' ;
4+ import { groupBy } from 'lodash-es' ;
55import { Observable , Subject } from 'rxjs' ;
66import { startWith } from 'rxjs/operators' ;
77import { LegendPosition } from '../../../legend/legend.component' ;
@@ -28,7 +28,6 @@ export class CartesianLegend<TData> {
2828 private readonly groupedSeries : Dictionary < Series < TData > [ ] > ;
2929
3030 private readonly isGrouped : boolean = true ;
31- private readonly isNonTitledGrouped : boolean = false ;
3231 private isSelectionModeOn : boolean = false ;
3332 private legendElement ?: HTMLDivElement ;
3433 private activeSeries : Series < TData > [ ] ;
@@ -41,8 +40,8 @@ export class CartesianLegend<TData> {
4140 private readonly intervalData ?: CartesianIntervalData ,
4241 private readonly summaries : Summary [ ] = [ ]
4342 ) {
44- this . isGrouped = ! isNil ( this . series [ 0 ] ?. groupName ) ;
45- this . isNonTitledGrouped = this . series . length > 0 && this . series [ 0 ] . name = == this . series [ 0 ] . groupName ;
43+ this . isGrouped =
44+ this . series . length > 0 && this . series . every ( seriesEntry => seriesEntry . groupName ! == seriesEntry . name ) ;
4645 this . groupedSeries = this . isGrouped ? groupBy ( this . series , seriesEntry => seriesEntry . groupName ) : { } ;
4746
4847 this . activeSeries = [ ...this . series ] ;
@@ -106,23 +105,21 @@ export class CartesianLegend<TData> {
106105 . data ( Object . values ( this . groupedSeries ) )
107106 . enter ( )
108107 . append ( 'div' )
109- . attr ( 'class' , ( _ , index ) => ` legend-entries group- ${ index + 1 } ` )
108+ . classed ( ' legend-entries' , true )
110109 . each ( ( seriesGroup , index , elements ) => this . drawLegendEntriesTitleAndValues ( seriesGroup , elements [ index ] ) ) ;
111110 }
112111 }
113112
114113 private drawLegendEntriesTitleAndValues ( seriesGroup : Series < TData > [ ] , element : HTMLDivElement ) : void {
115114 const legendEntriesSelection = select ( element ) ;
116- if ( ! this . isNonTitledGrouped ) {
117- legendEntriesSelection
118- . selectAll ( '.legend-entries-title' )
119- . data ( [ seriesGroup ] )
120- . enter ( )
121- . append ( 'div' )
122- . classed ( 'legend-entries-title' , true )
123- . text ( group => `${ group [ 0 ] . groupName } :` )
124- . on ( 'click' , ( ) => this . updateActiveSeriesGroup ( seriesGroup ) ) ;
125- }
115+ legendEntriesSelection
116+ . selectAll ( '.legend-entries-title' )
117+ . data ( [ seriesGroup ] )
118+ . enter ( )
119+ . append ( 'div' )
120+ . classed ( 'legend-entries-title' , true )
121+ . text ( group => `${ group [ 0 ] . groupName } :` )
122+ . on ( 'click' , ( ) => this . updateActiveSeriesGroup ( seriesGroup ) ) ;
126123
127124 legendEntriesSelection
128125 . append ( 'div' )
0 commit comments