Skip to content

Commit 503de04

Browse files
Bug: Initialize proper minMaxSteps when there are no points. (#6053)
* Motivation for features / changes This fixes a bug where the start step was sometimes initialized as INFINITY. Math.min([]) returns INFINITY and Math.max([]) return -INFINITY. This makes sense for some applications but for us this was causing bugs. I went ahead and forced the value to be the other way around when the array was empty. This fixed the bug. Co-authored-by: Riley Jones <[email protected]>
1 parent 65566b6 commit 503de04

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,10 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
375375
const allPoints = series
376376
.map(({points}) => points.map(({x}) => x))
377377
.flat();
378-
const min = Math.min(...allPoints);
379-
const max = Math.max(...allPoints);
378+
const min =
379+
allPoints.length === 0 ? DEFAULT_MIN : Math.min(...allPoints);
380+
const max =
381+
allPoints.length === 0 ? DEFAULT_MAX : Math.max(...allPoints);
380382
const minStep = Math.max(min, viewPort.minStep);
381383
const maxStep = Math.min(max, viewPort.maxStep);
382384

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,29 @@ describe('scalar card', () => {
21642164
).toEqual('30');
21652165
}));
21662166

2167+
it('initializes minMaxSteps when there is no run data', fakeAsync(async () => {
2168+
const runToSeries = {
2169+
run1: [],
2170+
};
2171+
provideMockCardRunToSeriesData(
2172+
selectSpy,
2173+
PluginType.SCALARS,
2174+
'card1',
2175+
null /* metadataOverride */,
2176+
runToSeries
2177+
);
2178+
const fixture = createComponent('card1');
2179+
let newSteps: MinMaxStep | null = null;
2180+
fixture.componentInstance.minMaxSteps$?.subscribe((minMaxStep) => {
2181+
newSteps = minMaxStep;
2182+
});
2183+
2184+
expect(newSteps!).toEqual({
2185+
minStep: -Infinity,
2186+
maxStep: Infinity,
2187+
});
2188+
}));
2189+
21672190
describe('stepSelectorTimeSelection', () => {
21682191
beforeEach(() => {
21692192
provideMockCardRunToSeriesData(

0 commit comments

Comments
 (0)