import { getEnv } from '../utils'; const getCoordnateType = (series) => { const isCartesian = series.every((item) => item.type === 'line' || item.type === 'bar'); return isCartesian ? 'cartesian' : 'polar'; }; const isCartesian = (chartType: string): Boolean => ['line', 'bar'].includes(chartType); const mapping2MathCoord = async (touch: Touch | any, canvas: HTMLCanvasElement | any) => { const inWeb = getEnv() === 'web'; if (inWeb) { const { element, padding } = canvas; const rect = element.getBoundingClientRect(); // web实现 const { left, top, right, bottom, width, height } = rect; const { clientX, clientY } = touch; const x = clientX - left - padding.left; const y = bottom - clientY - padding.bottom; return { pointsInCartesian: { x, y, }, rawSize: { left, top, right, bottom, width, height, }, }; } // mp环境中,注意查询方法是异步 const { getBoundingClientRectInMp, padding } = canvas; return new Promise((resolve) => { getBoundingClientRectInMp.exec((res) => { const { left, top, right, bottom, width, height } = res[0]; // mp实现 const { clientX, clientY } = touch; const x = clientX - left - padding.left; const y = bottom - clientY - padding.bottom; resolve({ pointsInCartesian: { x, y, }, rawSize: { left, top, right, bottom, width, height, }, }); }); }); }; export { isCartesian, getCoordnateType, mapping2MathCoord };