|
1 | 1 | import {directionEnabled, debounce, keyNotPressed, getModifierKey, keyPressed} from './utils';
|
2 | 2 | import {zoom, zoomRect} from './core';
|
3 |
| -import {callback as call} from 'chart.js/helpers'; |
| 3 | +import {callback as call, getRelativePosition} from 'chart.js/helpers'; |
4 | 4 | import {getState} from './state';
|
5 | 5 |
|
6 | 6 | function removeHandler(chart, type) {
|
@@ -49,11 +49,7 @@ function keyDown(chart, event) {
|
49 | 49 | function zoomStart(chart, event, zoomOptions) {
|
50 | 50 | const {onZoomStart, onZoomRejected} = zoomOptions;
|
51 | 51 | if (onZoomStart) {
|
52 |
| - const {left: offsetX, top: offsetY} = event.target.getBoundingClientRect(); |
53 |
| - const point = { |
54 |
| - x: event.clientX - offsetX, |
55 |
| - y: event.clientY - offsetY |
56 |
| - }; |
| 52 | + const point = getRelativePosition(event, chart); |
57 | 53 | if (call(onZoomStart, [{chart, event, point}]) === false) {
|
58 | 54 | call(onZoomRejected, [{chart, event}]);
|
59 | 55 | return false;
|
@@ -81,20 +77,22 @@ export function mouseDown(chart, event) {
|
81 | 77 | addHandler(chart, window.document, 'keydown', keyDown);
|
82 | 78 | }
|
83 | 79 |
|
84 |
| -export function computeDragRect(chart, mode, beginPoint, endPoint) { |
85 |
| - const {left: offsetX, top: offsetY} = beginPoint.target.getBoundingClientRect(); |
| 80 | +export function computeDragRect(chart, mode, beginPointEvent, endPointEvent) { |
86 | 81 | const xEnabled = directionEnabled(mode, 'x', chart);
|
87 | 82 | const yEnabled = directionEnabled(mode, 'y', chart);
|
88 | 83 | let {top, left, right, bottom, width: chartWidth, height: chartHeight} = chart.chartArea;
|
89 | 84 |
|
| 85 | + const beginPoint = getRelativePosition(beginPointEvent, chart); |
| 86 | + const endPoint = getRelativePosition(endPointEvent, chart); |
| 87 | + |
90 | 88 | if (xEnabled) {
|
91 |
| - left = Math.min(beginPoint.clientX, endPoint.clientX) - offsetX; |
92 |
| - right = Math.max(beginPoint.clientX, endPoint.clientX) - offsetX; |
| 89 | + left = Math.min(beginPoint.x, endPoint.x); |
| 90 | + right = Math.max(beginPoint.x, endPoint.x); |
93 | 91 | }
|
94 | 92 |
|
95 | 93 | if (yEnabled) {
|
96 |
| - top = Math.min(beginPoint.clientY, endPoint.clientY) - offsetY; |
97 |
| - bottom = Math.max(beginPoint.clientY, endPoint.clientY) - offsetY; |
| 94 | + top = Math.min(beginPoint.y, endPoint.y); |
| 95 | + bottom = Math.max(beginPoint.y, endPoint.y); |
98 | 96 | }
|
99 | 97 | const width = right - left;
|
100 | 98 | const height = bottom - top;
|
|
0 commit comments