blob: a5bec59b8e9af93d2f35106032331aba28d5278f [file] [log] [blame]
Simon Huntef31fb22014-12-19 13:16:44 -08001/*
Simon Hunt8ead3a22015-01-06 11:00:15 -08002 * Copyright 2014,2015 Open Networking Laboratory
Simon Huntef31fb22014-12-19 13:16:44 -08003 *
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 View Module
19
20 @author Simon Hunt
21 */
22
23(function () {
24 'use strict';
Simon Hunt6cc53692015-01-07 11:33:45 -080025
26 var moduleDependencies = [
27 'onosUtil',
28 'onosSvg'
29 ];
30
31 // references to injected services etc.
Simon Hunt1e8eff42015-01-08 17:19:02 -080032 var $log, ks, zs, gs, ms;
Simon Hunt6cc53692015-01-07 11:33:45 -080033
34 // DOM elements
Simon Hunta7b6a6b2015-01-13 19:53:09 -080035 var svg, defs, zoomLayer, map;
Simon Hunt6cc53692015-01-07 11:33:45 -080036
37 // Internal state
Simon Huntcacce342015-01-07 16:13:05 -080038 var zoomer;
Simon Hunt6cc53692015-01-07 11:33:45 -080039
40 // Note: "exported" state should be properties on 'self' variable
41
Simon Huntcacce342015-01-07 16:13:05 -080042 // --- Short Cut Keys ------------------------------------------------
43
Simon Hunt6cc53692015-01-07 11:33:45 -080044 var keyBindings = {
Simon Huntcacce342015-01-07 16:13:05 -080045 W: [logWarning, '(temp) log a warning'],
46 E: [logError, '(temp) log an error'],
47 R: [resetZoom, 'Reset pan / zoom']
Simon Hunt6cc53692015-01-07 11:33:45 -080048 };
49
50 // -----------------
51 // these functions are necessarily temporary examples....
52 function logWarning() {
53 $log.warn('You have been warned!');
54 }
55 function logError() {
56 $log.error('You are erroneous!');
57 }
58 // -----------------
59
Simon Huntcacce342015-01-07 16:13:05 -080060 function resetZoom() {
61 zoomer.reset();
62 }
63
Simon Hunt6cc53692015-01-07 11:33:45 -080064 function setUpKeys() {
65 ks.keyBindings(keyBindings);
66 }
67
Simon Huntcacce342015-01-07 16:13:05 -080068
69 // --- Glyphs, Icons, and the like -----------------------------------
70
Simon Hunt6cc53692015-01-07 11:33:45 -080071 function setUpDefs() {
Simon Huntcacce342015-01-07 16:13:05 -080072 defs = svg.append('defs');
Simon Hunt6cc53692015-01-07 11:33:45 -080073 gs.loadDefs(defs);
74 }
75
76
Simon Huntcacce342015-01-07 16:13:05 -080077 // --- Pan and Zoom --------------------------------------------------
78
79 // zoom enabled predicate. ev is a D3 source event.
80 function zoomEnabled(ev) {
81 return (ev.metaKey || ev.altKey);
82 }
83
84 function zoomCallback() {
85 var tr = zoomer.translate(),
86 sc = zoomer.scale();
87 $log.log('ZOOM: translate = ' + tr + ', scale = ' + sc);
88
89 // TODO: keep the map lines constant width while zooming
90 //bgImg.style('stroke-width', 2.0 / scale + 'px');
91 }
92
93 function setUpZoom() {
Simon Hunta7b6a6b2015-01-13 19:53:09 -080094 zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer');
Simon Huntcacce342015-01-07 16:13:05 -080095 zoomer = zs.createZoomer({
96 svg: svg,
97 zoomLayer: zoomLayer,
98 zoomEnabled: zoomEnabled,
99 zoomCallback: zoomCallback
100 });
101 }
102
103
Simon Hunta7b6a6b2015-01-13 19:53:09 -0800104 // --- Background Map ------------------------------------------------
105
106 function setUpMap() {
107 map = zoomLayer.append('g').attr('id', '#topo-map');
108 ms.loadMapInto(map, '*continental_us');
109 }
110
Simon Huntcacce342015-01-07 16:13:05 -0800111 // --- Controller Definition -----------------------------------------
112
Simon Hunt6cc53692015-01-07 11:33:45 -0800113 angular.module('ovTopo', moduleDependencies)
114
115 .controller('OvTopoCtrl', [
Simon Hunt1e8eff42015-01-08 17:19:02 -0800116 '$log', 'KeyService', 'ZoomService', 'GlyphService', 'MapService',
Simon Hunt6cc53692015-01-07 11:33:45 -0800117
Simon Hunt1e8eff42015-01-08 17:19:02 -0800118 function (_$log_, _ks_, _zs_, _gs_, _ms_) {
Simon Hunt6cc53692015-01-07 11:33:45 -0800119 var self = this;
Simon Hunt6cc53692015-01-07 11:33:45 -0800120 $log = _$log_;
121 ks = _ks_;
Simon Huntcacce342015-01-07 16:13:05 -0800122 zs = _zs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800123 gs = _gs_;
Simon Hunt1e8eff42015-01-08 17:19:02 -0800124 ms = _ms_;
Simon Huntef31fb22014-12-19 13:16:44 -0800125
Simon Huntcacce342015-01-07 16:13:05 -0800126 // exported state
Simon Huntef31fb22014-12-19 13:16:44 -0800127 self.message = 'Topo View Rocks!';
128
Simon Huntcacce342015-01-07 16:13:05 -0800129 // svg layer and initialization of components
130 svg = d3.select('#ov-topo svg');
Simon Hunt6cc53692015-01-07 11:33:45 -0800131 setUpKeys();
132 setUpDefs();
Simon Huntcacce342015-01-07 16:13:05 -0800133 setUpZoom();
Simon Hunta7b6a6b2015-01-13 19:53:09 -0800134 setUpMap();
Simon Hunt6cc53692015-01-07 11:33:45 -0800135
136 $log.log('OvTopoCtrl has been created');
Simon Huntef31fb22014-12-19 13:16:44 -0800137 }]);
138}());