1
|
|
|
'use strict'; |
2
|
|
|
|
3
|
|
|
define(['helper'], function (helper) { |
4
|
|
|
var self = this; |
5
|
|
|
|
6
|
|
|
var ctx; |
7
|
|
|
var transform; |
8
|
|
|
|
9
|
|
|
var highlight; |
10
|
|
|
|
11
|
|
|
const nonUplinkColor = '#F2E3C6'; |
12
|
|
|
const locationColor = '#00ff00'; |
13
|
|
|
const noLocationColor = '#0000ff'; |
14
|
|
|
const clientColor = 'rgba(230, 50, 75, 1.0)'; |
15
|
|
|
|
16
|
|
|
const cableColor = '#50B0F0'; |
17
|
|
|
const highlightColor = 'rgba(255, 255, 255, 0.2)'; |
18
|
|
|
|
19
|
|
|
const NODE_RADIUS = 15; |
20
|
|
|
const LINE_RADIUS = 12; |
21
|
|
|
|
22
|
|
|
function drawDetailNode(d) { |
23
|
|
|
ctx.beginPath(); |
24
|
|
|
helper.positionClients(ctx, d, Math.PI, d.o.node.statistics.clients, 15); |
25
|
|
|
ctx.fillStyle = clientColor; |
26
|
|
|
ctx.fill(); |
27
|
|
|
ctx.beginPath(); |
28
|
|
|
var name = d.o.node_id; |
29
|
|
|
if (d.o.node && d.o.node.nodeinfo) { |
30
|
|
|
name = d.o.node.nodeinfo.hostname; |
31
|
|
|
} |
32
|
|
|
ctx.textAlign = 'center'; |
33
|
|
|
ctx.fillStyle = '#fff'; |
34
|
|
|
ctx.fillText(name, d.x, d.y + 20); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
self.drawNode = function drawNode(d) { |
38
|
|
|
ctx.beginPath(); |
39
|
|
|
if (highlight && highlight.type === 'node' && d.o.node === highlight.o) { |
40
|
|
|
ctx.arc(d.x, d.y, NODE_RADIUS * 1.5, 0, 2 * Math.PI); |
41
|
|
|
ctx.fillStyle = highlightColor; |
42
|
|
|
ctx.fill(); |
43
|
|
|
ctx.beginPath(); |
44
|
|
|
} |
45
|
|
|
ctx.moveTo(d.x + 3, d.y); |
46
|
|
|
ctx.arc(d.x, d.y, 6, 0, 2 * Math.PI); |
47
|
|
|
ctx.fillStyle = noLocationColor; |
48
|
|
|
if (d.o.node && d.o.node.nodeinfo && d.o.node.nodeinfo.location) { |
49
|
|
|
ctx.fillStyle = locationColor; |
50
|
|
|
} |
51
|
|
|
ctx.strokeStyle = nonUplinkColor; |
52
|
|
|
ctx.lineWidth = 5; |
53
|
|
|
ctx.globalAlpha = 1; |
54
|
|
|
ctx.fill(); |
55
|
|
|
ctx.stroke(); |
56
|
|
|
if (transform.k > 1) { |
57
|
|
|
drawDetailNode(d); |
58
|
|
|
} |
59
|
|
|
}; |
60
|
|
|
|
61
|
|
|
self.drawLink = function drawLink(d) { |
62
|
|
|
ctx.beginPath(); |
63
|
|
|
ctx.moveTo(d.source.x, d.source.y); |
64
|
|
|
var to = [d.target.x, d.target.y]; |
65
|
|
|
if (highlight && highlight.type === 'link' && d.o === highlight.o) { |
66
|
|
|
ctx.lineTo(to[0], to[1]); |
67
|
|
|
ctx.strokeStyle = highlightColor; |
68
|
|
|
ctx.lineWidth = LINE_RADIUS * 2; |
69
|
|
|
ctx.lineCap = 'round'; |
70
|
|
|
ctx.stroke(); |
71
|
|
|
to = [d.source.x, d.source.y]; |
72
|
|
|
} |
73
|
|
|
ctx.lineTo(to[0], to[1]); |
74
|
|
|
ctx.strokeStyle = d.o.type === 'Kabel' ? cableColor : d.color; |
75
|
|
|
if (d.o.type === 'fastd' || d.o.type === 'L2TP') { |
76
|
|
|
ctx.globalAlpha = 0.2; |
77
|
|
|
ctx.lineWidth = 1.5; |
78
|
|
|
} else { |
79
|
|
|
ctx.globalAlpha = 0.8; |
80
|
|
|
ctx.lineWidth = 2.5; |
81
|
|
|
} |
82
|
|
|
ctx.stroke(); |
83
|
|
|
}; |
84
|
|
|
|
85
|
|
|
self.setCTX = function setCTX(newValue) { |
86
|
|
|
ctx = newValue; |
87
|
|
|
}; |
88
|
|
|
self.setHighlight = function setHighlight(newValue) { |
89
|
|
|
highlight = newValue; |
90
|
|
|
}; |
91
|
|
|
self.setTransform = function setTransform(newValue) { |
92
|
|
|
transform = newValue; |
93
|
|
|
}; |
94
|
|
|
return self; |
95
|
|
|
}); |
96
|
|
|
|