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

feat(wordcloud): accept custom canvas #6354

Merged
merged 4 commits into from
Jul 11, 2024
Merged

feat(wordcloud): accept custom canvas #6354

merged 4 commits into from
Jul 11, 2024

Conversation

pearmini
Copy link
Member

@pearmini pearmini commented Jul 11, 2024

WordCloud Mark 支持传入自定义的 Canvas,可以用于服务端渲染。

const chart = new Chart({
  createCanvas: () => {
    // 传入自定义的 Canvas
    return document.createElement('canvas');
  },
});

chart.options({
  type: 'wordCloud',
  data: {
    type: 'fetch',
    value: 'data/philosophyWord.json',
  }
});
  • code
  • test
  • docs

@hustcc
Copy link
Member

hustcc commented Jul 11, 2024

不是这样的,应该是还是用 G 的 canvas,这样在 g2-ssr 中直接传入 node-canvas 就可以了,这样用户不敢感知了,不然对于 ssr,用户还需要对 词云图的 mark 做特殊的配置。

@pearmini
Copy link
Member Author

不是这样的,应该是还是用 G 的 canvas,这样在 g2-ssr 中直接传入 node-canvas 就可以了,这样用户不敢感知了,不然对于 ssr,用户还需要对 词云图的 mark 做特殊的配置。

这里需要一个新的 canvas 吧?不应该是 G 的 canvas,毕竟这里会对传入的 canvas 操作。ssr 应该传入一个新的 node-canvas 才对?

@coveralls
Copy link

coveralls commented Jul 11, 2024

Pull Request Test Coverage Report for Build 9888515796

Details

  • 30 of 31 (96.77%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 86.587%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/runtime/plot.ts 24 25 96.0%
Totals Coverage Status
Change from base Build 9858605089: 0.3%
Covered Lines: 10444
Relevant Lines: 11684

💛 - Coveralls

@lvisei
Copy link
Member

lvisei commented Jul 11, 2024

不是这样的,应该是还是用 G 的 canvas,这样在 g2-ssr 中直接传入 node-canvas 就可以了,这样用户不敢感知了,不然对于 ssr,用户还需要对 词云图的 mark 做特殊的配置。

是的,渲染的时候是使用 renderChart 方法,透传了 createCanvas 方法

// https://github.com/pearmini/g2-ssr-node/blob/main/src/render.js
import { stdlib, render as renderChart, G2Context } from '@antv/g2';

export function render(type?: 'pdf' | 'svg') {
  return async (options: any) => {
    const { width = 640, height = 480, ...rest } = options;
    const [gCanvas, canvas] = createGCanvas(width, height, type);
    const spec = { ...rest, width, height };
    const context: G2Context = {
      canvas: gCanvas,
      library: updateLight(stdlib),
      createCanvas: () => createCanvas(300, 150),
    };
    await new Promise((resolve: any) => renderChart(spec, context, resolve));
    return canvas;
  };
}

@pearmini pearmini marked this pull request as draft July 11, 2024 06:13
@pearmini pearmini marked this pull request as ready for review July 11, 2024 09:01
@pearmini
Copy link
Member Author

pearmini commented Jul 11, 2024

@hustcc 我重构了一下 runtime,可以把 context(包括 createCanvas)透穿给各个可视化组件。

@pearmini pearmini merged commit 759ee3f into v5 Jul 11, 2024
2 checks passed
@pearmini pearmini deleted the pass-canvas-word-cloud branch July 11, 2024 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants