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

registerShape,多次addShape后return shape,渲染是没有问题的,但是使用legend过滤之后,会残留部分shape #3765

Closed
PiDazhong opened this issue Dec 31, 2021 · 2 comments

Comments

@PiDazhong
Copy link

  • G2 Version: ^4.1.30
  • Platform: react
  • Mini Showcase(like screenshots):

image
image

  • CodePen Link:
registerShape('point', 'maxOrMinPoint', {
  draw(cfg, group) {
    const color = 'red';
    const showMinPoint = _.get(cfg, 'data.isMin', false);
    const showMaxPoint = _.get(cfg, 'data.isMax', false);
    const cfgX = cfg.x as number;
    const cfgY = cfg.y as number;
    let resultShape = group.addShape('circle', {
      attrs: {
        x: cfg.x as number,
        y: cfg.y as number,
      },
    });
    if (showMaxPoint || showMinPoint) {
      resultShape = group.addShape('circle', {
        attrs: {
          x: cfgX,
          y: cfgY,
          r: 3,
          lineWidth: 2,
          stroke: color,
          fill: '#fff',
        },
        name: 'maxCircle',
      });
      resultShape = group.addShape('path', {
        attrs: {
          path: `M${cfgX} ${cfgY - 4} L${cfgX + 4} ${cfgY - 8} L${cfgX - 4} ${cfgY - 8} Z`,
          lineWidth: 2,
          stroke: color,
          fill: color,
        },
        name: 'maxPath',
      });
      resultShape = group.addShape('rect', {
        attrs: {
          x: cfgX - 20, // 矩形起始点为左上角
          y: cfgY - 32,
          width: 40,
          height: 24,
          radius: 4,
          stroke: color,
          fill: color,
        },
        name: 'maxPath',
      });
      resultShape = group.addShape('text', {
        attrs: {
          x: cfgX,
          y: cfgY - 14,
          fontSize: 12,
          lineWidth: 1,
          shadowBlur: 0,
          text: showMaxPoint ? 'Max' : 'Min',
          fontStyle: 'normal',
          textAlign: 'center',
          stroke: '#fff',
          fill: '#fff',
          fontWeight: 'lighter',
        },
        name: showMaxPoint ? 'maxCircleText' : 'minCircleText',
      });
      return resultShape;
    }
    return resultShape;
  },
});
@tanggd
Copy link

tanggd commented Sep 26, 2022

@PiDazhong 解决了吗?我也遇到这个问题了

@tanweijiu
Copy link

tanweijiu commented Nov 12, 2022

可以先 const newGroup = group.addGroup(); 然后 newGroup.addShape() 上操作。 最后return newGroup;

其实就是图例只操作你最后的那个resultShape。 但是你实际上是添加了几个resultShape。

@hustcc hustcc closed this as completed Dec 7, 2022
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

4 participants