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