GUI Topo -- Badges - WIP.
Change-Id: I84a4d688f960f5162b9ae7c7c14ee4c118e2c707
Showing
1 changed file
with
40 additions
and
17 deletions
... | @@ -55,8 +55,22 @@ | ... | @@ -55,8 +55,22 @@ |
55 | height: 14 | 55 | height: 14 |
56 | } | 56 | } |
57 | }, | 57 | }, |
58 | + badgeConfig = { | ||
59 | + radius: 12, | ||
60 | + yoff: 5 | ||
61 | + }, | ||
58 | icfg; | 62 | icfg; |
59 | 63 | ||
64 | + var status = { | ||
65 | + i: 'badgeInfo', | ||
66 | + w: 'badgeWarn', | ||
67 | + e: 'badgeError' | ||
68 | + }; | ||
69 | + | ||
70 | + function badgeStatus(badge) { | ||
71 | + return status[badge.status] || status.i; | ||
72 | + } | ||
73 | + | ||
60 | // internal state | 74 | // internal state |
61 | var deviceLabelIndex = 0, | 75 | var deviceLabelIndex = 0, |
62 | hostLabelIndex = 0; | 76 | hostLabelIndex = 0; |
... | @@ -186,12 +200,14 @@ | ... | @@ -186,12 +200,14 @@ |
186 | } | 200 | } |
187 | 201 | ||
188 | 202 | ||
189 | - function updateDeviceLabel(d) { | 203 | + function updateDeviceRendering(d) { |
190 | var label = trimLabel(deviceLabel(d)), | 204 | var label = trimLabel(deviceLabel(d)), |
191 | noLabel = !label, | 205 | noLabel = !label, |
192 | node = d.el, | 206 | node = d.el, |
193 | dim = icfg.device.dim, | 207 | dim = icfg.device.dim, |
194 | - box, dx, dy; | 208 | + box, dx, dy, bsel, |
209 | + bdg = d.badge, | ||
210 | + bcr = badgeConfig.radius; | ||
195 | 211 | ||
196 | node.select('text') | 212 | node.select('text') |
197 | .text(label) | 213 | .text(label) |
... | @@ -216,23 +232,31 @@ | ... | @@ -216,23 +232,31 @@ |
216 | node.select('g.deviceIcon') | 232 | node.select('g.deviceIcon') |
217 | .transition() | 233 | .transition() |
218 | .attr('transform', sus.translate(dx, dy)); | 234 | .attr('transform', sus.translate(dx, dy)); |
219 | - } | ||
220 | - | ||
221 | - function updateDeviceBadge(d) { | ||
222 | - // TODO: Fix this WIP | ||
223 | - var node = d.el, | ||
224 | - bsel; | ||
225 | 235 | ||
226 | - if (d.badge) { | 236 | + // handle badge, if defined |
237 | + if (bdg) { | ||
227 | bsel = node.append('g') | 238 | bsel = node.append('g') |
228 | .classed('badge', true) | 239 | .classed('badge', true) |
229 | - .attr('transform', sus.translate(-14, -14)); | 240 | + .classed(badgeStatus(bdg), true) |
241 | + .attr('transform', sus.translate(dx + dim, dy)); | ||
230 | 242 | ||
231 | bsel.append('circle') | 243 | bsel.append('circle') |
232 | - .attr('r', 14); | 244 | + .attr('r', bcr); |
233 | - bsel.append('text') | 245 | + |
234 | - .attr('transform', sus.translate(-5, 3)) | 246 | + if (bdg.txt) { |
235 | - .text('42'); | 247 | + bsel.append('text') |
248 | + .attr('dy', badgeConfig.yoff) | ||
249 | + .attr('text-anchor', 'middle') | ||
250 | + .text(bdg.txt); | ||
251 | + } else if (bdg.gid) { | ||
252 | + bsel.append('use') | ||
253 | + .attr({ | ||
254 | + width: bcr * 2, | ||
255 | + height: bcr * 2, | ||
256 | + 'xlink:href': '#' + bdg.gid | ||
257 | + }); | ||
258 | + | ||
259 | + } | ||
236 | } | 260 | } |
237 | } | 261 | } |
238 | 262 | ||
... | @@ -258,8 +282,7 @@ | ... | @@ -258,8 +282,7 @@ |
258 | function deviceExisting(d) { | 282 | function deviceExisting(d) { |
259 | var node = d.el; | 283 | var node = d.el; |
260 | node.classed('online', d.online); | 284 | node.classed('online', d.online); |
261 | - updateDeviceLabel(d); | 285 | + updateDeviceRendering(d); |
262 | - updateDeviceBadge(d); | ||
263 | api.posNode(d, true); | 286 | api.posNode(d, true); |
264 | } | 287 | } |
265 | 288 | ||
... | @@ -574,7 +597,7 @@ | ... | @@ -574,7 +597,7 @@ |
574 | deviceLabel: deviceLabel, | 597 | deviceLabel: deviceLabel, |
575 | trimLabel: trimLabel, | 598 | trimLabel: trimLabel, |
576 | 599 | ||
577 | - updateDeviceLabel: updateDeviceLabel, | 600 | + updateDeviceLabel: updateDeviceRendering, |
578 | updateHostLabel: updateHostLabel, | 601 | updateHostLabel: updateHostLabel, |
579 | updateDeviceColors: updateDeviceColors, | 602 | updateDeviceColors: updateDeviceColors, |
580 | 603 | ... | ... |
-
Please register or login to post a comment