Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: import @antv/g-base getOffScreenContext #473

Merged
merged 2 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/g-canvas/src/shape/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import ShapeBase from './base';
import { isNil, isString, each, getOffScreenContext } from '../util/util';
import { isNil, isString, each } from '../util/util';
import { getTextHeight, assembleFont } from '@antv/g-base/lib/util/text';
class Text extends ShapeBase {
// 默认文本属性
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvas/src/util/in-path/point-in-path.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getOffScreenContext } from '../util';
import { getOffScreenContext } from '@antv/g-base/lib/util/offscreen';

export default function isPointInPath(shape, x, y) {
const ctx = getOffScreenContext();
Expand Down
12 changes: 0 additions & 12 deletions packages/g-canvas/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ export function inBox(minX: number, minY: number, width: number, height: number,
return x >= minX && x <= minX + width && y >= minY && y <= minY + height;
}

// 全局设置一个唯一离屏的 ctx,用于计算 isPointInPath
let offScreenCtx = null;
export function getOffScreenContext() {
if (!offScreenCtx) {
const canvas = document.createElement('canvas');
canvas.width = 1;
canvas.height = 1;
offScreenCtx = canvas.getContext('2d');
}
return offScreenCtx;
}

export function intersectRect(box1, box2) {
return !(box2.minX > box1.maxX || box2.maxX < box1.minX || box2.minY > box1.maxY || box2.maxY < box1.minY);
}
Expand Down