#! /usr/bin/perl

my %colors = (
    northern => 'azure4', circle => 'yellow', victoria => 'cornflowerblue',
    district => 'green', jubilee => 'gray', central => 'red',
    eastlondon => 'darkorange', bakerloo => 'sienna', picadilly => 'blue',
    metropolitan => 'pink', waterloo => 'cyan', hamcity => 'hotpink'
);

my $depth = shift @ARGV || 500;
print "graph G {\nrankdir=LR;\nfontsize=8;\n";
while (<>) {
    my @p = split(' ', $_);
    my $l = shift @p;
    print "label=$l;\n";
    my $c = $colors{$l} || die "missing colour for line $l";
    my $from = shift @p;
    print "$from [color=$c,style=filled,fontsize=8]\n";
    $depth--;
    last if $depth < 1;

    while (scalar @p > 1) {
        my $dist = shift @p;
        my $to = shift @p;
        print "{ node [style=filled,color=$c,fontsize=8] $from $to}\n";
        print "$from -- $to [weight=$dist,color=$c]\n";
        $from = $to;
        $depth--;
        last if $depth < 1;
    }
    last if $depth < 1;
}
print "}\n";

