antvis/G6

点击节点或者路径时 如何让edge上的label样式发生改变 #4629

History-1024 posted onGitHub

问题描述

在点击节点或者路径时 如何让edge上的label样式发生改变,见下图,我现在通过点击事件让edge改变了颜色 image ` bindEvent () { const { graph } = this;

  graph.on("node:click", ({ e, node, view }) => {
    if (node.store?.data.type === "lane-rect") {

      graph.getEdges().forEach(edge => {
        edge.zIndex = 1;
        edge.attr({
          line: {
            stroke: "#409EFF",
          },
        });
      })

      graph.getNodes().forEach(node => {
        if (node._parent) {
          node.zIndex = 1;
          node.attr({
            body: {
              stroke: "rgba(0,0,0,0)",
              strokeWidth: 2,
            },
          });
        }
      })
      const nodeId = node.getProp("id");
      node.attr({
        body: {
          stroke: "orange",
          strokeWidth: 4,
        },
      });
      graph
        .getEdges()
        .filter((edge) => {
          return (
            edge.getSource().cell == nodeId
          );
        })
        .forEach((edge) => {
          edge.zIndex = 2;
          edge.attr({
            line: {
              stroke: "orange",
            },
          });
    }
  });

},`

重现链接

见描述

重现步骤

暂无,见问题描述

预期行为

我期望看到当点击节点或者路径时 label会改变颜色 选择其他路径或者节点时 之前改变的label样式会复原,新的会改变

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]
  • G6 版本: [4.5.1 ... ]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response


改变边的 label 颜色可以通过修改边配置项 labelcfg,贴一个官方文档~ https://g6.antv.antgroup.com/api/items/edge-properties#labelcfg

posted by yvonneyx almost 2 years ago

可以通过自定义点边不同状态的样式来实现,在点击点边时 set 成对应的状态即可,可以参考这个文档 https://g6.antv.antgroup.com/manual/middle/states/state#%E9%85%8D%E7%BD%AE-state-%E6%A0%B7%E5%BC%8F

posted by yangzy0603 almost 2 years ago

好的,谢谢,我研究一下。还有一个问题,如图下,我有三个节点的label 展示在了一条线上,导致我不知道label 对应的是那条路径,这个如何解决呢? 86E43F22-5F35-4496-9363-1CF856695218

posted by 542473232 almost 2 years ago

这是因为3条边重合了,默认 label 的 position 应该是 middle,尝试修改成 其他位置看看效果呢?https://g6.antv.antgroup.com/manual/middle/elements/edges/default-edge#%E6%A0%87%E7%AD%BE%E6%96%87%E6%9C%AC-label-%E5%8F%8A%E5%85%B6%E9%85%8D%E7%BD%AE-labelcfg

posted by yangzy0603 almost 2 years ago

image gai'bu'fe该部分代码 labelCfg 我配置了 但是没有变化 ,是因为这个泳道图的自定义路径原因吗

posted by 542473232 almost 2 years ago

看了下 registerEdge 的类型定义,可以尝试下设置 labelPosition 或者 options.labelCfg https://github.com/antvis/G6/blob/4e13ecc54918a2a48bf4e1389670729b6b48c7f9/packages/core/src/interface/shape.ts#L16

posted by yangzy0603 almost 2 years ago

看楼主的代码完全不是 G6 的写法呢,建议先看看文档

posted by Yanyan-Wang almost 2 years ago

This issue has been closed because it has been outdate for a long time. Please open a new issue if you still need help.

这个 issue 已经被关闭,因为 它已经过期很久了。 如果你仍然需要帮助,请创建一个新的 issue。

posted by github-actions[bot] 10 months ago

Fund this Issue

$0.00
Funded

Pull requests