From 8547b545ec2c05304f525ea7de68904a54e27e33 Mon Sep 17 00:00:00 2001 From: limichange Date: Fri, 10 Apr 2020 13:44:10 +0800 Subject: [PATCH 1/2] refactor: import @antv/g-base getOffScreenContext --- packages/g-canvas/src/util/in-path/point-in-path.ts | 2 +- packages/g-canvas/src/util/util.ts | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/packages/g-canvas/src/util/in-path/point-in-path.ts b/packages/g-canvas/src/util/in-path/point-in-path.ts index 56872971d..4731d10ff 100644 --- a/packages/g-canvas/src/util/in-path/point-in-path.ts +++ b/packages/g-canvas/src/util/in-path/point-in-path.ts @@ -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(); diff --git a/packages/g-canvas/src/util/util.ts b/packages/g-canvas/src/util/util.ts index 3208ff8e3..540109415 100644 --- a/packages/g-canvas/src/util/util.ts +++ b/packages/g-canvas/src/util/util.ts @@ -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); } From 99b8e3f6c3ad76ec8d417cac47f3282476c3b98f Mon Sep 17 00:00:00 2001 From: limichange Date: Fri, 10 Apr 2020 13:55:21 +0800 Subject: [PATCH 2/2] refactor: remove getOffScreenContext variable --- packages/g-canvas/src/shape/text.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/g-canvas/src/shape/text.ts b/packages/g-canvas/src/shape/text.ts index 10db79d6a..57bf1f955 100644 --- a/packages/g-canvas/src/shape/text.ts +++ b/packages/g-canvas/src/shape/text.ts @@ -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 { // 默认文本属性