Skip to content

Commit 2c82781

Browse files
committed
sort by alphabetical order
1 parent 633b84b commit 2c82781

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

tensorboard/webapp/metrics/internal_types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export enum TooltipSort {
3131
ASCENDING = 'ascending',
3232
DESCENDING = 'descending',
3333
NEAREST = 'nearest',
34+
ALPHABETICAL = 'Alphabetical',
3435
}
3536

3637
export enum XAxisType {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ export class ScalarCardComponent<Downloader> {
167167
return scalarTooltipData.sort((a, b) => {
168168
return a.metadata.distSqToCursor - b.metadata.distSqToCursor;
169169
});
170+
case TooltipSort.ALPHABETICAL:
171+
return scalarTooltipData.sort((a, b) => {
172+
if (a.metadata.displayName < b.metadata.displayName) {
173+
return -1;
174+
}
175+
if (a.metadata.displayName > b.metadata.displayName) {
176+
return 1;
177+
}
178+
return 0;
179+
});
170180
}
171181
}
172182

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,77 @@ describe('scalar card', () => {
16141614
['', 'Row 3', '3', '10,000', anyString, anyString],
16151615
]);
16161616
}));
1617+
1618+
it('sorts by displayname alphabetical order', fakeAsync(() => {
1619+
store.overrideSelector(
1620+
selectors.getMetricsTooltipSort,
1621+
TooltipSort.ALPHABETICAL
1622+
);
1623+
store.overrideSelector(selectors.getMetricsScalarSmoothing, 0);
1624+
const fixture = createComponent('card1');
1625+
setTooltipData(fixture, [
1626+
buildTooltipDatum(
1627+
{
1628+
id: 'row1',
1629+
type: SeriesType.ORIGINAL,
1630+
displayName: 'hello',
1631+
alias: null,
1632+
visible: true,
1633+
color: '#f00',
1634+
aux: false,
1635+
},
1636+
{
1637+
x: 0,
1638+
step: 0,
1639+
y: 1000,
1640+
value: 1000,
1641+
wallTime: new Date('2020-01-01').getTime(),
1642+
}
1643+
),
1644+
buildTooltipDatum(
1645+
{
1646+
id: 'row2',
1647+
type: SeriesType.ORIGINAL,
1648+
displayName: 'world',
1649+
alias: null,
1650+
visible: true,
1651+
color: '#0f0',
1652+
aux: false,
1653+
},
1654+
{
1655+
x: 1000,
1656+
step: 1000,
1657+
y: -500,
1658+
value: -500,
1659+
wallTime: new Date('2020-12-31').getTime(),
1660+
}
1661+
),
1662+
buildTooltipDatum(
1663+
{
1664+
id: 'row3',
1665+
type: SeriesType.ORIGINAL,
1666+
displayName: 'cat',
1667+
alias: null,
1668+
visible: true,
1669+
color: '#00f',
1670+
aux: false,
1671+
},
1672+
{
1673+
x: 10000,
1674+
step: 10000,
1675+
y: 3,
1676+
value: 3,
1677+
wallTime: new Date('2021-01-01').getTime(),
1678+
}
1679+
),
1680+
]);
1681+
fixture.detectChanges();
1682+
assertTooltipRows(fixture, [
1683+
['', 'cat', '3', '10,000', anyString, anyString],
1684+
['', 'hello', '1000', '0', anyString, anyString],
1685+
['', 'world', '-500', '1,000', anyString, anyString],
1686+
]);
1687+
}));
16171688
});
16181689

16191690
describe('non-monotonic increase in x-axis', () => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class SettingsViewComponent {
8484
{value: TooltipSort.ASCENDING, displayText: 'Ascending'},
8585
{value: TooltipSort.DESCENDING, displayText: 'Descending'},
8686
{value: TooltipSort.NEAREST, displayText: 'Nearest'},
87+
{value: TooltipSort.ALPHABETICAL, displayText: 'Alphabetical'},
8788
];
8889
@Input() tooltipSort!: TooltipSort;
8990
@Output() tooltipSortChanged = new EventEmitter<TooltipSort>();

0 commit comments

Comments
 (0)