-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgraphics.go
62 lines (47 loc) · 1.62 KB
/
graphics.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
/*
Functinality for taking control of layout of graph
*/
package gographer
import (
"fmt"
"strconv"
)
type NodeGraphics struct {
Name string `json:"name, string"`
FGColor string `json:"fgcolor, string"`
BGColor string `json:"bgcolor, string"`
Shape string `json:"shape, string"`
X int `json:"x, int"`
Y int `json:"y, int"`
Height int `json:"height, int"`
Width int `json:"width, int"`
}
type EdgeGraphics struct {
Type string `json:"type, string"`
Name string `json:"name, string"`
Value string `json:"value, string"`
}
func (g *Graph) AddGraphicNode(id int, name string, group int, size int,
description string, fgcolor string, bgcolor string, shape string, x int,
y int, height int, width int) {
graphics := NodeGraphics{description, fgcolor, bgcolor, shape, x, y, height, width}
// TODO: Maybe clean up the below and write this and AddNode as one func
n := &Node{Id: id, Name: name, Group: "group " + strconv.Itoa(group),
Size: size, Graphics: graphics}
n.stringIdentifier = fmt.Sprintf("%d", id)
// Prevents nodes being added multiple times
if _, alreadyAdded := g.Nodes[n.stringIdentifier]; !alreadyAdded {
g.Nodes[n.stringIdentifier] = n
g.BroadcastAddNode(*n)
}
}
func (g *Graph) AddGraphicEdge(from, to, id, weight int, typ, name, value string) {
graphics := EdgeGraphics{typ, name, value}
e := &Edge{Source: from, Target: to, Id: id, Weight: weight, Graphics: graphics}
e.stringIdentifier = fmt.Sprintf("%d-%d:%d", from, to, id)
e.Weight = 1
if _, exists := g.Edges[e.stringIdentifier]; !exists {
g.Edges[e.stringIdentifier] = e
g.BroadcastAddEdge(*e)
}
}