-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10forceDirectedLayout.html
62 lines (58 loc) · 2.02 KB
/
10forceDirectedLayout.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GoJS布局——第四节 力导向布局(ForceDirectedLayout)</title>
<script src="go.js"></script>
<script>
function init() {
let $ = go.GraphObject.make;
let myDiagram = $(go.Diagram, "myDiagramDiv");
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, "RoundedRectangle", {
fill: "lightblue"
}),
$(go.TextBlock, {
margin: 8
},
new go.Binding("text", "key"))
);
myDiagram.layout = $(go.ForceDirectedLayout, {
defaultElectricalCharge: 300,
defaultSpringLength: 200,
defaultSpringStiffness: 0.2,
defaultGravitationalMass:0,
isFixed: function (v) {
let node = v.node;
if (!node) return false;
else return node.data.key === "Beta";
}
});
myDiagram.model =
$(go.GraphLinksModel, {
nodeDataArray: [{
key: "Alpha",
}, {
key: "Beta",
}, {
key: "Gamma"
}, ],
linkDataArray: [{
from: "Alpha",
to: "Beta"
},
{
from: "Alpha",
to: "Gamma"
}
]
})
}
</script>
</head>
<body onload="init()">
<div id="myDiagramDiv" style="height: 900px;width: 600px;border: 1px solid #000;"></div>
</body>
</html>