}
};
- let listener = function(e) {
+ let listener = function(e, x, y) {
+ e.offsetX = x;
+ e.offsetY = y;
me._eventHandler(e);
};
const e = evt.originalEvent || evt;
const touches = e.touches;
const source = touches && touches.length ? touches[0] : e;
- const {offsetX, offsetY, layerX, layerY, target} = source;
+ const {offsetX, offsetY} = source;
if (offsetX > 0 || offsetY > 0) {
return {
};
}
- if (layerX > 0 || layerY > 0) {
- return {
- x: layerX - target.offsetLeft,
- y: layerY - target.offsetTop
- };
- }
-
return calculateRelativePositionFromClientXY(source, chart);
}
* Latest argments are used on the actual call
* @param {function} fn
* @param {*} thisArg
+ * @param {function} [updateFn]
*/
-export function throttled(fn, thisArg) {
+export function throttled(fn, thisArg, updateFn) {
+ const updateArgs = updateFn || ((args) => Array.prototype.slice.call(args));
let ticking = false;
let args = [];
return function(...rest) {
- args = Array.prototype.slice.call(rest);
+ args = updateArgs(rest);
if (!ticking) {
ticking = true;
if (chart.ctx !== null) {
listener(fromNativeEvent(event, chart));
}
- }, chart);
+ }, chart, (args) => {
+ const event = args[0];
+ return [event, event.offsetX, event.offsetY];
+ });
addListener(canvas, type, proxy);
expect(helpers.getRelativePosition(event, chart)).toEqual({x: 0, y: 10});
});
- it('should use layerX/Y - target offsets when available', function() {
- const chart = undefined;
-
- const event1 = {
- layerX: 0,
- layerY: 10,
- target: {
- offsetLeft: 0,
- offsetTop: 5
- }
- };
- expect(helpers.getRelativePosition(event1, chart)).toEqual({x: 0, y: 5});
-
- const event2 = {
- offsetX: 0,
- offsetY: 0,
- layerX: 10,
- layerY: 10,
- target: {
- offsetLeft: 0,
- offsetTop: 5
- }
- };
- expect(helpers.getRelativePosition(event2, chart)).toEqual({x: 10, y: 5});
- });
-
- it('should calculate from clientX/Y if offset/layer coords are not available', function() {
+ it('should calculate from clientX/Y as fallback', function() {
const chart = window.acquireChart({}, {
canvas: {
height: 200,