-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewPX.html
More file actions
347 lines (323 loc) · 11.4 KB
/
newPX.html
File metadata and controls
347 lines (323 loc) · 11.4 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="position: absolute; width: 800px;height:600px; top: 0px; bottom: 0px;border: 1px solid #ccc;" id="canvas"></div>
</body>
<script type="application/javascript" src="resource/jquery-1.12.4.js"></script>
<script type="application/javascript" src="resource/jqTool.js"></script>
<script type="application/javascript" src="resource/a.js"></script>
<script type="application/javascript" src="resource/commons/qunee.js"></script>
<script type="application/javascript" src="resource/commons/common.js"></script>
<script>
/**
* This file is part of Qunee for HTML5.
* Copyright (c) 2016 by qunee.com
**/
if(!window.getI18NString){getI18NString = function(s){return s;}}
var graph = new Q.Graph('canvas');
var p = graph.toLogical(0, 0);
graph.zoomOut(p.x, p.y);
graph.zoomIn(p.x, p.y);
graph.minScale = 0.5
graph.maxScale = 2
graph.delayedRendering = false;
function ExpandableNode() {
Q.doSuperConstructor(this, ExpandableNode, arguments);
this.size = {width: 25};
this.setStyle(Q.Styles.LABEL_ON_TOP, true);
this._invalidateExpandedStatus();
}
var LOAD_STATUS_PENDING = 'pending';
var LOAD_STATUS_LOADING = 'loading';
var LOAD_STATUS_LOADED = 'loaded';
var LOAD_STATUS_ERROR = 'error';
ExpandableNode.prototype = {
$expanded: false,
loadable: true,
_loadStatus: LOAD_STATUS_PENDING,
_setLoadStatus: function (v) {
if (this._loadStatus == v) {
return;
}
this._loadStatus = v;
this._invalidateExpandedStatus();
},
_canLoad: function () {
return this.loadable && (this.loadStatus == LOAD_STATUS_PENDING || this.loadStatus == LOAD_STATUS_ERROR);
},
_loadData: function (callback) {
this.loadStatus = LOAD_STATUS_LOADING;
this._doLoadData(function () {
this.loadStatus = LOAD_STATUS_LOADED;
if (callback) {
callback();
}
}.bind(this), function () {
this.expanded = false;
this.loadStatus = LOAD_STATUS_ERROR;
}.bind(this))
},
_doLoadData: function (onSuccess, onError) {
var nodeWidth;
/* if (this.size && this.size.width) {
nodeWidth = this.size.width - 8;
} else {*/
nodeWidth = 50;
/* }*/
var datas=this.get('data');
var THIS=this;
$.each(datas.children,function(cx,cy){
/* if(nodeWidth < 50 && Q.randomInt(10) > 7){
onError();
return;
}
var i = 3 + Q.randomInt(5);*/
var node = createNode('C-' + cy.NODE_NAME, THIS);
node.size = {width: 50};
node.set('data',cy);
node.loadable = true;
onSuccess();
})
/*setTimeout(function () {
console.log(this.get('data'));
if(nodeWidth < 50 && Q.randomInt(10) > 7){
onError();
return;
}
var i = 3 + Q.randomInt(5);
while (i-- > 0) {
var node = createNode('C-' + i, this);
node.size = {width: nodeWidth}
node.loadable = nodeWidth > 20 && Q.randomBool();
}
onSuccess();
}.bind(this), 1000)*/
},
onChildAdd: function (child, index) {
this._invalidateExpandedStatus();
},
onChildRemove: function (child) {
this._invalidateExpandedStatus();
},
getExpandImage: function () {
var hasChildren = this.hasChildren();
var expanded = this.expanded;
var loadStatus = this.loadStatus;
if (!this.loadable || loadStatus == LOAD_STATUS_LOADED) {
if (!hasChildren) {
return null;
}
return expanded ? 'resource/svg/more.svg' : 'resource/svg/less.svg';
}
if (loadStatus == LOAD_STATUS_PENDING) {
return 'resource/svg/more.svg';
}
if (loadStatus == LOAD_STATUS_LOADING) {
return 'resource/svg/unknown.svg';
}
if (loadStatus == LOAD_STATUS_ERROR) {
return 'resource/svg/less.svg';
}
return null;
},
checkChildrenVisibilty: function () {
function checkChildren() {
var visible = this.visible !== false && this.expanded;
this.forEachChild(function (child) {
child.visible = visible;
checkChildren.call(child);
})
}
checkChildren.call(this)
},
_findExpandHandler: function(){
if(this.expandHandler){
return this.expandHandler;
}
if(this.bindingUIs){
var result;
this.bindingUIs.forEach(function(ui){
ui = ui.ui;
Q.log(ui.name)
if(ui.name == 'expandHandler'){
result = ui;
return false;
}
})
return this.expandHandler = result;
}
return null;
},
_validateExpandedStatus: function (callback) {
this.$expandedInvalidateFlag = false;
if (this.expanded && this._canLoad()) {
this._loadData(callback);
callback = null;
}
var icon = this.getExpandImage();
var expandHandler = this._findExpandHandler();
if (!icon) {
if (expandHandler) {
expandHandler.visible = false;
this.invalidate();
}
return;
}
if (!expandHandler) {
expandHandler = new Q.ImageUI();
expandHandler.shadowBlur = 3;
expandHandler.shadowColor = '#888'
expandHandler.position = Q.Position.RIGHT_TOP;
expandHandler.anchorPosition = Q.Position.LEFT_TOP;
expandHandler.offsetX = -10;
expandHandler.fontSize = 11;
expandHandler.showOnTop = true;
expandHandler.name = 'expandHandler';
this.expandHandler = expandHandler;
this.addUI(expandHandler);
}
expandHandler.data = icon;
expandHandler.visible = true;
this.checkChildrenVisibilty();
this.invalidate();
if (callback) {
callback();
}
},
_invalidateExpandedStatus: function (callback) {
if (this.$expandedInvalidateFlag) {
return;
}
this.$expandedInvalidateFlag = true;
Q.nextFrame(this._validateExpandedStatus.bind(this, callback))
},
setExpandedAndLoad: function (expanded, callback) {
if (this.expanded == expanded) {
return;
}
var old = this.$expanded;
this.$expanded = expanded;
this.onEvent(new Q.PropertyChangeEvent(this, "expanded", expanded, old));
this._invalidateExpandedStatus(callback);
}
}
Q.extend(ExpandableNode, Q.Node);
Object.defineProperties(ExpandableNode.prototype, {
loadStatus: {
get: function () {
return this._loadStatus;
},
set: function (v) {
this._setLoadStatus(v);
}
},
expanded: {
get: function () {
return this.$expanded;
},
set: function (v) {
this.setExpandedAndLoad(v);
}
},
visible: {
get: function () {
return this._visible !== false;
},
set: function (v) {
if (this.visible === v) {
return;
}
this._visible = v;
this.invalidateVisibility();
this.invalidate();
}
}
})
if(Q.loadClassPath){
Q.ExpandableNode = ExpandableNode;
Q.loadClassPath(ExpandableNode, 'Q.ExpandableNode');
ExpandableNode.prototype.addOutProperty('visible');
ExpandableNode.prototype.addOutProperty('loadStatus');
ExpandableNode.prototype.addOutProperty('expanded');
}
graph.onclick = function (evt) {
var data = evt.getData();
if (data instanceof ExpandableNode) {
var target = graph.hitTest(evt);
if (target && target.name == 'expandHandler') {
var oldLocation = {x: data.x, y: data.y};
data.setExpandedAndLoad(!data.expanded, function () {
doLayout({
callback: function () {
var dx = data.x - oldLocation.x;
var dy = data.y - oldLocation.y;
dx *= graph.scale;
dy *= graph.scale;
graph.translate(-dx, -dy, false)
}
})
});
}
}
}
function createNode(name, from, edgeType) {
var node = new ExpandableNode(name);
node.size = {width: 130}
graph.addElement(node);
if (from) {
node.parent = node.host = from;
var edge = createEdge(from, node);
edge.edgeType = edgeType || Q.Consts.EDGE_TYPE_VERTICAL_HORIZONTAL;
}
return node;
}
function createEdge(from, to) {
var edge = graph.createEdge(from, to);
edge.setStyle(Q.Styles.ARROW_TO, false);
edge.setStyle(Q.Styles.EDGE_COLOR, "#ff6600");
edge.setStyle(Q.Styles.ARROW_FROM_FILL_GRADIENT, Q.Gradient.LINEAR_GRADIENT_HORIZONTAL);
edge.setStyle(Q.Styles.ARROW_FROM_SIZE, {width: 30, height: 30});
/* edge.setStyle(Q.Styles.ARROW_FROM_FILL_COLOR, "red");
edge.setStyle(Q.Styles.ARROW_TO_FILL_COLOR, "red");*/
return edge;
}
var datas=$.tool.JsonTool.toTree(Conts, 'NODE_ID','RELATION_RELATED_ID','children')
var layouter = new Q.TreeLayouter(graph);
layouter.hGap = 10;
layouter.vGap = 20;
function doLayout(options) {
layouter.doLayout(options)
}
$.each(datas,function(a,b){
var root = createNode(b.NODE_NAME);
root.size = {width: 50}
root.parentChildrenDirection = Q.Consts.DIRECTION_RIGHT_BOTTOM;
root.hGap = 30;
root.set('data',b);
doLayout({
callback: function () {
graph.moveToCenter()
}
})
})
/*var root = createNode('Root');
root.size = {width: 50}
root.parentChildrenDirection = Q.Consts.DIRECTION_RIGHT_BOTTOM;
root.hGap = 30;
var layouter = new Q.TreeLayouter(graph);
layouter.hGap = 10;
layouter.vGap = 20;
function doLayout(options) {
layouter.doLayout(options)
}
doLayout({
callback: function () {
graph.moveToCenter()
}
})*/
</script>
</html>