Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
173 lines (141 loc) · 5.55 KB
/
Copy pathindex.js
File metadata and controls
173 lines (141 loc) · 5.55 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
var DiagramView = MindFusion.Diagramming.DiagramView;
var Diagram = MindFusion.Diagramming.Diagram;
var GlassEffect = MindFusion.Diagramming.GlassEffect;
var Style = MindFusion.Diagramming.Style;
var PathFinder = MindFusion.Diagramming.PathFinder;
var Rect = MindFusion.Drawing.Rect;
var shapeNodeStyle = new Style();
var diagram = null;
document.addEventListener("DOMContentLoaded", function () {
// create a DiagramView component that wraps the "diagram" canvas
var diagramView = DiagramView.create(document.getElementById("diagram"));
diagramView.linkBackId = "mindfusionLink";
diagram = diagramView.diagram;
// styling
shapeNodeStyle.brush = { type: 'SolidBrush', color: '#e0e9e9' };
shapeNodeStyle.stroke = "#7F7F7F";
shapeNodeStyle.fontName = "Verdana";
shapeNodeStyle.fontSize = 4;
shapeNodeStyle.nodeEffects = [new GlassEffect()];
diagram.style = shapeNodeStyle;
// set the size of diagram's scrollable area (unit is millimeter by default)
diagram.bounds = new Rect(0, 0, 1000, 1000);
// you can create diagram items from code;
// alternative syntax is diagram.addItem(new ShapeNode());
var node1 = diagram.factory.createShapeNode(10, 10, 30, 30);
node1.text = "Hello";
var node2 = diagram.factory.createShapeNode(60, 25, 30, 30);
node2.text = "World";
diagram.factory.createDiagramLink(node1, node2);
// automatically route links drawn by user
diagram.routeLinks = true;
// the Palette component lets users create shapes using drag-and-drop;
// users can also draw on the canvas using mouse or other pointing devices, as
// specified via DiagramView.behavior property;
var palette = MindFusion.Diagramming.Controls.Palette.create(document.getElementById("palette"));
//palette.padding = 2;
palette.captionFont = new MindFusion.Drawing.Font("sans-serif", 3);
palette.setTop("200px");
palette.setWidth("200px");
palette.setHeight("");
palette.theme = "business";
initPalette(palette);
// create an Overview component that displays scaled-down version of the diagram
var overview = MindFusion.Diagramming.Overview.create(document.getElementById("overview"));
overview.diagramView = diagramView;
overview.backColor = "#eee";
// create a ZoomControl to allow changing zoom level using slider UI
var zoomer = MindFusion.Controls.ZoomControl.create(document.getElementById("zoomer"));
zoomer.target = diagramView;
zoomer.borderColor = "#5a79a5";
// create a Ruler component that shows measurement scales and allows aligning nodes
var ruler = MindFusion.Diagramming.Ruler.create(document.getElementById("ruler"));
ruler.diagramView = diagramView;
ruler.backColor = "#fff";
ruler.foreColor = "#5a79a5";
ruler.textColor = "#5a79a5";
// buttons to save and load diagrams
document.getElementById("newButton").addEventListener("click", onNewClick);
document.getElementById("saveButton").addEventListener("click", onSaveClick);
document.getElementById("loadButton").addEventListener("click", onLoadClick);
// detect user's actions by handling diagram events, such as nodeCreated
diagram.nodeCreated.addEventListener(
(sender, args) =>
{
console.log("user has created a node");
args.node.brush = "lightblue";
});
// validation events let us prevent users' actions; for example,
// onLinkCreating handler below prevents users from drawing a cycle
diagram.linkCreating.addEventListener(onLinkCreating);
});
function onLinkCreating(diagram, args)
{
if (args.destination == null)
{
// not pointing to a node yet
return;
}
var pathFinder = new PathFinder(diagram);
var path = pathFinder.findShortestPath(
args.destination, args.origin);
if (path != null)
{
// adding this new link would create a cycle
// [origin]--[dest]--[path internal nodes]--[origin]
args.cancel = true;
}
}
function initPalette(palette)
{
// stock shape geometries are listed here:
// https://mindfusion.dev/docs/javascript/diagramming/CC_refTable_of_Predefined_Shapes_4.htm
// use the shape designer tool to draw custom shape geometries:
// https://mindfusion.dev/tools/shape-designer.html
// apart from ShapeNode, you could also add TableNode or ContainerNode objects
palette.addCategory("Flowchart Shapes");
var shapes = ["Start", "Input", "Process", "Decision"]
for (var i = 0; i < shapes.length; ++i) {
var node = new MindFusion.Diagramming.ShapeNode();
node.shape = shapes[i];
node.style = shapeNodeStyle;
palette.addItem(node, "Flowchart Shapes", shapes[i]);
}
palette.addCategory("Data Shapes");
var shapes = ["Database", "Input", "Delay", "Document", "ManualOperation"];
for (var i = 0; i < shapes.length; ++i) {
var node = new MindFusion.Diagramming.ShapeNode();
node.shape = shapes[i];
node.style = shapeNodeStyle;
palette.addItem(node, "Data Shapes", shapes[i]);
}
palette.addCategory("BPMN Shapes");
var shapes = ["BpmnStartLink", "BpmnIntermediateLink", "BpmnEndLink",
"BpmnStartMessage", "BpmnIntermediateMessage", "BpmnEndMessage"];
for (var i = 0; i < shapes.length; ++i) {
var node = new MindFusion.Diagramming.ShapeNode();
node.shape = shapes[i];
node.style = shapeNodeStyle;
palette.addItem(node, "BPMN Shapes", shapes[i]);
}
// expand the first accordion item (Flowchart Shapes category)
palette.collapseItems(palette.items.item(2));
palette.expandItems(palette.items.item(0));
}
function onNewClick()
{
diagram.clearAll();
}
async function onSaveClick()
{
const json = diagram.toJson();
await window.electronAPI.saveDiagram(json);
}
async function onLoadClick()
{
const content = await window.electronAPI.loadDiagram();
if (content) {
diagram.fromJson(content);
}
}