-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
565 lines (519 loc) · 24.7 KB
/
index.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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
<!DOCTYPE html>
<html lang="fa" style="background: #00ccca;">
<head>
<meta charset="UTF-8">
<title>نمودار روند وضعیت امور</title>
<script src="app/go.js"></script>
<link rel="stylesheet" href="app/styles.css">
<script src="app/Figures.js"></script>
<script src="app/farsidate-1.0.1.min.js"></script>
<script src="app/DataInspector.js"></script>
<link rel="stylesheet" href="app/DataInspector.css">
</head>
<body onload="init()" onresize="correctSize()" style="background: #ffffff; border-radius: 5px;">
<table id="maintbl" style="width: 100%; height: 100%; font-family: Traffic, serif;">
<tr>
<td colspan="2" style="">
<span style="float: right; line-height: 40px; padding: 0 10px; font-family: Titrbold,serif;">به نام خدا</span>
<button id="SaveButton" onclick="save()" class="btn">ذخیره</button>
<!--<button onclick="load('data/model.txt')">Load</button>-->
<label for="file" class="btn">بارگزاری از فایل</label>
<input type="file" style="visibility:hidden;" id="file" name="file"/>
</td>
</tr>
<tr>
<td width="99%">
<div id="myDiagramDiv" style="border: solid 1px black; width: 100%; height: 100px; margin: auto;"></div>
</td>
<td width="227px" style="text-align: center; ">
<div style="background: #eeeeee;height: 100%;overflow-y: scroll;">
<div style="font-family: Titrbold,serif; background: #777777; color: #fff; line-height: 40px;">
ابزارها
</div>
<hr class="style-three">
<label class="container"> قفل نمودار
<input type="checkbox" id="myCheck" onclick="onlockdiagram()">
<span class="checkmark"></span>
</label>
<hr class="style-three">
<label class="container">نمایش گرید
<input type="checkbox" id="showgrid" onclick="showgrid()">
<span class="checkmark"></span>
</label>
<hr class="style-three">
<div id="myOverviewDiv" style="width:150px; height: 150px; display: inline-block;"></div>
<!--<button id="process" onclick="process()" class="btn">پردازش</button>-->
<hr class="style-three">
<div id="myInspectorDiv" class="inspector" style="direction: rtl;"></div>
</div>
</td>
</tr>
</table>
</body>
<script id="code">
window.onbeforeunload = function (evt) {
let message = confirm("آیا می خواهید خارج شوید ؟");
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
};
myDiagram = null;
function init() {
correctSize();
const $ = go.GraphObject.make; // for conciseness in defining templates
myDiagram =
$(go.Diagram, "myDiagramDiv", // must name or refer to the DIV HTML element
{
// have mouse wheel events zoom in and out instead of scroll up and down
"toolManager.mouseWheelBehavior": go.ToolManager.WheelZoom,
// support double-click in background creating a new node
"clickCreatingTool.archetypeNodeData": {
fill: "#dedede",
text: "شروع",
time: new Date().fa().toString('yyyy dddd dd MMMM'),
desc: "گره آغازین",
type: "start"
},
// enable undo & redo
"undoManager.isEnabled": true,
"LinkReshaped": function (e) {
e.subject.routing = go.Link.Orthogonal;
},
layout:
$(FlatTreeLayout, // custom Layout, defined below
{
angle: 90,
compaction: go.TreeLayout.CompactionNone
}),
});
myDiagram.grid.visible = false;
// myDiagram.grid.gridCellSize = new go.Size(30, 20);
myDiagram.toolManager.draggingTool.isGridSnapEnabled = false;
myDiagram.toolManager.resizingTool.isGridSnapEnabled = false;
// when the document is modified, add a "*" to the title and enable the "Save" button
myDiagram.addDiagramListener("Modified", function (e) {
let button = document.getElementById("SaveButton");
if (button) {
button.disabled = !myDiagram.isModified;
if (button.disabled) {
button.style.background = "#aaaaaa";
} else {
button.style.background = "#ffa100";
}
}
let idx = document.title.indexOf("*");
if (myDiagram.isModified) {
if (idx < 0) document.title += "*";
} else {
if (idx >= 0) document.title = document.title.substr(0, idx);
}
});
// define the Node template
myDiagram.nodeTemplate =
$(go.Node, "Vertical",
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
{selectionObjectName: "BODY"},
$(go.Panel, "Auto", {name: "BODY"},
// define the node's outer shape, which will surround the TextBlock
$(go.Shape, "RoundedRectangle",
{
parameter1: 10, // the corner has a large radius,
// fill: $(go.Brush, "Linear", {0: "rgb(254, 201, 0)", 1: "rgb(254, 162, 0)"}),
fill: "#aaaaaa",
stroke: null,
portId: "", // this Shape is the Node's port, not the whole Node
fromLinkable: true, fromLinkableSelfNode: true, fromLinkableDuplicates: true,
toLinkable: true, toLinkableSelfNode: true, toLinkableDuplicates: true,
cursor: "pointer"
}, new go.Binding("fill").makeTwoWay()),
$(go.TextBlock,
{
font: "bold 11pt Titrbold, helvetica, bold arial, sans-serif",
margin: new go.Margin(4, 2, 2, 2),
// editable: true // editing the text automatically updates the model data
},
new go.Binding("text").makeTwoWay(),
),
{
toolTip: // define a tooltip for each node that displays the color as text
$("ToolTip",
$(go.TextBlock, {margin: 4},
new go.Binding("text", "time"))
) // end of Adornment
},
{
contextMenu: // define a context menu for each node
$("ContextMenu", // that has one button
$("ContextMenuButton",
$(go.TextBlock, "گره ویژه"),
{click: changeColor})
// more ContextMenuButtons would go here
) // end Adornment
},
),
$(go.Panel, // this is underneath the "BODY"
{height: 17}, // always this height, even if the TreeExpanderButton is not visible
$("TreeExpanderButton")
),
);
// a function that produces the content of the diagram tooltip
function diagramInfo(model) {
return "Model:\n" + model.nodeDataArray.length + " nodes, " +
model.linkDataArray.length + " links";
}
// provide a tooltip for the background of the Diagram, when not over any Part
myDiagram.toolTip =
$("ToolTip",
$(go.TextBlock, {margin: 4},
// use a converter to display information about the diagram model
new go.Binding("text", "", diagramInfo))
);
// unlike the normal selection Adornment, this one includes a Button
myDiagram.nodeTemplate.selectionAdornmentTemplate =
$(go.Adornment, "Spot",
$(go.Panel, "Auto",
$(go.Shape, {fill: null, stroke: "blue", strokeWidth: 2}),
$(go.Placeholder) // a Placeholder sizes itself to the selected Node
),
// the button to create a "next" node, at the top-right corner
$("Button",
{
alignment: go.Spot.TopRight,
click: addNodeAndLink // this function is defined below
},
$(go.Shape, "PlusLine", {width: 6, height: 6})
), // end button,
// the button to create a "next" node, at the top-right corner
$("Button",
{
alignment: go.Spot.TopLeft,
click: showInfo // this function is defined below
},
$(go.Shape, "RoundedRectangle", {width: 6, height: 6})
) // end button
); // end Adornment
// clicking the button inserts a new node to the right of the selected node,
// and adds a link to that new node
function addNodeAndLink(e, obj) {
let adornment = obj.part;
let diagram = e.diagram;
diagram.startTransaction("Add State");
// get the node data for which the user clicked the button
let fromNode = adornment.adornedPart;
let fromData = fromNode.data;
// create a new "State" data object, positioned off to the right of the adorned Node
let toData = {
text: "وضعیت جدید",
time: new Date().fa().toString('yyyy dddd dd MMMM'),
desc: "توضیحات",
type: "unknown",
closed: false
}; // convert : let d = Date(Date.now()).toString();
let p = fromNode.location.copy();
// p.x -= 200;
// p.y += 50;
toData.loc = go.Point.stringify(p); // the "loc" property is a string, not a Point object
// add the new node data to the model
let model = diagram.model;
model.addNodeData(toData);
// create a link data from the old node data to the new node data
let linkdata = {
from: model.getKeyForNodeData(fromData), // or just: fromData.id
to: model.getKeyForNodeData(toData),
// text: ""
};
// and add the link data to the model
model.addLinkData(linkdata);
// select the new Node
let newnode = diagram.findNodeForData(toData);
diagram.select(newnode);
diagram.commitTransaction("Add State");
// if the new node is off-screen, scroll the diagram to show the new node
diagram.scrollToRect(newnode.actualBounds);
}
function showInfo(e, obj) {
let adornment = obj.part;
let diagram = e.diagram;
let txt = prompt("Please enter your name:", adornment.data['desc']);
if (txt == null || txt === "") {
adornment.data['desc'] = "توضیحات";
} else {
adornment.data['desc'] = txt;
}
// debugger;
}
// replace the default Link template in the linkTemplateMap
myDiagram.linkTemplate =
$(go.Link, // the whole link panel
// {
// curve: go.Link.Bezier, adjusting: go.Link.Stretch,
// reshapable: true, relinkableFrom: true, relinkableTo: true,
// toShortLength: 3
// },
{
routing: go.Link.AvoidsNodes, // but this is changed to go.Link.Orthgonal when the Link is reshaped
adjusting: go.Link.End,
curve: go.Link.JumpOver,
corner: 5,
toShortLength: 4
},
new go.Binding("points").makeTwoWay(),
// remember the Link.routing too
new go.Binding("routing", "routing", go.Binding.parseEnum(go.Link, go.Link.AvoidsNodes))
.makeTwoWay(go.Binding.toString),
// new go.Binding("curviness"),
$(go.Shape, // the link shape
{strokeWidth: 1.5}),
$(go.Shape, // the arrowhead
{toArrow: "standard", stroke: null}),
// $(go.Panel, "Auto",
// $(go.Shape, // the label background, which becomes transparent around the edges
// {
// fill: $(go.Brush, "Radial",
// {0: "rgb(255, 255, 255)", 0.3: "rgb(255, 255, 255)", 1: "rgba(255, 255, 255, 0)"}),
// stroke: null
// }),
// $(go.TextBlock, "سعی مجدد", // the label text
// {
// textAlign: "center",
// font: "9pt Traffic, helvetica, arial, sans-serif",
// margin: 4,
// editable: true // enable in-place editing
// },
// // editing the text automatically updates the model data
// new go.Binding("text").makeTwoWay())
// )
);
// also define a context menu for the diagram's background
myDiagram.contextMenu =
$("ContextMenu",
$("ContextMenuButton",
$(go.TextBlock, "Undo"),
{
click: function (e, obj) {
e.diagram.commandHandler.undo();
}
},
new go.Binding("visible", "", function (o) {
return o.diagram.commandHandler.canUndo();
}).ofObject()),
$("ContextMenuButton",
$(go.TextBlock, "Redo"),
{
click: function (e, obj) {
e.diagram.commandHandler.redo();
}
},
new go.Binding("visible", "", function (o) {
return o.diagram.commandHandler.canRedo();
}).ofObject()),
// no binding, always visible button:
$("ContextMenuButton",
$(go.TextBlock, "گره آغازین جدید"),
{
click: function (e, obj) {
e.diagram.commit(function (d) {
let data = {};
d.model.addNodeData(data);
part = d.findPartForData(data); // must be same data reference, not a new {}
// set location to saved mouseDownPoint in ContextMenuTool
part.location = d.toolManager.contextMenuTool.mouseDownPoint;
}, 'new node');
}
})
);
document.getElementById('file').addEventListener('change', handleFileSelect, false);
document.addEventListener("keydown", function (e) {
if ((window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) && e.keyCode === 83) {
e.preventDefault();
// Process the event here (such as click on submit button)
save();
}
}, false);
// create the Overview and initialize it to show the main Diagram
let myOverview =
$(go.Overview, "myOverviewDiv",
{observed: myDiagram});
// Show the primary selection's data, or blanks if no Part is selected:
let inspector = new Inspector('myInspectorDiv', myDiagram,
{
// allows for multiple nodes to be inspected at once
multipleSelection: true,
// max number of node properties will be shown when multiple selection is true
showSize: 4,
// when multipleSelection is true, when showAllProperties is true it takes the union of properties
// otherwise it takes the intersection of properties
showAllProperties: true,
includesOwnProperties: false,
// uncomment this line to only inspect the named properties below instead of all properties on each object:
// includesOwnProperties: false,
properties: {
"text": {title:"عنوان"},
"desc": {
title:"توضیحات",
show: Inspector.showIfNode,
type:"textarea"
},
// key would be automatically added for nodes, but we want to declare it read-only also:
// "key": {readOnly: true, show: Inspector.showIfPresent},
// color would be automatically added for nodes, but we want to declare it a color also:
// "color": {show: Inspector.showIfPresent, type: 'color'},
// Comments and LinkComments are not in any node or link data (yet), so we add them here:
// "Comments": {show: Inspector.showIfNode},
// "LinkComments": {show: Inspector.showIfLink},
// "isGroup": {readOnly: true, show: Inspector.showIfPresent},
// "flag": {show: Inspector.showIfNode, type: 'checkbox'},
"type": {
title:"نوع",
show: Inspector.showIfNode,
type: "select",
choices: function (node, propName) {
if (Array.isArray(node.data.choices)) return node.data.choices;
return ["unknown", "start", "middle", "end"];
}
},
// "choices": {show: false}, // must not be shown at all
// // an example of specifying the type
// "password": {show: Inspector.showIfPresent, type: 'password'}
"time": {
title:"زمان ایجاد",
readOnly: true,},
"closed":{
title:"توقف",
show: Inspector.showIfNode,
type:"checkbox"
}
}
});
}
function changeColor(e, obj) {
myDiagram.commit(function (d) {
// get the context menu that holds the button that was clicked
let contextmenu = obj.part;
// get the node data to which the Node is data bound
let nodedata = contextmenu.data;
// compute the next color for the node
let newcolor = "lightblue";
switch (nodedata.color) {
case "lightblue":
newcolor = "lightgreen";
break;
case "lightgreen":
newcolor = "lightyellow";
break;
case "lightyellow":
newcolor = "orange";
break;
case "orange":
newcolor = "lightblue";
break;
}
// modify the node data
// this evaluates data Bindings and records changes in the UndoManager
d.model.set(nodedata, "color", newcolor);
}, "changed color");
}
function correctSize() {
document.getElementById('myDiagramDiv').style.height = window.innerHeight - 16 - 40 - 2 - 2 - 8 + "px";
}
// Show the diagram's model in JSON format
function save() {
let element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(myDiagram.model.toJson()));
let dt = new Date();
let fname = "model_" + dt.getFullYear() +"-"+dt.getMonth() + "-"+dt.getDay() + "-"+dt.getHours()+"-"+dt.getMinutes()+"-"+dt.getSeconds() + ".txt";
element.setAttribute('download', fname);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
// function load(fname) {
// let client = new XMLHttpRequest();
// client.open('GET', fname);
// client.onreadystatechange = function() {
// myDiagram.model = go.Model.fromJson(client.responseText);
//
// };
// client.send();
// }
function handleFileSelect(evt) {
let files = evt.target.files; // FileList object
// files is a FileList of File objects. List some properties.
for (let i = 0, f; f = files[i]; i++) {
let fr = new FileReader();
fr.onload = function () {
myDiagram.model = go.Model.fromJson(fr.result);
};
fr.readAsText(f);
}
}
// Customize the TreeLayout to position all of the leaf nodes at the same vertical Y position.
function FlatTreeLayout() {
go.TreeLayout.call(this); // call base constructor
}
go.Diagram.inherit(FlatTreeLayout, go.TreeLayout);
// This assumes the TreeLayout.angle is 90 -- growing downward
FlatTreeLayout.prototype.commitLayout = function () {
go.TreeLayout.prototype.commitLayout.call(this); // call base method first
// find maximum Y position of all Nodes
let y = -Infinity;
this.network.vertexes.each(function (v) {
y = Math.max(y, v.node.position.y);
});
// move down all leaf nodes to that Y position, but keeping their X position
this.network.vertexes.each(function (v) {
if (v.sourceEdges.count === 0) {
} else {
if (v.destinationEdges.count === 0) {
// shift the node down to Y
v.node.position = new go.Point(v.node.position.x, y);
// extend the last segment vertically
v.node.toEndSegmentLength = Math.abs(v.centerY - y);
if (v.node.isTreeLeaf) {
// all model changes should happen in a transaction
myDiagram.model.commit(function (m) {
m.set(v.node.data, "type", "end");
m.set(v.node.data, "fill", "#00cccb");
}, "leaf");
}
} else { // restore to normal value
v.node.toEndSegmentLength = 10;
myDiagram.model.commit(function (m) {
m.set(v.node.data, "type", "middle");
m.set(v.node.data, "fill", "#ffa100");
}, "middle");
}
if(v.node.data.closed){
myDiagram.model.commit(function (m) {
m.set(v.node.data, "fill", "#5a5a5a");
v.node.adornments = null;
// debugger
}, "closed");
}
}
});
// myDiagram.layout.invalidateLayout();
this.invalidateLayout();
};
// end FlatTreeLayout
function onlockdiagram() {
// Get the checkbox
let checkBox = document.getElementById("myCheck");
// If the checkbox is checked, display the output text
// myDiagram.isEnabled = !checkBox.checked; // Disable the diagram!
myDiagram.model.isReadOnly = checkBox.checked; // Disable adding or removing parts
myDiagram.isReadOnly = checkBox.checked;
}
function showgrid() {
let shgr = document.getElementById("showgrid");
myDiagram.grid.visible = shgr.checked;
myDiagram.toolManager.draggingTool.isGridSnapEnabled = shgr.checked;
myDiagram.toolManager.resizingTool.isGridSnapEnabled = shgr.checked;
}
</script>
</html>