blob: 603a5a1014b346962d5e67e0c3574f467a904a56 [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 Huntcacce342015-01-07 16:13:05 -080032 var $log, ks, zs, gs;
Simon Hunt6cc53692015-01-07 11:33:45 -080033
34 // DOM elements
Simon Huntcacce342015-01-07 16:13:05 -080035 var svg, defs;
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() {
94 var zoomLayer = svg.append('g').attr('id', 'topo-zoomlayer');
95 zoomer = zs.createZoomer({
96 svg: svg,
97 zoomLayer: zoomLayer,
98 zoomEnabled: zoomEnabled,
99 zoomCallback: zoomCallback
100 });
101 }
102
103
104 // --- Controller Definition -----------------------------------------
105
Simon Hunt6cc53692015-01-07 11:33:45 -0800106 angular.module('ovTopo', moduleDependencies)
107
108 .controller('OvTopoCtrl', [
Simon Huntcacce342015-01-07 16:13:05 -0800109 '$log', 'KeyService', 'ZoomService', 'GlyphService',
Simon Hunt6cc53692015-01-07 11:33:45 -0800110
Simon Huntcacce342015-01-07 16:13:05 -0800111 function (_$log_, _ks_, _zs_, _gs_) {
Simon Hunt6cc53692015-01-07 11:33:45 -0800112 var self = this;
Simon Hunt6cc53692015-01-07 11:33:45 -0800113 $log = _$log_;
114 ks = _ks_;
Simon Huntcacce342015-01-07 16:13:05 -0800115 zs = _zs_;
Simon Hunt6cc53692015-01-07 11:33:45 -0800116 gs = _gs_;
Simon Huntef31fb22014-12-19 13:16:44 -0800117
Simon Huntcacce342015-01-07 16:13:05 -0800118 // exported state
Simon Huntef31fb22014-12-19 13:16:44 -0800119 self.message = 'Topo View Rocks!';
120
Simon Huntcacce342015-01-07 16:13:05 -0800121 // svg layer and initialization of components
122 svg = d3.select('#ov-topo svg');
Simon Hunt6cc53692015-01-07 11:33:45 -0800123 setUpKeys();
124 setUpDefs();
Simon Huntcacce342015-01-07 16:13:05 -0800125 setUpZoom();
Simon Hunt6cc53692015-01-07 11:33:45 -0800126
127 $log.log('OvTopoCtrl has been created');
Simon Huntef31fb22014-12-19 13:16:44 -0800128 }]);
129}());