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: chart support hoc mark #4701

Closed
pepper-nice opened this issue Feb 27, 2023 · 0 comments
Closed

feat: chart support hoc mark #4701

pepper-nice opened this issue Feb 27, 2023 · 0 comments

Comments

@pepper-nice
Copy link
Contributor

使用方法

function HOMMark(options) {
  const { encode, ...res } = options;
  return () => {
    return [
      {
        type: 'interval',
        ...res,
        encode: {
          ...encode,
          color: 'genre',
        },
      },
      {
        type: 'line',
        ...options,
      },
      {
        type: 'point',
        ...options,
      },
    ];
  };
}

const chart = new Chart({
  container,
  canvas,
});
chart.data([
  { genre: 'Sports', sold: 275 },
  { genre: 'Strategy', sold: 115 },
  { genre: 'Action', sold: 120 },
  { genre: 'Shooter', sold: 350 },
  { genre: 'Other', sold: 150 },
]);
chart
  .mark(HOMMark)
  .encode('x', 'genre')
  .encode('y', 'sold');

改造点

Chart API 支持 mark 类型

function defineMarkProps(Node, { name, ctor }: NodePropertyDescriptor) {
  Node.prototype[name] = function () {
    // ...
  };
}
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

No branches or pull requests

1 participant