如何动态的改变端口的颜色,比如右键点击报警变成红色。

如何动态改变连线的颜色,连线的颜色实在数据中,color中设置的,如何动态的改变这个颜色呢?image
,比如右键点击端口有个报警,点击当前端口到端口的连线变成红色,帖子必须超过150字符才能发布吗?

So the Dynamic Ports sample already shows how to change the color of a port. Are you asking how to make sure all Links that come out of that port to also change color?

Well, in the changeColor function, you could iterate over all of the links that connect with that port that go out of that port:

var node = port.part;
node.findLinksOutOf(port.portId).each(function(link) { link.path.stroke = newcolor; });

If the link data has a property for the color, you should set that instead of assuming the color is only used in the Link.path’s Shape.stroke.

If you want to update a link’s color when the link is reconnected to a different port, implement something like this on the link template:

          fromPortChanged: function(link, oldport, newport) {
            if (newport) link.path.stroke = newport.elt(0).fill;
          }

If you want the link path’s color to depend on both ports that it connects with, rather than just the Link.fromPort, then you’ll need to update your code to consider both ports connected by the link and use Node.findLinksConnected and Link.toPortChanged.

您好,非常感谢,使用了您的第一种方法,已经成功的将链接的线条成功的改变了颜色,但是如果是外部的按钮,传入一个节点ID,出端口ID,入端口ID,在传入颜色,如何点击外部的这个按钮,使链接的颜色发生动态的改变呢?


比如以上图片中的方式,点击按钮,改变对应的连线颜色,我的linkDataArray数据中有颜色的属性,

我用了以上的方法,他会重新初始化画布,我只想他动态改变,不刷新页面或者画布。

再次非常感谢!!!

您好:非常感谢您的回答,以上问题我已经找到了解决方法!


以上是外部按钮传入对应的参数进行更改颜色。谢谢!