forked from NorthwoodsSoftware/GoJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetwork.html
More file actions
232 lines (213 loc) · 8.75 KB
/
Copy pathnetwork.html
File metadata and controls
232 lines (213 loc) · 8.75 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Network Configuration</title>
<meta name="description" content="A simple network configuration editor." />
<!-- Copyright 1998-2017 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="../release/go.js"></script>
<script src="../assets/js/goSamples.js"></script> <!-- this is only for the GoJS Samples framework -->
<script id="code">
function init() {
if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this
var $ = go.GraphObject.make;
myDiagram =
$(go.Diagram, "myDiagramDiv",
{
allowDrop: true,
initialContentAlignment: go.Spot.Center,
"linkingTool.direction": go.LinkingTool.ForwardsOnly,
"undoManager.isEnabled": true
});
// when the document is modified, add a "*" to the title and enable the "Save" button
myDiagram.addDiagramListener("Modified", function(e) {
var button = document.getElementById("saveModel");
if (button) button.disabled = !myDiagram.isModified;
var idx = document.title.indexOf("*");
if (myDiagram.isModified) {
if (idx < 0) document.title += "*";
} else {
if (idx >= 0) document.title = document.title.substr(0, idx);
}
});
myDiagram.nodeTemplateMap.add("Generator",
$(go.Node,
{ locationSpot: go.Spot.Center, background: "darkblue" },
new go.Binding("location", "location", go.Point.parse).makeTwoWay(go.Point.stringify),
$(go.Shape, "ACVoltageSource",
{ stroke: "white", strokeWidth: 3, fill: "transparent",
width: 40, height: 40, margin: 5,
portId: "", fromLinkable: true, cursor: "pointer", fromSpot: go.Spot.TopBottomSides, toSpot: go.Spot.TopBottomSides
})
));
myDiagram.nodeTemplateMap.add("Connector",
$(go.Node,
{ locationSpot: go.Spot.Center, background: "gray" },
new go.Binding("location", "location", go.Point.parse).makeTwoWay(go.Point.stringify),
$(go.Shape, "Circle",
{ stroke: null, fill: $(go.Brush, "Linear", { 0: "lightgray", 1: "gray" }),
width: 20, height: 20, margin: 2,
portId: "", fromLinkable: true, cursor: "pointer", fromSpot: go.Spot.TopBottomSides, toSpot: go.Spot.TopBottomSides
})
));
myDiagram.nodeTemplateMap.add("Consumer",
$(go.Node, "Spot",
{ locationSpot: go.Spot.Center, locationObjectName: "BODY",
selectionObjectName: "BODY" },
new go.Binding("location", "location", go.Point.parse).makeTwoWay(go.Point.stringify),
$(go.Picture, "images/pc.jpg",
{ name: "BODY", width: 50, height: 40, margin: 2,
portId: "", fromLinkable: true, cursor: "pointer", fromSpot: go.Spot.TopBottomSides, toSpot: go.Spot.TopBottomSides
}),
$(go.TextBlock,
{ alignment: go.Spot.Right, alignmentFocus: go.Spot.Left },
new go.Binding("text", "key"))
));
myDiagram.nodeTemplateMap.add("HBar",
$(go.Node,
new go.Binding("location", "location", go.Point.parse).makeTwoWay(go.Point.stringify),
{ layerName: "Background",
// special resizing: just at the ends
resizable: true, resizeObjectName: "SHAPE",
resizeAdornmentTemplate:
$(go.Adornment, "Spot",
$(go.Placeholder),
$(go.Shape, // left resize handle
{ alignment: go.Spot.Left, cursor: "col-resize",
desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue" }),
$(go.Shape, // right resize handle
{ alignment: go.Spot.Right, cursor: "col-resize",
desiredSize: new go.Size(6, 6), fill: "lightblue", stroke: "dodgerblue" }))
},
$(go.Shape, "Rectangle",
{ name: "SHAPE",
fill: "black", stroke: null, strokeWidth: 0,
width: 1000, height: 4,
minSize: new go.Size(100, 4),
maxSize: new go.Size(Infinity, 4) },
new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify),
new go.Binding("fill"),
{ portId: "", toLinkable: true })
));
myDiagram.linkTemplate =
$(BarLink, // subclass defined below
{
routing: go.Link.Orthogonal,
relinkableFrom: true, relinkableTo: true,
toPortChanged: function(link, oldport, newport) {
if (newport instanceof go.Shape) link.path.stroke = newport.fill;
}
},
$(go.Shape,
{ strokeWidth: 2 })
);
// start off with a simple diagram
load();
// initialize Palette
myPalette =
$(go.Palette, "myPaletteDiv",
{ nodeTemplateMap: myDiagram.nodeTemplateMap,
layout:
$(go.GridLayout,
{ cellSize: new go.Size(2, 2),
isViewportSized: true })
}
);
myPalette.model.nodeDataArray = [
{ "key": "Gen", "category": "Generator" },
{ "key": "Cons", "category": "Consumer" },
{ "key": "Dest", "category": "Connector" },
{ "key": "Bar", "category":"HBar", "size":"100 4"},
];
// remove cursors on all ports in the Palette
// make TextBlocks invisible, to reduce size of Nodes
myPalette.nodes.each(function(node) {
node.ports.each(function(port) {
port.cursor = "";
});
node.elements.each(function(tb) {
if (tb instanceof go.TextBlock) tb.visible = false;
});
});
// initialize Overview
myOverview =
$(go.Overview, "myOverviewDiv",
{ observed: myDiagram,
contentAlignment: go.Spot.Center });
}
function BarLink() {
go.Link.call(this);
}
go.Diagram.inherit(BarLink, go.Link);
/** @override */
BarLink.prototype.getLinkPoint = function(node, port, spot, from, ortho, othernode, otherport) {
if (node.category === "HBar") {
var op = go.Link.prototype.getLinkPoint.call(this, othernode, otherport, this.computeSpot(!from), !from, ortho, node, port);
var r = new go.Rect(port.getDocumentPoint(go.Spot.TopLeft),
port.getDocumentPoint(go.Spot.BottomRight));
var y = (op.y > r.centerY) ? r.bottom : r.top;
if (op.x < r.left) return new go.Point(r.left, y);
if (op.x > r.right) return new go.Point(r.right, y);
return new go.Point(op.x, y);
} else {
return go.Link.prototype.getLinkPoint.call(this, node, port, spot, from, ortho, othernode, otherport);
}
};
/** @override */
BarLink.prototype.getLinkDirection = function(node, port, linkpoint, spot, from, ortho, othernode, otherport) {
var p = port.getDocumentPoint(go.Spot.Center);
var op = otherport.getDocumentPoint(go.Spot.Center);
var below = op.y > p.y;
return below ? 90 : 270;
};
// end BarLink class
// save a model to and load a model from JSON text, displayed below the Diagram
function save() {
document.getElementById("mySavedModel").value = myDiagram.model.toJson();
myDiagram.isModified = false;
}
function load() {
myDiagram.model = go.Model.fromJson(document.getElementById("mySavedModel").value);
}
</script>
</head>
<body onload="init()">
<div id="sample">
<div style="width:100%; white-space:nowrap;">
<span style="display: inline-block; vertical-align: top; width:140px">
<div id="myPaletteDiv" style="background-color: lightgray; border: solid 1px black; height: 500px"></div>
<div id="myOverviewDiv" style="border: solid 1px black; margin-top: 3px; height: 100px"></div>
</span>
<span style="display: inline-block; vertical-align: top; width:80%">
<div id="myDiagramDiv" style="border: solid 1px black; height: 605px"></div>
</span>
</div>
<div id="buttons">
<button id="loadModel" onclick="load()">Load</button>
<button id="saveModel" onclick="save()">Save</button>
</div>
<textarea id="mySavedModel" style="width:100%;height:300px">
{ "class": "go.GraphLinksModel",
"nodeDataArray": [
{"key":"Gen1", "category":"Generator", "location":"300 0"},
{"key":"1", "category":"HBar", "location":"100 100", "size":"500 4", "fill":"green"},
{"key":"Cons1", "category":"Consumer", "location":"53 234"},
{"key":"2", "category":"HBar", "location":"0 300", "size":"600 4", "fill":"orange"},
{"key":"Conn1", "category":"Connector", "location":"232.5 207.75"},
{"key":"Cons3", "category":"Consumer", "location":"357.5 230.75"},
{"key":"Cons2", "category":"Consumer", "location":"484.5 164.75"}
],
"linkDataArray": [
{"from":"Gen1", "to":"1"},
{"from":"Gen1", "to":"2"},
{"from":"Cons1", "to":"2"},
{"from":"Conn1", "to":"1"},
{"from":"Conn1", "to":"2"},
{"from":"Cons3", "to":"2"},
{"from":"Cons2", "to":"1"}
]}
</textarea>
</div>
</body>
</html>