Add styling to graphviz devices and links (#894)

* Add styling to graphviz devices and links

* Fix eslint error and gvrender_set_style warning
This commit is contained in:
clockbrain 2019-01-23 05:07:38 +10:00 committed by Koen Kanters
parent dcd81cbbf2
commit 5970e498f3

View File

@ -42,6 +42,7 @@ class NetworkMap {
graphviz(zigbee, topology) {
let text = 'digraph G {\nnode[shape=record];\n';
let devStyle = '';
zigbee.getDevices().forEach((device) => {
const labels = [];
@ -67,8 +68,17 @@ class NetworkMap {
// Add the device status (online/offline)
labels.push(device.status);
// Shape the record according to device type
if (device.type == 'Coordinator') {
devStyle = 'style="bold"';
} else if (device.type == 'Router') {
devStyle = 'style="rounded"';
} else {
devStyle = 'style="rounded, dashed"';
}
// Add the device with its labels to the graph as a node.
text += ` "${device.ieeeAddr}" [label="{${labels.join('|')}}"];\n`;
text += ` "${device.ieeeAddr}" [`+devStyle+`, label="{${labels.join('|')}}"];\n`;
/**
* Add an edge between the device and its parent to the graph
@ -76,7 +86,8 @@ class NetworkMap {
* due to not responded to the lqi scan. In that case we do not add an edge for this device.
*/
topology.filter((e) => e.ieeeAddr === device.ieeeAddr).forEach((e) => {
text += ` "${device.ieeeAddr}" -> "${e.parent}" [label="${e.lqi}"]\n`;
const lineStyle = (e.lqi==0) ? `style="dashed", ` : ``;
text += ` "${device.ieeeAddr}" -> "${e.parent}" [`+lineStyle+`label="${e.lqi}"]\n`;
});
});