Create a range selection by clicking on a screenshot
As a ~PM stumbling through a profile~ user investigating a responsiveness issue, I want to be able to select the nsRefreshDriver::Tick for a screenshot, so that I can quickly and accurately focus on the code that produced the frame.
I can currently select nsRefreshDriver::Tick by double clicking on the entry in the Stack Chart. It would nice if I could create the range selection by, for example, clicking a screenshot. This would allow me to remain on my current view and to more quickly and accurately create the selection than trying to eyeball the correct Tick below (and starting slightly before) a screenshot.
Would be a good stopgap until we have an FPS graph where users can select individual frames.
To be consistent with the stacks, the heuristic could be that double-clicking a screenshot puts the selected range on the related vsync range.
I wrote up a description as a comment in a diff of how this could be handled.
diff --git a/src/components/timeline/TrackScreenshots.js b/src/components/timeline/TrackScreenshots.js
index 5500029e..4adf06c1 100644
--- a/src/components/timeline/TrackScreenshots.js
+++ b/src/components/timeline/TrackScreenshots.js
@@ -93,6 +93,16 @@ class Screenshots extends PureComponent<Props, State> {
style={{ height: trackHeight }}
onMouseLeave={this._handleMouseLeave}
onMouseMove={this._handleMouseMove}
+ onClick={
+ // Dispatch the UPDATE_PREVIEW_SELECTION action with the correct range.
+ // The mouse click event can be translated to a screenshot marker
+ // using the function findScreenshotAtMouse
+ // Then, use that screenshot marker's start and end time to create
+ // the preview selection. You may need to compare the start time of the
+ // marker at that point, and the next marker.
+ //
+ // Make sure to handle clicking the last or first screenshot correctly.
+ }
>
<ScreenshotStrip
thread={thread}
This will also need a test.
diff --git a/src/test/components/TrackScreenshots.test.js b/src/test/components/TrackScreenshots.test.js
index 4291e153..c4020840 100644
--- a/src/test/components/TrackScreenshots.test.js
+++ b/src/test/components/TrackScreenshots.test.js
@@ -56,6 +56,18 @@ describe('timeline/TrackScreenshots', function() {
expect(screenshotHover()).toBeTruthy();
});
+ it('sets a preview selection when clicking with the mouse', () => {
+ // TODO
+ });
+
+ it('sets a preview selection when clicking before the first screenshot', () => {
+ // TODO
+ });
+
+ it('sets a preview selection when clicking after the last screenshot', () => {
+ // TODO
+ });
+
it('removes the hover when moving the mouse out', () => {
const { screenshotHover, screenshotTrack, moveMouse } = setup();
@gregtatum @julienw @canova Can I work on this? It looks scary but I am sure I will be able to do something useful.
Given the instructions by @gregtatum above, these are my thoughts.
findScreenshotAtMousereferred to here is the one which has already been defined inHoverPreviewcomponentfindScreenshotAtMouseis invoked withoffsetXas argument in_clickHandleroffsetXis obtained from the synthetic event usingevent.pageX - event.currentTarget.getBoundingClientRect().left- The index
ireturned byfindScreenshotAtMouseis the screenshot marker - If the returned index
iisnull, exit_clickHandlerelse dispatch an action like:
updatePreviewSelection({
hasSelection: true,
isModifying: false,
selectionStart: start,
selectionEnd: end,
});
I have failed to understand the instructions below which makes me believe my thought process above is not really correct.
- You may need to compare the start time of the marker at that point, and the next marker.
- Make sure to handle clicking the last or first screenshot correctly.
@gregtatum @canova @julienw I need your guidance here. Am I on the right track? You can see more in the PR.
I think your outline looks good.
Just a quick precision from looking at the code: I think we'll have to change a bit HoverPreview too. Indeed, I believe the new code you'll add will be in Screenshots. Therefore I suggest that findScreenshotAtMouse will be moved to Screenshots: then Screenshots will retrieve the current hovered screenshot, and pass directly a ScreenshotPayload to HoverPreview.
About the 2 remarks from Greg:
- You may need to compare the start time of the marker at that point, and the next marker.
He meant that, to find the new range, you might need to look at the next screenshot.
I think that should be OK to look at start and start + dur which should already take that into account, but Greg's comment was that this might not be the case.
- Make sure to handle clicking the last or first screenshot correctly.
This is only a warning that the last or first screenshot in a track may behave differently. So just take care that they work. Again I think that start and start+dur should already take that into account, but please just double-check these cases.
Hope this helps!
Therefore I suggest that
findScreenshotAtMousewill be moved to Screenshots: then Screenshots will retrieve the current hovered screenshot, and pass directly a ScreenshotPayload to HoverPreview
Since the above comment, I have made some major changes.
- I wanted to do the extraction in the
rendermethod but then essentially I will have to do something like:
const { pageX, offsetX, containerTop } = this.state;
let payload: ScreenshotPayload | null;
if (offsetX !== null) {
const screenshotIndex = this.findScreenshotAtMouse(offsetX);
if (screenshotIndex === null) {
payload = null;
} else {
payload = (screenshots[screenshotIndex].data: any);
}
} else {
payload = null;
}
and then pass payload to HoverPreview.
2) Have payload in state and then pass it to HoverPreview.
I prefer the first one over the second one because I think payload will just be redundant in state because it is derived from offsetX.
This is what is left in HoverPreview after moving findScreenshotAtMouse to Screenshots.
if (
isMakingPreviewSelection ||
offsetX === null ||
pageX === null ||
payload === null
) {
return null;
}
const { url, windowWidth, windowHeight } = payload;