Navigation graph output: add color and improve layout

This commit is contained in:
Mattéo Delabre 2021-05-22 23:45:22 +02:00
parent 452c7b9586
commit 474fc94a06
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
1 changed files with 26 additions and 6 deletions

View File

@ -1,23 +1,43 @@
#!/usr/bin/env -S node --experimental-json-modules #!/usr/bin/env -S node --experimental-json-modules
import network from "../src/tam/network.json"; import network from "../src/tam/network.json";
import color from "color";
console.log("digraph {"); console.log("digraph {");
console.log("graph[layout=neato, overlap=scalexy, splines=true, outputorder=nodesfirst]"); console.log(`graph[\
layout=neato, \
mode=ipsep, \
overlap=ipsep, \
outputorder=nodesfirst, \
]`);
for (const [stopId, stop] of Object.entries(network.stops)) { const stops = new Set();
console.log(`${stopId}[label="${stop.properties.name}", shape=box]`);
for (const stop of Object.values(network.stops)) {
stops.add(stop.properties.node);
const {node, name, routes} = stop.properties;
const backgrounds = routes.map(([line]) => network.lines[line].color);
const font = color(backgrounds[0]).isLight() ? "black" : "white";
console.log(`${node}[\
label="${name}", \
style=striped, \
fillcolor="${[...new Set(backgrounds)].join(":")}", \
fontcolor="${font}", \
shape=box, \
]`);
} }
const junctions = new Set(); const junctions = new Set();
for (const [beginId, begin] of Object.entries(network.navigation)) { for (const [beginId, begin] of Object.entries(network.navigation)) {
if (!(beginId in network.stops)) { if (!stops.has(beginId)) {
junctions.add(beginId); junctions.add(beginId);
} }
for (const endId in begin) { for (const endId in begin) {
if (!(endId in network.stops)) { if (!stops.has(endId)) {
junctions.add(endId); junctions.add(endId);
} }
} }
@ -29,7 +49,7 @@ for (const junction of junctions) {
for (const [beginId, begin] of Object.entries(network.navigation)) { for (const [beginId, begin] of Object.entries(network.navigation)) {
for (const endId in begin) { for (const endId in begin) {
console.log(`${beginId} -> ${endId}`); console.log(`${beginId} -> ${endId}[len=2]`);
} }
} }