Navigation graph output: add color and improve layout
This commit is contained in:
		
							parent
							
								
									452c7b9586
								
							
						
					
					
						commit
						474fc94a06
					
				|  | @ -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]"); | ||||
| console.log(`graph[\
 | ||||
|     layout=neato, \ | ||||
|     mode=ipsep, \ | ||||
|     overlap=ipsep, \ | ||||
|     outputorder=nodesfirst, \ | ||||
| ]`);
 | ||||
| 
 | ||||
| for (const [stopId, stop] of Object.entries(network.stops)) { | ||||
|     console.log(`${stopId}[label="${stop.properties.name}", shape=box]`); | ||||
| 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]`); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue