Skip to content
3 changes: 2 additions & 1 deletion tensorboard/webapp/metrics/internal_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ export enum PluginType {

export enum XAxisType {
STEP = 'step',
RELATIVE = 'relative',
RELATIVE_STEP = 'relative_step',
WALL_TIME = 'walltime',
RELATIVE_TIME = 'relative_time',
}

export interface CardMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ export class HistogramCardComponent {
switch (xAxisType) {
case XAxisType.STEP:
return TimeProperty.STEP;
case XAxisType.RELATIVE_STEP:
return TimeProperty.RELATIVE_STEP;
case XAxisType.WALL_TIME:
return TimeProperty.WALL_TIME;
case XAxisType.RELATIVE:
return TimeProperty.RELATIVE;
case XAxisType.RELATIVE_TIME:
return TimeProperty.RELATIVE_TIME;
default:
throw new Error('Invalid xAxisType for histogram time property.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,30 @@ describe('histogram card', () => {
expect(histogramEl.componentInstance.timeProperty).toBe(
TimeProperty.WALL_TIME
);

store.overrideSelector(
selectors.getMetricsXAxisType,
XAxisType.RELATIVE_STEP
);
store.refreshState();

fixture.detectChanges();

expect(histogramEl.componentInstance.timeProperty).toBe(
TimeProperty.RELATIVE_STEP
);

store.overrideSelector(
selectors.getMetricsXAxisType,
XAxisType.RELATIVE_TIME
);
store.refreshState();

fixture.detectChanges();

expect(histogramEl.componentInstance.timeProperty).toBe(
TimeProperty.RELATIVE_TIME
);
});

describe('full size', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
<th>Run</th>
<th *ngIf="smoothingEnabled">Smoothed</th>
<th>Value</th>
<th>Step</th>
<th>{{ getStepTooltipHeader() }}</th>
<th>Time</th>
<th>Relative</th>
</tr>
Expand Down Expand Up @@ -168,7 +168,7 @@
</td>
<td>{{ valueFormatter.formatShort(datum.dataPoint.value) }}</td>
<!-- Print the step with comma for readability. -->
<td>{{ stepFormatter.formatShort(datum.dataPoint.step) }}</td>
<td>{{ getStepTooltipValue(datum.dataPoint) }}</td>
<td>{{ datum.dataPoint.wallTime | date: 'short' }}</td>
<td>
{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class ScalarCardComponent<Downloader> {
readonly DataLoadState = DataLoadState;
readonly RendererType = RendererType;
readonly ScaleType = ScaleType;
readonly XAxisType = XAxisType;

@Input() cardId!: string;
@Input() chartMetadataMap!: ScalarCardSeriesMetadataMap;
Expand Down Expand Up @@ -184,8 +185,9 @@ export class ScalarCardComponent<Downloader> {

getCustomXFormatter(): Formatter | undefined {
switch (this.xAxisType) {
case XAxisType.RELATIVE:
case XAxisType.RELATIVE_TIME:
return relativeTimeFormatter;
case XAxisType.RELATIVE_STEP:
case XAxisType.STEP:
return siNumberFormatter;
case XAxisType.WALL_TIME:
Expand All @@ -194,6 +196,20 @@ export class ScalarCardComponent<Downloader> {
}
}

getStepTooltipHeader(): string {
return this.xAxisType === XAxisType.RELATIVE_STEP
? 'Relative Step'
: 'Step';
}

getStepTooltipValue(point: ScalarCardPoint): string {
const step =
this.xAxisType === XAxisType.RELATIVE_STEP
? point.relativeStep ?? point.step
: point.step;
return this.stepFormatter.formatShort(step);
}

getCursorAwareTooltipData(
tooltipData: TooltipDatum<ScalarCardSeriesMetadata, ScalarCardPoint>[],
cursorLocationInDataCoord: {x: number; y: number},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
map((xAxisType) => {
switch (xAxisType) {
case XAxisType.STEP:
case XAxisType.RELATIVE:
case XAxisType.RELATIVE_STEP:
case XAxisType.RELATIVE_TIME:
return ScaleType.LINEAR;
case XAxisType.WALL_TIME:
return ScaleType.TIME;
Expand Down Expand Up @@ -418,12 +419,14 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
map((partitionedSeriesList) => {
return partitionedSeriesList.map((partitionedSeries) => {
const firstWallTime = partitionedSeries.points[0]?.wallTime;
const firstStep = partitionedSeries.points[0]?.step;
return {
...partitionedSeries,
points: partitionedSeries.points.map((point) => {
return {
...point,
relativeTimeInMs: point.wallTime - firstWallTime,
relativeStep: point.step - firstStep,
};
}),
};
Expand All @@ -437,7 +440,10 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
points: series.points.map((point) => {
let x: number;
switch (xAxisType) {
case XAxisType.RELATIVE:
case XAxisType.RELATIVE_STEP:
x = point.relativeStep;
break;
case XAxisType.RELATIVE_TIME:
x = point.relativeTimeInMs;
break;
case XAxisType.WALL_TIME:
Expand Down Expand Up @@ -721,7 +727,8 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
stepSeries: ScalarStepDatum[],
xAxisType: XAxisType
): ScalarCardPoint[] {
const isStepBased = xAxisType === XAxisType.STEP;
const isStepBased =
xAxisType === XAxisType.STEP || xAxisType === XAxisType.RELATIVE_STEP;
return stepSeries.map((stepDatum) => {
// Normalize data and convert wallTime in seconds to milliseconds.
// TODO(stephanwlee): when the legacy line chart is removed, do the conversion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ export class ScalarCardLineChartComponent {

getCustomXFormatter(): Formatter | undefined {
switch (this.xAxisType) {
case XAxisType.RELATIVE:
case XAxisType.RELATIVE_TIME:
return relativeTimeFormatter;
case XAxisType.RELATIVE_STEP:
case XAxisType.STEP:
return siNumberFormatter;
case XAxisType.WALL_TIME:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export class ScalarCardLineChartContainer
map((xAxisType) => {
switch (xAxisType) {
case XAxisType.STEP:
case XAxisType.RELATIVE:
case XAxisType.RELATIVE_STEP:
case XAxisType.RELATIVE_TIME:
return ScaleType.LINEAR;
case XAxisType.WALL_TIME:
return ScaleType.TIME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import {
} from './scalar_card_types';

@Component({
changeDetection: ChangeDetectionStrategy.Default,
changeDetection: ChangeDetectionStrategy.Eager,
standalone: false,
selector: 'line-chart',
template: `
Expand Down Expand Up @@ -168,7 +168,7 @@ class TestableLineChart {
}

@Component({
changeDetection: ChangeDetectionStrategy.Default,
changeDetection: ChangeDetectionStrategy.Eager,
standalone: false,
selector: 'test-scalar-card-line-chart',
template: `
Expand Down Expand Up @@ -538,10 +538,23 @@ describe('scalar card line chart', () => {
).toBe(siNumberFormatter);
}));

it('uses relative time formatter when xAxisType is RELATIVE', fakeAsync(() => {
it('uses SI unit formatter when xAxisType is RELATIVE_STEP', fakeAsync(() => {
store.overrideSelector(
selectors.getMetricsXAxisType,
XAxisType.RELATIVE
XAxisType.RELATIVE_STEP
);
const fixture = createComponent();

expect(
fixture.debugElement.query(Selector.LINE_CHART).componentInstance
.customXFormatter
).toBe(siNumberFormatter);
}));

it('uses relative time formatter when xAxisType is RELATIVE_TIME', fakeAsync(() => {
store.overrideSelector(
selectors.getMetricsXAxisType,
XAxisType.RELATIVE_TIME
);
const fixture = createComponent();

Expand Down Expand Up @@ -958,8 +971,11 @@ describe('scalar card line chart', () => {
]);
}));

it('shows relative time when XAxisType is RELATIVE', fakeAsync(() => {
store.overrideSelector(selectors.getMetricsXAxisType, XAxisType.RELATIVE);
it('shows relative time when XAxisType is RELATIVE_TIME', fakeAsync(() => {
store.overrideSelector(
selectors.getMetricsXAxisType,
XAxisType.RELATIVE_TIME
);
const fixture = createComponent();
setTooltipData(fixture, [
buildTooltipDatum(
Expand Down Expand Up @@ -1398,10 +1414,31 @@ describe('scalar card line chart', () => {
).toEqual(1);
}));

it('does not render fobs when axis type is RELATIVE', fakeAsync(() => {
it('does not render fobs when axis type is RELATIVE_STEP', fakeAsync(() => {
store.overrideSelector(
selectors.getMetricsXAxisType,
XAxisType.RELATIVE_STEP
);
const fixture = createComponent();
fixture.componentInstance.minMaxStep = {
minStep: 0,
maxStep: 100,
};
fixture.componentInstance.stepOrLinkedTimeSelection = {
start: {step: 20},
end: null,
};
fixture.detectChanges();

expect(
fixture.debugElement.queryAll(By.directive(CardFobComponent)).length
).toEqual(0);
}));

it('does not render fobs when axis type is RELATIVE_TIME', fakeAsync(() => {
store.overrideSelector(
selectors.getMetricsXAxisType,
XAxisType.RELATIVE
XAxisType.RELATIVE_TIME
);
const fixture = createComponent();
fixture.detectChanges();
Expand Down
Loading
Loading