From 6205fb5d8cc87cb9f560fd2a1980e72dc7c35665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Qu=C3=A8ze?= Date: Thu, 14 Sep 2023 17:42:03 +0200 Subject: [PATCH] Show the hovered time in the ruler at the top of the timeline. --- src/components/timeline/Selection.css | 10 ++ src/components/timeline/Selection.js | 16 ++- src/profile-logic/committed-ranges.js | 10 +- .../ActiveTabTimeline.test.js.snap | 6 +- .../__snapshots__/Timeline.test.js.snap | 8 +- src/test/unit/marker-schema.test.js | 14 ++- src/utils/format-numbers.js | 107 +++++++++++++----- 7 files changed, 134 insertions(+), 37 deletions(-) diff --git a/src/components/timeline/Selection.css b/src/components/timeline/Selection.css index 8552eb9139..e3bfa7ceb4 100644 --- a/src/components/timeline/Selection.css +++ b/src/components/timeline/Selection.css @@ -29,6 +29,16 @@ pointer-events: none; } +.timelineSelectionOverlayTime { + position: absolute; + z-index: 1; + padding: 3.25px 8px; + border-radius: 0 4px 4px 0; + margin-left: 1px; + background-color: rgb(153 153 153); + color: #fff; +} + .timelineSelectionOverlay { position: absolute; z-index: 2; diff --git a/src/components/timeline/Selection.js b/src/components/timeline/Selection.js index 8229d5695a..c81ea1ba14 100644 --- a/src/components/timeline/Selection.js +++ b/src/components/timeline/Selection.js @@ -243,6 +243,10 @@ class TimelineRulerAndSelection extends React.PureComponent { return; } const { width, committedRange, changeMouseTimePosition } = this.props; + if (width === 0) { + // This can happen when hovering before the profile is fully loaded. + return; + } const rect = getContentRect(this._container); if ( @@ -399,6 +403,7 @@ class TimelineRulerAndSelection extends React.PureComponent { mouseTimePosition, width, committedRange, + zeroAt, } = this.props; let hoverLocation = null; @@ -431,7 +436,16 @@ class TimelineRulerAndSelection extends React.PureComponent { : undefined, left: hoverLocation === null ? '0' : `${hoverLocation}px`, }} - /> + > + + {mouseTimePosition !== null + ? getFormattedTimeLength( + mouseTimePosition - zeroAt, + (committedRange.end - committedRange.start) / width + ) + : null} + + ); } diff --git a/src/profile-logic/committed-ranges.js b/src/profile-logic/committed-ranges.js index 7995c8df13..64b8e50cc8 100644 --- a/src/profile-logic/committed-ranges.js +++ b/src/profile-logic/committed-ranges.js @@ -4,7 +4,7 @@ // @flow import { formatTimestamp } from 'firefox-profiler/utils/format-numbers'; -import type { StartEndRange } from 'firefox-profiler/types'; +import type { Milliseconds, StartEndRange } from 'firefox-profiler/types'; /** * Users can make preview range selections on the profile, and then can commit these @@ -164,11 +164,15 @@ export function stringifyCommittedRanges( return arrayValue.map(stringifyStartEnd).join('~'); } -export function getFormattedTimeLength(length: number): string { +export function getFormattedTimeLength( + length: Milliseconds, + precision: Milliseconds = Infinity +): string { return formatTimestamp( length, /*significantdigits*/ 2, - /*maxFractionalDigits*/ 2 + /*maxFractionalDigits*/ 2, + precision ); } diff --git a/src/test/components/__snapshots__/ActiveTabTimeline.test.js.snap b/src/test/components/__snapshots__/ActiveTabTimeline.test.js.snap index b2ababdffe..097fc11f8c 100644 --- a/src/test/components/__snapshots__/ActiveTabTimeline.test.js.snap +++ b/src/test/components/__snapshots__/ActiveTabTimeline.test.js.snap @@ -502,6 +502,10 @@ exports[`ActiveTabTimeline should be rendered properly from the Timeline compone `; diff --git a/src/test/components/__snapshots__/Timeline.test.js.snap b/src/test/components/__snapshots__/Timeline.test.js.snap index 77465d5312..ea86c5e0a9 100644 --- a/src/test/components/__snapshots__/Timeline.test.js.snap +++ b/src/test/components/__snapshots__/Timeline.test.js.snap @@ -253,7 +253,13 @@ Process: \\"default\\" (0)"
+ > + + 3ms + +