Simon Hunt

GUI -- [ONOS-265] - fixed quick help:

- 'keymap' renamed 'quickhelp'
- opacity of text now solid.
- translucent background now auto-fits the content.
- renamed files.

Change-Id: I217f9e26acb0beb2686d1935e1e986f1404980db
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
40 <link rel="stylesheet" href="mast2.css"> 40 <link rel="stylesheet" href="mast2.css">
41 <link rel="stylesheet" href="floatPanel.css"> 41 <link rel="stylesheet" href="floatPanel.css">
42 <link rel="stylesheet" href="feedback.css"> 42 <link rel="stylesheet" href="feedback.css">
43 - <link rel="stylesheet" href="keymap.css"> 43 + <link rel="stylesheet" href="onosQuickHelp.css">
44 44
45 <!-- This is where contributed stylesheets get INJECTED --> 45 <!-- This is where contributed stylesheets get INJECTED -->
46 <!-- TODO: replace with template marker and inject refs server-side --> 46 <!-- TODO: replace with template marker and inject refs server-side -->
...@@ -70,10 +70,10 @@ ...@@ -70,10 +70,10 @@
70 <!-- NOTE: alert content injected here, as needed --> 70 <!-- NOTE: alert content injected here, as needed -->
71 </div> 71 </div>
72 <div id="feedback"> 72 <div id="feedback">
73 - <!-- NOTE: feedback to user --> 73 + <!-- NOTE: feedback flashes to user -->
74 </div> 74 </div>
75 - <div id="keymap"> 75 + <div id="quickhelp">
76 - <!-- NOTE: key bindings map --> 76 + <!-- NOTE: key bindings and mouse gesture help -->
77 </div> 77 </div>
78 </div> 78 </div>
79 79
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
93 <!-- Framework module files included here --> 93 <!-- Framework module files included here -->
94 <script src="mast2.js"></script> 94 <script src="mast2.js"></script>
95 <script src="feedback.js"></script> 95 <script src="feedback.js"></script>
96 - <script src="keymap.js"></script> 96 + <script src="onosQuickHelp.js"></script>
97 97
98 <!-- View Module Templates; REMOVE THESE LINES, FOR PRODUCTION --> 98 <!-- View Module Templates; REMOVE THESE LINES, FOR PRODUCTION -->
99 <script src="module-svg-template.js"></script> 99 <script src="module-svg-template.js"></script>
......
...@@ -415,7 +415,7 @@ ...@@ -415,7 +415,7 @@
415 415
416 function setupGlobalKeys() { 416 function setupGlobalKeys() {
417 keyHandler.globalKeys = { 417 keyHandler.globalKeys = {
418 - slash: [keyMap, 'Show / hide keyboard shortcuts'], 418 + slash: [quickHelp, 'Show / hide Quick Help'],
419 esc: [escapeKey, 'Dismiss dialog or cancel selections'], 419 esc: [escapeKey, 'Dismiss dialog or cancel selections'],
420 T: [toggleTheme, "Toggle theme"] 420 T: [toggleTheme, "Toggle theme"]
421 }; 421 };
...@@ -427,19 +427,19 @@ ...@@ -427,19 +427,19 @@
427 }; 427 };
428 } 428 }
429 429
430 - function keyMap(view, key, code, ev) { 430 + function quickHelp(view, key, code, ev) {
431 - libApi.keymap.show(keyHandler); 431 + libApi.quickHelp.show(keyHandler);
432 return true; 432 return true;
433 } 433 }
434 434
435 function escapeKey(view, key, code, ev) { 435 function escapeKey(view, key, code, ev) {
436 - if (libApi.keymap.hide()) {
437 - return true;
438 - }
439 if (alerts.open) { 436 if (alerts.open) {
440 closeAlerts(); 437 closeAlerts();
441 return true; 438 return true;
442 } 439 }
440 + if (libApi.quickHelp.hide()) {
441 + return true;
442 + }
443 return false; 443 return false;
444 } 444 }
445 445
......
...@@ -15,53 +15,54 @@ ...@@ -15,53 +15,54 @@
15 */ 15 */
16 16
17 /* 17 /*
18 - ONOS GUI -- Key map layer -- CSS file 18 + ONOS GUI -- Quick Help layer -- CSS file
19 19
20 @author Simon Hunt 20 @author Simon Hunt
21 */ 21 */
22 22
23 -#keymap { 23 +#quickhelp {
24 z-index: 1300; 24 z-index: 1300;
25 } 25 }
26 26
27 -#keymap svg { 27 +#quickhelp svg {
28 position: absolute; 28 position: absolute;
29 bottom: 40px; 29 bottom: 40px;
30 - opacity: 0.7; 30 + opacity: 1;
31 } 31 }
32 32
33 -#keymap svg g.pane { 33 +#quickhelp svg g.help rect {
34 fill: black; 34 fill: black;
35 + opacity: 0.7;
35 } 36 }
36 37
37 -#keymap svg text.title { 38 +#quickhelp svg text.title {
38 font-size: 10pt; 39 font-size: 10pt;
39 font-style: italic; 40 font-style: italic;
40 text-anchor: middle; 41 text-anchor: middle;
41 fill: #999; 42 fill: #999;
42 } 43 }
43 44
44 -#keymap svg g.keyItem { 45 +#quickhelp svg g.keyItem {
45 fill: white; 46 fill: white;
46 } 47 }
47 48
48 -#keymap svg g.keyItem line { 49 +#quickhelp svg g.keyItem line {
49 - stroke: #444; 50 + stroke: #888;
50 - stroke-dasharray: 4 4; 51 + stroke-dasharray: 2 2;
51 } 52 }
52 53
53 -#keymap svg text { 54 +#quickhelp svg text {
54 font-size: 7pt; 55 font-size: 7pt;
55 alignment-baseline: middle; 56 alignment-baseline: middle;
56 } 57 }
57 58
58 -#keymap svg text.key { 59 +#quickhelp svg text.key {
59 font-size: 7pt; 60 font-size: 7pt;
60 fill: #add; 61 fill: #add;
61 } 62 }
62 63
63 -#keymap svg text.desc { 64 +#quickhelp svg text.desc {
64 font-size: 7pt; 65 font-size: 7pt;
65 - fill: #aaa; 66 + fill: #ddd;
66 } 67 }
67 68
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
15 */ 15 */
16 16
17 /* 17 /*
18 - ONOS GUI -- Keymap Layer 18 + ONOS GUI -- Quick Help Layer
19 19
20 Defines the key-map layer for the UI. Used to give user a list of 20 Defines the key-map layer for the UI. Used to give user a list of
21 key bindings; both global, and for the current view. 21 key bindings; both global, and for the current view.
...@@ -33,34 +33,54 @@ ...@@ -33,34 +33,54 @@
33 var w = '100%', 33 var w = '100%',
34 h = '80%', 34 h = '80%',
35 fade = 500, 35 fade = 500,
36 - vb = '-220 -220 440 440', 36 + vb = '-200 0 400 400';
37 - paneW = 400,
38 - paneH = 280,
39 - offy = 65,
40 - dy = 14,
41 - offKey = 40,
42 - offDesc = offKey + 50,
43 - lineW = paneW - (2*offKey);
44 37
45 // State variables 38 // State variables
46 var data = []; 39 var data = [];
47 40
48 // DOM elements and the like 41 // DOM elements and the like
49 - var kmdiv = d3.select('#keymap'); 42 + var qhdiv = d3.select('#quickhelp'),
43 + svg = qhdiv.select('svg'),
44 + pane,
45 + rect,
46 + items;
50 47
48 + // General functions
51 function isA(a) { 49 function isA(a) {
52 return $.isArray(a) ? a : null; 50 return $.isArray(a) ? a : null;
53 } 51 }
54 52
53 + var keyDisp = {
54 + equals: '=',
55 + dash: '-',
56 + slash: '/',
57 + leftArrow: 'L-arrow',
58 + upArrow: 'U-arrow',
59 + rightArrow: 'R-arrow',
60 + downArrow: 'D-arrow'
61 + };
62 +
63 + function cap(s) {
64 + return s.replace(/^[a-z]/, function (m) { return m.toUpperCase(); });
65 + }
66 +
67 + function mkKeyDisp(id) {
68 + var v = keyDisp[id] || id;
69 + return cap(v);
70 + }
55 71
56 - var svg = kmdiv.select('svg'), 72 + // layout configuration
57 - pane; 73 + var pad = 8,
74 + offy = 45,
75 + dy = 14,
76 + offDesc = 40;
58 77
78 + // D3 magic
59 function updateKeyItems() { 79 function updateKeyItems() {
60 - var items = pane.selectAll('.keyItem') 80 + var keyItems = items.selectAll('.keyItem')
61 .data(data); 81 .data(data);
62 82
63 - var entering = items.enter() 83 + var entering = keyItems.enter()
64 .append('g') 84 .append('g')
65 .attr({ 85 .attr({
66 id: function (d) { return d.id; }, 86 id: function (d) { return d.id; },
...@@ -73,19 +93,13 @@ ...@@ -73,19 +93,13 @@
73 93
74 if (d.id === '_') { 94 if (d.id === '_') {
75 el.append('line') 95 el.append('line')
76 - .attr({ 96 + .attr({ x1: 0, y1: y, x2: 1, y2: y});
77 - class: 'sep',
78 - x1: offKey,
79 - y1: y,
80 - x2: offKey + lineW,
81 - y2: y
82 - });
83 } else { 97 } else {
84 el.append('text') 98 el.append('text')
85 .text(d.key) 99 .text(d.key)
86 .attr({ 100 .attr({
87 class: 'key', 101 class: 'key',
88 - x: offKey, 102 + x: 0,
89 y: y 103 y: y
90 }); 104 });
91 105
...@@ -98,6 +112,22 @@ ...@@ -98,6 +112,22 @@
98 }); 112 });
99 } 113 }
100 }); 114 });
115 +
116 + var box = items.node().getBBox(),
117 + paneW = box.width + pad * 2,
118 + paneH = box.height + offy;
119 +
120 + items.select('line').attr('x2', box.width);
121 + items.attr('transform', translate(-paneW/2, -pad));
122 + rect.attr({
123 + width: paneW,
124 + height: paneH,
125 + transform: translate(-paneW/2-pad, 0)
126 + });
127 + }
128 +
129 + function translate(x, y) {
130 + return 'translate(' + x + ',' + y + ')';
101 } 131 }
102 132
103 function aggregateData(bindings) { 133 function aggregateData(bindings) {
...@@ -127,7 +157,7 @@ ...@@ -127,7 +157,7 @@
127 { 157 {
128 id: id, 158 id: id,
129 type: type, 159 type: type,
130 - key: k, 160 + key: mkKeyDisp(k),
131 desc: desc 161 desc: desc
132 } 162 }
133 ); 163 );
...@@ -138,51 +168,47 @@ ...@@ -138,51 +168,47 @@
138 }); 168 });
139 } 169 }
140 } 170 }
141 -
142 } 171 }
143 172
144 - function populateBindings(bindings) { 173 + function popBind(bindings) {
145 - svg.append('g') 174 + pane = svg.append('g')
146 .attr({ 175 .attr({
147 - class: 'keyBindings', 176 + class: 'help',
148 - transform: 'translate(-200,-200)',
149 opacity: 0 177 opacity: 0
150 - })
151 - .transition()
152 - .duration(fade)
153 - .attr('opacity', 1);
154 -
155 - pane = svg.select('g');
156 -
157 - pane.append('rect')
158 - .attr({
159 - width: paneW,
160 - height: paneH,
161 - rx: 8
162 }); 178 });
163 179
180 + rect = pane.append('rect')
181 + .attr('rx', 8);
182 +
164 pane.append('text') 183 pane.append('text')
165 - .text('Keyboard Shortcuts') 184 + .text('Quick Help')
166 .attr({ 185 .attr({
167 - x: 200, 186 + class: 'title',
168 - y: 0, 187 + dy: '1.2em',
169 - dy: '1.4em', 188 + transform: translate(-pad,0)
170 - class: 'title'
171 }); 189 });
172 190
191 + items = pane.append('g');
192 +
173 aggregateData(bindings); 193 aggregateData(bindings);
174 updateKeyItems(); 194 updateKeyItems();
195 +
196 + _fade(1);
175 } 197 }
176 198
177 function fadeBindings() { 199 function fadeBindings() {
178 - svg.selectAll('g.keyBindings') 200 + _fade(0);
201 + }
202 +
203 + function _fade(o) {
204 + svg.selectAll('g.help')
179 .transition() 205 .transition()
180 .duration(fade) 206 .duration(fade)
181 - .attr('opacity', 0); 207 + .attr('opacity', o);
182 } 208 }
183 209
184 function addSvg() { 210 function addSvg() {
185 - svg = kmdiv.append('svg') 211 + svg = qhdiv.append('svg')
186 .attr({ 212 .attr({
187 width: w, 213 width: w,
188 height: h, 214 height: h,
...@@ -196,18 +222,18 @@ ...@@ -196,18 +222,18 @@
196 .remove(); 222 .remove();
197 } 223 }
198 224
199 - function showKeyMap(bindings) { 225 + function showQuickHelp(bindings) {
200 - svg = kmdiv.select('svg'); 226 + svg = qhdiv.select('svg');
201 if (svg.empty()) { 227 if (svg.empty()) {
202 addSvg(); 228 addSvg();
203 - populateBindings(bindings); 229 + popBind(bindings);
204 } else { 230 } else {
205 - hideKeyMap(); 231 + hideQuickHelp();
206 } 232 }
207 } 233 }
208 234
209 - function hideKeyMap() { 235 + function hideQuickHelp() {
210 - svg = kmdiv.select('svg'); 236 + svg = qhdiv.select('svg');
211 if (!svg.empty()) { 237 if (!svg.empty()) {
212 fadeBindings(); 238 fadeBindings();
213 removeSvg(); 239 removeSvg();
...@@ -216,8 +242,8 @@ ...@@ -216,8 +242,8 @@
216 return false; 242 return false;
217 } 243 }
218 244
219 - onos.ui.addLib('keymap', { 245 + onos.ui.addLib('quickHelp', {
220 - show: showKeyMap, 246 + show: showQuickHelp,
221 - hide: hideKeyMap 247 + hide: hideQuickHelp
222 }); 248 });
223 }(ONOS)); 249 }(ONOS));
......