-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (68 loc) · 1.73 KB
/
main.go
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
package main
import (
"flag"
"image/png"
"log"
"os"
"strconv"
"strings"
)
func main() {
infile := flag.String("input", "map.gdf", "Input GDF map to read.")
outfile := flag.String("output", "fediverse.png", "Output filename for the visualization.")
scaling := flag.Float64("scale", 1, "Scaling factor of image")
flag.Parse()
fedMap := NewFedMap()
nodeFn := func(s string) {
line := strings.Split(s, ",")
if len(line) != 2 {
log.Printf("node line does not have two values: %q", s)
return
}
i64, err := strconv.ParseInt(line[0], 10, 32)
if err != nil {
log.Printf("node line does not have integer id: %s", err)
return
}
fedMap.AddNode(int(i64), line[1])
}
edgeFn := func(s string) {
line := strings.Split(s, ",")
if len(line) != 2 {
log.Printf("edge line does not have two values: %q", s)
return
}
f64, err := strconv.ParseInt(line[0], 10, 32)
if err != nil {
log.Printf("edge line does not have integer 'from' id: %s", err)
return
}
t64, err := strconv.ParseInt(line[1], 10, 32)
if err != nil {
log.Printf("edge line does not have integer 'to' id: %s", err)
return
}
fedMap.AddEdge(int(f64), int(t64))
}
gdfScanner := NewGDFScanner(*infile, nodeFn, edgeFn)
if err := gdfScanner.Open(); err != nil {
log.Fatalf("gdf scanner cannot open file: %s", err)
}
for !gdfScanner.Done() {
gdfScanner.Scan()
}
gen := &FedMapVisualizer{
F: fedMap,
I: &RGBFactory{},
A: NewCenterRandomWalker(0, 100),
Scaling: *scaling,
}
image, _ := gen.Generate()
out, err := os.Create(*outfile)
if err != nil {
log.Fatalf("error creating %q: %s", *outfile, err)
}
if err := png.Encode(out, image); err != nil {
log.Fatalf("error writing to %q: %s", *outfile, err)
}
}