Skip to content

Commit f52eb8c

Browse files
authored
Use maximum step as default for single step selection. (#6372)
## Motivation for features / changes We are changing single step selection to default to the maximum step. We think this is more useful than making the default the minimum step. This also means that when step selection changes from single selection to range selection, the minimum value of the chart is added as the start of the range and the previous single step now becomes the end of the range. Similarly, when step selection changes from range selection to single selection, the new single selection is the previous maximum value of the range. ## Technical description of changes Where default value is set to "min" step, instead set it to the "max" step. Where range selection is enabled, ensure the new start of the range is the "min" step. I have three internal CLs that accompagny this change. * cl/528745120 adjusts or comments out code to allow the import to succeed. It will be submitted prior to merging this PR. * cl/528745440 is a set of harmless screenshot-updates. It will be patched into the import CL and submitted at the same time as the import. * cl/528745657 is a set of changes to uncomment out the code from the first CL and make remaining adjustments. It will be submitted after the import. ## Detailed steps to verify changes work correctly (as executed by you) * I tested it manually quite a bit. * I imported it into the internal repo and ensured that end-to-end tests pass (after adjusting for the change in behavior).
1 parent 5ea918e commit f52eb8c

File tree

5 files changed

+47
-25
lines changed

5 files changed

+47
-25
lines changed

tensorboard/webapp/metrics/store/metrics_reducers.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,8 +1141,8 @@ const reducer = createReducer(
11411141

11421142
// Updates cardStepIndex only when toggle to enable linked time.
11431143
if (nextLinkedTimeEnabled) {
1144-
const {min} = state.stepMinMax;
1145-
const startStep = min === Infinity ? 0 : min;
1144+
const {max} = state.stepMinMax;
1145+
const startStep = max === -Infinity ? 0 : max;
11461146
nextLinkedTimeSelection = state.linkedTimeSelection ?? {
11471147
start: {step: startStep},
11481148
end: null,
@@ -1202,15 +1202,19 @@ const reducer = createReducer(
12021202
};
12031203
}
12041204
if (!linkedTimeSelection.end) {
1205+
// Enabling range selection from single selection selects the first
1206+
// step as the start of the range. The previous start step from single
1207+
// selection is now the end step.
12051208
linkedTimeSelection = {
1206-
...linkedTimeSelection,
1207-
end: {step: state.stepMinMax.max},
1209+
start: {step: state.stepMinMax.min},
1210+
end: linkedTimeSelection.start,
12081211
};
12091212
}
12101213
} else {
12111214
if (linkedTimeSelection) {
1215+
// Disabling range selection keeps the largest step from the range.
12121216
linkedTimeSelection = {
1213-
...linkedTimeSelection,
1217+
start: linkedTimeSelection.end ?? linkedTimeSelection.start,
12141218
end: null,
12151219
};
12161220
}

tensorboard/webapp/metrics/store/metrics_reducers_test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4057,8 +4057,8 @@ describe('metrics reducers', () => {
40574057

40584058
const state2 = reducers(state1, actions.rangeSelectionToggled({}));
40594059
expect(state2.linkedTimeSelection).toEqual({
4060-
start: {step: 100},
4061-
end: {step: -Infinity},
4060+
start: {step: Infinity},
4061+
end: {step: 100},
40624062
});
40634063
});
40644064

@@ -4073,7 +4073,7 @@ describe('metrics reducers', () => {
40734073

40744074
const state2 = reducers(state1, actions.rangeSelectionToggled({}));
40754075
expect(state2.linkedTimeSelection).toEqual({
4076-
start: {step: 100},
4076+
start: {step: 1000},
40774077
end: null,
40784078
});
40794079
});
@@ -4358,15 +4358,15 @@ describe('metrics reducers', () => {
43584358
});
43594359
});
43604360

4361-
it('sets linkedTimeSelection to min step when linkedTimeSelection is null before toggling', () => {
4361+
it('sets linkedTimeSelection to max step when linkedTimeSelection is null before toggling', () => {
43624362
const state1 = buildMetricsState({
43634363
stepMinMax: {min: 10, max: 100},
43644364
});
43654365

43664366
const state2 = reducers(state1, actions.linkedTimeToggled({}));
43674367

43684368
expect(state2.linkedTimeSelection).toEqual({
4369-
start: {step: 10},
4369+
start: {step: 100},
43704370
end: null,
43714371
});
43724372
});

tensorboard/webapp/metrics/store/metrics_selectors.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ export const getMetricsLinkedTimeSelectionSetting = createSelector(
440440
if (!state.linkedTimeSelection) {
441441
return {
442442
start: {
443-
step: stepMinMax.min,
443+
step: stepMinMax.max,
444444
},
445445
end: null,
446446
};
@@ -599,15 +599,33 @@ export const getMetricsCardTimeSelection = createSelector(
599599
globalRangeSelectionEnabled
600600
);
601601

602-
const startStep = cardState.timeSelection?.start.step ?? minMaxStep.minStep;
603-
const endStep = cardState.timeSelection?.end?.step ?? minMaxStep.maxStep;
602+
let timeSelection = cardState.timeSelection;
603+
if (!timeSelection) {
604+
timeSelection = {
605+
start: {step: minMaxStep.minStep},
606+
end: {step: minMaxStep.maxStep},
607+
};
608+
}
609+
if (rangeSelectionEnabled) {
610+
if (!timeSelection.end) {
611+
// Enabling range selection from single selection selects the first
612+
// step as the start of the range. The previous start step from single
613+
// selection is now the end step.
614+
timeSelection = {
615+
start: {step: minMaxStep.minStep},
616+
end: timeSelection.start,
617+
};
618+
}
619+
} else {
620+
// Disabling range selection keeps the largest step from the range.
621+
timeSelection = {
622+
start: timeSelection.end ?? timeSelection.start,
623+
end: null,
624+
};
625+
}
604626

605-
// The default time selection
606627
return formatTimeSelection(
607-
{
608-
start: {step: startStep},
609-
end: {step: endStep},
610-
},
628+
timeSelection,
611629
minMaxStep,
612630
rangeSelectionEnabled
613631
);

tensorboard/webapp/metrics/store/metrics_selectors_test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ describe('metrics selectors', () => {
549549
).toBeUndefined();
550550
});
551551

552-
it('uses max step as end value if none exists', () => {
552+
it('uses min step as start value if end value does not exists', () => {
553553
const state = appStateFromMetricsState(
554554
buildMetricsState({
555555
...partialState,
@@ -562,7 +562,7 @@ describe('metrics selectors', () => {
562562
maxStep: 10,
563563
},
564564
timeSelection: {
565-
start: {step: 0},
565+
start: {step: 5},
566566
end: null,
567567
},
568568
},
@@ -572,7 +572,7 @@ describe('metrics selectors', () => {
572572

573573
expect(selectors.getMetricsCardTimeSelection(state, 'card1')).toEqual({
574574
start: {step: 0},
575-
end: {step: 10},
575+
end: {step: 5},
576576
});
577577
});
578578

@@ -619,7 +619,7 @@ describe('metrics selectors', () => {
619619
);
620620

621621
expect(selectors.getMetricsCardTimeSelection(state, 'card1')).toEqual({
622-
start: {step: 0},
622+
start: {step: 5},
623623
end: null,
624624
});
625625
});
@@ -642,7 +642,7 @@ describe('metrics selectors', () => {
642642
);
643643

644644
expect(selectors.getMetricsCardTimeSelection(state, 'card1')).toEqual({
645-
start: {step: 0},
645+
start: {step: 5},
646646
end: null,
647647
});
648648
});
@@ -1436,7 +1436,7 @@ describe('metrics selectors', () => {
14361436
})
14371437
);
14381438
expect(selectors.getMetricsLinkedTimeSelectionSetting(state)).toEqual({
1439-
start: {step: 0},
1439+
start: {step: 1000},
14401440
end: null,
14411441
});
14421442
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3971,7 +3971,7 @@ describe('scalar card', () => {
39713971
);
39723972
const fakeEvent = new MouseEvent('mousemove', {
39733973
clientX: 25 + controllerStartPosition,
3974-
movementX: 1,
3974+
movementX: -1,
39753975
});
39763976
testController.mouseMove(fakeEvent);
39773977

0 commit comments

Comments
 (0)