Simon Hunt

GUI -- Starting to migrate the 'force layout' functionality from the old GUI.

Change-Id: I38c5e5cd45a3bdc9cf6f0ec68736f3b5fbcb289f
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/*
18 + ONOS GUI -- SVG -- Util Service
19 + */
20 +
21 +/*
22 + The SVG Util Service provides a miscellany of utility functions.
23 + */
24 +
25 +(function () {
26 + 'use strict';
27 +
28 + // injected references
29 + var $log, fs;
30 +
31 + angular.module('onosSvg')
32 + .factory('SvgUtilService', ['$log', 'FnService',
33 + function (_$log_, _fs_) {
34 + $log = _$log_;
35 + fs = _fs_;
36 +
37 + function createDragBehavior() {
38 + $log.warn('SvgUtilService: createDragBehavior -- To Be Implemented');
39 + }
40 +
41 + function loadGlow() {
42 + $log.warn('SvgUtilService: loadGlow -- To Be Implemented');
43 + }
44 +
45 + function cat7() {
46 + $log.warn('SvgUtilService: cat7 -- To Be Implemented');
47 + }
48 +
49 + return {
50 + createDragBehavior: createDragBehavior,
51 + loadGlow: loadGlow,
52 + cat7: cat7
53 + };
54 + }]);
55 +}());
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
47 <script src="fw/svg/geodata.js"></script> 47 <script src="fw/svg/geodata.js"></script>
48 <script src="fw/svg/map.js"></script> 48 <script src="fw/svg/map.js"></script>
49 <script src="fw/svg/zoom.js"></script> 49 <script src="fw/svg/zoom.js"></script>
50 + <script src="fw/svg/svgUtil.js"></script>
50 51
51 <script src="fw/remote/remote.js"></script> 52 <script src="fw/remote/remote.js"></script>
52 <script src="fw/remote/urlfn.js"></script> 53 <script src="fw/remote/urlfn.js"></script>
...@@ -74,6 +75,7 @@ ...@@ -74,6 +75,7 @@
74 <script src="view/sample/sample.js"></script> 75 <script src="view/sample/sample.js"></script>
75 <script src="view/topo/topo.js"></script> 76 <script src="view/topo/topo.js"></script>
76 <script src="view/topo/topoEvent.js"></script> 77 <script src="view/topo/topoEvent.js"></script>
78 + <script src="view/topo/topoForce.js"></script>
77 <script src="view/device/device.js"></script> 79 <script src="view/device/device.js"></script>
78 <!-- TODO: inject javascript refs server-side --> 80 <!-- TODO: inject javascript refs server-side -->
79 81
......
...@@ -28,10 +28,10 @@ ...@@ -28,10 +28,10 @@
28 ]; 28 ];
29 29
30 // references to injected services etc. 30 // references to injected services etc.
31 - var $log, ks, zs, gs, ms, ps, tes; 31 + var $log, ks, zs, gs, ms, ps, tes, tfs;
32 32
33 // DOM elements 33 // DOM elements
34 - var ovtopo, svg, defs, zoomLayer, map; 34 + var ovtopo, svg, defs, zoomLayer, mapG, forceG;
35 35
36 // Internal state 36 // Internal state
37 var zoomer, evDispatcher; 37 var zoomer, evDispatcher;
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
86 $log.log('ZOOM: translate = ' + tr + ', scale = ' + sc); 86 $log.log('ZOOM: translate = ' + tr + ', scale = ' + sc);
87 87
88 // keep the map lines constant width while zooming 88 // keep the map lines constant width while zooming
89 - map.style('stroke-width', (2.0 / sc) + 'px'); 89 + mapG.style('stroke-width', (2.0 / sc) + 'px');
90 } 90 }
91 91
92 function setUpZoom() { 92 function setUpZoom() {
...@@ -112,7 +112,7 @@ ...@@ -112,7 +112,7 @@
112 var points = [ 112 var points = [
113 [0, 0], [0, 1000], [1000, 0], [1000, 1000] 113 [0, 0], [0, 1000], [1000, 0], [1000, 1000]
114 ]; 114 ];
115 - map.selectAll('circle') 115 + mapG.selectAll('circle')
116 .data(points) 116 .data(points)
117 .enter() 117 .enter()
118 .append('circle') 118 .append('circle')
...@@ -123,12 +123,19 @@ ...@@ -123,12 +123,19 @@
123 } 123 }
124 124
125 function setUpMap() { 125 function setUpMap() {
126 - map = zoomLayer.append('g').attr('id', 'topo-map'); 126 + mapG = zoomLayer.append('g').attr('id', 'topo-map');
127 //ms.loadMapInto(map, '*continental_us', {mapFillScale:0.5}); 127 //ms.loadMapInto(map, '*continental_us', {mapFillScale:0.5});
128 - ms.loadMapInto(map, '*continental_us'); 128 + ms.loadMapInto(mapG, '*continental_us');
129 //showCallibrationPoints(); 129 //showCallibrationPoints();
130 } 130 }
131 131
132 + // --- Force Layout --------------------------------------------------
133 +
134 + function setUpForce() {
135 + forceG = zoomLayer.append('g').attr('id', 'topo-force');
136 + tfs.initForce(forceG);
137 + }
138 +
132 139
133 // --- Controller Definition ----------------------------------------- 140 // --- Controller Definition -----------------------------------------
134 141
...@@ -137,10 +144,10 @@ ...@@ -137,10 +144,10 @@
137 .controller('OvTopoCtrl', [ 144 .controller('OvTopoCtrl', [
138 '$scope', '$log', '$location', '$timeout', 145 '$scope', '$log', '$location', '$timeout',
139 'KeyService', 'ZoomService', 'GlyphService', 'MapService', 146 'KeyService', 'ZoomService', 'GlyphService', 'MapService',
140 - 'PanelService', 'TopoEventService', 147 + 'PanelService', 'TopoEventService', 'TopoForceService',
141 148
142 function ($scope, _$log_, $loc, $timeout, 149 function ($scope, _$log_, $loc, $timeout,
143 - _ks_, _zs_, _gs_, _ms_, _ps_, _tes_) { 150 + _ks_, _zs_, _gs_, _ms_, _ps_, _tes_, _tfs_) {
144 var self = this; 151 var self = this;
145 $log = _$log_; 152 $log = _$log_;
146 ks = _ks_; 153 ks = _ks_;
...@@ -149,6 +156,7 @@ ...@@ -149,6 +156,7 @@
149 ms = _ms_; 156 ms = _ms_;
150 ps = _ps_; 157 ps = _ps_;
151 tes = _tes_; 158 tes = _tes_;
159 + tfs = _tfs_;
152 160
153 self.notifyResize = function () { 161 self.notifyResize = function () {
154 svgResized(svg.style('width'), svg.style('height')); 162 svgResized(svg.style('width'), svg.style('height'));
...@@ -172,6 +180,7 @@ ...@@ -172,6 +180,7 @@
172 setUpDefs(); 180 setUpDefs();
173 setUpZoom(); 181 setUpZoom();
174 setUpMap(); 182 setUpMap();
183 + setUpForce();
175 184
176 // open up a connection to the server... 185 // open up a connection to the server...
177 tes.openSock(); 186 tes.openSock();
......
...@@ -124,6 +124,6 @@ ...@@ -124,6 +124,6 @@
124 bindDispatcher: bindDispatcher, 124 bindDispatcher: bindDispatcher,
125 openSock: openSock, 125 openSock: openSock,
126 closeSock: closeSock 126 closeSock: closeSock
127 - } 127 + };
128 }]); 128 }]);
129 }()); 129 }());
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/*
18 + ONOS GUI -- Topology Event Module.
19 + Defines event handling for events received from the server.
20 + */
21 +
22 +(function () {
23 + 'use strict';
24 +
25 + // injected refs
26 + var $log, sus;
27 +
28 + // internal state
29 + var settings,
30 + force, // force layout object
31 + drag, // drag behavior handler
32 + network = {
33 + nodes: [],
34 + links: [],
35 + lookup: {},
36 + revLinkToKey: {}
37 + };
38 +
39 +
40 + // SVG elements;
41 + var linkG, linkLabelG, nodeG;
42 +
43 + // D3 selections;
44 + var link, linkLabel, node;
45 +
46 + // default settings for force layout
47 + var defaultSettings = {
48 + gravity: 0.4,
49 + friction: 0.7,
50 + charge: {
51 + // note: key is node.class
52 + device: -8000,
53 + host: -5000,
54 + _def_: -12000
55 + },
56 + linkDistance: {
57 + // note: key is link.type
58 + direct: 100,
59 + optical: 120,
60 + hostLink: 3,
61 + _def_: 50
62 + },
63 + linkStrength: {
64 + // note: key is link.type
65 + // range: {0.0 ... 1.0}
66 + //direct: 1.0,
67 + //optical: 1.0,
68 + //hostLink: 1.0,
69 + _def_: 1.0
70 + }
71 + };
72 +
73 +
74 + // force layout tick function
75 + function tick() {
76 +
77 + }
78 +
79 +
80 + function selectCb() { }
81 + function atDragEnd() {}
82 + function dragEnabled() {}
83 + function clickEnabled() {}
84 +
85 +
86 + // ==========================
87 +
88 + angular.module('ovTopo')
89 + .factory('TopoForceService',
90 + ['$log', 'SvgUtilService',
91 +
92 + function (_$log_, _sus_) {
93 + $log = _$log_;
94 + sus = _sus_;
95 +
96 + // forceG is the SVG group to display the force layout in
97 + // w, h are the initial dimensions of the SVG
98 + // opts are, well, optional :)
99 + function initForce (forceG, w, h, opts) {
100 + // TODO: create the force layout and initialize
101 + settings = angular.extend({}, defaultSettings, opts);
102 +
103 + linkG = forceG.append('g').attr('id', 'topo-links');
104 + linkLabelG = forceG.append('g').attr('id', 'topo-linkLabels');
105 + nodeG = forceG.append('g').attr('id', 'topo-nodes');
106 +
107 + link = linkG.selectAll('.link');
108 + linkLabel = linkLabelG.selectAll('.linkLabel');
109 + node = nodeG.selectAll('.node');
110 +
111 + force = d3.layout.force()
112 + .size(w, h)
113 + .nodes(network.nodes)
114 + .links(network.links)
115 + .gravity(settings.gravity)
116 + .friction(settings.friction)
117 + .charge(settings.charge._def_)
118 + .linkDistance(settings.linkDistance._def_)
119 + .linkStrength(settings.linkStrength._def_)
120 + .on('tick', tick);
121 +
122 + drag = sus.createDragBehavior(force,
123 + selectCb, atDragEnd, dragEnabled, clickEnabled);
124 + }
125 +
126 + function resize(w, h) {
127 + force.size(w, h);
128 + // Review -- do we need to nudge the layout ?
129 + }
130 +
131 + return {
132 + initForce: initForce,
133 + resize: resize
134 + };
135 + }]);
136 +}());
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/*
18 + ONOS GUI -- SVG -- SVG Util Service - Unit Tests
19 + */
20 +describe('factory: fw/svg/svgUtil.js', function() {
21 + var $log, fs, sus, d3Elem;
22 +
23 + beforeEach(module('onosUtil', 'onosSvg'));
24 +
25 + beforeEach(inject(function (_$log_, FnService, SvgUtilService) {
26 + $log = _$log_;
27 + fs = FnService;
28 + sus = SvgUtilService;
29 + d3Elem = d3.select('body').append('svg').append('defs').attr('id', 'myDefs');
30 + }));
31 +
32 + afterEach(function () {
33 + d3.select('svg').remove();
34 + });
35 +
36 + it('should define SvgUtilService', function () {
37 + expect(sus).toBeDefined();
38 + });
39 +
40 + it('should define api functions', function () {
41 + expect(fs.areFunctions(sus, [
42 + 'createDragBehavior', 'loadGlow', 'cat7'
43 + ])).toBeTruthy();
44 + });
45 +
46 +});
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/*
18 + ONOS GUI -- Topo View -- Topo Event Service - Unit Tests
19 + */
20 +describe('factory: view/topo/topoEvent.js', function() {
21 + var $log, fs, tes;
22 +
23 + beforeEach(module('ovTopo', 'onosUtil'));
24 +
25 + beforeEach(inject(function (_$log_, FnService, TopoEventService) {
26 + $log = _$log_;
27 + fs = FnService;
28 + tes = TopoEventService;
29 + }));
30 +
31 + it('should define TopoEventService', function () {
32 + expect(tes).toBeDefined();
33 + });
34 +
35 + it('should define api functions', function () {
36 + expect(fs.areFunctions(tes, [
37 + 'bindDispatcher', 'openSock', 'closeSock'
38 + ])).toBeTruthy();
39 + });
40 +
41 + // TODO: more tests...
42 +});
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/*
18 + ONOS GUI -- Topo View -- Topo Force Service - Unit Tests
19 + */
20 +describe('factory: view/topo/topoForce.js', function() {
21 + var $log, fs, tfs;
22 +
23 + beforeEach(module('ovTopo', 'onosUtil'));
24 +
25 + beforeEach(inject(function (_$log_, FnService, TopoForceService) {
26 + $log = _$log_;
27 + fs = FnService;
28 + tfs = TopoForceService;
29 + }));
30 +
31 + it('should define TopoForceService', function () {
32 + expect(tfs).toBeDefined();
33 + });
34 +
35 + it('should define api functions', function () {
36 + expect(fs.areFunctions(tfs, [
37 + 'initForce'
38 + ])).toBeTruthy();
39 + });
40 +
41 + // TODO: more tests...
42 +});
...@@ -25,12 +25,15 @@ module.exports = function(config) { ...@@ -25,12 +25,15 @@ module.exports = function(config) {
25 // production code... 25 // production code...
26 // make sure modules are defined first... 26 // make sure modules are defined first...
27 '../app/onos.js', 27 '../app/onos.js',
28 - '../app/directives.js', 28 +
29 '../app/fw/util/util.js', 29 '../app/fw/util/util.js',
30 '../app/fw/svg/svg.js', 30 '../app/fw/svg/svg.js',
31 '../app/fw/remote/remote.js', 31 '../app/fw/remote/remote.js',
32 '../app/fw/widget/widget.js', 32 '../app/fw/widget/widget.js',
33 '../app/fw/layer/layer.js', 33 '../app/fw/layer/layer.js',
34 +
35 + '../app/view/topo/topo.js',
36 +
34 // now load services etc. that augment the modules 37 // now load services etc. that augment the modules
35 '../app/**/*.js', 38 '../app/**/*.js',
36 39
......