Skip to content

Commit e5c5aca

Browse files
committed
Returned to previous state files related to linear chart with tooltip template default. Updated type assertion for unit tests
1 parent 728b63c commit e5c5aca

8 files changed

Lines changed: 30 additions & 279 deletions

File tree

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

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

6666
dispatchedActions = [];
6767
store = TestBed.inject<Store<State>>(Store) as MockStore<State>;
68-
spyOn(store, 'dispatch').and.callFake(((action: Action) => {
68+
// Cast to jasmine.Spy for compatibility between NgRx dispatch signature overloads.
69+
(spyOn(store, 'dispatch') as jasmine.Spy).and.callFake((action: Action) => {
6970
dispatchedActions.push(action);
70-
}) as any);
71+
});
7172
store.overrideSelector(selectors.getRunColorMap, {});
7273
intersectionObserver = TestBed.inject(IntersectionObserverTestingModule);
7374
});

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,10 @@ describe('histogram card', () => {
267267
provideMockCardSeriesData(selectSpy, PluginType.HISTOGRAMS, 'card1');
268268

269269
dispatchedActions = [];
270-
spyOn(store, 'dispatch').and.callFake(((action: Action) => {
270+
// Cast to jasmine.Spy for compatibility between NgRx dispatch signature overloads.
271+
(spyOn(store, 'dispatch') as jasmine.Spy).and.callFake((action: Action) => {
271272
dispatchedActions.push(action);
272-
}) as any);
273+
});
273274
});
274275

275276
it('dispatches metricsCardFullSizeToggled on full size toggle', () => {
@@ -301,9 +302,10 @@ describe('histogram card', () => {
301302
const fixture = createHistogramCardContainer();
302303
fixture.detectChanges();
303304
const dispatchedActions: Action[] = [];
304-
spyOn(store, 'dispatch').and.callFake(((action: Action) => {
305+
// Cast to jasmine.Spy for compatibility between NgRx dispatch signature overloads.
306+
(spyOn(store, 'dispatch') as jasmine.Spy).and.callFake((action: Action) => {
305307
dispatchedActions.push(action);
306-
}) as any);
308+
});
307309

308310
const histogramWidget = fixture.debugElement.query(
309311
By.directive(TestableHistogramWidget)
@@ -584,9 +586,10 @@ describe('histogram card', () => {
584586
const fixture = createHistogramCardContainer();
585587
fixture.detectChanges();
586588
const dispatchedActions: Action[] = [];
587-
spyOn(store, 'dispatch').and.callFake(((action: Action) => {
589+
// Cast to jasmine.Spy for compatibility between NgRx dispatch signature overloads.
590+
(spyOn(store, 'dispatch') as jasmine.Spy).and.callFake((action: Action) => {
588591
dispatchedActions.push(action);
589-
}) as any);
592+
});
590593

591594
const histogramWidget = fixture.debugElement.query(
592595
By.directive(TestableHistogramWidget)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ describe('image card', () => {
107107
store = TestBed.inject<Store<State>>(Store) as MockStore<State>;
108108
dataSource = TestBed.inject<MetricsDataSource>(MetricsDataSource);
109109
selectSpy = spyOn(store, 'select').and.callThrough();
110-
spyOn(store, 'dispatch').and.callFake(((action: Action) => {
110+
// Cast to jasmine.Spy for compatibility between NgRx dispatch signature overloads.
111+
(spyOn(store, 'dispatch') as jasmine.Spy).and.callFake((action: Action) => {
111112
dispatchedActions.push(action);
112-
}) as any);
113+
});
113114

114115
store.overrideSelector(getExperimentIdForRunId, null);
115116
store.overrideSelector(getExperimentIdToExperimentAliasMap, {});

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

Lines changed: 11 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ class TestableLineChart {
199199
<ng-container
200200
*ngFor="
201201
let datum of getCursorAwareTooltipData(
202-
tooltipData,
203-
cursorLocationInDataCoord,
204-
cursorLocation
202+
tooltipDataForTesting,
203+
cursorLocationInDataCoordForTesting,
204+
cursorLocationForTesting
205205
)
206206
"
207207
>
@@ -233,12 +233,6 @@ class TestableLineChart {
233233
</td>
234234
</tr>
235235
</ng-container>
236-
<tr class="legend" *ngIf="additionalItemsCount > 0">
237-
<td colspan="100">
238-
{{ additionalItemsCount }} additional
239-
{{ additionalItemsCount === 1 ? 'item' : 'items' }}
240-
</td>
241-
</tr>
242236
</tbody>
243237
</table>
244238
</ng-template>
@@ -263,13 +257,10 @@ class TestableScalarCardLineChart {
263257
readonly valueFormatter = numberFormatter;
264258
readonly stepFormatter = intlNumberFormatter;
265259

266-
readonly MAX_TOOLTIP_ITEMS = 5;
267-
tooltipTotalCount = 0;
268-
269260
constructor(public readonly changeDetectorRef: ChangeDetectorRef) {}
270261

271262
getCursorAwareTooltipData(
272-
tooltipData: TooltipDatum<ScalarCardSeriesMetadata, ScalarCardPoint>[],
263+
tooltipData: TooltipDatum<ScalarCardSeriesMetadata>[],
273264
cursorLocationInDataCoord: {x: number; y: number},
274265
cursorLocation: {x: number; y: number}
275266
) {
@@ -302,31 +293,22 @@ class TestableScalarCardLineChart {
302293
scalarTooltipData[minIndex].metadata.closest = true;
303294
}
304295

305-
let sortedData;
306296
switch (this.tooltipSort) {
307297
case TooltipSort.ASCENDING:
308-
sortedData = scalarTooltipData.sort(
309-
(a, b) => a.dataPoint.y - b.dataPoint.y
310-
);
311-
break;
298+
return scalarTooltipData.sort((a, b) => a.dataPoint.y - b.dataPoint.y);
312299
case TooltipSort.DESCENDING:
313-
sortedData = scalarTooltipData.sort(
314-
(a, b) => b.dataPoint.y - a.dataPoint.y
315-
);
316-
break;
300+
return scalarTooltipData.sort((a, b) => b.dataPoint.y - a.dataPoint.y);
317301
case TooltipSort.NEAREST:
318-
sortedData = scalarTooltipData.sort((a, b) => {
302+
return scalarTooltipData.sort((a, b) => {
319303
return a.metadata.distToCursorPixels - b.metadata.distToCursorPixels;
320304
});
321-
break;
322305
case TooltipSort.NEAREST_Y:
323-
sortedData = scalarTooltipData.sort((a, b) => {
306+
return scalarTooltipData.sort((a, b) => {
324307
return a.metadata.distToCursorY - b.metadata.distToCursorY;
325308
});
326-
break;
327309
case TooltipSort.DEFAULT:
328310
case TooltipSort.ALPHABETICAL:
329-
sortedData = scalarTooltipData.sort((a, b) => {
311+
return scalarTooltipData.sort((a, b) => {
330312
if (a.metadata.displayName < b.metadata.displayName) {
331313
return -1;
332314
}
@@ -335,15 +317,7 @@ class TestableScalarCardLineChart {
335317
}
336318
return 0;
337319
});
338-
break;
339320
}
340-
341-
this.tooltipTotalCount = sortedData.length;
342-
return sortedData.slice(0, this.MAX_TOOLTIP_ITEMS);
343-
}
344-
345-
get additionalItemsCount(): number {
346-
return Math.max(0, this.tooltipTotalCount - this.MAX_TOOLTIP_ITEMS);
347321
}
348322
}
349323

@@ -487,9 +461,9 @@ describe('scalar card line chart', () => {
487461
store.overrideSelector(selectors.getMetricsCardUserViewBox, null);
488462

489463
dispatchedActions = [];
490-
spyOn(store, 'dispatch').and.callFake(((action: Action) => {
464+
spyOn(store, 'dispatch').and.callFake((action: Action) => {
491465
dispatchedActions.push(action);
492-
}) as any);
466+
});
493467
});
494468

495469
afterEach(() => {
@@ -810,11 +784,6 @@ describe('scalar card line chart', () => {
810784
tooltipData: TooltipDatum[]
811785
) {
812786
fixture.componentInstance.tooltipDataForTesting = tooltipData;
813-
const lineChart = fixture.debugElement.query(Selector.LINE_CHART);
814-
if (lineChart) {
815-
lineChart.componentInstance.tooltipDataForTesting = tooltipData;
816-
lineChart.componentInstance.changeDetectorRef.markForCheck();
817-
}
818787
fixture.componentInstance.changeDetectorRef.markForCheck();
819788
}
820789

@@ -823,23 +792,11 @@ describe('scalar card line chart', () => {
823792
dataPoint?: {x: number; y: number},
824793
domPoint?: Point
825794
) {
826-
const lineChart = fixture.debugElement.query(Selector.LINE_CHART);
827795
if (dataPoint) {
828796
fixture.componentInstance.dataPointForTesting = dataPoint;
829-
if (lineChart) {
830-
lineChart.componentInstance.dataPointForTesting = dataPoint;
831-
lineChart.componentInstance.cursorLocationInDataCoordForTesting =
832-
dataPoint;
833-
}
834797
}
835798
if (domPoint) {
836799
fixture.componentInstance.cursorLocationForTesting = domPoint;
837-
if (lineChart) {
838-
lineChart.componentInstance.cursorLocationForTesting = domPoint;
839-
}
840-
}
841-
if (lineChart) {
842-
lineChart.componentInstance.changeDetectorRef.markForCheck();
843800
}
844801
fixture.componentInstance.changeDetectorRef.markForCheck();
845802
}
@@ -1412,96 +1369,6 @@ describe('scalar card line chart', () => {
14121369
['', 'world', '-500', '1,000', anyString, anyString],
14131370
]);
14141371
}));
1415-
1416-
describe('tooltip item limiting and legend', () => {
1417-
const colors = [
1418-
'#00f',
1419-
'#0f0',
1420-
'#f00',
1421-
'#ff0',
1422-
'#0ff',
1423-
'#f0f',
1424-
'#fff',
1425-
'#000',
1426-
];
1427-
1428-
function buildTooltipData(count: number) {
1429-
return Array.from({length: count}, (_, i) =>
1430-
buildTooltipDatum({
1431-
id: `row${i + 1}`,
1432-
type: SeriesType.ORIGINAL,
1433-
displayName: `Row ${i + 1}`,
1434-
alias: null,
1435-
visible: true,
1436-
color: colors[i % colors.length],
1437-
})
1438-
);
1439-
}
1440-
1441-
function getLegendRow(
1442-
fixture: ComponentFixture<TestableScalarCardLineChart>
1443-
) {
1444-
return fixture.debugElement.query(By.css('table.tooltip tr.legend'));
1445-
}
1446-
1447-
it('displays all items when there are 5 or fewer', fakeAsync(() => {
1448-
store.overrideSelector(selectors.getMetricsScalarSmoothing, 0);
1449-
const fixture = createComponent();
1450-
setTooltipData(fixture, buildTooltipData(5));
1451-
fixture.detectChanges();
1452-
1453-
expect(fixture.debugElement.queryAll(Selector.TOOLTIP_ROW).length).toBe(
1454-
5
1455-
);
1456-
expect(getLegendRow(fixture)).toBeNull();
1457-
}));
1458-
1459-
it('limits tooltip to 5 items when there are more than 5', fakeAsync(() => {
1460-
store.overrideSelector(selectors.getMetricsScalarSmoothing, 0);
1461-
const fixture = createComponent();
1462-
setTooltipData(fixture, buildTooltipData(7));
1463-
fixture.detectChanges();
1464-
1465-
expect(fixture.debugElement.queryAll(Selector.TOOLTIP_ROW).length).toBe(
1466-
5
1467-
);
1468-
}));
1469-
1470-
it('shows legend with singular text for 1 additional item', fakeAsync(() => {
1471-
store.overrideSelector(selectors.getMetricsScalarSmoothing, 0);
1472-
const fixture = createComponent();
1473-
setTooltipData(fixture, buildTooltipData(6));
1474-
fixture.detectChanges();
1475-
1476-
const legendRow = getLegendRow(fixture);
1477-
expect(legendRow).not.toBeNull();
1478-
expect(legendRow.nativeElement.textContent.trim()).toBe(
1479-
'1 additional item'
1480-
);
1481-
}));
1482-
1483-
it('shows legend with plural text for multiple additional items', fakeAsync(() => {
1484-
store.overrideSelector(selectors.getMetricsScalarSmoothing, 0);
1485-
const fixture = createComponent();
1486-
setTooltipData(fixture, buildTooltipData(8));
1487-
fixture.detectChanges();
1488-
1489-
const legendRow = getLegendRow(fixture);
1490-
expect(legendRow).not.toBeNull();
1491-
expect(legendRow.nativeElement.textContent.trim()).toBe(
1492-
'3 additional items'
1493-
);
1494-
}));
1495-
1496-
it('does not show legend when there are exactly 5 items', fakeAsync(() => {
1497-
store.overrideSelector(selectors.getMetricsScalarSmoothing, 0);
1498-
const fixture = createComponent();
1499-
setTooltipData(fixture, buildTooltipData(5));
1500-
fixture.detectChanges();
1501-
1502-
expect(getLegendRow(fixture)).toBeNull();
1503-
}));
1504-
});
15051372
});
15061373

15071374
describe('linked time feature integration', () => {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,10 @@ describe('scalar card', () => {
408408
store.overrideSelector(selectors.getMetricsCardUserViewBox, null);
409409

410410
dispatchedActions = [];
411-
spyOn(store, 'dispatch').and.callFake(((action: Action) => {
411+
// Cast to jasmine.Spy for compatibility between NgRx dispatch signature overloads.
412+
(spyOn(store, 'dispatch') as jasmine.Spy).and.callFake((action: Action) => {
412413
dispatchedActions.push(action);
413-
}) as any);
414+
});
414415
});
415416

416417
afterEach(() => {

tensorboard/webapp/widgets/line_chart_v2/sub_view/line_chart_interactive_view.ng.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<ng-container
6868
[ngTemplateOutlet]="tooltipTemplate ? tooltipTemplate : defaultTooltip"
6969
[ngTemplateOutletContext]="{
70-
data: tooltipTemplate ? cursoredData : limitedCursoredData,
70+
data: cursoredData,
7171
cursorLocationInDataCoord: cursorLocationInDataCoord,
7272
cursorLocation: cursorLocation
7373
}"
@@ -98,12 +98,6 @@
9898
<td>{{ datum.dataPoint.x }}</td>
9999
</tr>
100100
</ng-container>
101-
<tr class="legend" *ngIf="additionalItemsCount > 0">
102-
<td colspan="100">
103-
{{ additionalItemsCount }} additional {{ additionalItemsCount === 1 ?
104-
'item' : 'items' }}
105-
</td>
106-
</tr>
107101
</tbody>
108102
</table>
109103
</ng-template>

tensorboard/webapp/widgets/line_chart_v2/sub_view/line_chart_interactive_view.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,8 @@ export class LineChartInteractiveViewComponent
208208
cursorLocationInDataCoord: {x: number; y: number} | null = null;
209209
cursorLocation: {x: number; y: number} | null = null;
210210
cursoredData: TooltipDatum[] = [];
211-
limitedCursoredData: TooltipDatum[] = [];
212211
tooltipDisplayAttached: boolean = false;
213212

214-
readonly MAX_TOOLTIP_ITEMS = 5;
215-
tooltipTotalCount = 0;
216-
217213
@HostBinding('class.show-zoom-instruction')
218214
showZoomInstruction: boolean = false;
219215

@@ -490,10 +486,6 @@ export class LineChartInteractiveViewComponent
490486
return datum.id;
491487
}
492488

493-
get additionalItemsCount(): number {
494-
return Math.max(0, this.tooltipTotalCount - this.MAX_TOOLTIP_ITEMS);
495-
}
496-
497489
getDomX(uiCoord: number): number {
498490
return this.xScale.forward(
499491
this.viewExtent.x,
@@ -550,8 +542,6 @@ export class LineChartInteractiveViewComponent
550542
const cursorLoc = this.cursorLocationInDataCoord;
551543
if (cursorLoc === null) {
552544
this.cursoredData = [];
553-
this.limitedCursoredData = [];
554-
this.tooltipTotalCount = 0;
555545
this.tooltipDisplayAttached = false;
556546
return;
557547
}
@@ -583,12 +573,6 @@ export class LineChartInteractiveViewComponent
583573
})
584574
.filter((tooltipDatumOrNull) => tooltipDatumOrNull) as TooltipDatum[])
585575
: [];
586-
587-
this.tooltipTotalCount = this.cursoredData.length;
588-
this.limitedCursoredData = this.cursoredData.slice(
589-
0,
590-
this.MAX_TOOLTIP_ITEMS
591-
);
592576
this.tooltipDisplayAttached = Boolean(this.cursoredData.length);
593577
}
594578
}

0 commit comments

Comments
 (0)