Skip to content

Conversation

Eomnational
Copy link
Contributor

@Eomnational Eomnational commented May 28, 2025

@coveralls
Copy link

coveralls commented May 28, 2025

Pull Request Test Coverage Report for Build 15323906186

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 8 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.01%) to 83.169%

Files with Coverage Reduction New Missed Lines %
src/api/runtime.ts 8 91.51%
Totals Coverage Status
Change from base Build 15292742828: 0.01%
Covered Lines: 9709
Relevant Lines: 11267

💛 - Coveralls


例 3: **适合展示用户交互行为热区**

下面这个例子展示了用户在界面上的鼠标移动轨迹热力图,用于分析用户的关注热区。(此示例仅作展示说明,实际运行需要用户交互)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eomnational 这里的data有问题,playground转换api调用为spec是通过返回内部运行时的配置得来的,这地方的data应该是已经交互过的,正确的代码如下:

import { Chart } from '@antv/g2';
import { throttle } from 'lodash';

const data = {};

const chart = new Chart({
  container: 'container',
  width: 640,
  height: 480,
  padding: 0,
});


chart.data([]);

chart.options({
  type: "view",
  style: { viewFill: "#4e79a7" },
  axis: false,
  children: [
    {
      type: "heatmap",
      data: [],
      encode: { x: "x", y: "y", color: "v" },
      scale: {
        x: { domain: [0, 640] },
        y: { domain: [0, 480], range: [0, 1] },
      },
      style: { opacity: 0 },
      animate: false,
      tooltip: false,
    },
  ],
});

chart.render();

chart.on(
  'plot:pointermove',
  throttle((e) => {
    const { x, y } = e;

    const kx = Math.floor(x - (x % 8));
    const ky = Math.floor(y - (y % 8));

    if (!data[kx]) data[kx] = {};
    if (!data[kx][ky]) data[kx][ky] = 0;

    data[kx][ky] += 1;

    const d = transform(data);

    chart.changeData(d);
  }),
);

function transform(dataMap) {
  const arr = [];
  Object.keys(dataMap).forEach((x) => {
    Object.keys(dataMap[x]).forEach((y) => {
      arr.push({ x, y, v: dataMap[x][y] });
    });
  });
  return arr;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这个代码试过了,还是没用。不知道为啥

@interstellarmt
Copy link
Contributor

感谢您的贡献 🎉
关于文档的修改建议已经在相应的地方评论~修改完后记得同步到英文文档
代码可以现在官网的playground里运行一下,没有错误再粘到文档里~

@Eomnational
Copy link
Contributor Author

@interstellarmt 已修改

@Eomnational
Copy link
Contributor Author

@interstellarmt

@interstellarmt interstellarmt merged commit 0af9647 into antvis:v5 May 29, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OSCP AntV Open Source Contribution Plan
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[Docs]: 新增文档 「图表介绍」
3 participants