Skip to content

Commit 435d8d4

Browse files
committed
add three new tooltip sort orders
1 parent 66c07f8 commit 435d8d4

File tree

9 files changed

+63
-37
lines changed

9 files changed

+63
-37
lines changed

tensorboard/webapp/metrics/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ tf_ts_library(
4646
],
4747
visibility = ["//tensorboard/webapp/metrics:__subpackages__"],
4848
deps = [
49+
"//tensorboard/webapp/persistent_settings/_data_source:types",
4950
"//tensorboard/webapp/widgets/card_fob:types",
5051
"//tensorboard/webapp/widgets/histogram:types",
5152
],

tensorboard/webapp/metrics/internal_types.ts

+1-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
import {TimeSelection} from '../widgets/card_fob/card_fob_types';
1616
import {HistogramMode} from '../widgets/histogram/histogram_types';
1717

18+
export {TooltipSort} from '../persistent_settings/_data_source/types';
1819
export {HistogramMode, TimeSelection};
1920

2021
export enum PluginType {
@@ -23,18 +24,6 @@ export enum PluginType {
2324
IMAGES = 'images',
2425
}
2526

26-
// When adding a new value to the enum, please implement the deserializer on
27-
// data_source/metrics_data_source.ts.
28-
// When editing a value of the enum, please write a backward compatible
29-
// deserializer in data_source/metrics_data_source.ts.
30-
export enum TooltipSort {
31-
DEFAULT = 'default',
32-
ALPHABETICAL = 'alphabetical',
33-
ASCENDING = 'ascending',
34-
DESCENDING = 'descending',
35-
NEAREST = 'nearest',
36-
}
37-
3827
export enum XAxisType {
3928
STEP,
4029
RELATIVE,

tensorboard/webapp/metrics/store/metrics_reducers.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
CardUniqueInfo,
4343
SCALARS_SMOOTHING_MAX,
4444
SCALARS_SMOOTHING_MIN,
45-
TooltipSort,
4645
URLDeserializedState,
4746
} from '../internal_types';
4847
import {groupCardIdWithMetdata} from '../utils';
@@ -427,22 +426,7 @@ const reducer = createReducer(
427426
on(globalSettingsLoaded, (state, {partialSettings}) => {
428427
const metricsSettings: Partial<MetricsSettings> = {};
429428
if (partialSettings.tooltipSortString) {
430-
switch (partialSettings.tooltipSortString) {
431-
case TooltipSort.DEFAULT:
432-
case TooltipSort.ALPHABETICAL:
433-
metricsSettings.tooltipSort = TooltipSort.ALPHABETICAL;
434-
break;
435-
case TooltipSort.ASCENDING:
436-
metricsSettings.tooltipSort = TooltipSort.ASCENDING;
437-
break;
438-
case TooltipSort.DESCENDING:
439-
metricsSettings.tooltipSort = TooltipSort.DESCENDING;
440-
break;
441-
case TooltipSort.NEAREST:
442-
metricsSettings.tooltipSort = TooltipSort.NEAREST;
443-
break;
444-
default:
445-
}
429+
metricsSettings.tooltipSort = partialSettings.tooltipSortString;
446430
}
447431
if (typeof partialSettings.timeSeriesCardMinWidth === 'number') {
448432
metricsSettings.cardMinWidth = partialSettings.timeSeriesCardMinWidth;

tensorboard/webapp/metrics/views/card_renderer/scalar_card_component.ng.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@
119119
<ng-template
120120
#tooltip
121121
let-tooltipData="data"
122-
let-cursorLoc="cursorLocationInDataCoord"
122+
let-cursorLocationInDataCoord="cursorLocationInDataCoord"
123+
let-cursorLocation="cursorLocation"
123124
>
124125
<table class="tooltip">
125126
<thead>
@@ -136,7 +137,7 @@
136137
<tbody>
137138
<ng-container
138139
*ngFor="
139-
let datum of getCursorAwareTooltipData(tooltipData, cursorLoc);
140+
let datum of getCursorAwareTooltipData(tooltipData, cursorLocationInDataCoord, cursorLocation);
140141
trackBy: trackByTooltipDatum
141142
"
142143
>

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

+30-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ export class ScalarCardComponent<Downloader> {
163163

164164
getCursorAwareTooltipData(
165165
tooltipData: TooltipDatum<ScalarCardSeriesMetadata>[],
166-
cursorLoc: {x: number; y: number}
166+
cursorLocationInDataCoord: {x: number; y: number},
167+
cursorLocation: {x: number; y: number}
167168
): ScalarTooltipDatum[] {
168169
const scalarTooltipData = tooltipData.map((datum) => {
169170
return {
@@ -172,8 +173,20 @@ export class ScalarCardComponent<Downloader> {
172173
...datum.metadata,
173174
closest: false,
174175
distSqToCursor: Math.hypot(
175-
datum.point.x - cursorLoc.x,
176-
datum.point.y - cursorLoc.y
176+
datum.point.x - cursorLocationInDataCoord.x,
177+
datum.point.y - cursorLocationInDataCoord.y
178+
),
179+
distSqToCursorPixels: Math.hypot(
180+
datum.point.x - cursorLocation.x,
181+
datum.point.y - cursorLocation.y
182+
),
183+
distSqToCursorX: Math.hypot(
184+
datum.point.x - cursorLocationInDataCoord.x,
185+
0
186+
),
187+
distSqToCursorY: Math.hypot(
188+
0,
189+
datum.point.y - cursorLocationInDataCoord.y
177190
),
178191
},
179192
};
@@ -201,6 +214,20 @@ export class ScalarCardComponent<Downloader> {
201214
return scalarTooltipData.sort((a, b) => {
202215
return a.metadata.distSqToCursor - b.metadata.distSqToCursor;
203216
});
217+
case TooltipSort.NEAREST_PIXEL:
218+
return scalarTooltipData.sort((a, b) => {
219+
return (
220+
a.metadata.distSqToCursorPixels - b.metadata.distSqToCursorPixels
221+
);
222+
});
223+
case TooltipSort.NEAREST_X:
224+
return scalarTooltipData.sort((a, b) => {
225+
return a.metadata.distSqToCursorX - b.metadata.distSqToCursorX;
226+
});
227+
case TooltipSort.NEAREST_Y:
228+
return scalarTooltipData.sort((a, b) => {
229+
return a.metadata.distSqToCursorY - b.metadata.distSqToCursorY;
230+
});
204231
case TooltipSort.DEFAULT:
205232
case TooltipSort.ALPHABETICAL:
206233
return scalarTooltipData.sort((a, b) => {

tensorboard/webapp/metrics/views/right_pane/settings_view_component.ts

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ export class SettingsViewComponent {
8787
{value: TooltipSort.ASCENDING, displayText: 'Ascending'},
8888
{value: TooltipSort.DESCENDING, displayText: 'Descending'},
8989
{value: TooltipSort.NEAREST, displayText: 'Nearest'},
90+
{value: TooltipSort.NEAREST_PIXEL, displayText: 'Nearest Pixel'},
91+
{value: TooltipSort.NEAREST_X, displayText: 'Nearest X'},
92+
{value: TooltipSort.NEAREST_Y, displayText: 'Nearest Y'},
9093
];
9194
@Input() tooltipSort!: TooltipSort;
9295
@Output() tooltipSortChanged = new EventEmitter<TooltipSort>();

tensorboard/webapp/persistent_settings/_data_source/types.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ export enum ThemeValue {
1919
DARK = 'dark',
2020
}
2121

22+
// When adding a new value to the enum, please implement the deserializer on
23+
// data_source/metrics_data_source.ts.
24+
// When editing a value of the enum, please write a backward compatible
25+
// deserializer in tensorboard/webapp/metrics/store/metrics_reducers.ts
26+
export enum TooltipSort {
27+
DEFAULT = 'default',
28+
ALPHABETICAL = 'alphabetical',
29+
ASCENDING = 'ascending',
30+
DESCENDING = 'descending',
31+
NEAREST = 'nearest',
32+
NEAREST_PIXEL = 'nearest_pixel',
33+
NEAREST_X = 'nearest_x',
34+
NEAREST_Y = 'nearest_Y',
35+
}
36+
2237
/**
2338
* Global settings that the backend remembers. `declare`d so properties do not
2439
* get mangled or mangled differently when a version compiler changes.
@@ -28,7 +43,7 @@ export enum ThemeValue {
2843
*/
2944
export declare interface BackendSettings {
3045
scalarSmoothing?: number;
31-
tooltipSort?: string;
46+
tooltipSort?: TooltipSort;
3247
ignoreOutliers?: boolean;
3348
autoReload?: boolean;
3449
autoReloadPeriodInMs?: number;
@@ -50,7 +65,7 @@ export declare interface BackendSettings {
5065
*/
5166
export interface PersistableSettings {
5267
scalarSmoothing?: number;
53-
tooltipSortString?: string;
68+
tooltipSortString?: TooltipSort;
5469
ignoreOutliers?: boolean;
5570
autoReload?: boolean;
5671
autoReloadPeriodInMs?: number;

tensorboard/webapp/widgets/line_chart_v2/sub_view/line_chart_interactive_view.ng.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
[ngTemplateOutlet]="tooltipTemplate ? tooltipTemplate : defaultTooltip"
6868
[ngTemplateOutletContext]="{
6969
data: cursoredData,
70-
cursorLocationInDataCoord: cursorLocationInDataCoord
70+
cursorLocationInDataCoord: cursorLocationInDataCoord,
71+
cursorLocation: cursorLocation
7172
}"
7273
></ng-container>
7374
</div>

tensorboard/webapp/widgets/line_chart_v2/sub_view/line_chart_interactive_view.ts

+5
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export class LineChartInteractiveViewComponent
202202
];
203203

204204
cursorLocationInDataCoord: {x: number; y: number} | null = null;
205+
cursorLocation: {x: number; y: number} | null = null;
205206
cursoredData: TooltipDatum[] = [];
206207
tooltipDisplayAttached: boolean = false;
207208

@@ -522,6 +523,10 @@ export class LineChartInteractiveViewComponent
522523
x: this.getDataX(event.offsetX),
523524
y: this.getDataY(event.offsetY),
524525
};
526+
this.cursorLocation = {
527+
x: event.offsetX,
528+
y: event.offsetY,
529+
};
525530
this.updateCursoredDataAndTooltipVisibility();
526531
}
527532

0 commit comments

Comments
 (0)