Skip to content

Commit

Permalink
fix(crosshair): use offsetX/Y instead of clientX/Y (#128)
Browse files Browse the repository at this point in the history
This commit correct the behaviour of using clientX and clientY instead of offsetX and offsetY. The
previous behavious used the synthetic position of the mouse cursor, this commit change it to use the
native event value that already take care of the border box.

fix #123
  • Loading branch information
markov00 authored Mar 28, 2019
1 parent cc2cc5e commit 7c1155f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
6 changes: 2 additions & 4 deletions src/components/chart_resizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ class Resizer extends React.Component<ResizerProps> {
}

onResize = (entries: ResizeObserverEntry[]) => {
entries.forEach((entry) => {
const { width, height } = entry.contentRect;
const { top, left } = entry.target.getBoundingClientRect();
this.props.chartStore!.updateParentDimensions(width, height, top, left);
entries.forEach(({ contentRect: { width, height } }) => {
this.props.chartStore!.updateParentDimensions(width, height, 0, 0);
});
}

Expand Down
8 changes: 2 additions & 6 deletions src/components/react_canvas/reactive_chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,8 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
left: 0,
boxSizing: 'border-box',
}}
onMouseMove={({ clientX, clientY }) => {
// this cause a layout reflow on the browser https://gist.github.com/paulirish/5d52fb081b3570c81e3a
const { left, top } = this.props.chartStore!.parentDimensions;
const x = clientX - left;
const y = clientY - top;
setCursorPosition(x, y);
onMouseMove={({ nativeEvent: { offsetX, offsetY } }) => {
setCursorPosition(offsetX, offsetY);
}}
onMouseLeave={() => {
setCursorPosition(-1, -1);
Expand Down

0 comments on commit 7c1155f

Please sign in to comment.