@mui/x-charts
Version:
The community edition of MUI X Charts components.
36 lines (35 loc) • 979 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getChartPoint = getChartPoint;
/**
* Transform mouse event position to coordinates relative to the layer container.
* (0, 0) is the top-left corner of the layer container.
* @param element The the layer container
* @param event The mouseEvent to transform
*/
function getChartPoint(element, event) {
const rect = element.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
if (typeof DOMMatrix === 'undefined') {
// Fallback for environments like JSDOM where DOMMatrix is not available.
return {
x,
y,
z: 0,
w: 1,
matrixTransform: () => ({
x,
y,
z: 0,
w: 1
})
};
}
const style = getComputedStyle(element);
const transform = new DOMMatrix(style.transform);
const point = new DOMPoint(x, y);
return point.matrixTransform(transform.inverse());
}