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

【v5】自定义形状, 在 animate 为 false 时的错误问题。 #5491

Closed
ai-qing-hai opened this issue Aug 31, 2023 · 2 comments · Fixed by #5514
Closed

【v5】自定义形状, 在 animate 为 false 时的错误问题。 #5491

ai-qing-hai opened this issue Aug 31, 2023 · 2 comments · Fixed by #5514
Assignees

Comments

@ai-qing-hai
Copy link
Collaborator

在更新 size 图表大小时,自定义形状如果 animate 的配置为 false 时,会出现问题。
image

import { Chart, register } from '@antv/g2';

register('shape.interval.customShape', customShape);

function customShape(o, con) {
  return (points) => {
    const { document } = con.canvas;
    const g = document.createElement('g', {});

    const centerX = (points[0][0] + points[1][0]) / 2;
    const w = points[1][0] - points[0][0];

    const h1 = points[0][1] - w / 4;
    const h2 = points[0][1] + w / 4;

    const g1 = points[2][1] + w / 4;

    const t1 = document.createElement('path', {
      style: {
        path: [
          ['M', ...points[0]],
          ['C',
            ...points[0],
            points[0][0],
            h2,
            centerX,
            h2,
          ],
          ['C',
            centerX,
            h2,
            points[1][0],
            h2,
            ...points[1],
          ],
          ['L', ...points[2]],
          ['C',
            ...points[2],
            points[2][0],
            g1,
            centerX,
            g1,
          ],
          ['C',
            centerX,
            g1,
            points[0][0],
            g1,
            ...points[3],
          ],
          ['Z']
        ],
        fill: 'rgba(255, 0, 0, 0.75)'
      }
    });

    const r = document.createElement('path', {
      style: {
        path: [
          ['M', ...points[0]],
          ['C',
            ...points[0],
            points[0][0],
            h1,
            centerX,
            h1,
          ],
          ['C',
            centerX,
            h1,
            points[1][0],
            h1,
            ...points[1],
          ],
          ['C',
            ...points[1],
            points[1][0],
            h2,
            centerX,
            h2
          ],
          ['C',
            centerX,
            h2,
            points[0][0],
            h2,
            ...points[0],
          ],
          ['Z']
        ],
        fill: 'rgba(255, 0, 0, 0.4)'
      }
    });

    g.appendChild(t1);
    g.appendChild(r);

    return g;
  }
}
const chart = new Chart({
  container: 'container',
  theme: 'classic',
  autoFit: true,
});

chart
  .interval()
  .data({
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv',
  })
  .encode('key','letter')
  .encode('x', 'letter')
  .encode('y', 'frequency')
  .encode('shape', 'customShape')
  .axis('y', { labelFormatter: '.0%' })
  .animate(false);



chart.render();

@hustcc
Copy link
Member

hustcc commented Sep 4, 2023

设置 animate 为 false 的时候,在 resize 画布的时候,自定义图形没有办法清除,带来泄漏!

@pearmini
Copy link
Member

pearmini commented Sep 6, 2023

shape 的 API 接口其实有点问题,之后可能需要处理一下,不过这个问题应该解决。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants