Andrea Campanella
Committed by Gerrit Code Review

Add GUI badging to hosts

Change-Id: I5c791acd6696b455b4416d2dd413edcf30d41886
...@@ -131,6 +131,10 @@ public final class TopoJson { ...@@ -131,6 +131,10 @@ public final class TopoJson {
131 if (hh.subdued()) { 131 if (hh.subdued()) {
132 n.put(SUBDUE, true); 132 n.put(SUBDUE, true);
133 } 133 }
134 + NodeBadge badge = hh.badge();
135 + if (badge != null) {
136 + n.set(BADGE, json(badge));
137 + }
134 return n; 138 return n;
135 } 139 }
136 140
......
...@@ -265,6 +265,51 @@ ...@@ -265,6 +265,51 @@
265 } 265 }
266 } 266 }
267 267
268 + function updateHostRendering(d) {
269 + var node = d.el,
270 + dim = icfg.host.radius.withGlyph,
271 + box, dx, dy, bsel,
272 + bdg = d.badge,
273 + bcr = badgeConfig.radius,
274 + bcgd = badgeConfig.gdelta;
275 +
276 +
277 + updateHostLabel(d);
278 +
279 + // TODO: fine-tune dx, dy for badge placement relative to host Circle.
280 + dx = -dim/2;
281 + dy = -dim/2;
282 +
283 + // handle badge, if defined
284 + if (bdg) {
285 + node.select('g.badge').remove();
286 +
287 + bsel = node.append('g')
288 + .classed('badge', true)
289 + .classed(badgeStatus(bdg), true)
290 + .attr('transform', sus.translate(dx + dim, dy));
291 +
292 + bsel.append('circle')
293 + .attr('r', bcr);
294 +
295 + if (bdg.txt) {
296 + bsel.append('text')
297 + .attr('dy', badgeConfig.yoff)
298 + .attr('text-anchor', 'middle')
299 + .text(bdg.txt);
300 + } else if (bdg.gid) {
301 + bsel.append('use')
302 + .attr({
303 + width: bcgd * 2,
304 + height: bcgd * 2,
305 + transform: sus.translate(-bcgd, -bcgd),
306 + 'xlink:href': '#' + bdg.gid
307 + });
308 +
309 + }
310 + }
311 + }
312 +
268 function updateHostLabel(d) { 313 function updateHostLabel(d) {
269 var label = trimLabel(hostLabel(d)); 314 var label = trimLabel(hostLabel(d));
270 d.el.select('text').text(label); 315 d.el.select('text').text(label);
...@@ -292,7 +337,7 @@ ...@@ -292,7 +337,7 @@
292 } 337 }
293 338
294 function hostExisting(d) { 339 function hostExisting(d) {
295 - updateHostLabel(d); 340 + updateHostRendering(d);
296 api.posNode(d, true); 341 api.posNode(d, true);
297 } 342 }
298 343
......
...@@ -312,8 +312,11 @@ ...@@ -312,8 +312,11 @@
312 } 312 }
313 313
314 data.hosts.forEach(function (host) { 314 data.hosts.forEach(function (host) {
315 - var hdata = api.findNodeById(host.id); 315 + var hdata = api.findNodeById(host.id),
316 + badgeData = host.badge || null;
317 +
316 if (hdata && !hdata.el.empty()) { 318 if (hdata && !hdata.el.empty()) {
319 + hdata.badge = badgeData;
317 if (!host.subdue) { 320 if (!host.subdue) {
318 api.unsupNode(hdata.id, less); 321 api.unsupNode(hdata.id, less);
319 } 322 }
......