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
|
|
|
if (transform.k > 1) { |
24
|
|
|
ctx.beginPath(); |
25
|
|
|
helper.positionClients(ctx, d, Math.PI, d.o.node.statistics.clients, 15); |
26
|
|
|
ctx.fillStyle = clientColor; |
27
|
|
|
ctx.fill(); |
28
|
|
|
ctx.beginPath(); |
29
|
|
|
var name = d.o.node_id; |
30
|
|
|
if (d.o.node && d.o.node.nodeinfo) { |
31
|
|
|
name = d.o.node.nodeinfo.hostname; |
32
|
|
|
} |
33
|
|
|
ctx.textAlign = 'center'; |
34
|
|
|
ctx.fillStyle = '#fff'; |
35
|
|
|
ctx.fillText(name, d.x, d.y + 20); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function drawHighlightNode(d) { |
40
|
|
|
if (highlight && highlight.type === 'node' && d.o.node === highlight.o) { |
41
|
|
|
ctx.arc(d.x, d.y, NODE_RADIUS * 1.5, 0, 2 * Math.PI); |
42
|
|
|
ctx.fillStyle = highlightColor; |
43
|
|
|
ctx.fill(); |
44
|
|
|
ctx.beginPath(); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
function drawHighlightLink(d) { |
49
|
|
|
if (highlight && highlight.type === 'link' && d.o === highlight.o) { |
50
|
|
|
ctx.lineTo(to[0], to[1]); |
51
|
|
|
ctx.strokeStyle = highlightColor; |
52
|
|
|
ctx.lineWidth = LINE_RADIUS * 2; |
53
|
|
|
ctx.lineCap = 'round'; |
54
|
|
|
ctx.stroke(); |
55
|
|
|
to = [d.source.x, d.source.y]; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
self.drawNode = function drawNode(d) { |
60
|
|
|
ctx.beginPath(); |
61
|
|
|
|
62
|
|
|
drawHighlightNode(d); |
63
|
|
|
|
64
|
|
|
ctx.moveTo(d.x + 3, d.y); |
65
|
|
|
ctx.arc(d.x, d.y, 6, 0, 2 * Math.PI); |
66
|
|
|
ctx.fillStyle = noLocationColor; |
67
|
|
|
if (d.o.node && d.o.node.nodeinfo && d.o.node.nodeinfo.location) { |
68
|
|
|
ctx.fillStyle = locationColor; |
69
|
|
|
} |
70
|
|
|
ctx.strokeStyle = nonUplinkColor; |
71
|
|
|
ctx.lineWidth = 5; |
72
|
|
|
ctx.globalAlpha = 1; |
73
|
|
|
ctx.fill(); |
74
|
|
|
ctx.stroke(); |
75
|
|
|
|
76
|
|
|
drawDetailNode(d); |
77
|
|
|
}; |
78
|
|
|
|
79
|
|
|
self.drawLink = function drawLink(d) { |
80
|
|
|
ctx.beginPath(); |
81
|
|
|
ctx.moveTo(d.source.x, d.source.y); |
82
|
|
|
var to = [d.target.x, d.target.y]; |
83
|
|
|
|
84
|
|
|
drawHighlightLink(d); |
85
|
|
|
|
86
|
|
|
ctx.lineTo(to[0], to[1]); |
87
|
|
|
ctx.strokeStyle = d.o.type === 'Kabel' ? cableColor : d.color; |
88
|
|
|
if (d.o.type === 'fastd' || d.o.type === 'L2TP') { |
89
|
|
|
ctx.globalAlpha = 0.2; |
90
|
|
|
ctx.lineWidth = 1.5; |
91
|
|
|
} else { |
92
|
|
|
ctx.globalAlpha = 0.8; |
93
|
|
|
ctx.lineWidth = 2.5; |
94
|
|
|
} |
95
|
|
|
ctx.stroke(); |
96
|
|
|
}; |
97
|
|
|
|
98
|
|
|
self.setCTX = function setCTX(newValue) { |
99
|
|
|
ctx = newValue; |
100
|
|
|
}; |
101
|
|
|
self.setHighlight = function setHighlight(newValue) { |
102
|
|
|
highlight = newValue; |
103
|
|
|
}; |
104
|
|
|
self.setTransform = function setTransform(newValue) { |
105
|
|
|
transform = newValue; |
106
|
|
|
}; |
107
|
|
|
return self; |
108
|
|
|
}); |
109
|
|
|
|