1
1
angular . module ( 'patternfly.charts' ) . component ( 'pfTopologyMap' , {
2
2
bindings : {
3
- force : '<?' ,
4
3
nodes : '<' ,
5
- edges : '<'
4
+ edges : '<' ,
5
+ force : '<?' ,
6
+ radius : '<?' ,
6
7
} ,
7
8
templateUrl : 'charts/topology-map.html' ,
8
9
controller : function ( $element ) {
@@ -19,12 +20,18 @@ angular.module('patternfly.charts').component('pfTopologyMap', {
19
20
var maxNodeSize ;
20
21
var transform ;
21
22
var simulation ;
23
+ var options ;
24
+ var radius = ctrl . radius || 17 ;
25
+ var graph ;
22
26
23
- ctrl . canvas = $element [ 0 ] ;
27
+ ctrl . canvas ;
28
+ ctrl . showLabels = false ;
24
29
25
30
this . $onInit = function ( ) {
26
31
var coords ;
27
- ctrl . canvas = ctrl . canvas . querySelector ( 'canvas.topology-graph' ) ;
32
+
33
+ options = { force : ctrl . force , radius : ctrl . radius } ;
34
+ ctrl . canvas = $element [ 0 ] . querySelector ( 'canvas.topology-graph' ) ;
28
35
// Store the CSS computed width and the height of the canvas
29
36
ctrl . canvasW = ctrl . canvas . clientWidth ;
30
37
ctrl . canvasH = ctrl . canvas . clientHeight ;
@@ -36,10 +43,44 @@ angular.module('patternfly.charts').component('pfTopologyMap', {
36
43
ctrl . canvasX = coords . left ;
37
44
ctrl . canvasY = coords . top ;
38
45
// Store the canvas' context
39
- ctrl . context = this . canvas . getContext ( '2d' ) ;
40
- // Set up the initial transform
41
- ctrl . transform = d3 . zoomIdentity ;
42
- console . log ( 'controller: ' , ctrl ) ;
46
+ ctrl . context = ctrl . canvas . getContext ( '2d' ) ;
47
+ ctrl . context . font = '17px FontAwesome' ;
48
+ if ( ! ctrl . force ) {
49
+ ctrl . force = d3 . layout . force ( )
50
+ . charge ( - 800 )
51
+ . gravity ( 0.2 )
52
+ . linkDistance ( 80 )
53
+ . size ( [ ctrl . canvasW , ctrl . canvasH ] ) ;
54
+ }
55
+ ctrl . force . nodes ( ctrl . nodes )
56
+ . links ( ctrl . edges )
57
+ . on ( 'tick' , tick )
58
+ . start ( ) ;
59
+ function tick ( ) {
60
+ ctrl . context . clearRect ( 0 , 0 , ctrl . canvasW , ctrl . canvasH ) ;
61
+ ctrl . context . strokeStyle = "#ccc" ;
62
+ ctrl . context . beginPath ( ) ;
63
+ ctrl . edges . forEach ( function ( d ) {
64
+ ctrl . context . moveTo ( d . source . x , d . source . y ) ;
65
+ ctrl . context . lineTo ( d . target . x , d . target . y ) ;
66
+ } ) ;
67
+ ctrl . context . stroke ( ) ;
68
+
69
+ // draw nodes
70
+ ctrl . nodes . forEach ( function ( d ) {
71
+ ctrl . context . beginPath ( ) ;
72
+ ctrl . context . fillStyle = "steelblue" ;
73
+ ctrl . context . moveTo ( d . x , d . y ) ;
74
+ ctrl . context . arc ( d . x , d . y , 17 , 0 , 2 * Math . PI ) ;
75
+ ctrl . context . fill ( ) ;
76
+ ctrl . context . beginPath ( ) ;
77
+ ctrl . context . fillStyle = 'black' ;
78
+ ctrl . context . textAlign = 'center' ;
79
+ ctrl . context . fillText ( '\uF047' , d . x , d . y - ( 17 / 2 ) ) ;
80
+ ctrl . context . fill ( ) ;
81
+ } ) ;
82
+ }
83
+ console . log ( ctrl . force ) ;
43
84
} ;
44
85
} ,
45
86
} ) ;
0 commit comments