-
Notifications
You must be signed in to change notification settings - Fork 3
/
todot
executable file
·174 lines (156 loc) · 4.95 KB
/
todot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/perl
#
# Original todot from the Unix History Graphing Project by Warren Toomey,
# http://minnie.tuhs.org/Unix_History/. "Author", "Based on" and "Comments"
# fields and other modifications by Claudio Matsuoka for the Tracker History
# Graphing Project, Nov/2007
$default_succweight=200;
$default_ideaweight=10;
$minyear=3000;
$maxyear=0;
$linkcnt=0;
while (<>) {
s/\s*#.*//;
if (/^$/) { next; }
if (/^\.COLOR\s+(\S+)/) { $section_color = $1; next; }
if (/^(\S+)/) { $node=$1; $Color{$node}=$section_color; next; }
if (/\tName: (.*)/) { $Name{$node}=$1; next; }
if (/\tAuthor: (.*)/) { $Author{$node}=$1; next; }
if (/\tComment: (.*)/) { $Comment{$node}=$1; next; }
# For timeline
if (/\tAfter (\S+)/) {
$From[$linkcnt]=$1; $To[$linkcnt]=$node; $Link[$linkcnt]="after";
$Weight[$linkcnt]=10000;
$Implist[$linkcnt] = parse_list($_);
$linkcnt++; next;
}
if (/\tBased on (\S+)\s+(\d+)/) {
$From[$linkcnt]=$1; $To[$linkcnt]=$node; $Link[$linkcnt]="succ";
$Weight[$linkcnt]=$2;
$Implist[$linkcnt] = parse_list($_);
$linkcnt++; next;
}
if (/\tInfluenced by (\S+)\s+(\d+)/) {
$From[$linkcnt]=$1; $To[$linkcnt]=$node; $Link[$linkcnt]="idea";
$Weight[$linkcnt]=$2;
$Implist[$linkcnt] = parse_list($_);
$linkcnt++; next;
}
if (/\tBased on (\S+)/) {
$From[$linkcnt]=$1; $To[$linkcnt]=$node; $Link[$linkcnt]="succ";
$Weight[$linkcnt]=$default_succweight;
$Implist[$linkcnt] = parse_list($_);
$linkcnt++; next;
}
if (/\tInfluenced by (\S+)/) {
$From[$linkcnt]=$1; $To[$linkcnt]=$node; $Link[$linkcnt]="idea";
$Weight[$linkcnt]=$default_ideaweight;
$Implist[$linkcnt] = parse_list($_);
$linkcnt++; next;
}
if (/\tDate:\s*(\d\d\d\d)/) {
$yr=$1; $mon="00"; $day="00";
if (/\tDate:\s*\d\d\d\d-(\d\d)/) {
$mon=$1;
}
if (/\tDate:\s*\d\d\d\d-\d\d-(\d\d)/) {
$day=$1;
}
$d="${yr}${mon}${day}"; $Date{$d}{$node}=$node;
$Date{$d}{$d}=$d; $Name{$d}=$d;
if ($yr > $maxyear) { $maxyear=$yr; }
if ($yr < $minyear) { $minyear=$yr; }
next;
}
}
#print("digraph tracker {\nratio=auto; page=\"8.25,11.65\";\n");
print("digraph tracker {\nratio=auto;\n");
#print("node [shape=plaintext,fontsize=12];\n");
print("node [shape=rectangle,fontsize=12];\n");
print("edge [fontsize=9,fontcolor=blue];\n");
print("ranksep=0.2; nodesep=0.3; center=true;\n");
# Draw the visible years
print("{ edge [style=bold];\n");
print(" node [shape=plaintext,fontsize=36,fontname=\"Times-Bold\"];\n");
for ($i=$minyear; $i<=$maxyear; $i++) {
$d= "${i}0000"; $Date{$d}{$d}=$d; $Name{$d}=$d;
$Date{$d}{$i}=$i; $Name{$i}=$i;
print(" $i ->\n");
}
print(" future;\n}\n");
print("{ rank=max; future }\n");
foreach $i (sort(keys(%Date))) {
print("{ rank=same; ");
foreach $j (keys(%{ $Date{$i} })) {
print("\"$Name{$j}\"");
if ($Author{$j}) {
$c = "style=filled,color=\"#$Color{$j}\",";
if ($Comment{$j}) {
print("[${c}label=\"$Name{$j}\\n$Author{$j}\\n$Comment{$j}\"] ");
} else {
print("[${c}label=\"$Name{$j}\\n$Author{$j}\"] ");
}
} else {
# Timeline
print("[shape=plaintext ");
if ($Comment{$j}) {
print("label=\"$Name{$j}\\n$Comment{$j}\"] ");
} else {
print("label=\"$Name{$j}\"];");
}
}
}
print("}\n");
}
# Do the invisible years
for ($i=$minyear; $i<=$maxyear; $i++) {
print("{ edge [style=invis];\n");
for ($j=0; $j<=12; $j++) {
for ($k=0; $k<=31; $k++) {
$d= sprintf("%d%02d%02d", $i,$j,$k);
if (!defined($Date{$d}{$d})) { next; }
print(" $d [style=invis,height=0.1,width=0.1,fontsize=2];\n");
}
}
for ($j=0; $j<=12; $j++) {
for ($k=0; $k<=31; $k++) {
$d= sprintf("%d%02d%02d", $i,$j,$k);
if (!defined($Date{$d}{$d})) { next; }
print(" $d ->\n");
}
}
printf(" %d0000;\n}\n",$i+1);
}
$j=$maxyear+1; $j .= "0000";
print("{ $j [style=invis,height=0.1,width=0.1,fontsize=2]; }\n");
for ($i=0; $i<$linkcnt; $i++) {
if (!defined($Name{$From[$i]})) {
print(STDERR "Warning: node $From[$i] doesn't exist\n"); next;
}
print("\"$Name{$From[$i]}\" -> \"$Name{$To[$i]}\" ");
$label = $Implist[$i] ? " label=\"$Implist[$i]\"" : "";
#if ($Link[$i] eq "succ") { print("[weight=$Weight[$i],style=bold]"); }
if ($Link[$i] eq "after") { print("[style=dashed]"); }
if ($Link[$i] eq "succ") { print("[weight=$Weight[$i]$label]"); }
if ($Link[$i] eq "idea") { print("[weight=$Weight[$i],fontcolor=green,style=dotted$label]"); }
print(";\n");
}
print("}\n");
# Parse improvement/influence list
# Get comma-separated values between [ ], can be multiline
# not a very pretty code but it works
sub parse_list {
my $imp = "";
if (($k) = /\[([^\]]*)/) {
while (1) {
foreach (split(/[\],]+/, $k)) {
s/^\s*(.*\S)\s*$/$1/;
$imp .= "$_\\l" if $_ =~ /\S/;
}
/\]/ && last;
chomp($_=<>); s/\s*#.*//;
($k) = m/([^\]]*)/;
}
}
$imp;
}