From 68c19f262e66404f35d2c19d10819d88f461bdc4 Mon Sep 17 00:00:00 2001 From: Andreas Brett Date: Sun, 23 Jun 2019 14:56:44 +0200 Subject: [PATCH 1/8] Update settings.js added default color options for network map --- lib/util/settings.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/util/settings.js b/lib/util/settings.js index 952201ae12..23a4c55cf1 100644 --- a/lib/util/settings.js +++ b/lib/util/settings.js @@ -13,6 +13,18 @@ const defaults = { }, groups: {}, device_options: {}, + map_options: { + timestamp_color: '#ffffff', + timestamp_fillcolor: '#784399', + coordinator_color: '#ffffff', + coordinator_fillcolor: '#e04e5d', + router_color: '#ffffff', + router_fillcolor: '#4ea3e0', + enddevice_color: '#000000', + enddevice_fillcolor: '#fff8ce', + route_active_color: '#009900', + route_inactive_color: '#994444', + }, experimental: { livolo: false, // json or attribute From 76fb0fb2732c835ad11af171453d3abcd524bc37 Mon Sep 17 00:00:00 2001 From: Andreas Brett Date: Sun, 23 Jun 2019 15:03:21 +0200 Subject: [PATCH 2/8] Update networkMap.js - add timestamp node to indicate when the map was created - colorize nodes by device type - colorize edges by activity --- lib/extension/networkMap.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/extension/networkMap.js b/lib/extension/networkMap.js index e308956189..c69379985e 100644 --- a/lib/extension/networkMap.js +++ b/lib/extension/networkMap.js @@ -53,8 +53,24 @@ class NetworkMap { } graphviz(zigbee, topology) { + // fetch node/edge colors + const timestamp_color = settings.get().map_options.timestamp_color + const timestamp_fillcolor = settings.get().map_options.timestamp_fillcolor + const coordinator_color = settings.get().map_options.coordinator_color + const coordinator_fillcolor = settings.get().map_options.coordinator_fillcolor + const router_color = settings.get().map_options.router_color + const router_fillcolor = settings.get().map_options.router_fillcolor + const enddevice_color = settings.get().map_options.enddevice_color + const enddevice_fillcolor = settings.get().map_options.enddevice_fillcolor + const route_active_color = settings.get().map_options.route_active_color + const route_inactive_color = settings.get().map_options.route_inactive_color + let text = 'digraph G {\nnode[shape=record];\n'; let devStyle = ''; + + // add timestamp node + const now = utils.toLocalISOString(new Date(Date.now())); + text += ` "timestamp" [style="rounded, filled", fillcolor="${timestamp_fillcolor}", fontcolor="${timestamp_color}", label="Map created: ${now}"];\n`; zigbee.getDevices().forEach((device) => { const labels = []; @@ -95,11 +111,11 @@ class NetworkMap { // Shape the record according to device type if (deviceType == 'Coordinator') { - devStyle = 'style="bold"'; + devStyle = `style="bold, filled", fillcolor="${coordinator_fillcolor}", fontcolor="${coordinator_color}"`; } else if (deviceType == 'Router') { - devStyle = 'style="rounded"'; + devStyle = `style="rounded, filled", fillcolor="${router_fillcolor}", fontcolor="${router_color}"`; } else { - devStyle = 'style="rounded, dashed"'; + devStyle = `style="rounded, dashed, filled", fillcolor="${enddevice_fillcolor}", fontcolor="${enddevice_color}"`; } // Add the device with its labels to the graph as a node. @@ -111,10 +127,9 @@ 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) || (e.nwkAddr === device.nwkAddr)).forEach((e) => { - const lineStyle = (e.lqi==0) ? `style="dashed", ` : ``; - const textRoutes = e.routes.map((r) => `0x${r.toString(16)}`); - const lineLabels = e.lqi + '\\n[' + textRoutes.join(']\\n[') + ']'; - text += ` "${e.parent}" -> "${device.ieeeAddr}" [`+lineStyle+`label="${lineLabels}"]\n`; + const lineStyle = (deviceType=='EndDevice') ? `style="dashed", `: (!e.routes.length) ? `style="dotted", ` : ``; + const lineWeight = (!e.routes.length) ? `weight=0, color="${route_inactive_color}", ` : `weight=1, color="${route_active_color}", `; + text += ` "${device.ieeeAddr}" -> "${e.parent}" [`+lineStyle+lineWeight+`label="${e.lqi}"]\n`; }); }); From 9902d7e9c3dad3ad86f2da8c2bdb2b0c796889ef Mon Sep 17 00:00:00 2001 From: Andreas Brett Date: Sun, 23 Jun 2019 15:20:57 +0200 Subject: [PATCH 3/8] Update networkMap.js make travis happy --- lib/extension/networkMap.js | 39 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/extension/networkMap.js b/lib/extension/networkMap.js index c69379985e..2c9f1e4ae0 100644 --- a/lib/extension/networkMap.js +++ b/lib/extension/networkMap.js @@ -54,23 +54,24 @@ class NetworkMap { graphviz(zigbee, topology) { // fetch node/edge colors - const timestamp_color = settings.get().map_options.timestamp_color - const timestamp_fillcolor = settings.get().map_options.timestamp_fillcolor - const coordinator_color = settings.get().map_options.coordinator_color - const coordinator_fillcolor = settings.get().map_options.coordinator_fillcolor - const router_color = settings.get().map_options.router_color - const router_fillcolor = settings.get().map_options.router_fillcolor - const enddevice_color = settings.get().map_options.enddevice_color - const enddevice_fillcolor = settings.get().map_options.enddevice_fillcolor - const route_active_color = settings.get().map_options.route_active_color - const route_inactive_color = settings.get().map_options.route_inactive_color - + const tColor = settings.get().map_options.timestamp_color; + const tFillColor = settings.get().map_options.timestamp_fillcolor; + const cColor = settings.get().map_options.coordinator_color; + const cFillColor = settings.get().map_options.coordinator_fillcolor; + const rColor = settings.get().map_options.router_color; + const rFillColor = settings.get().map_options.router_fillcolor; + const eColor = settings.get().map_options.enddevice_color; + const eFillColor = settings.get().map_options.enddevice_fillcolor; + const rActiveColor = settings.get().map_options.route_active_color; + const rInactiveColor = settings.get().map_options.route_inactive_color; + let text = 'digraph G {\nnode[shape=record];\n'; let devStyle = ''; - + // add timestamp node const now = utils.toLocalISOString(new Date(Date.now())); - text += ` "timestamp" [style="rounded, filled", fillcolor="${timestamp_fillcolor}", fontcolor="${timestamp_color}", label="Map created: ${now}"];\n`; + text += ` "timestamp" [style="rounded, filled", fillcolor="${tFillColor}", fontcolor="${tColor}",` + text += ` label="Map created: ${now}"];\n`; zigbee.getDevices().forEach((device) => { const labels = []; @@ -111,11 +112,11 @@ class NetworkMap { // Shape the record according to device type if (deviceType == 'Coordinator') { - devStyle = `style="bold, filled", fillcolor="${coordinator_fillcolor}", fontcolor="${coordinator_color}"`; + devStyle = `style="bold, filled", fillcolor="${cFillColor}", fontcolor="${cColor}"`; } else if (deviceType == 'Router') { - devStyle = `style="rounded, filled", fillcolor="${router_fillcolor}", fontcolor="${router_color}"`; + devStyle = `style="rounded, filled", fillcolor="${rFillColor}", fontcolor="${rColor}"`; } else { - devStyle = `style="rounded, dashed, filled", fillcolor="${enddevice_fillcolor}", fontcolor="${enddevice_color}"`; + devStyle = `style="rounded, dashed, filled", fillcolor="${eFillColor}", fontcolor="${eColor}"`; } // Add the device with its labels to the graph as a node. @@ -127,8 +128,10 @@ 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) || (e.nwkAddr === device.nwkAddr)).forEach((e) => { - const lineStyle = (deviceType=='EndDevice') ? `style="dashed", `: (!e.routes.length) ? `style="dotted", ` : ``; - const lineWeight = (!e.routes.length) ? `weight=0, color="${route_inactive_color}", ` : `weight=1, color="${route_active_color}", `; + const lineStyle = (deviceType=='EndDevice') ? `style="dashed", ` + : (!e.routes.length) ? `style="dotted", ` : ``; + const lineWeight = (!e.routes.length) ? `weight=0, color="${rInactiveColor}", ` + : `weight=1, color="${rActiveColor}", `; text += ` "${device.ieeeAddr}" -> "${e.parent}" [`+lineStyle+lineWeight+`label="${e.lqi}"]\n`; }); }); From 2eabfd64be22984fa5d485e046c89b757d47ff8f Mon Sep 17 00:00:00 2001 From: Andreas Brett Date: Sun, 23 Jun 2019 15:26:13 +0200 Subject: [PATCH 4/8] Update networkMap.js --- lib/extension/networkMap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extension/networkMap.js b/lib/extension/networkMap.js index 2c9f1e4ae0..78148ceb54 100644 --- a/lib/extension/networkMap.js +++ b/lib/extension/networkMap.js @@ -70,7 +70,7 @@ class NetworkMap { // add timestamp node const now = utils.toLocalISOString(new Date(Date.now())); - text += ` "timestamp" [style="rounded, filled", fillcolor="${tFillColor}", fontcolor="${tColor}",` + text += ` "timestamp" [style="rounded, filled", fillcolor="${tFillColor}", fontcolor="${tColor}",`; text += ` label="Map created: ${now}"];\n`; zigbee.getDevices().forEach((device) => { From 9e491cba438381aa72ba6fa0df0632920039e0d5 Mon Sep 17 00:00:00 2001 From: Andreas Brett Date: Tue, 25 Jun 2019 19:25:31 +0200 Subject: [PATCH 5/8] Update networkMap.js --- lib/extension/networkMap.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/extension/networkMap.js b/lib/extension/networkMap.js index 78148ceb54..0d04ba561d 100644 --- a/lib/extension/networkMap.js +++ b/lib/extension/networkMap.js @@ -54,8 +54,6 @@ class NetworkMap { graphviz(zigbee, topology) { // fetch node/edge colors - const tColor = settings.get().map_options.timestamp_color; - const tFillColor = settings.get().map_options.timestamp_fillcolor; const cColor = settings.get().map_options.coordinator_color; const cFillColor = settings.get().map_options.coordinator_fillcolor; const rColor = settings.get().map_options.router_color; @@ -68,11 +66,6 @@ class NetworkMap { let text = 'digraph G {\nnode[shape=record];\n'; let devStyle = ''; - // add timestamp node - const now = utils.toLocalISOString(new Date(Date.now())); - text += ` "timestamp" [style="rounded, filled", fillcolor="${tFillColor}", fontcolor="${tColor}",`; - text += ` label="Map created: ${now}"];\n`; - zigbee.getDevices().forEach((device) => { const labels = []; const friendlyDevice = settings.getDevice(device.ieeeAddr); @@ -128,11 +121,13 @@ 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) || (e.nwkAddr === device.nwkAddr)).forEach((e) => { - const lineStyle = (deviceType=='EndDevice') ? `style="dashed", ` - : (!e.routes.length) ? `style="dotted", ` : ``; + const lineStyle = (device.type=='EndDevice') ? 'style="dashed", ' + : (!e.routes.length) ? 'style="dotted", ' : ''; const lineWeight = (!e.routes.length) ? `weight=0, color="${rInactiveColor}", ` : `weight=1, color="${rActiveColor}", `; - text += ` "${device.ieeeAddr}" -> "${e.parent}" [`+lineStyle+lineWeight+`label="${e.lqi}"]\n`; + const textRoutes = e.routes.map((r) => `0x${r.toString(16)}`); + const lineLabels = `label="${e.lqi}\\n[${textRoutes.join(']\\n[')}]"`; + text += ` "${e.parent}" -> "${device.ieeeAddr}" [${lineStyle}${lineWeight}${lineLabels}]\n`; }); }); From 9b3ba24bf6564f63e3a9a374c15863de93fb7dbe Mon Sep 17 00:00:00 2001 From: Andreas Brett Date: Tue, 25 Jun 2019 19:25:56 +0200 Subject: [PATCH 6/8] Update settings.js --- lib/util/settings.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/util/settings.js b/lib/util/settings.js index 23a4c55cf1..7dd0616bdc 100644 --- a/lib/util/settings.js +++ b/lib/util/settings.js @@ -14,8 +14,6 @@ const defaults = { groups: {}, device_options: {}, map_options: { - timestamp_color: '#ffffff', - timestamp_fillcolor: '#784399', coordinator_color: '#ffffff', coordinator_fillcolor: '#e04e5d', router_color: '#ffffff', From 18f0e4c12aba45085cb5ea9556bf97d93b3ec478 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Tue, 25 Jun 2019 19:53:31 +0200 Subject: [PATCH 7/8] Refactor --- lib/extension/networkMap.js | 23 +++++++++-------------- lib/util/settings.js | 24 ++++++++++++++++-------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/extension/networkMap.js b/lib/extension/networkMap.js index 0d04ba561d..30ee9862f7 100644 --- a/lib/extension/networkMap.js +++ b/lib/extension/networkMap.js @@ -53,15 +53,7 @@ class NetworkMap { } graphviz(zigbee, topology) { - // fetch node/edge colors - const cColor = settings.get().map_options.coordinator_color; - const cFillColor = settings.get().map_options.coordinator_fillcolor; - const rColor = settings.get().map_options.router_color; - const rFillColor = settings.get().map_options.router_fillcolor; - const eColor = settings.get().map_options.enddevice_color; - const eFillColor = settings.get().map_options.enddevice_fillcolor; - const rActiveColor = settings.get().map_options.route_active_color; - const rInactiveColor = settings.get().map_options.route_inactive_color; + const colors = settings.get().map_options.colors; let text = 'digraph G {\nnode[shape=record];\n'; let devStyle = ''; @@ -105,11 +97,14 @@ class NetworkMap { // Shape the record according to device type if (deviceType == 'Coordinator') { - devStyle = `style="bold, filled", fillcolor="${cFillColor}", fontcolor="${cColor}"`; + devStyle = `style="bold, filled", fillcolor="${colors.fill.coordinator}", ` + + `fontcolor="${colors.font.coordinator}"`; } else if (deviceType == 'Router') { - devStyle = `style="rounded, filled", fillcolor="${rFillColor}", fontcolor="${rColor}"`; + devStyle = `style="rounded, filled", fillcolor="${colors.fill.router}", ` + + `fontcolor="${colors.font.router}"`; } else { - devStyle = `style="rounded, dashed, filled", fillcolor="${eFillColor}", fontcolor="${eColor}"`; + devStyle = `style="rounded, dashed, filled", fillcolor="${colors.fill.enddevice}", ` + + `fontcolor="${colors.font.enddevice}"`; } // Add the device with its labels to the graph as a node. @@ -123,8 +118,8 @@ class NetworkMap { topology.filter((e) => (e.ieeeAddr === device.ieeeAddr) || (e.nwkAddr === device.nwkAddr)).forEach((e) => { const lineStyle = (device.type=='EndDevice') ? 'style="dashed", ' : (!e.routes.length) ? 'style="dotted", ' : ''; - const lineWeight = (!e.routes.length) ? `weight=0, color="${rInactiveColor}", ` - : `weight=1, color="${rActiveColor}", `; + const lineWeight = (!e.routes.length) ? `weight=0, color="${colors.line.inactive}", ` + : `weight=1, color="${colors.line.active}", `; const textRoutes = e.routes.map((r) => `0x${r.toString(16)}`); const lineLabels = `label="${e.lqi}\\n[${textRoutes.join(']\\n[')}]"`; text += ` "${e.parent}" -> "${device.ieeeAddr}" [${lineStyle}${lineWeight}${lineLabels}]\n`; diff --git a/lib/util/settings.js b/lib/util/settings.js index 2e5e50f73a..b2ff817148 100644 --- a/lib/util/settings.js +++ b/lib/util/settings.js @@ -14,14 +14,22 @@ const defaults = { groups: {}, device_options: {}, map_options: { - coordinator_color: '#ffffff', - coordinator_fillcolor: '#e04e5d', - router_color: '#ffffff', - router_fillcolor: '#4ea3e0', - enddevice_color: '#000000', - enddevice_fillcolor: '#fff8ce', - route_active_color: '#009900', - route_inactive_color: '#994444', + colors: { + fill: { + enddevice: '#fff8ce', + coordinator: '#e04e5d', + router: '#4ea3e0', + }, + font: { + coordinator: '#ffffff', + router: '#ffffff', + enddevice: '#000000', + }, + line: { + active: '#009900', + inactive: '#994444', + }, + }, }, experimental: { livolo: false, From 1860925c87949fd3e7365f9d7d348a4e3385b259 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Wed, 26 Jun 2019 19:25:49 +0200 Subject: [PATCH 8/8] Move to graphviz. --- lib/extension/networkMap.js | 2 +- lib/util/settings.js | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/extension/networkMap.js b/lib/extension/networkMap.js index 30ee9862f7..fed7a997e3 100644 --- a/lib/extension/networkMap.js +++ b/lib/extension/networkMap.js @@ -53,7 +53,7 @@ class NetworkMap { } graphviz(zigbee, topology) { - const colors = settings.get().map_options.colors; + const colors = settings.get().map_options.graphviz.colors; let text = 'digraph G {\nnode[shape=record];\n'; let devStyle = ''; diff --git a/lib/util/settings.js b/lib/util/settings.js index b2ff817148..6deb2286f4 100644 --- a/lib/util/settings.js +++ b/lib/util/settings.js @@ -14,20 +14,22 @@ const defaults = { groups: {}, device_options: {}, map_options: { - colors: { - fill: { - enddevice: '#fff8ce', - coordinator: '#e04e5d', - router: '#4ea3e0', - }, - font: { - coordinator: '#ffffff', - router: '#ffffff', - enddevice: '#000000', - }, - line: { - active: '#009900', - inactive: '#994444', + graphviz: { + colors: { + fill: { + enddevice: '#fff8ce', + coordinator: '#e04e5d', + router: '#4ea3e0', + }, + font: { + coordinator: '#ffffff', + router: '#ffffff', + enddevice: '#000000', + }, + line: { + active: '#009900', + inactive: '#994444', + }, }, }, },