UNPKG

1.52 kBPlain TextView Raw
1// 注册 G 渲染引擎
2import * as CanvasEngine from '@antv/g-canvas/lib';
3import * as SVGEngine from '@antv/g-svg/lib';
4import { registerEngine } from '@antv/g2/lib/core';
5// 导出自定义比例尺的能力
6export { registerScale, getScale, registerTickMethod } from '@antv/scale';
7
8import './extend/scale/scale';
9
10// 动画
11import './animations';
12// 主题
13export * from './theme';
14
15registerEngine('canvas', CanvasEngine);
16registerEngine('svg', SVGEngine);
17
18// @ts-ignore
19export * from '@antv/g2/lib/core';
20export const VERSION = '4.1.11';
21
22
23
24// fixme: supportCSSTransform 在g2@4.1.0 后支持
25
26// 原始的计算坐标方法
27const rawGetPointByClient = CanvasEngine.Canvas.prototype.getPointByClient;
28
29CanvasEngine.Canvas.prototype.getPointByClient = function(clientX, clientY) {
30 // 获取原函数返回的坐标值
31 const raw = rawGetPointByClient.call(this, clientX, clientY);
32 // 获取设定高宽和真实高宽。
33 // 当设定的高宽不等于getBoundingClientRect获取的高宽时,说明存在缩放。
34 const el = this.get('el');
35 const bbox = el.getBoundingClientRect();
36 const setWidth = this.get('width');
37 const setHeight = this.get('height');
38 const { width: realWidth, height: realHeight } = bbox;
39 // 除以缩放比(真实高宽 / 设定高宽)获得真实的坐标。
40 return {
41 x: raw.x / (realWidth / setWidth),
42 y: raw.y / (realHeight / setHeight),
43 };
44};
45
46// 设置全局默认的error fallback
47export { setDefaultErrorFallback } from './boundary/ErrorBoundary';