<!DOCTYPE html>
<html>
<head>
<title>Minimal GoJS Sample</title>
<!-- Copyright 1998-2024 by Northwoods Software Corporation. -->
</head>
<body>
<div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:600px"></div>
<button id="myTestButton">Start Walking Animations</button>
<script src="https://unpkg.com/gojs"></script>
<script id="code">
const myDiagram =
new go.Diagram("myDiagramDiv", {
renderer: "svg",
layout: new go.ForceDirectedLayout(),
"undoManager.isEnabled": true
});
myDiagram.nodeTemplate =
new go.Node("Auto")
.add(
new go.Shape("RoundedRectangle", { fill: "white", strokeWidth: 0 })
.bind("fill", "color"),
new go.TextBlock({ margin: 8 })
.bind("text")
);
myDiagram.linkTemplate =
new go.Link()
.add(
new go.Shape(),
new go.Shape({ toArrow: "OpenTriangle" }),
new go.Picture("80e3ec0bf1df8f0a314cee2f39000c637d272655.gif", {
name: "WALKER",
scale: 0.15,
segmentOrientation: go.Link.OrientAlong,
segmentIndex: NaN, // fraction extends along whole path
segmentFraction: 0.5, // initial fraction
alignmentFocus: go.Spot.Bottom
})
);
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" }
],
[
{ from: 1, to: 2 },
{ from: 1, to: 3 },
{ from: 3, to: 4 },
{ from: 4, to: 1 }
]);
go.AnimationManager.defineAnimationEffect('fraction',
(obj, startValue, endValue, easing, currentTime, duration, animation) => {
obj.segmentFraction = easing(currentTime, startValue, endValue - startValue, duration);
});
var anim = null;
function startAnimation() {
if (anim) anim.stop();
anim = new go.Animation();
anim.duration = 3000;
anim.runCount = Infinity;
myDiagram.links.each(link => {
const walker = link.findObject("WALKER");
if (walker) anim.add(walker, "fraction", 0, 1);
});
anim.start();
}
document.getElementById("myTestButton").addEventListener("click", startAnimation);
startAnimation();
</script>
</body>
</html>