-
Notifications
You must be signed in to change notification settings - Fork 369
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
Implement IntervalMarkerOverview using canvas. #168
Conversation
Codecov Report
@@ 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.
|
d0d11a1
to
e951b81
Compare
There was a problem hiding this 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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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--) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why backwards?
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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 });
}
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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.
e951b81
to
09c3019
Compare
We were using DOM elements before which wasn't good for performance.