Skip to content

Commit 728b63c

Browse files
committed
Updated solution with code review suggestions
1 parent b710d6e commit 728b63c

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

tensorboard/webapp/metrics/views/card_renderer/card_lazy_loader_test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ describe('card view test', () => {
109109

110110
dispatchedActions = [];
111111
store = TestBed.inject<Store<State>>(Store) as MockStore<State>;
112-
spyOn(store, 'dispatch').and.callFake(((action: Action) => {
112+
// Cast to jasmine.Spy for compatibility between NgRx dispatch signature overloads.
113+
(spyOn(store, 'dispatch') as jasmine.Spy).and.callFake((action: Action) => {
113114
dispatchedActions.push(action);
114-
}) as any);
115+
});
115116

116117
observeSpy = spyOn(IntersectionObserver.prototype, 'observe');
117118
unobserveSpy = spyOn(IntersectionObserver.prototype, 'unobserve');

tensorboard/webapp/metrics/views/card_renderer/scalar_card_component.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ type ScalarTooltipDatum = TooltipDatum<
7575
}
7676
>;
7777

78+
const MAX_TOOLTIP_ITEMS = 5;
79+
7880
@Component({
7981
standalone: false,
8082
selector: 'scalar-card-component',
@@ -149,13 +151,11 @@ export class ScalarCardComponent<Downloader> {
149151
@ViewChild('dataTableContainer')
150152
dataTableContainer?: ElementRef;
151153

152-
readonly MAX_TOOLTIP_ITEMS = 5;
153-
154154
constructor(private readonly ref: ElementRef, private dialog: MatDialog) {}
155155

156156
yScaleType = ScaleType.LINEAR;
157157
isViewBoxOverridden: boolean = false;
158-
tooltipTotalCount = 0;
158+
additionalItemsCount = 0;
159159

160160
toggleYScaleType() {
161161
this.yScaleType =
@@ -227,31 +227,26 @@ export class ScalarCardComponent<Downloader> {
227227
scalarTooltipData[minIndex].metadata.closest = true;
228228
}
229229

230-
let sortedData: ScalarTooltipDatum[];
231230
switch (this.tooltipSort) {
232231
case TooltipSort.ASCENDING:
233-
sortedData = scalarTooltipData.sort(
234-
(a, b) => a.dataPoint.y - b.dataPoint.y
235-
);
232+
scalarTooltipData.sort((a, b) => a.dataPoint.y - b.dataPoint.y);
236233
break;
237234
case TooltipSort.DESCENDING:
238-
sortedData = scalarTooltipData.sort(
239-
(a, b) => b.dataPoint.y - a.dataPoint.y
240-
);
235+
scalarTooltipData.sort((a, b) => b.dataPoint.y - a.dataPoint.y);
241236
break;
242237
case TooltipSort.NEAREST:
243-
sortedData = scalarTooltipData.sort((a, b) => {
238+
scalarTooltipData.sort((a, b) => {
244239
return a.metadata.distToCursorPixels - b.metadata.distToCursorPixels;
245240
});
246241
break;
247242
case TooltipSort.NEAREST_Y:
248-
sortedData = scalarTooltipData.sort((a, b) => {
243+
scalarTooltipData.sort((a, b) => {
249244
return a.metadata.distToCursorY - b.metadata.distToCursorY;
250245
});
251246
break;
252247
case TooltipSort.DEFAULT:
253248
case TooltipSort.ALPHABETICAL:
254-
sortedData = scalarTooltipData.sort((a, b) => {
249+
scalarTooltipData.sort((a, b) => {
255250
if (a.metadata.displayName < b.metadata.displayName) {
256251
return -1;
257252
}
@@ -263,12 +258,11 @@ export class ScalarCardComponent<Downloader> {
263258
break;
264259
}
265260

266-
this.tooltipTotalCount = sortedData.length;
267-
return sortedData.slice(0, this.MAX_TOOLTIP_ITEMS);
268-
}
269-
270-
get additionalItemsCount(): number {
271-
return Math.max(0, this.tooltipTotalCount - this.MAX_TOOLTIP_ITEMS);
261+
this.additionalItemsCount = Math.max(
262+
0,
263+
scalarTooltipData.length - MAX_TOOLTIP_ITEMS
264+
);
265+
return scalarTooltipData.slice(0, MAX_TOOLTIP_ITEMS);
272266
}
273267

274268
openDataDownloadDialog(): void {

0 commit comments

Comments
 (0)