|
|
@ -1,23 +1,43 @@ |
|
|
|
#!/usr/bin/env -S node --experimental-json-modules
|
|
|
|
|
|
|
|
import network from "../src/tam/network.json"; |
|
|
|
import color from "color"; |
|
|
|
|
|
|
|
console.log("digraph {"); |
|
|
|
console.log("graph[layout=neato, overlap=scalexy, splines=true, outputorder=nodesfirst]"); |
|
|
|
|
|
|
|
for (const [stopId, stop] of Object.entries(network.stops)) { |
|
|
|
console.log(`${stopId}[label="${stop.properties.name}", shape=box]`); |
|
|
|
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, \ |
|
|
|
]`);
|
|
|
|
} |
|
|
|
|
|
|
|
const junctions = new Set(); |
|
|
|
|
|
|
|
for (const [beginId, begin] of Object.entries(network.navigation)) { |
|
|
|
if (!(beginId in network.stops)) { |
|
|
|
if (!stops.has(beginId)) { |
|
|
|
junctions.add(beginId); |
|
|
|
} |
|
|
|
|
|
|
|
for (const endId in begin) { |
|
|
|
if (!(endId in network.stops)) { |
|
|
|
if (!stops.has(endId)) { |
|
|
|
junctions.add(endId); |
|
|
|
} |
|
|
|
} |
|
|
@ -29,7 +49,7 @@ for (const junction of junctions) { |
|
|
|
|
|
|
|
for (const [beginId, begin] of Object.entries(network.navigation)) { |
|
|
|
for (const endId in begin) { |
|
|
|
console.log(`${beginId} -> ${endId}`); |
|
|
|
console.log(`${beginId} -> ${endId}[len=2]`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|