Show the hovered time in the ruler at the top of the timeline.#4748
Conversation
fqueze
commented
Sep 14, 2023
8d86e90 to
3d99abd
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #4748 +/- ##
==========================================
- Coverage 88.33% 88.32% -0.02%
==========================================
Files 300 300
Lines 26768 26794 +26
Branches 7220 7237 +17
==========================================
+ Hits 23646 23666 +20
- Misses 2910 2916 +6
Partials 212 212
☔ View full report in Codecov by Sentry. |
julienw
left a comment
There was a problem hiding this comment.
This looks pretty good to me, however I think that getFormattedTimeLength doesn't do the right thing in this case. Please have a look at my suggestion instead :-)
| event.pageY < rect.top || | ||
| event.pageY >= rect.bottom | ||
| event.pageY >= rect.bottom || | ||
| width === 0 |
There was a problem hiding this comment.
Can you please explain why this change in a comment?
There was a problem hiding this comment.
Do you want a comment in the code or is a comment here good enough?
The reason was that when moving the mouse around over the profiler page while the profiler was still loading, this code was triggered, with width == 0, causing the mouseTimePosition to become Infinity, and my new code to explode attempting to number format NaN.
I think a cleaner fix would be finding a way to register the mousemove handler later when the profile has finished loading, but returning early when width === 0 seemed good enough to avoid the crash.
There was a problem hiding this comment.
Would it be better to do an early return for width==0? It would be good to have a proper comment in the code too indeed :-)
| > | ||
| <span className="timelineSelectionOverlayTime"> | ||
| {mouseTimePosition !== null | ||
| ? getFormattedTimeLength(mouseTimePosition - zeroAt) |
There was a problem hiding this comment.
I believe it should use a similar logic for the precision than the ruler, because otherwise it's not useful when zoomed in a lot (except at the start of the profile).
The logic is in timeline/Ruler.js, but here is what is I believe a good enough approximation:
const range = committedRange.end - committedRange.start;
const exponent = Math.floor(Math.log10(range));
const digits = Math.max(0, -(exponent - 4))
const timeString = (mouseTimePosition - zeroAt).toFixed(digits);I haven't tried it though, tell me how that looks.
There was a problem hiding this comment.
I actually care more about showing something useful for long profiles (ie. not hundreads or thousands of seconds, but something in minutes and seconds) than about the high precision when zoomed into extremely short intervals.
Of course having both would be best, but that might require a lot more, like an alternative version of formatNumber(or adding an extra parameter to it) to specify the required smallest unit to display.
The numbers displayed in the ruler are currently difficult to read for long profiles. That's something I would like to improve someday. Maybe I could fix the numbers displayed in the ruler and polish the number in this new overlay at the same time?
A short term alternative if you really care about short intervals could be to switch to the implementation you suggested when the commited range lasts less than a few seconds. Not sure if that would be better or more confusing.
There was a problem hiding this comment.
I believe you could do:
const range = committedRange.end - committedRange.start;
const exponent = Math.floor(Math.log10(range));
const digits = Math.max(0, -(exponent - 4))
const timeString =
digits > 0
? ((mouseTimePosition - zeroAt)/1000).toFixed(digits) + "s"
: getFormattedTimeLength(mouseTimePosition - zeroAt);
}There was a problem hiding this comment.
I thought about it some more, and I think the correct behavior is to ensure that whenever we move the mouse by 1px, the displayed time changes. So we need to adjust the precision of the displayed timestamp based on how much time is represented by 1px. I updated the PR to do that.
Here's a long (> 1 day) profile that I used for testing: https://share.firefox.dev/46mER8G
3d99abd to
128bd24
Compare
| event.pageY < rect.top || | ||
| event.pageY >= rect.bottom | ||
| event.pageY >= rect.bottom || | ||
| width === 0 |
There was a problem hiding this comment.
Would it be better to do an early return for width==0? It would be good to have a proper comment in the code too indeed :-)
| precision: Milliseconds = Infinity | ||
| ) { | ||
| if (precision !== Infinity) { | ||
| precision = 10 ** Math.floor(Math.log10(precision)); |
There was a problem hiding this comment.
I just wonder if this part should be done in the caller, so that the precision arguments have the same meaning in all the functions here. What do you think?
Although I'm not 100% sure about this line does. Would we have too much precision without this line?
There was a problem hiding this comment.
I think doing it in the caller would be more effort once there are multiple callers (I'm hoping the TimelineRuler code will eventually use this code path too). The precision argument still works in the same way in all the functions, thanks to the Math.floor(Math.log10( call in formatSeconds.
I added a comment in the code to explain what behavior these lines implement. Not the most useful part of the patch, unless it was needed to fix an edge case I don't remember.
128bd24 to
6205fb5
Compare
* main: (37 commits) Show the hovered time in the ruler at the top of the timeline. (PR firefox-devtools#4748) Hardcode 'project' to 'firefox-profiler' in .taskcluster.yml (PR firefox-devtools#4759) Update all Yarn dependencies (2023-09-27) (PR firefox-devtools#4758) Update the uploading command in the developer documentation (PR firefox-devtools#4752) Make prettier ignore the taskcluster files Add taskcluster Update all Yarn dependencies (2023-09-20) (PR firefox-devtools#4756) Add a robots.txt file to disallow indexing our profile links (PR firefox-devtools#4753) Avoid showing the calltree panel in profiles without samples. (PR firefox-devtools#4744) Display the vertical line in the timeline when hovering the marker chart or stack chart (PR firefox-devtools#4742) Draw a single rectangle for 2 markers in bar charts only if both the start and end horizontal pixels match. (PR firefox-devtools#4734) Update all Yarn dependencies (2023-09-13) (firefox-devtools#4746) Update all Yarn dependencies (2023-09-06) (PR firefox-devtools#4741) Remove prefer-wait-for rule in our config because it's been removed from the plugin ⬆️ Update eslint-plugin-testing-library to version 6.0.1 Use a cache for prettier (PR firefox-devtools#4731) Remove leftover eslint error Run prettier on the codebase Upgrade prettier to latest version Ignore the coverage directory when present ...