Skip to content

Commit 888dcdc

Browse files
authored
Linked Time: Fix bug with zooming always maximizing end step (#6058)
## Motivation for features / changes When changing the zoom on the scalar card with an the end fob the end fob was always placed at the maximum possible step. For Googlers b/259562961 ## Technical description of changes The `StepSelectorTimeSelection` derived by a subscription to a bunch of other Observables. The main issue was that it simply never checked if an existing end step existed. The code was also kinda hard to read(:raised_hand_with_fingers_splayed: my fault) so I went ahead with a bit of a cleanup there. ## Screenshots of UI changes Before: Zooming In: ![129f960a-2ee0-4762-98eb-875594b31b6f](https://user-images.githubusercontent.com/78179109/202584325-cdd164e7-2b04-4930-8de7-4c551ce85bcd.gif) Resetting Zoom Level: ![00194071-2280-4d9b-953c-18740f7cad77](https://user-images.githubusercontent.com/78179109/202584465-4ddb3235-93b7-431b-92e1-16a7961d79e5.gif) After: ![cf40658d-c57c-4d76-a267-9feb8b35f7fe](https://user-images.githubusercontent.com/78179109/202583150-6e7c662c-8230-4060-a289-7880dafda39a.gif) ## Detailed steps to verify changes work correctly (as executed by you) 1) Start tensorboard 2) Navigate to http://localhost:6006?enableRangeSelection&enableDataTable 3) Place two fobs on the scalar card 4) Zoom in on a segment of the chart which contains both fobs (much easier now that #5932 is closed) 5) Assert neither fob has moved 6) Reset the chart zoom level 7) Assert that neither fob has moved.
1 parent 0246da2 commit 888dcdc

File tree

6 files changed

+67
-32
lines changed

6 files changed

+67
-32
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {CardId, CardMetadata} from '../../types';
4848
import {CardRenderer} from '../metrics_view_types';
4949
import {getTagDisplayName} from '../utils';
5050
import {
51-
maybeClipLinkedTimeSelection,
51+
maybeClipTimeSelectionView,
5252
maybeSetClosestStartStep,
5353
TimeSelectionView,
5454
} from './utils';
@@ -182,7 +182,7 @@ export class HistogramCardContainer implements CardRenderer, OnInit {
182182
minStep = Math.min(step, minStep);
183183
maxStep = Math.max(step, maxStep);
184184
}
185-
const linkedTimeSelectionView = maybeClipLinkedTimeSelection(
185+
const linkedTimeSelectionView = maybeClipTimeSelectionView(
186186
linkedTimeSelection,
187187
minStep,
188188
maxStep

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import {
5656
import {CardId, CardMetadata} from '../../types';
5757
import {CardRenderer} from '../metrics_view_types';
5858
import {getTagDisplayName} from '../utils';
59-
import {maybeClipLinkedTimeSelection, TimeSelectionView} from './utils';
59+
import {maybeClipTimeSelectionView, TimeSelectionView} from './utils';
6060

6161
const DISTANCE_RATIO = 0.1;
6262

@@ -263,7 +263,7 @@ export class ImageCardContainer implements CardRenderer, OnInit, OnDestroy {
263263

264264
const minStep = Math.min(...steps);
265265
const maxStep = Math.max(...steps);
266-
return maybeClipLinkedTimeSelection(
266+
return maybeClipTimeSelectionView(
267267
linkedTimeSelection,
268268
minStep,
269269
maxStep

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ import {
101101
SortingInfo,
102102
} from './scalar_card_types';
103103
import {
104-
clipStepWithinMinMax,
105-
maybeClipLinkedTimeSelection,
104+
maybeClipTimeSelection,
105+
maybeClipTimeSelectionView,
106106
partitionSeries,
107107
TimeSelectionView,
108108
} from './utils';
@@ -445,7 +445,7 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
445445
forkedTimeSelection.end = {step: maxStep};
446446
}
447447

448-
return maybeClipLinkedTimeSelection(
448+
return maybeClipTimeSelectionView(
449449
forkedTimeSelection,
450450
minStep,
451451
maxStep
@@ -615,21 +615,28 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
615615
this.store.select(getMetricsRangeSelectionEnabled),
616616
]).subscribe(
617617
([{minStep, maxStep}, enableStepSelector, rangeSelectionEnabled]) => {
618-
this.stepSelectorTimeSelection$.next(
619-
enableStepSelector
620-
? {
621-
start: {
622-
step: clipStepWithinMinMax(
623-
this.stepSelectorTimeSelection$.getValue()?.start.step ??
624-
minStep,
625-
minStep,
626-
maxStep
627-
),
628-
},
629-
end: rangeSelectionEnabled ? {step: maxStep} : null,
630-
}
631-
: null
618+
if (!enableStepSelector) {
619+
this.stepSelectorTimeSelection$.next(null);
620+
return;
621+
}
622+
const currentStartStep =
623+
this.stepSelectorTimeSelection$.getValue()?.start.step;
624+
const currentEndStep =
625+
this.stepSelectorTimeSelection$.getValue()?.end?.step;
626+
627+
const potentiallyClippedTimeSelection = maybeClipTimeSelection(
628+
{
629+
start: {
630+
step: currentStartStep ?? minStep,
631+
},
632+
end: rangeSelectionEnabled
633+
? {step: currentEndStep ?? maxStep}
634+
: null,
635+
},
636+
minStep,
637+
maxStep
632638
);
639+
this.stepSelectorTimeSelection$.next(potentiallyClippedTimeSelection);
633640
}
634641
);
635642
}
@@ -689,7 +696,7 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
689696
newTimeSelectionWithAffordance: TimeSelectionWithAffordance
690697
) {
691698
const {minStep, maxStep} = this.minMaxSteps$.getValue();
692-
const {startStep, endStep} = maybeClipLinkedTimeSelection(
699+
const {startStep, endStep} = maybeClipTimeSelectionView(
693700
newTimeSelectionWithAffordance.timeSelection,
694701
minStep,
695702
maxStep

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,15 @@ describe('scalar card', () => {
25092509
minStep: 10,
25102510
maxStep: 30,
25112511
});
2512+
2513+
fixture.componentInstance.onLineChartZoom({
2514+
x: [8, 31],
2515+
y: [0, 100],
2516+
});
2517+
expect(newSteps!).toEqual({
2518+
minStep: 10,
2519+
maxStep: 30,
2520+
});
25122521
}));
25132522
});
25142523
});

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,26 @@ export function clipStepWithinMinMax(value: number, min: number, max: number) {
101101
return value;
102102
}
103103

104-
export function maybeClipLinkedTimeSelection(
104+
export function maybeClipTimeSelection(
105+
timeSelection: TimeSelection,
106+
minStep: number,
107+
maxStep: number
108+
): TimeSelection {
109+
const timeSelectionView = maybeClipTimeSelectionView(
110+
timeSelection,
111+
minStep,
112+
maxStep
113+
);
114+
return {
115+
start: {step: timeSelectionView.startStep},
116+
end:
117+
timeSelectionView.endStep === null
118+
? null
119+
: {step: timeSelectionView.endStep},
120+
};
121+
}
122+
123+
export function maybeClipTimeSelectionView(
105124
timeSelection: TimeSelection,
106125
minStep: number,
107126
maxStep: number

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
clipStepWithinMinMax,
1919
getClosestStep,
2020
getDisplayNameForRun,
21-
maybeClipLinkedTimeSelection,
21+
maybeClipTimeSelectionView,
2222
maybeSetClosestStartStep,
2323
partitionSeries,
2424
} from './utils';
@@ -335,7 +335,7 @@ describe('metrics card_renderer utils test', () => {
335335
describe('#maybeClipLinkedTimeSelection', () => {
336336
it('clips to the minStep when time selection start step is smaller than the view extend', () => {
337337
expect(
338-
maybeClipLinkedTimeSelection(
338+
maybeClipTimeSelectionView(
339339
{
340340
start: {step: 0},
341341
end: null,
@@ -352,7 +352,7 @@ describe('metrics card_renderer utils test', () => {
352352

353353
it('clips to maxStep when time selection end step is greater than view extend', () => {
354354
expect(
355-
maybeClipLinkedTimeSelection(
355+
maybeClipTimeSelectionView(
356356
{
357357
start: {step: 0},
358358
end: {step: 4},
@@ -369,7 +369,7 @@ describe('metrics card_renderer utils test', () => {
369369

370370
it('does not clip when time selection falls into the view extend', () => {
371371
expect(
372-
maybeClipLinkedTimeSelection(
372+
maybeClipTimeSelectionView(
373373
{
374374
start: {step: 10},
375375
end: null,
@@ -386,7 +386,7 @@ describe('metrics card_renderer utils test', () => {
386386

387387
it('returns minStep and maxStep when the timeselection is a superset of the min/maxstep', () => {
388388
expect(
389-
maybeClipLinkedTimeSelection(
389+
maybeClipTimeSelectionView(
390390
{
391391
start: {step: 0},
392392
end: {step: 100},
@@ -403,7 +403,7 @@ describe('metrics card_renderer utils test', () => {
403403

404404
it('clips both fobs to maxStep when timeSelection is greater than maxStep', () => {
405405
expect(
406-
maybeClipLinkedTimeSelection(
406+
maybeClipTimeSelectionView(
407407
{
408408
start: {step: 50},
409409
end: {step: 100},
@@ -420,7 +420,7 @@ describe('metrics card_renderer utils test', () => {
420420

421421
it('returns startStep === endStep === minStep when timeSelection is below minStep', () => {
422422
expect(
423-
maybeClipLinkedTimeSelection(
423+
maybeClipTimeSelectionView(
424424
{
425425
start: {step: 0},
426426
end: {step: 10},
@@ -437,7 +437,7 @@ describe('metrics card_renderer utils test', () => {
437437

438438
it('does not clip when time selection falls within the view extent', () => {
439439
expect(
440-
maybeClipLinkedTimeSelection(
440+
maybeClipTimeSelectionView(
441441
{
442442
start: {step: 0},
443443
end: {step: 4},
@@ -452,7 +452,7 @@ describe('metrics card_renderer utils test', () => {
452452
});
453453

454454
expect(
455-
maybeClipLinkedTimeSelection(
455+
maybeClipTimeSelectionView(
456456
{
457457
start: {step: 1},
458458
end: {step: 3},

0 commit comments

Comments
 (0)