Skip to content

Commit 565718c

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Replace adhoc number formatting with i18n module
Additionally: * Modify the progress status dialog for recording a trace to update every 0.1s instead of 1000s, and display the time in "x.x s" format * For the same progress status dialog, use `tabular-nums` font variant to prevent seconds text from jumping around Fixed: 372723536 Change-Id: I4798d81b4335ef60265e352f02e0dec92a4c16c8 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6039734 Reviewed-by: Paul Irish <[email protected]> Commit-Queue: Connor Clark <[email protected]> Auto-Submit: Connor Clark <[email protected]>
1 parent 88e3d03 commit 565718c

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

front_end/core/i18n/time-utilities.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,23 @@ export function preciseMillisToString(ms: number, precision = 0): string {
160160
return formatter.format(ms);
161161
}
162162

163+
const preciseSecondsToStringFormattersCache = new Map<number, NumberFormatter>();
164+
165+
export function preciseSecondsToString(ms: number, precision = 0): string {
166+
let formatter = preciseSecondsToStringFormattersCache.get(precision);
167+
if (!formatter) {
168+
formatter = defineFormatter({
169+
style: 'unit',
170+
unit: 'second',
171+
unitDisplay: 'narrow',
172+
minimumFractionDigits: precision,
173+
maximumFractionDigits: precision,
174+
});
175+
preciseSecondsToStringFormattersCache.set(precision, formatter);
176+
}
177+
return formatter.format(ms);
178+
}
179+
163180
export function secondsToString(seconds: number, higherResolution?: boolean): string {
164181
if (!isFinite(seconds)) {
165182
return '-';

front_end/panels/timeline/EventsTimelineTreeView.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ const UIStrings = {
2525
*@description Screen reader label for a select box that filters the Performance panel Event Log by duration.
2626
*/
2727
durationFilter: 'Duration filter',
28-
/**
29-
*@description Text in Events Timeline Tree View of the Performance panel
30-
*@example {2} PH1
31-
*/
32-
Dms: '{PH1} ms',
3328
/**
3429
*@description Text for everything
3530
*/
@@ -170,7 +165,7 @@ export class Filters extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
170165
durationFilterChanged.bind(this), i18nString(UIStrings.durationFilter), undefined, 'duration');
171166
for (const durationMs of Filters.durationFilterPresetsMs) {
172167
durationFilterUI.addOption(durationFilterUI.createOption(
173-
durationMs ? `≥ ${i18nString(UIStrings.Dms, {PH1: durationMs})}` : i18nString(UIStrings.all),
168+
durationMs ? `≥ ${i18n.TimeUtilities.millisToString(durationMs)}` : i18nString(UIStrings.all),
174169
String(durationMs)));
175170
}
176171
toolbar.appendToolbarItem(durationFilterUI);

front_end/panels/timeline/TimelinePanel.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,6 @@ const UIStrings = {
257257
*@description Text of an item that stops the running task
258258
*/
259259
stop: 'Stop',
260-
/**
261-
*@description Time text content in Timeline Panel of the Performance panel
262-
*@example {2.12} PH1
263-
*/
264-
ssec: '{PH1} sec',
265260
/**
266261
*
267262
* @description Text for exporting basic traces
@@ -2635,7 +2630,7 @@ export class StatusPane extends UI.Widget.VBox {
26352630

26362631
startTimer(): void {
26372632
this.startTime = Date.now();
2638-
this.timeUpdateTimer = window.setInterval(this.updateTimer.bind(this), 1000);
2633+
this.timeUpdateTimer = window.setInterval(this.updateTimer.bind(this), 100);
26392634
this.updateTimer();
26402635
}
26412636

@@ -2653,8 +2648,9 @@ export class StatusPane extends UI.Widget.VBox {
26532648
if (!this.timeUpdateTimer || !this.time) {
26542649
return;
26552650
}
2656-
const elapsed = (Date.now() - this.startTime) / 1000;
2657-
this.time.textContent = i18nString(UIStrings.ssec, {PH1: Math.round(elapsed)});
2651+
2652+
const seconds = (Date.now() - this.startTime) / 1000;
2653+
this.time.textContent = i18n.TimeUtilities.preciseSecondsToString(seconds, 1);
26582654
}
26592655

26602656
private arrangeDialog(parent: Element): void {

front_end/panels/timeline/TimelineTreeView.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ const UIStrings = {
4343
*@description Text of a DOM element in Timeline Tree View of the Performance panel
4444
*/
4545
selectItemForDetails: 'Select item for details.',
46-
/**
47-
*@description Time in miliseconds
48-
*@example {30.1} PH1
49-
*/
50-
fms: '{PH1} ms',
5146
/**
5247
*@description Number followed by percent sign
5348
*@example {20} PH1
@@ -743,9 +738,9 @@ export class GridNode extends DataGrid.SortableDataGrid.SortableDataGridNode<Gri
743738
}
744739
const cell = this.createTD(columnId);
745740
cell.className = 'numeric-column';
746-
cell.setAttribute('title', i18nString(UIStrings.fms, {PH1: value.toFixed(4)}));
741+
cell.setAttribute('title', i18n.TimeUtilities.preciseMillisToString(value, 4));
747742
const textDiv = cell.createChild('div');
748-
textDiv.createChild('span').textContent = i18nString(UIStrings.fms, {PH1: value.toFixed(1)});
743+
textDiv.createChild('span').textContent = i18n.TimeUtilities.preciseMillisToString(value, 1);
749744

750745
if (showPercents && this.treeView.exposePercentages()) {
751746
textDiv.createChild('span', 'percent-column').textContent =

front_end/panels/timeline/timelineStatusDialog.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
min-height: auto;
2121
display: flex;
2222
align-items: baseline;
23+
font-variant-numeric: tabular-nums;
2324
}
2425

2526
.status-dialog-line .label {

0 commit comments

Comments
 (0)