MCPcopy
hub / github.com/chartjs/Chart.js / getCanvasPosition

Function getCanvasPosition

src/helpers/helpers.dom.ts:73–96  ·  view source on GitHub ↗

* @param e * @param canvas * @returns Canvas position

(
  e: Event | TouchEvent | MouseEvent,
  canvas: HTMLCanvasElement
)

Source from the content-addressed store, hash-verified

71 * @returns Canvas position
72 */
73function getCanvasPosition(
74 e: Event | TouchEvent | MouseEvent,
75 canvas: HTMLCanvasElement
76): {
77 x: number;
78 y: number;
79 box: boolean;
80 } {
81 const touches = (e as TouchEvent).touches;
82 const source = (touches && touches.length ? touches[0] : e) as MouseEvent;
83 const {offsetX, offsetY} = source as MouseEvent;
84 let box = false;
85 let x, y;
86 if (useOffsetPos(offsetX, offsetY, e.target)) {
87 x = offsetX;
88 y = offsetY;
89 } else {
90 const rect = canvas.getBoundingClientRect();
91 x = source.clientX - rect.left;
92 y = source.clientY - rect.top;
93 box = true;
94 }
95 return {x, y, box};
96}
97
98/**
99 * Gets an event's x, y coordinates, relative to the chart area

Callers 1

getRelativePositionFunction · 0.85

Calls 1

useOffsetPosFunction · 0.85

Tested by

no test coverage detected