Skip to content

Commit f243622

Browse files
fix: addressing review comments
1 parent f8b591a commit f243622

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

projects/observability/src/shared/components/cartesian/d3/legend/cartesian-legend.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ComponentRef, Injector } from '@angular/core';
22
import { Color, Dictionary, DynamicComponentService } from '@hypertrace/common';
33
import { ContainerElement, EnterElement, select, Selection } from 'd3-selection';
4-
import { groupBy, isNil } from 'lodash-es';
4+
import { groupBy } from 'lodash-es';
55
import { Observable, Subject } from 'rxjs';
66
import { startWith } from 'rxjs/operators';
77
import { 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')

projects/observability/src/shared/dashboard/data/graphql/explore/explore-cartesian-data-source.model.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ColorService, forkJoinSafeEmpty, RequireBy, TimeDuration } from '@hypertrace/common';
22
import { ModelInject } from '@hypertrace/hyperdash-angular';
3-
import { isNil } from 'lodash-es';
3+
import { isEmpty } from 'lodash-es';
44
import { NEVER, Observable, of } from 'rxjs';
55
import { map, mergeMap } from 'rxjs/operators';
66
import { Series } from '../../../../components/cartesian/chart';
@@ -134,12 +134,9 @@ export abstract class ExploreCartesianDataSourceModel extends GraphQlDataSourceM
134134
data: result.data,
135135
units: obj.attribute.units !== '' ? obj.attribute.units : undefined,
136136
type: request.series.find(series => series.specification === result.spec)!.visualizationOptions.type,
137-
name: result.groupName ?? obj.specDisplayName,
138-
groupName: !isNil(result.groupName)
139-
? request.useGroupName
140-
? result.groupName
141-
: obj.specDisplayName
142-
: undefined,
137+
name: !isEmpty(result.groupName) ? result.groupName! : obj.specDisplayName,
138+
groupName:
139+
!isEmpty(result.groupName) && (request.useGroupName ?? false) ? result.groupName! : obj.specDisplayName,
143140
color: color
144141
}))
145142
);

0 commit comments

Comments
 (0)