#!/usr/bin/env -S node --experimental-json-modules import network from "../src/data/network.json"; import color from "color"; console.log("digraph {"); 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 (!stops.has(beginId)) { junctions.add(beginId); } for (const endId in begin) { if (!stops.has(endId)) { junctions.add(endId); } } } for (const junction of junctions) { console.log(`${junction}[label="", shape=point]`); } for (const [beginId, begin] of Object.entries(network.navigation)) { for (const endId in begin) { console.log(`${beginId} -> ${endId}[len=2]`); } } console.log("}");