如何在 goJS 中为新的 link 设置动画
How animate a new link in goJS
在我的应用程序中,我在图表中动态添加节点或链接。但是,我这样做没有新的效果转换。如何将 addLinkData 与动画一起使用?
这是一个完整的例子:
function init() {
var $ = go.GraphObject.make;
myDiagram =
$(go.Diagram, "myDiagramDiv",
{
"LinkDrawn": function(e) {
var link = e.subject;
link.isSelected = false;
var orig = link.toShortLength;
link.toShortLength = 2;
var anim = new go.Animation();
var sw = link.path.strokeWidth;
anim.add(link.path, "strokeWidth", sw, sw+5);
anim.add(link.elt(1), "strokeWidth", sw, sw+5);
anim.reversible = true;
anim.finished = function(a) { link.toShortLength = orig; link.isSelected = true; };
anim.start();
}
});
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape,
{ fill: "white", portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer" },
new go.Binding("fill", "color")),
$(go.TextBlock,
{ margin: 8 },
new go.Binding("text"))
);
myDiagram.linkTemplate =
$(go.Link,
$(go.Shape),
$(go.Shape, { toArrow: "OpenTriangle" })
);
myDiagram.model = new go.GraphLinksModel(
[
{ key: 1, text: "Alpha", color: "lightblue" },
{ key: 2, text: "Beta", color: "orange" },
{ key: 3, text: "Gamma", color: "lightgreen" },
{ key: 4, text: "Delta", color: "pink" }
]);
}
这主要是典型的简单模板和模型,您可以在 https://gojs.net/learn and https://gojs.net/intro 上阅读。唯一与自定义动画相关的是 "LinkDrawn" DiagramEvent 侦听器,它创建一个 Animation 并为 Link的路径(Link.path,一个形状)。
阅读更多关于动画的信息:https://gojs.net/latest/intro/animation.html and https://gojs.net/latest/api/symbols/Animation.html。
在我的应用程序中,我在图表中动态添加节点或链接。但是,我这样做没有新的效果转换。如何将 addLinkData 与动画一起使用?
这是一个完整的例子:
function init() {
var $ = go.GraphObject.make;
myDiagram =
$(go.Diagram, "myDiagramDiv",
{
"LinkDrawn": function(e) {
var link = e.subject;
link.isSelected = false;
var orig = link.toShortLength;
link.toShortLength = 2;
var anim = new go.Animation();
var sw = link.path.strokeWidth;
anim.add(link.path, "strokeWidth", sw, sw+5);
anim.add(link.elt(1), "strokeWidth", sw, sw+5);
anim.reversible = true;
anim.finished = function(a) { link.toShortLength = orig; link.isSelected = true; };
anim.start();
}
});
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape,
{ fill: "white", portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer" },
new go.Binding("fill", "color")),
$(go.TextBlock,
{ margin: 8 },
new go.Binding("text"))
);
myDiagram.linkTemplate =
$(go.Link,
$(go.Shape),
$(go.Shape, { toArrow: "OpenTriangle" })
);
myDiagram.model = new go.GraphLinksModel(
[
{ key: 1, text: "Alpha", color: "lightblue" },
{ key: 2, text: "Beta", color: "orange" },
{ key: 3, text: "Gamma", color: "lightgreen" },
{ key: 4, text: "Delta", color: "pink" }
]);
}
这主要是典型的简单模板和模型,您可以在 https://gojs.net/learn and https://gojs.net/intro 上阅读。唯一与自定义动画相关的是 "LinkDrawn" DiagramEvent 侦听器,它创建一个 Animation 并为 Link的路径(Link.path,一个形状)。
阅读更多关于动画的信息:https://gojs.net/latest/intro/animation.html and https://gojs.net/latest/api/symbols/Animation.html。