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 bind autoFit in render #4941

Merged
merged 1 commit into from
May 5, 2023
Merged

Conversation

pepper-nice
Copy link
Contributor

问题描述

Chart.options 中申明 autoFit 属性无法正常绑定 onResize 事件。因为该事件绑定在 Chart 的初始化中进行,此时拿不到 autoFit 属性。
修改方式:将 bindAutoFit 方法放在 render 函数中执行。

import { Chart } from "@antv/g2";

const chart = new Chart({ container: "container" });

chart.options({
  type: "interval",
  theme: "classic",
  autoFit: true,
  data: {
    type: "fetch",
    value:
      "https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv",
  },
  encode: { x: "letter", y: "frequency" },
  axis: { y: { labelFormatter: ".0%" } },
});

chart.render();

Copy link
Member

@pearmini pearmini left a comment

Choose a reason for hiding this comment

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

加一下单测:

  • chart.options({ autoFit: true });
  • chart.options({ autoFit: true }); 之后调用 chart.options({ autoFit: false})

src/api/chart.ts Outdated Show resolved Hide resolved
src/api/chart.ts Outdated Show resolved Hide resolved
__tests__/unit/api/chart.spec.ts Outdated Show resolved Hide resolved
@pepper-nice pepper-nice force-pushed the feat/bindFit-in-render branch from 06bca8f to 3767316 Compare May 5, 2023 07:15
@pepper-nice pepper-nice merged commit c16191a into v5 May 5, 2023
@pepper-nice pepper-nice deleted the feat/bindFit-in-render branch May 5, 2023 07:52
hustcc pushed a commit that referenced this pull request May 16, 2023
hustcc pushed a commit that referenced this pull request May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants