blob: 35520343c073faed408a526a7414b15105f2c5eb [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',
29 d: 'M26.9,57 M27,86c0.5-9.6,5.8-25.3,13.6-35.2c4.2-5.4,6.2-10.6,6.2-13.8' +
30 'c0-11-8.9-20-19.9-20h0C15.9,17,7,26,7,37c0,3.2,1.9,8.4,6.2,13.8c7.8,9.9,13.1,25.5,13.6,35.2H27z M27.7,86.7l0-0.7' +
31 'c0.5-9.3,5.6-24.8,13.4-34.7c4.7-5.9,6.3-11.3,6.3-14.3c0-11.4-9.3-20.7-20.6-20.7C15.5,16.3,6.2,25.6,6.2,37c0,3,1.7,8.3,6.3,14.3' +
32 'c7.8,9.9,13,25.5,13.4,34.7l0,0.7H27.7L27.7,86.7z M26.9,17.8C37.4,17.8,46,26.4,46,37c0,2.6-1.6,7.7-6,13.3' +
33 'c-6.6,8.4-11.4,20.8-13.1,30.2c-1.7-9.4-6.5-21.8-13.1-30.2c-4.4-5.6-6-10.7-6-13.3C7.7,26.4,16.3,17.8,26.9,17.8L26.9,17.8z' +
34 'M87.3,35.5H46.9v2h40.4V35.5z M26.8,27.9c-4.7,0-8.4,3.8-8.4,8.4c0,4.6,3.8,8.4,8.4,8.4s8.4-3.7,8.4-8.4' +
35 'C35.2,31.6,31.4,27.9,26.8,27.9z M87.3,44.9 M87.3,28.1c-0.1,3.1-0.1,12.6,0,16.7c0.1,4.1,13.9-5.5,13.8-8.4' +
36 'C101,33.6,87.3,24.2,87.3,28.1z'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080037 },
Andrea Campanella8583e6b2015-12-01 21:24:45 -080038 dst: {
39 vb: '0 0 110 110',
40 d: 'M80.6,57 M80.7,86c0.5-9.6,5.8-25.3,13.5-35.2c4.2-5.4,6.1-10.6,6.1-13.8' +
41 'c0-11-8.8-20-19.7-20h0C69.7,17,60.8,26,60.8,37c0,3.2,1.9,8.4,6.1,13.8c7.7,9.9,13,25.5,13.5,35.2H80.7z M81.4,86.7l0-0.7' +
42 'c0.5-9.3,5.6-24.8,13.4-34.7c4.6-5.9,6.3-11.3,6.3-14.3c0-11.4-9.2-20.7-20.5-20.7S60.1,25.6,60.1,37c0,3,1.7,8.3,6.3,14.3' +
43 'c7.8,9.9,12.9,25.5,13.4,34.7l0,0.7H81.4L81.4,86.7z M80.6,17.8c10.5,0,19,8.6,19,19.2c0,2.6-1.6,7.7-6,13.3' +
44 'c-6.6,8.4-11.3,20.8-13,30.2c-1.7-9.4-6.4-21.8-13-30.2c-4.4-5.6-6-10.7-6-13.3C61.6,26.4,70.1,17.8,80.6,17.8L80.6,17.8z' +
45 'M46.3,35.2H6.2v2h40.1V35.2z M80.5,27.9c-4.6,0-8.4,3.7-8.4,8.4c0,4.6,3.7,8.4,8.4,8.4s8.4-3.7,8.4-8.4' +
46 'C88.9,31.6,85.1,27.9,80.5,27.9z M46.3,44.6 M46.3,27.9c-0.1,3.1-0.1,12.6,0,16.7c0.1,4.1,13.9-5.5,13.7-8.4' +
47 'C60,33.3,46.3,24,46.3,27.9z'
48 },
49 jp: {
50 vb: '0 0 110 110',
51 d: 'M27,26.8H7.4V7.6H27V26.8z M102.1,79.5H82.6v19.2h19.5V79.5z M59.3,47.1H39.8v19.2' +
52 'h19.5V47.1z M41.7,47.5L17.1,25.2l-1.3,1.4l24.6,22.3L41.7,47.5z M84.5,89.5L59,64.3l-1.4,1.4l25.4,25.2L84.5,89.5z'
53 },
54 djp: {
55 vb: '0 0 110 110',
56 d: 'M27.6,28.8H7.7V9h19.9V28.8z M103,37.2H83.1V57H103V37.2z M36.2,84.5H16.3v19.9' +
57 'h19.9V84.5z M27.9,85.7L18.7,28l-2,0.3L25.9,86L27.9,85.7z M92.2,59.1L91,57.4L34.6,96.8l1.1,1.6L92.2,59.1z M28.5,80.7' +
58 'c-0.8,0.2-3.5,0.7-4.6,1c-1.1,0.3,2.2,3.1,3,2.9S29.6,80.5,28.5,80.7z M88.8,57.5c0.5,0.7,2,2.9,2.7,3.8c0.7,0.9,2-3.2,1.5-3.9' +
59 'C92.5,56.8,88.2,56.6,88.8,57.5z M97.7,42.5L27.2,17.9l-0.7,1.9l70.5,24.6L97.7,42.5z M30.7,22.6c0.3-0.8,1.2-3.3,1.5-4.4' +
60 'c0.4-1.1-3.8,0.3-4,1.1C27.9,20.1,30.3,23.7,30.7,22.6z'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080061 }
Andrea Campanella8583e6b2015-12-01 21:24:45 -080062
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080063 },
64
65 activate: function () {
66 $log.debug("Path painter topology overlay ACTIVATED");
67 },
68 deactivate: function () {
69 $log.debug("Path painter topology overlay DEACTIVATED");
70 },
71
72 // detail panel button definitions
73 // FIXME: new icons for src/dst
74 buttons: {
75 src: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -080076 gid: '*src',
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080077 tt: 'Set source node',
78 cb: function (data) {
79 $log.debug('Set src action invoked with data:', data);
80 pps.setSrc(selection);
81 }
82 },
83 dst: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -080084 gid: '*dst',
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080085 tt: 'Set destination node',
86 cb: function (data) {
87 $log.debug('Set dst action invoked with data:', data);
88 pps.setDst(selection);
89 }
90 }
91 },
92
93 // Key bindings for traffic overlay buttons
94 // NOTE: fully qual. button ID is derived from overlay-id and key-name
95 // FIXME: use into [ and ] instead of 1 and 2
96 // FIXME: new icons for src/dst
Andrea Campanella8583e6b2015-12-01 21:24:45 -080097 // FIXME: find better keys for shortest paths & disjoint paths modes
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080098 keyBindings: {
99 1: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800100 cb: function () {
101 pps.setSrc(selection);
102 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800103 tt: 'Set source node',
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800104 gid: '*src'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800105 },
106 2: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800107 cb: function () {
108 pps.setDst(selection);
109 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800110 tt: 'Set destination node',
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800111 gid: '*dst'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800112 },
Andrea Campanella0c17a0a2015-12-01 09:53:51 -0800113 3: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800114 cb: function () {
115 pps.swapSrcDst();
116 },
Andrea Campanella0c17a0a2015-12-01 09:53:51 -0800117 tt: 'Swap source and destination nodes',
118 gid: 'refresh'
119 },
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800120 4: {
121 cb: function () {
122 pps.setMode("shortest");
123 },
124 tt: 'Set shortest paths mode',
125 gid: '*jp'
126 },
127 5: {
128 cb: function () {
129 pps.setMode("disjoint");
130 },
131 tt: 'Set disjoint paths mode',
132 gid: '*djp'
133 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800134 leftArrow: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800135 cb: function () {
136 pps.prevPath();
137 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800138 tt: 'Highlight previous path',
139 gid: 'prevIntent'
140 },
141 rightArrow: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800142 cb: function () {
143 pps.nextPath();
144 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800145 tt: 'Highlight next path',
146 gid: 'nextIntent'
147 },
148
149 _keyOrder: [
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800150 '1', '2', '3', '4', '5', 'leftArrow', 'rightArrow'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800151 ]
152 },
153
154 hooks: {
155 // hook for handling escape key
156 // Must return true to consume ESC, false otherwise.
157 escape: function () {
158 selectionCallback();
159 pps.setSrc();
160 pps.setDst();
161 },
162
163 // hooks for when the selection changes...
164 empty: function () {
165 selectionCallback();
166 },
167 single: function (data) {
168 selectionCallback(data);
169 }
170 }
171 };
172
173
174 function buttonCallback(x) {
175 $log.debug('Toolbar-button callback', x);
176 }
177
178 function selectionCallback(d) {
179 $log.debug('Selection callback', d);
180 selection = d;
181 }
182
183 // invoke code to register with the overlay service
184 angular.module('ovPpTopov')
185 .run(['$log', 'TopoOverlayService', 'PathPainterTopovService',
186
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800187 function (_$log_, _tov_, _pps_) {
188 $log = _$log_;
189 tov = _tov_;
190 pps = _pps_;
191 tov.register(overlay);
192 }]);
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800193
194}());