Skip to content

shape text 计算文字尺寸的过程中丢失 context 导致 measureText 时尝试新建 canvas #1015

Closed
@cncolder

Description

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

chart.tooltip({
  showXTip: true
});

使用 showXTip 属性, 会调用 graphic/shape/text.js 中的 calculateBox 方法.

calculateBox() {
const self = this;
const attrs = self._attrs.attrs;
const { x, y, textAlign, textBaseline } = attrs;
let width = self._getTextWidth(); // attrs.width

其中用到了 util/dom.js 中的 measureText 函数.
但不知是什么原因, 这中间的 context 丢失了. 导致 measureText 函数尝试创建新的 canvas 用来计算文字尺寸.

F2/src/util/dom.js

Lines 148 to 150 in d9611fe

if (!ctx) {
ctx = document.createElement('canvas').getContext('2d');
}

Environment Info
f2 3.7.0
System -
Browser -

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions