2021-05-21 21:59:51 +00:00
|
|
|
#!/usr/bin/env -S node --experimental-json-modules
|
|
|
|
|
2022-07-05 22:20:12 +00:00
|
|
|
import network from "../src/data/network.json";
|
2021-05-22 21:45:22 +00:00
|
|
|
import color from "color";
|
2021-05-21 21:59:51 +00:00
|
|
|
|
|
|
|
console.log("digraph {");
|
2021-05-22 21:45:22 +00:00
|
|
|
console.log(`graph[\
|
|
|
|
layout=neato, \
|
|
|
|
mode=ipsep, \
|
|
|
|
overlap=ipsep, \
|
|
|
|
outputorder=nodesfirst, \
|
|
|
|
]`);
|
|
|
|
|
|
|
|
const stops = new Set();
|
|
|
|
|
|
|
|
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, \
|
|
|
|
]`);
|
2021-05-21 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const junctions = new Set();
|
|
|
|
|
|
|
|
for (const [beginId, begin] of Object.entries(network.navigation)) {
|
2021-05-22 21:45:22 +00:00
|
|
|
if (!stops.has(beginId)) {
|
2021-05-21 21:59:51 +00:00
|
|
|
junctions.add(beginId);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const endId in begin) {
|
2021-05-22 21:45:22 +00:00
|
|
|
if (!stops.has(endId)) {
|
2021-05-21 21:59:51 +00:00
|
|
|
junctions.add(endId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const junction of junctions) {
|
|
|
|
console.log(`${junction}[label="", shape=point]`);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const [beginId, begin] of Object.entries(network.navigation)) {
|
2021-05-21 22:21:26 +00:00
|
|
|
for (const endId in begin) {
|
2021-05-22 21:45:22 +00:00
|
|
|
console.log(`${beginId} -> ${endId}[len=2]`);
|
2021-05-21 21:59:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("}");
|