Steven Burrows
Committed by Gerrit Code Review

Topo2: Scale links when zooming in and out

Topo2: Limit icon scaling

Change-Id: I9b203183ebfe25ae9993a9ee8813608969867849
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
93 function adjustZoomLayer(translate, scale) { 93 function adjustZoomLayer(translate, scale) {
94 settings.zoomLayer.attr('transform', 94 settings.zoomLayer.attr('transform',
95 'translate(' + translate + ')scale(' + scale + ')'); 95 'translate(' + translate + ')scale(' + scale + ')');
96 - settings.zoomCallback(); 96 + settings.zoomCallback(translate, scale);
97 } 97 }
98 98
99 zoomer = { 99 zoomer = {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
25 25
26 // references to injected services 26 // references to injected services
27 var $scope, $log, fs, mast, ks, zs, 27 var $scope, $log, fs, mast, ks, zs,
28 - gs, sus, ps, t2es, t2fs, t2is, t2bcs, t2kcs, t2ms, t2mcs; 28 + gs, sus, ps, t2es, t2fs, t2is, t2bcs, t2kcs, t2ms, t2mcs, t2zs;
29 29
30 // DOM elements 30 // DOM elements
31 var ovtopo2, svg, defs, zoomLayer, forceG; 31 var ovtopo2, svg, defs, zoomLayer, forceG;
...@@ -63,14 +63,12 @@ ...@@ -63,14 +63,12 @@
63 tr = zoomer.translate(); 63 tr = zoomer.translate();
64 64
65 ps.setPrefs('topo_zoom', { tx: tr[0], ty: tr[1], sc: sc }); 65 ps.setPrefs('topo_zoom', { tx: tr[0], ty: tr[1], sc: sc });
66 -
67 - // keep the map lines constant width while zooming
68 - // mapG.style('stroke-width', (2.0 / sc) + 'px');
69 } 66 }
70 67
71 function setUpZoom() { 68 function setUpZoom() {
72 zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer'); 69 zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer');
73 - zoomer = zs.createZoomer({ 70 +
71 + zoomer = t2zs.createZoomer({
74 svg: svg, 72 svg: svg,
75 zoomLayer: zoomLayer, 73 zoomLayer: zoomLayer,
76 zoomEnabled: zoomEnabled, 74 zoomEnabled: zoomEnabled,
...@@ -88,14 +86,14 @@ ...@@ -88,14 +86,14 @@
88 'WebSocketService', 'PrefsService', 'ThemeService', 86 'WebSocketService', 'PrefsService', 'ThemeService',
89 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService', 87 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService',
90 'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService', 88 'Topo2BreadcrumbService', 'Topo2KeyCommandService', 'Topo2MapService',
91 - 'Topo2MapConfigService', 'Topo2SummaryPanelService', 89 + 'Topo2MapConfigService', 'Topo2SummaryPanelService', 'Topo2ZoomService',
92 90
93 function (_$scope_, _$log_, _$loc_, 91 function (_$scope_, _$log_, _$loc_,
94 _fs_, _mast_, _ks_, _zs_, 92 _fs_, _mast_, _ks_, _zs_,
95 _gs_, _ms_, _sus_, _flash_, 93 _gs_, _ms_, _sus_, _flash_,
96 _wss_, _ps_, _th_, 94 _wss_, _ps_, _th_,
97 _t2es_, _t2fs_, _t2is_, _t2bcs_, _t2kcs_, _t2ms_, _t2mcs_, 95 _t2es_, _t2fs_, _t2is_, _t2bcs_, _t2kcs_, _t2ms_, _t2mcs_,
98 - summaryPanel 96 + summaryPanel, _t2zs_
99 ) { 97 ) {
100 98
101 var params = _$loc_.search(), 99 var params = _$loc_.search(),
...@@ -131,6 +129,7 @@ ...@@ -131,6 +129,7 @@
131 t2kcs = _t2kcs_; 129 t2kcs = _t2kcs_;
132 t2ms = _t2ms_; 130 t2ms = _t2ms_;
133 t2mcs = _t2mcs_; 131 t2mcs = _t2mcs_;
132 + t2zs = _t2zs_;
134 133
135 // capture selected intent parameters (if they are set in the 134 // capture selected intent parameters (if they are set in the
136 // query string) so that the traffic overlay can highlight 135 // query string) so that the traffic overlay can highlight
...@@ -189,7 +188,6 @@ ...@@ -189,7 +188,6 @@
189 // Now the map has load and we have a projection we can 188 // Now the map has load and we have a projection we can
190 // get the info from the server 189 // get the info from the server
191 t2es.start(); 190 t2es.start();
192 -
193 } 191 }
194 ); 192 );
195 193
......
...@@ -194,14 +194,14 @@ ...@@ -194,14 +194,14 @@
194 var allNodes = t2rs.regionNodes(); 194 var allNodes = t2rs.regionNodes();
195 angular.forEach(allNodes, function (node) { 195 angular.forEach(allNodes, function (node) {
196 node.update(); 196 node.update();
197 - }) 197 + });
198 } 198 }
199 199
200 angular.module('ovTopo2') 200 angular.module('ovTopo2')
201 .factory('Topo2ForceService', 201 .factory('Topo2ForceService',
202 ['$log', 'WebSocketService', 'Topo2InstanceService', 'Topo2RegionService', 202 ['$log', 'WebSocketService', 'Topo2InstanceService', 'Topo2RegionService',
203 - 'Topo2LayoutService', 'Topo2ViewService', 'Topo2BreadcrumbService', 203 + 'Topo2LayoutService', 'Topo2ViewService', 'Topo2BreadcrumbService', 'Topo2ZoomService',
204 - function (_$log_, _wss_, _t2is_, _t2rs_, _t2ls_, _t2vs_, _t2bcs_) { 204 + function (_$log_, _wss_, _t2is_, _t2rs_, _t2ls_, _t2vs_, _t2bcs_, zoomService) {
205 205
206 $log = _$log_; 206 $log = _$log_;
207 wss = _wss_; 207 wss = _wss_;
...@@ -211,6 +211,19 @@ ...@@ -211,6 +211,19 @@
211 t2vs = _t2vs_; 211 t2vs = _t2vs_;
212 t2bcs = _t2bcs_; 212 t2bcs = _t2bcs_;
213 213
214 + var onZoom = function () {
215 + var nodes = [].concat(
216 + t2rs.regionNodes(),
217 + t2rs.regionLinks()
218 + );
219 +
220 + angular.forEach(nodes, function (node) {
221 + node.setScale();
222 + });
223 + };
224 +
225 + zoomService.addZoomEventListener(onZoom);
226 +
214 return { 227 return {
215 228
216 init: init, 229 init: init,
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
23 'use strict'; 23 'use strict';
24 24
25 var $log; 25 var $log;
26 - var Collection, Model, ts, sus; 26 + var Collection, Model, ts, sus, t2zs;
27 27
28 var linkLabelOffset = '0.35em'; 28 var linkLabelOffset = '0.35em';
29 29
...@@ -171,7 +171,9 @@ ...@@ -171,7 +171,9 @@
171 rect = el.append('rect'), 171 rect = el.append('rect'),
172 text = el.append('text').text(d.num); 172 text = el.append('text').text(d.num);
173 173
174 - rect.attr(rectAroundText(el)) 174 + var rectSize = rectAroundText(el);
175 +
176 + rect.attr(rectSize)
175 .attr('rx', 2) 177 .attr('rx', 2)
176 .attr('ry', 2); 178 .attr('ry', 2);
177 179
...@@ -211,7 +213,6 @@ ...@@ -211,7 +213,6 @@
211 type = this.get('type'), 213 type = this.get('type'),
212 online = this.online(), 214 online = this.online(),
213 modeCls = this.expected() ? 'inactive' : 'not-permitted', 215 modeCls = this.expected() ? 'inactive' : 'not-permitted',
214 - lw = 1.2,
215 delay = immediate ? 0 : 1000; 216 delay = immediate ? 0 : 1000;
216 217
217 // NOTE: understand why el is sometimes undefined on addLink events... 218 // NOTE: understand why el is sometimes undefined on addLink events...
...@@ -230,7 +231,7 @@ ...@@ -230,7 +231,7 @@
230 } 231 }
231 el.transition() 232 el.transition()
232 .duration(delay) 233 .duration(delay)
233 - .attr('stroke-width', linkScale(lw)) 234 + .attr('stroke-width', linkScale(widthRatio))
234 .attr('stroke', linkConfig[th].baseColor); 235 .attr('stroke', linkConfig[th].baseColor);
235 } 236 }
236 }, 237 },
...@@ -243,6 +244,10 @@ ...@@ -243,6 +244,10 @@
243 if (this.get('type') === 'hostLink') { 244 if (this.get('type') === 'hostLink') {
244 // sus.visible(link, api.showHosts()); 245 // sus.visible(link, api.showHosts());
245 } 246 }
247 + },
248 + setScale: function () {
249 + var width = linkScale(widthRatio / t2zs.scale());
250 + this.el.style('stroke-width', width + 'px');
246 } 251 }
247 }); 252 });
248 253
...@@ -256,13 +261,14 @@ ...@@ -256,13 +261,14 @@
256 angular.module('ovTopo2') 261 angular.module('ovTopo2')
257 .factory('Topo2LinkService', 262 .factory('Topo2LinkService',
258 ['$log', 'Topo2Collection', 'Topo2Model', 263 ['$log', 'Topo2Collection', 'Topo2Model',
259 - 'ThemeService', 'SvgUtilService', 264 + 'ThemeService', 'SvgUtilService', 'Topo2ZoomService',
260 265
261 - function (_$log_, _Collection_, _Model_, _ts_, _sus_) { 266 + function (_$log_, _Collection_, _Model_, _ts_, _sus_, _t2zs_) {
262 267
263 $log = _$log_; 268 $log = _$log_;
264 ts = _ts_; 269 ts = _ts_;
265 sus = _sus_; 270 sus = _sus_;
271 + t2zs = _t2zs_;
266 Collection = _Collection_; 272 Collection = _Collection_;
267 Model = _Model_; 273 Model = _Model_;
268 274
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
29 var nearDist = 15; 29 var nearDist = 15;
30 30
31 var devIconDim = 36, 31 var devIconDim = 36,
32 + devIconDimMin = 20,
33 + devIconDimMax = 40,
32 labelPad = 5, 34 labelPad = 5,
33 textPad = 5, 35 textPad = 5,
34 halfDevIcon = devIconDim / 2; 36 halfDevIcon = devIconDim / 2;
...@@ -143,9 +145,9 @@ ...@@ -143,9 +145,9 @@
143 .factory('Topo2NodeModel', 145 .factory('Topo2NodeModel',
144 ['Topo2Model', 'FnService', 'RandomService', 'Topo2PrefsService', 146 ['Topo2Model', 'FnService', 'RandomService', 'Topo2PrefsService',
145 'SvgUtilService', 'IconService', 'ThemeService', 147 'SvgUtilService', 'IconService', 'ThemeService',
146 - 'Topo2MapConfigService', 148 + 'Topo2MapConfigService', 'Topo2ZoomService',
147 function (Model, _fn_, _RandomService_, _ps_, _sus_, _is_, _ts_, 149 function (Model, _fn_, _RandomService_, _ps_, _sus_, _is_, _ts_,
148 - _t2mcs_) { 150 + _t2mcs_, zoomService) {
149 151
150 randomService = _RandomService_; 152 randomService = _RandomService_;
151 ts = _ts_; 153 ts = _ts_;
...@@ -268,6 +270,20 @@ ...@@ -268,6 +270,20 @@
268 this.el = d3.select(el); 270 this.el = d3.select(el);
269 this.render(); 271 this.render();
270 }, 272 },
273 + setScale: function () {
274 +
275 + var dim = devIconDim,
276 + multipler = 1;
277 +
278 + if (dim * zoomService.scale() < devIconDimMin) {
279 + multipler = devIconDimMin / (dim * zoomService.scale());
280 + } else if (dim * zoomService.scale() > devIconDimMax) {
281 + multipler = devIconDimMax / (dim * zoomService.scale());
282 + }
283 +
284 +
285 + this.el.selectAll('*').style('transform', 'scale(' + multipler + ')');
286 + },
271 render: function () { 287 render: function () {
272 var node = this.el, 288 var node = this.el,
273 glyphId = this.icon(this.get('type')), 289 glyphId = this.icon(this.get('type')),
...@@ -289,6 +305,8 @@ ...@@ -289,6 +305,8 @@
289 if (this.events) { 305 if (this.events) {
290 this.setUpEvents(); 306 this.setUpEvents();
291 } 307 }
308 +
309 + this.setScale();
292 } 310 }
293 }); 311 });
294 }] 312 }]
......
1 +/*
2 + * Copyright 2016-present 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 Breadcrumb Module.
19 + Module that renders the breadcrumbs for regions
20 + */
21 +
22 +(function () {
23 +
24 + 'use strict';
25 +
26 + var zs, ps;
27 + var zoomer;
28 + var zoomEventListeners = [];
29 +
30 + function createZoomer(options) {
31 + var settings = angular.extend({}, options, {
32 + zoomCallback: zoomCallback
33 + });
34 +
35 + zoomer = zs.createZoomer(settings);
36 + return zoomer;
37 + }
38 +
39 + function zoomCallback() {
40 + var sc = zoomer.scale(),
41 + tr = zoomer.translate();
42 +
43 + ps.setPrefs('topo_zoom', { tx: tr[0], ty: tr[1], sc: sc });
44 +
45 + angular.forEach(zoomEventListeners, function (ev) {
46 + ev(zoomer);
47 + });
48 + }
49 +
50 + function findZoomEventListener(ev) {
51 + for (var i = 0, l = zoomEventListeners.length; i < l; i++) {
52 + if (zoomEventListeners[i] === ev) return i;
53 + }
54 +
55 + return -1;
56 + }
57 +
58 + function addZoomEventListener(callback) {
59 + zoomEventListeners.push(callback);
60 + }
61 +
62 + function removeZoomEventListener(callback) {
63 +
64 + var evIndex = findZoomEventListener(callback);
65 +
66 + if (evIndex !== -1) {
67 + zoomEventListeners.splice(evIndex);
68 + }
69 + }
70 +
71 + function scale() {
72 + return zoomer.scale();
73 + }
74 +
75 + angular.module('ovTopo2')
76 + .factory('Topo2ZoomService',
77 + ['ZoomService', 'PrefsService',
78 + function (_zs_, _ps_) {
79 +
80 + zs = _zs_;
81 + ps = _ps_;
82 +
83 + return {
84 + createZoomer: createZoomer,
85 + addZoomEventListener: addZoomEventListener,
86 + removeZoomEventListener: removeZoomEventListener,
87 +
88 + scale: scale
89 + };
90 + }]);
91 +})();
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
126 <link rel="stylesheet" href="app/fw/widget/table-theme.css"> 126 <link rel="stylesheet" href="app/fw/widget/table-theme.css">
127 127
128 <!-- Under development for Region support. --> 128 <!-- Under development for Region support. -->
129 -<!-- <script src="app/view/topo2/topo2.js"></script> 129 + <!--<script src="app/view/topo2/topo2.js"></script>
130 <script src="app/view/topo2/topo2Breadcrumb.js"></script> 130 <script src="app/view/topo2/topo2Breadcrumb.js"></script>
131 <script src="app/view/topo2/topo2Collection.js"></script> 131 <script src="app/view/topo2/topo2Collection.js"></script>
132 <script src="app/view/topo2/topo2D3.js"></script> 132 <script src="app/view/topo2/topo2D3.js"></script>
...@@ -153,10 +153,11 @@ ...@@ -153,10 +153,11 @@
153 <script src="app/view/topo2/topo2SubRegion.js"></script> 153 <script src="app/view/topo2/topo2SubRegion.js"></script>
154 <script src="app/view/topo2/topo2Theme.js"></script> 154 <script src="app/view/topo2/topo2Theme.js"></script>
155 <script src="app/view/topo2/topo2View.js"></script> 155 <script src="app/view/topo2/topo2View.js"></script>
156 + <script src="app/view/topo2/topo2Zoom.js"></script>
156 <link rel="stylesheet" href="app/view/topo2/topo2.css"> 157 <link rel="stylesheet" href="app/view/topo2/topo2.css">
157 - <link rel="stylesheet" href="app/view/topo2/topo2-theme.css"> 158 + <link rel="stylesheet" href="app/view/topo2/topo2-theme.css">-->
158 159
159 - <script src="app/view/topoX/topoX.js"></script> 160 + <!-- <script src="app/view/topoX/topoX.js"></script>
160 <script src="app/view/topoX/topoXEvent.js"></script> 161 <script src="app/view/topoX/topoXEvent.js"></script>
161 <script src="app/view/topoX/topoXForce.js"></script> 162 <script src="app/view/topoX/topoXForce.js"></script>
162 <link rel="stylesheet" href="app/view/topoX/topoX.css"> 163 <link rel="stylesheet" href="app/view/topoX/topoX.css">
......