antvis/G2

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

PiDazhong posted onGitHub

  • 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;
    },
    });

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

posted by tanggd over 2 years ago

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

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

posted by tanweijiu over 2 years ago

Fund this Issue

$0.00
Funded

Pull requests