-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtopo-2.html
More file actions
706 lines (677 loc) · 25.6 KB
/
topo-2.html
File metadata and controls
706 lines (677 loc) · 25.6 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
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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>the test for network topology</title>
<style type="text/css">
html, body{
font:14px/1.8 Arial,Microsoft YaHei,黑体,宋体,sans-serif;
height:100%;
}
/*菜单选项卡*/
*{
margin:0;
padding:0;
}
#uploadmenu{
list-style: none;
position:absolute;
left:0;
top:29px;
}
#uploadmenu>li>a{
display:block;
text-decoration: none;
width: 90px;
height: 24px;
margin-left: 10px;
padding-top:4px;
line-height:24px;
text-align: center;
color: #fff;
border-top:1px solid #ABA8A8;
}
#uploadmenu>li>ul>li>a{
display:inline-block;
width:27px;
height:28px;
padding-left:9px;
padding-right:9px;
background: #D1D1D1;
border-radius: 5px;
}
#uploadmenu>li>ul>li>a>img{
vertical-align: middle;
}
span{
display:inline-block;
height:30px;
line-height: 30px;
text-align: center;
width:70px;
padding-left: 5px;
padding-right:5px;
border-bottom: 1px #ADABAB solid;
}
.lili li:hover{
background: #E9E7E7;
border-radius: 5px;
}
.lili li:active{
background:#FFFFFF;
border-radius: 0px;
}
.nob{
border-bottom:none !important;
}
.lili li{
height:30px;
width:129px!important;
}
.lili{
border-radius:5px;
box-shadow: 0 0 5px #434343;
}
#uploadmenu .li1>a{
border: none;
}
.li1, .li2, .li3{
width: 110px;
height: 36px;
background: #666666;
position:relative;
cursor: pointer;
}
.li3{
border-radius:0 0 5px 5px;
}
.nav1, .nav2, .nav3{
list-style: none;
position:absolute;
left: 110px;
top: 0px;
display: none;
}
.li1:hover .nav1{
display:block;
background-color: #C5C5C5;
}
.li2:hover .nav2{
display:block;
background-color: #C5C5C5;
}
.li3:hover .nav3{
display:block;
background-color:#C5C5C5;
}
.lili1 li{
height:30px;
width:100px!important;
}
.lili1 li:hover{
background: #E9E7E7;
border-radius: 5px;
}
.lili1 li:active{
background:#FFFFFF;
border-radius: 0px;
}
.lili1{
border-radius:5px;
box-shadow: 0 0 5px #434343;
}
.lili1 li span{
display:inline-block;
height:30px;
line-height: 30px;
text-align: center;
width:70px;
margin-left: 10px;
border-bottom: 1px #ADABAB solid;
}
.nav4, .nav5, .nav6{
list-style: none;
position:absolute;
left: 123px;
top: 0px;
display: none;
cursor:pointer;
}
#level:hover .nav4{
display:block;
background-color:#C5C5C5;
}
#text:hover .nav5{
display:block;
background-color:#C5C5C5;
}
#alarm:hover .nav6{
display:block;
background-color:#C5C5C5;
}
#contextmenu {
width:122px;
border: 1px solid #aaa;
border-radius:7px;
border-bottom: 0;
background: #eee;
position: absolute;
list-style: none;
margin: 0;
padding: 0;
display: none;
box-shadow: 0 0 5px #434343;
}
#contextmenu li{
width:122px;
position:relative;
}
#contextmenu li a {
height:30px;
line-height: 30px;
width:100px;
margin-left: 11px;
text-align: center;
display: block;
border-bottom: 1px solid #aaa;
cursor: pointer;
}
#contextmenu>li:hover {
background: #fff;
border-radius:7px;
}
#linkmenu {
width:122px;
border: 1px solid #aaa;
border-radius:7px;
border-bottom: 0;
background: #eee;
position: absolute;
list-style: none;
margin: 0;
padding: 0;
display: none;
box-shadow: 0 0 5px #434343;
}
#linkmenu li {
width:122px;
}
#linkmenu li a {
width:100px;
height:30px;
line-height: 30px;
display: block;
border-bottom: 1px solid #aaa;
cursor: pointer;
margin-left: 11px;
text-align: center;
}
#linkmenu li:hover {
background: #fff;
border-radius:7px;
}
/*button*/
.jtopo_toolbar{
height:30px;
}
input[type="button"]{
display: inline-block;
outline: none;
cursor: pointer;
text-align: center;
text-decoration: none;
font: 10px/100% Arial, Helvetica, sans-serif;
padding: .5em 1em .55em;
-webkit-border-radius: .3em;
-moz-border-radius: .3em;
border-radius: .3em;
color: #2E2C2C;
border: solid 1px #D6D4D4;
background: #E4E0E0;
}
input[type="button"]:hover{
background: #CECDCD;
border: solid 1px #CECDCD;
}
</style>
<body>
<textarea id="jtopo_textfield" style="display:none;width: 60px;position: absolute;" onkeydown="if(event.keyCode==13)this.blur();"></textarea>
<div class="right">
<div id="content">
<canvas id="canvas">sorry,your browser do not support canvas label</canvas>
</div>
</div>
<ul id="uploadmenu" style="display:none;">
<li class = "li1"><a>网络设备</a>
<ul class = "nav1 lili">
<li id = "firework.png"><span>防火墙</span><a><img src="img/fk.png"></a></li>
<li id = "router.png"><span>路由器</span><a><img src="img/rr.png"></a></li>
<li id = "router1.png"><span>路由器</span><a><img src="img/rr1.png"></a></li>
<li id = "serve2.png"><span>服务器</span><a><img src="img/se2.png"></a></li>
<li id = "serve3.png"><span>服务器</span><a><img src="img/se3.png"></a></li>
<li id = "serve1.png"><span>服务器</span><a><img src="img/se1.png"></a></li>
<li id = "terminal.png"><span>终端</span><a><img src="img/tl.png"></a></li>
<li id = "switch.png"><span>交换机</span><a><img src="img/sh.png"></a></li>
<li id = "switchOptical.png"><span>光纤交换机</span><a><img src="img/sO.png"></a></li>
<li id = "monitor.png"><span>监测设备</span><a><img src="img/mr.png"></a></li>
<li id = "storageServer.png"><span>存储服务器</span><a><img src="img/ss.png"></a></li>
<li id = "cloud.png"><span class = "nob">internet</span><a><img src="img/cd.png"></a></li>
</ul>
</li>
<li class = "li2"><a>区域拓扑</a>
<ul class = "nav2 lili">
<li><span>7</span></li>
<li><span>7</span></li>
<li><span>7</span></li>
<li><span>7</span></li>
<li><span>7</span></li>
<li><span>7</span></li>
<li><span class = "nob">7</span></li>
</ul>
</li>
<li class = "li3"><a>行政拓扑</a>
<ul class = "nav3 lili">
<li><span>7</span></li>
<li><span>7</span></li>
<li><span>7</span></li>
<li><span>7</span></li>
<li><span>7</span></li>
<li><span>7</span></li>
<li><span class = "nob">7</span></li>
</ul>
</li>
</ul>
<ul id="contextmenu" style="display:none;">
<li><a>添加连线</a></li>
<li><a>添加节点</a></li>
<li id = "level"><a>设置等级</a>
<ul class = "lili1 nav4">
<li id = "1"><span>壹</span></li>
<li id = "2"><span>贰</span></li>
<li id = "3"><span>弎</span></li>
<li id = "4"><span>肆</span></li>
<li id = "5"><span>伍</span></li>
<li id = "6"><span class = "nob">陆</span></li>
</ul>
</li>
<li id = "text"><a>设置文字位置</a>
<ul class = "lili1 nav5">
<li id = "Top_Center"><span>上</span></li>
<li id = "Bottom_Center"><span>下</span></li>
<li id = "Middle_Left"><span>左</span></li>
<li id = "Middle_Right"><span>右</span></li>
<li id = "Middle_Center"><span class = "nob">中</span></li>
</ul>
</li>
<li id = "alarm"><a>警告</a>
<ul class = "lili1 nav6">
<li id = "11"><span>一级告警</span></li>
<li id = "22"><span>二级告警</span></li>
<li id = "33"><span>三级告警</span></li>
<li id = "44"><span class = "nob">取消告警</span></li>
</ul>
</li>
<li><a>顺时针旋转</a></li>
<li><a>逆时针旋转</a></li>
<li><a>放大</a></li>
<li><a>缩小</a></li>
<li><a>删除该节点</a></li>
<li><a>取消</a></li>
</ul>
<ul id="linkmenu" style="display:none;">
<li><a>修改颜色(随机)</a></li>
<li><a>改为红色</a></li>
<li><a>改为普通颜色</a></li>
<li><a>删除连线</a></li>
<li><a>取消</a></li>
</ul>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/jtopo-0.4.8-min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
var canvas = document.getElementById('canvas');
canvas.height = window.innerHeight - 30;
canvas.width = window.innerWidth;
var scene = new JTopo.Scene();
scene.background = './img/bg.jpeg';
var stage = new JTopo.Stage(canvas);
showJTopoToobar(stage);
var currentNode = null;
var endNode = null;
var tmpx = null;
var tmpy = null;
var validation = null;
//服务器载入绘制拓扑图
$.ajax({
typt:"GET",
url:"js/jsonstr.json",
dataType:"json",
success:function(data){
data.forEach(function(a){
//此处可以加入地域节点
if(a.elementType == "node"){
if(a.level <= 2) {
AddNode(a.x, a.y, a.text, a.Image, a.textPosition, a.level, a.larm);
}
}
});
data.forEach(function(a){
if(a.elementType == "link"){
var nodeA = scene.findElements(function(e){return e.id == a.nodeAid;});
var nodeZ = scene.findElements(function(e){return e.id == a.nodeZid;});
if(nodeA[0] && nodeZ[0]) {
Addlink(nodeA[0], nodeZ[0], a.text, a.fontColor);
}
}
});
}
});
//画出拓扑图(函数)
function AddNode(x, y, str, img, textPosition,level,larm)
{
var node = new JTopo.Node(str);
node.serializedProperties.push('id');
node.serializedProperties.push('level');
node.setLocation(x ,y);
node.Image = '';
node.id = x*y;
node.level = level;
if(null != img) {
node.setImage('./img/' + img, true);
node.Image = img;
}
if(larm == "2W"){
node.alarm = '2W';
}
node.textPosition = textPosition;
node.fontColor = '0,0,0';
node.addEventListener('mouseup',function(event){
handler(event,node);//将当前事件的node赋给currentNode并显示右键菜单
});
node.addEventListener('click', function(event){
endNode = node;
if(null != currentNode && currentNode != endNode && validation === true){
strr = "";
Addlink(currentNode, endNode, strr);
currentNode = null;
validation = false;//验证是否在当前节点上右键点击了添加节点
}
});
scene.add(node);
return node;
}
function Addlink(node1, node2, str, color)//-----增加折线------
{
var link = new JTopo.Link(node1, node2, str);
//node2.father = node1;
link.lineWidth = 3;//线宽
link.bundleOffset = 60;
link.bundleGap = 20;
link.textOffsetY = 3;
link.fontColor = color || '0, 200, 255';
link.strokeColor = color || '0, 200, 255';
link.addEventListener('mouseup',function(event){
currentLink = this;
handlelink(event);
});
scene.add(link);
}
function AddTextNode(x, y, str, scene)//加入单独的文字节点
{
var node = new JTopo.Node(str);
node.setLocation(x, y);
node.serializedProperties.push('id');
node.id = x+y;
node.fillColor = '255,255,255';
node.textPosition = 'Middle_Center';
node.fontColor = '0,0,0';
node.setSize(120,30);
node.dragable = false;
node.showSelected = false;
node.selected = false;
scene.add(node);
}
function handler(event, obj) {//绑定右键菜单
$("#linkmenu").hide();
if (event.button == 2) {
currentNode = obj;
tmpx = event.pageX + 30;
tmpy = event.pageY + 30;
$("#contextmenu").css({
top: event.pageY,
left: event.pageX
}).show();
$("#contextmenu a").click(function(){
var text = $(this).text();
if (text == '添加连线'){
validation = true;//验证是否在当前节点上右键点击了添加节点
}
});
}
}
function handlelink(event){
$("#contextmenu").hide();
if(event.button == 2){
$("#linkmenu").css({
top:event.pageY,
left:event.pageX
}).show();
}
}
stage.click(function (event) {
if (event.button == 0) {// 右键
// 关闭弹出菜单(div)
$("#contextmenu").hide();
$("#linkmenu").hide();
$("#uploadmenu").hide();
}
});
//右键菜单处理
$("#contextmenu a").click(function(){
var text = $(this).text();
if("取消" == text){
$("#contextmenu").hide();
}if(text == '删除该节点'){
scene.remove(currentNode);
currentNode = null;
$("#contextmenu").hide();
}
currentNode.save();
if (text == '添加连线'){
} else if(text == '添加节点'){
AddNode(tmpx, tmpy, currentNode.text, currentNode.Image,currentNode.level, 'Bottom_Center');
}else if(text == '顺时针旋转'){
currentNode.rotate += 0.5;
}else if(text == '逆时针旋转'){
currentNode.rotate -= 0.5;
}else if(text == '放大'){
currentNode.scaleX += 0.2;
currentNode.scaleY += 0.2;
}else if(text == '缩小'){
currentNode.scaleX -= 0.2;
currentNode.scaleY -= 0.2;
}else if(text == '警告')
{
if(currentNode.alarm == null) {
currentNode.alarm = '2W';
}else
{
currentNode.alarm = null;
}
}
$("#contextmenu").hide();
});
$("#linkmenu a").click(function(){
var text = $(this).text();
if("取消" == text){
$("#linkmenu").hide();
}
if(text == '修改颜色(随机)'){
//currentLink.fillColor = JTopo.util.randomColor();
currentLink.strokeColor = JTopo.util.randomColor();
}else if(text == '改为红色')
{
currentLink.strokeColor = '255,0,0';//线路
currentLink.text = "告警";
currentLink.fontColor = '255,0,0';
}else if(text == '改为普通颜色')
{
currentLink.strokeColor = '0,200,255';
}else if(text == '删除连线')
{
scene.remove(currentLink);
}
$("#linkmenu").hide();
});
//修改文字
var textfield = $("#jtopo_textfield");
scene.dbclick(function(event){
if(event.target == null) return;
var e = event.target;
textfield.css({
top: event.pageY,
left:event.pageX - e.width/2
}).val(e.text).show().focus().select();
console.log(textfield.val());
e.text = "";
textfield[0].JTopoNode = e;
});
$("#jtopo_textfield").blur(function(){
textfield[0].JTopoNode.text = textfield.hide().val();
});
stage.add(scene);
// 页面工具栏
function showJTopoToobar(stage){
var toobarDiv = $('<div class="jtopo_toolbar">').html(''
+'<input type="button" id="upLoadImage" value=" 载入设备 " />'
+'<input type="radio" name="modeRadio" value="normal" checked id="r1"/>'
+'<label for="r1"> 默认模式</label>'
+' <input type="radio" name="modeRadio" value="edit" id="r4"/><label for="r4">图片编辑模式</label>'
+' <input type="button" id="centerButton" value="居中显示"/>'
+'<input type="button" id="zoomOutButton" value=" 放 大 " />'
+'<input type="button" id="zoomInButton" value=" 缩 小 " />'
+' <input type="checkbox" id="zoomCheckbox"/><label for="zoomCheckbox">鼠标缩放</label>'
+' <input type = "button" id = "saveJsonStr" value = "保 存"/>'
+' <input type="button" id="exportButton" value="导出PNG">');
$('#content').prepend(toobarDiv);
// 工具栏按钮处理
$("input[name='modeRadio']").click(function(){
stage.mode = $("input[name='modeRadio']:checked").val();
});
$('#centerButton').click(function(){
stage.centerAndZoom(); //缩放并居中显示
});
$('#zoomOutButton').click(function(){//放大
stage.zoomOut();
});
$('#zoomInButton').click(function(){//缩小
stage.zoomIn();
});
$('#exportButton').click(function(){//保存PNG
stage.saveImageInfo();
});
$('#zoomCheckbox').click(function(){
if($('#zoomCheckbox').attr('checked')){
stage.wheelZoom = 0.85; // 设置鼠标缩放比例
}else{
stage.wheelZoom = null; // 取消鼠标缩放比例
}
});
$("#upLoadImage").click(function() {//载入节点
$("#uploadmenu").toggle();
});
$("#uploadmenu ul").on("click", "li",function(e){
var x = 10,y = 150;
var str = $(this).text();
var img = $(this).attr("id");
var textPosition = "Bottom_Center";
var level = 6;
AddNode(x, y, str, img, textPosition,level);
});
$("#contextmenu .nav4").on("click", "li", function(){//设置level
var lev = $(this).attr("id");
currentNode.level = lev;
});
$("#contextmenu .nav5").on("click", "li", function(){//设置文字位置
var tex = $(this).attr("id");
currentNode.textPosition = tex;
});
$("#contextmenu .nav6").on("click", "li", function(){//设置告警等级,动画,颜色
var ala = $(this).text();
var curr = currentNode;
var color = $(this).attr("id");
curr.alarm = ala;
/*var anima = setInterval(function(){
if(curr.alarm == ala){
curr.alarm = null;
}else{
curr.alarm = ala;
}
}, 600);*/
if(color == 11){
curr.alarmColor = '252, 233, 58';
}else if(color == 22){
curr.alarmColor = '255, 97, 0';
}else if(color == 33){
curr.alarmColor = '255, 0, 0';
}
console.log(curr.alarmColor);
});
$("#saveJsonStr").click(function(){//保存----大小,角度------非必须
var a = scene;
var d="[";
//d+='"scene":]';
for(var e=0;e< a.childs.length;e++){
var f= a.childs[e];
d+="{";
if(f.elementType == 'node')
{
f.id = f.x * f.y;
d += "\"elementType\":"+ '"'+f.elementType+'"';
d += ",\"x\":"+ f.x;
d += ",\"y\":"+ f.y;
d += ",\"id\":"+ f.id;
d += ",\"Image\":"+ '"'+ f.Image+ '"';
d += ",\"text\":"+ '"'+ f.text+ '"';
d +=",\"textPosition\":"+ '"'+ f.textPosition+ '"';
d +=",\"larm\":"+ '"'+ f.alarm+ '"';
d +=",\"level\":"+ f.level;
}else if(f.elementType == 'link'){
d += "\"elementType\":"+ '"'+ f.elementType+ '"';
d += ",\"nodeAid\":"+ f.nodeA.id;
d += ",\"nodeZid\":"+ f.nodeZ.id;
d += ",\"text\":"+ '"'+ f.text+ '"';
d +=",\"fontColor\":"+ '"'+ f.fontColor+ '"';
}
d+="},";
}
d= d.substring(0, d.length-1);
d+="]";
d = d.replace("\r\n", "\\r\\n");
console.log(d);
alert("保存成功");
});
}
var runPrefixMethod = function(element, method) {
var usablePrefixMethod;
["webkit", "moz", "ms", "o", ""].forEach(function(prefix) {
if (usablePrefixMethod) return;
if (prefix === "") {
// 无前缀,方法首字母小写
method = method.slice(0,1).toLowerCase() + method.slice(1);
}
var typePrefixMethod = typeof element[prefix + method];
if (typePrefixMethod + "" !== "undefined") {
if (typePrefixMethod === "function") {
usablePrefixMethod = element[prefix + method]();
} else {
usablePrefixMethod = element[prefix + method];
}
}
}
);
return usablePrefixMethod;
};
});
</script>
</body>
</html>