blob: 171e33ef53d84ba14acc9503cd96d76f227108e3 [file] [log] [blame]
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -08001// path painter topology overlay - client side
2//
3// This is the glue that binds our business logic (in ppTopovDemo.js)
4// to the overlay framework.
5
6(function () {
7 'use strict';
8
9 // injected refs
10 var $log, tov, pps;
11
12 // internal state should be kept in the service module (not here)
13 var selection;
14
15 // our overlay definition
16 var overlay = {
17 // NOTE: this must match the ID defined in AppUiTopovOverlay
18 overlayId: 'pp-overlay',
Andrea Campanella0c17a0a2015-12-01 09:53:51 -080019 glyphId: 'topo',
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080020 tooltip: 'Path Painter Topo Overlay',
21
22 // These glyphs get installed using the overlayId as a prefix.
Andrea Campanella8583e6b2015-12-01 21:24:45 -080023 // e.g. 'src' is installed as 'pp-overlay-src'
24 // They can be referenced (from this overlay) as '*src'
25 // That is, the '*' prefix stands in for 'pp-overlay-'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080026 glyphs: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -080027 src: {
28 vb: '0 0 110 110',
Andrea Campanella490e8392015-12-03 12:18:11 -080029 d: 'M28.7,59.3 M14.9,53 M8.7,39 M32.4,92.5H25l-0.2-3.6' +
30 'c-0.5-9-5.4-23.9-12.9-33.5c-5.2-6.6-7-12.8-7-16.3c0-13.3,10.7-24,23.8-24c13.1,0,23.8,10.8,23.8,24c0,3.5-1.8,9.7-7,16.3' +
31 'C38,65,33.1,80,32.6,88.9L32.4,92.5z M27.9,89.5h1.7l0-0.7c0.5-9.4,5.7-25.2,13.5-35.2c4.7-6,6.4-11.4,6.4-14.5' +
32 'c0-11.6-9.3-21-20.8-21C17.3,18,7.9,27.5,7.9,39c0,3,1.7,8.4,6.4,14.5c7.9,10.1,13.1,25.8,13.5,35.2L27.9,89.5z M28.7,83.2' +
33 'M28.6,29.8c-4.7,0-8.5,3.8-8.5,8.5c0,4.7,3.8,8.5,8.5,8.5s8.5-3.8,8.5-8.5C37.1,33.6,33.3,29.8,28.6,29.8z M89.6,47 M89.6,29.5' +
34 'c-0.1,3.1-0.1,12.8,0,17c0.1,4.2,14.1-5.5,13.9-8.5C103.4,35.1,89.6,25.6,89.6,29.5z M51,38.1L89.5,38 M89.5,39.5l0-3L51,36.5l0,3' +
35 'L89.5,39.5z'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080036 },
Andrea Campanella8583e6b2015-12-01 21:24:45 -080037 dst: {
38 vb: '0 0 110 110',
Andrea Campanella490e8392015-12-03 12:18:11 -080039 d: 'M80.3,59.8 M85.8,92.5h-7.2L78.4,89c-0.4-8.8-5.2-23.6-12.3-33' +
40 'c-4.9-6.5-6.7-12.5-6.7-16c0-13,10.2-23.7,22.7-23.7c12.5,0,22.7,10.6,22.7,23.7c0,3.5-1.8,9.5-6.7,16C91.2,65.4,86.4,80.1,86,89' +
41 'L85.8,92.5z M81.4,89.5H83l0-0.7c0.5-9.3,5.4-24.8,12.9-34.7c4.5-5.9,6.1-11.2,6.1-14.2c0-11.4-8.9-20.7-19.8-20.7' +
42 'c-10.9,0-19.8,9.3-19.8,20.7c0,3,1.6,8.3,6.1,14.2C76,64,80.9,79.5,81.4,88.8L81.4,89.5z M82.1,30.8c-4.5,0-8.1,3.7-8.1,8.4' +
43 's3.6,8.4,8.1,8.4c4.5,0,8.1-3.7,8.1-8.4S86.6,30.8,82.1,30.8z M47.2,47.5 M45.2,30.8c-0.1,3.1-0.1,12.6,0,16.7' +
44 'c0.1,4.1,13.4-5.4,13.3-8.4C58.4,36.2,45.2,26.9,45.2,30.8z M45.2,39.1L6.7,39.2 M45.2,40.6l0-3L6.7,37.7l0,3L45.2,40.6z'
Andrea Campanella8583e6b2015-12-01 21:24:45 -080045 },
46 jp: {
47 vb: '0 0 110 110',
Andrea Campanella490e8392015-12-03 12:18:11 -080048 d: 'M84.3,89.3L58.9,64.2l-1.4,1.4L83,90.7L84.3,89.3z M27,7.6H7.4v19.2H27V7.6z' +
49 'M59.3,47.1H39.8v19.2h19.5V47.1z M102.1,79.5H82.6v19.2h19.5V79.5z M41.7,47.6L19,25.1l-1.2,1.2l22.7,22.5L41.7,47.6z'
Andrea Campanella8583e6b2015-12-01 21:24:45 -080050 },
51 djp: {
52 vb: '0 0 110 110',
Andrea Campanella490e8392015-12-03 12:18:11 -080053 d: 'M25.8,84l-9.2-57 M27.3,83.8l-9.2-57l-3,0.5l9.2,57L27.3,83.8z M83.2,37.7L26.8,15.5 M83.7,36.1L26.6,14' +
54 'l-1,3.2l57,22.1L83.7,36.1z M34.1,95l61.4-40.6 M96.4,55.7l-1.9-2.5L33.2,93.8l1.9,2.5L96.4,55.7z M26.6,27.6H6.7V7.7h19.9V27.6z' +
55 'M102.1,36H82.2v19.9h19.9V36z M35.3,83.5H15.3v19.9h19.9V83.5z'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080056 }
Andrea Campanella8583e6b2015-12-01 21:24:45 -080057
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080058 },
59
60 activate: function () {
61 $log.debug("Path painter topology overlay ACTIVATED");
62 },
63 deactivate: function () {
64 $log.debug("Path painter topology overlay DEACTIVATED");
65 },
66
67 // detail panel button definitions
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080068 buttons: {
69 src: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -080070 gid: '*src',
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080071 tt: 'Set source node',
72 cb: function (data) {
73 $log.debug('Set src action invoked with data:', data);
74 pps.setSrc(selection);
75 }
76 },
77 dst: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -080078 gid: '*dst',
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080079 tt: 'Set destination node',
80 cb: function (data) {
81 $log.debug('Set dst action invoked with data:', data);
82 pps.setDst(selection);
83 }
84 }
85 },
86
87 // Key bindings for traffic overlay buttons
88 // NOTE: fully qual. button ID is derived from overlay-id and key-name
89 // FIXME: use into [ and ] instead of 1 and 2
Andrea Campanella8583e6b2015-12-01 21:24:45 -080090 // FIXME: find better keys for shortest paths & disjoint paths modes
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080091 keyBindings: {
92 1: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -080093 cb: function () {
94 pps.setSrc(selection);
95 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080096 tt: 'Set source node',
Andrea Campanella8583e6b2015-12-01 21:24:45 -080097 gid: '*src'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080098 },
99 2: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800100 cb: function () {
101 pps.setDst(selection);
102 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800103 tt: 'Set destination node',
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800104 gid: '*dst'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800105 },
Andrea Campanella0c17a0a2015-12-01 09:53:51 -0800106 3: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800107 cb: function () {
108 pps.swapSrcDst();
109 },
Andrea Campanella0c17a0a2015-12-01 09:53:51 -0800110 tt: 'Swap source and destination nodes',
111 gid: 'refresh'
112 },
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800113 4: {
114 cb: function () {
115 pps.setMode("shortest");
116 },
117 tt: 'Set shortest paths mode',
118 gid: '*jp'
119 },
120 5: {
121 cb: function () {
122 pps.setMode("disjoint");
123 },
124 tt: 'Set disjoint paths mode',
125 gid: '*djp'
126 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800127 leftArrow: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800128 cb: function () {
129 pps.prevPath();
130 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800131 tt: 'Highlight previous path',
132 gid: 'prevIntent'
133 },
134 rightArrow: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800135 cb: function () {
136 pps.nextPath();
137 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800138 tt: 'Highlight next path',
139 gid: 'nextIntent'
140 },
141
142 _keyOrder: [
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800143 '1', '2', '3', '4', '5', 'leftArrow', 'rightArrow'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800144 ]
145 },
146
147 hooks: {
148 // hook for handling escape key
149 // Must return true to consume ESC, false otherwise.
150 escape: function () {
151 selectionCallback();
152 pps.setSrc();
153 pps.setDst();
154 },
155
156 // hooks for when the selection changes...
157 empty: function () {
158 selectionCallback();
159 },
160 single: function (data) {
161 selectionCallback(data);
162 }
163 }
164 };
165
166
167 function buttonCallback(x) {
168 $log.debug('Toolbar-button callback', x);
169 }
170
171 function selectionCallback(d) {
172 $log.debug('Selection callback', d);
173 selection = d;
174 }
175
176 // invoke code to register with the overlay service
177 angular.module('ovPpTopov')
178 .run(['$log', 'TopoOverlayService', 'PathPainterTopovService',
179
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800180 function (_$log_, _tov_, _pps_) {
181 $log = _$log_;
182 tov = _tov_;
183 pps = _pps_;
184 tov.register(overlay);
185 }]);
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800186
187}());