Skip to content

Commit a53e9ef

Browse files
authored
linked time: set prospective fob position from prospective step (#5999)
This is pre-work of placing prospective fob at the mouse position. First we want to get the position which reflects the prospective step.
1 parent a48d619 commit a53e9ef

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {MinMaxStep} from './scalar_card_types';
3434
[timeSelection]="timeSelection"
3535
[startStepAxisPosition]="getAxisPositionFromStartStep()"
3636
[endStepAxisPosition]="getAxisPositionFromEndStep()"
37+
[prospectiveStepAxisPosition]="getAxisPositionFromProspectiveStep()"
3738
[highestStep]="getHighestStep()"
3839
[lowestStep]="getLowestStep()"
3940
[prospectiveStep]="prospectiveStep"
@@ -88,6 +89,16 @@ export class ScalarCardFobController {
8889
);
8990
}
9091

92+
getAxisPositionFromProspectiveStep() {
93+
if (this.prospectiveStep === null) return null;
94+
95+
return this.scale.forward(
96+
this.minMaxHorizontalViewExtend,
97+
[0, this.axisSize],
98+
this.prospectiveStep
99+
);
100+
}
101+
91102
getHighestStep(): number {
92103
return this.minMaxStep.maxStep;
93104
}

tensorboard/webapp/widgets/card_fob/card_fob_controller_component.ng.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
<div>
1919
<div
2020
#prospectiveFobWrapper
21-
class="time-fob-wrapper"
21+
class="time-fob-wrapper prospectiveFob"
2222
*ngIf="prospectiveStep !== null && isProspectiveFobFeatureEnabled"
23+
[style.transform]="getCssTranslatePxForProspectiveFob()"
2324
>
2425
<div *ngIf="showExtendedLine" class="extended-line"></div>
2526
<card-fob

tensorboard/webapp/widgets/card_fob/card_fob_controller_component.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ limitations under the License.
4949
padding: 0 20px;
5050
}
5151
}
52+
53+
.prospectiveFob {
54+
opacity: 0.8;
55+
cursor: pointer;
56+
}

tensorboard/webapp/widgets/card_fob/card_fob_controller_component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class CardFobControllerComponent {
6262
@Input() showExtendedLine?: Boolean = false;
6363
@Input() isProspectiveFobFeatureEnabled?: Boolean = false;
6464
@Input() prospectiveStep?: number | null = null;
65+
@Input() prospectiveStepAxisPosition?: number | null = null;
6566

6667
@Output() onTimeSelectionChanged =
6768
new EventEmitter<TimeSelectionWithAffordance>();
@@ -99,6 +100,17 @@ export class CardFobControllerComponent {
99100
return `translate(${this.endStepAxisPosition}px, 0px)`;
100101
}
101102

103+
getCssTranslatePxForProspectiveFob() {
104+
if (this.prospectiveStep === null) {
105+
return '';
106+
}
107+
108+
if (this.axisDirection === AxisDirection.VERTICAL) {
109+
return `translate(0px, ${this.prospectiveStepAxisPosition}px)`;
110+
}
111+
return `translate(${this.prospectiveStepAxisPosition}px, 0px)`;
112+
}
113+
102114
stopEventPropagation(e: Event) {
103115
e.stopPropagation();
104116
e.preventDefault();

tensorboard/webapp/widgets/card_fob/card_fob_controller_test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
[timeSelection]="timeSelection"
3636
[startStepAxisPosition]="getAxisPositionFromStartStep()"
3737
[endStepAxisPosition]="getAxisPositionFromEndStep()"
38+
[prospectiveStepAxisPosition]="getAxisPositionFromProspectiveStep()"
3839
[highestStep]="highestStep"
3940
[lowestStep]="lowestStep"
4041
[cardFobHelper]="cardFobHelper"
@@ -58,6 +59,7 @@ class TestableComponent {
5859
@Input() lowestStep!: number;
5960
@Input() getAxisPositionFromStartStep!: () => number;
6061
@Input() getAxisPositionFromEndStep!: () => number;
62+
@Input() getAxisPositionFromProspectiveStep!: () => number;
6163
@Input() isProspectiveFobFeatureEnabled!: Boolean;
6264
@Input() prospectiveStep!: number | null;
6365

@@ -72,6 +74,7 @@ describe('card_fob_controller', () => {
7274
let getStepLowerSpy: jasmine.Spy;
7375
let getAxisPositionFromStartStepSpy: jasmine.Spy;
7476
let getAxisPositionFromEndStepSpy: jasmine.Spy;
77+
let getAxisPositionFromProspectiveStepSpy: jasmine.Spy;
7578
let cardFobHelper: CardFobGetStepFromPositionHelper;
7679
beforeEach(async () => {
7780
await TestBed.configureTestingModule({
@@ -104,6 +107,7 @@ describe('card_fob_controller', () => {
104107
getStepLowerSpy = jasmine.createSpy();
105108
getAxisPositionFromStartStepSpy = jasmine.createSpy();
106109
getAxisPositionFromEndStepSpy = jasmine.createSpy();
110+
getAxisPositionFromProspectiveStepSpy = jasmine.createSpy();
107111
getStepHigherSpy.and.callFake((step: number) => {
108112
return step;
109113
});
@@ -118,6 +122,11 @@ describe('card_fob_controller', () => {
118122
? fixture.componentInstance.timeSelection.end.step
119123
: null;
120124
});
125+
getAxisPositionFromProspectiveStepSpy.and.callFake(() => {
126+
return fixture.componentInstance.prospectiveStep
127+
? fixture.componentInstance.prospectiveStep
128+
: null;
129+
});
121130
cardFobHelper = {
122131
getStepHigherThanAxisPosition: getStepHigherSpy,
123132
getStepLowerThanAxisPosition: getStepLowerSpy,
@@ -127,6 +136,8 @@ describe('card_fob_controller', () => {
127136
getAxisPositionFromStartStepSpy;
128137
fixture.componentInstance.getAxisPositionFromEndStep =
129138
getAxisPositionFromEndStepSpy;
139+
fixture.componentInstance.getAxisPositionFromProspectiveStep =
140+
getAxisPositionFromProspectiveStepSpy;
130141
fixture.componentInstance.highestStep = 4;
131142
fixture.componentInstance.lowestStep = 0;
132143
fixture.componentInstance.cardFobHelper = cardFobHelper;
@@ -1320,5 +1331,39 @@ describe('card_fob_controller', () => {
13201331
fixture.componentInstance.fobController.prospectiveFobWrapper
13211332
).toBeUndefined();
13221333
});
1334+
1335+
it('sets horizontal position based on prospective step', () => {
1336+
const fixture = createComponent({
1337+
timeSelection: {start: {step: 4}, end: null},
1338+
axisDirection: AxisDirection.HORIZONTAL,
1339+
isProspectiveFobFeatureEnabled: true,
1340+
prospectiveStep: 2,
1341+
});
1342+
fixture.detectChanges();
1343+
1344+
const fobController = fixture.componentInstance.fobController;
1345+
const prospectiveFobLeftPosition =
1346+
fobController.prospectiveFobWrapper.nativeElement.getBoundingClientRect()
1347+
.left;
1348+
1349+
expect(prospectiveFobLeftPosition).toEqual(2);
1350+
});
1351+
1352+
it('sets vertical position based on prospective step', () => {
1353+
const fixture = createComponent({
1354+
timeSelection: {start: {step: 4}, end: null},
1355+
axisDirection: AxisDirection.VERTICAL,
1356+
isProspectiveFobFeatureEnabled: true,
1357+
prospectiveStep: 2,
1358+
});
1359+
fixture.detectChanges();
1360+
1361+
const fobController = fixture.componentInstance.fobController;
1362+
const prospectiveFobTopPosition =
1363+
fobController.prospectiveFobWrapper.nativeElement.getBoundingClientRect()
1364+
.top;
1365+
1366+
expect(prospectiveFobTopPosition).toEqual(2);
1367+
});
13231368
});
13241369
});

0 commit comments

Comments
 (0)