Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement IntervalMarkerOverview using canvas. #168

Merged
merged 1 commit into from
Mar 3, 2017

Conversation

mstange
Copy link
Contributor

@mstange mstange commented Mar 1, 2017

We were using DOM elements before which wasn't good for performance.

@mstange mstange requested a review from gregtatum March 1, 2017 21:41
@mstange mstange self-assigned this Mar 1, 2017
@codecov-io
Copy link

codecov-io commented Mar 1, 2017

Codecov Report

Merging #168 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #168   +/-   ##
=======================================
  Coverage   48.07%   48.07%           
=======================================
  Files          34       34           
  Lines        1953     1953           
=======================================
  Hits          939      939           
  Misses       1014     1014

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e2f16b3...09c3019. Read the comment docs.

Copy link
Member

@gregtatum gregtatum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

import { withSize } from '../with-size';

type MarkerState = 'PRESSED' | 'HOVERED' | 'NONE';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point I'll stop gushing about flow, but I love this.

Also, flow won't be checked unless you have.// @flow at the top of flow files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks for the note about // @flow.


// Walk the list of intervalMarkers backwards to find the marker under the
// mouse. Later markers are drawn on top and we want to find the topmost one.
for (let i = intervalMarkers.length - 1; i >= 0; i--) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why backwards?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment tries to explain it: "Later markers are drawn on top and we want to find the topmost one." The word "later" is probably not the right one here - maybe "markers at a higher array index"? "subsequent"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about: "Markers are drawn in array order; the one drawn last is on top. So if there are multiple markers under the mouse, we want to find the one with the highest array index. That's why we walk the list of intervalMarkers backwards."

}

_hitTest(e) {
const r = this._canvas.getBoundingClientRect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will steal this for the timeline.

this.props.onSelect(this.props.threadIndex, +e.target.getAttribute('data-start'), +e.target.getAttribute('data-end'));
_onMouseMove(e) {
const hoveredItem = this._hitTest(e);
this.setState({ hoveredItem });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can save some object allocations and component update checks here.

if (this.state.hoveredItem !== hoveredItem) {
  this.setState({ hoveredItem });
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah ok, shouldn't matter much but I'll do it.

const mouseDownItem = this._hitTest(e);
this.setState({ mouseDownItem });
if (mouseDownItem !== null) {
if (e.target.setCapture) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa, I had no idea setCapture existed. Nice! Is it not well supported, hence the if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Chrome doesn't support it :(

ctx = c.getContext('2d');
ctx.clearRect(0, 0, pixelWidth, pixelHeight);
}
ctx.scale(devicePixelRatio, devicePixelRatio);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe setting the scale every draw can have some performance impacts on Gecko, at least it did when I was measuring it on the flame chart.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, all right.

@@ -0,0 +1,105 @@
/* stolen from the light theme at devtools/client/themes/variables.css */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I like this broken out like this.

We were using DOM elements before which wasn't good for performance.
@mstange mstange merged commit 6609160 into firefox-devtools:master Mar 3, 2017
@mstange mstange deleted the canvas-tracing-markers branch March 3, 2017 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants