Improve colors of graph
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5bf14bd1d4
commit
64f7ebe8f9
38
graph.go
38
graph.go
|
@ -15,7 +15,7 @@ type graphBuilder struct {
|
||||||
edges []Edge
|
edges []Edge
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeMap map[string]int
|
type NodeMap map[string]Node
|
||||||
|
|
||||||
func NewGraphBuilder(mp PagesRepository) (*graphBuilder, error) {
|
func NewGraphBuilder(mp PagesRepository) (*graphBuilder, error) {
|
||||||
refs := make(Refs)
|
refs := make(Refs)
|
||||||
|
@ -44,7 +44,7 @@ func (gb *graphBuilder) prepareGraph() error {
|
||||||
gb.nodes = prepareNodes(gb.nodeMap, func(node Node) Node {
|
gb.nodes = prepareNodes(gb.nodeMap, func(node Node) Node {
|
||||||
if node.Id == 0 {
|
if node.Id == 0 {
|
||||||
var green string
|
var green string
|
||||||
green = "green"
|
green = "#f57900"
|
||||||
node.Color = &green
|
node.Color = &green
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
|
@ -66,18 +66,18 @@ func (gb *graphBuilder) RemoveNodeWithSuffix(suffix string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gb *graphBuilder) buildFromCenter(name string) error {
|
func (gb *graphBuilder) buildFromCenter(name string) error {
|
||||||
_ = gb.addNode(name)
|
_ = gb.addNode(name, "#ef2929")
|
||||||
|
|
||||||
if ref, e := gb.refs[name]; e {
|
if ref, e := gb.refs[name]; e {
|
||||||
for _, item := range ref {
|
for _, item := range ref {
|
||||||
gb.addNode(item.Name)
|
gb.addNode(item.Name, "#fce94f")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, references := range gb.refs {
|
for key, references := range gb.refs {
|
||||||
for _, item := range references {
|
for _, item := range references {
|
||||||
if name == item.Name {
|
if name == item.Name {
|
||||||
gb.addNode(key)
|
gb.addNode(key, "#ad7fa8")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,12 +89,12 @@ func prepareEdges(refs Refs, nodeMap NodeMap) []Edge {
|
||||||
var edges []Edge
|
var edges []Edge
|
||||||
edgeSet := make(map[Edge]bool)
|
edgeSet := make(map[Edge]bool)
|
||||||
for key, references := range refs {
|
for key, references := range refs {
|
||||||
if toID, e := nodeMap[key]; e {
|
if to, e := nodeMap[key]; e {
|
||||||
for _, item := range references {
|
for _, item := range references {
|
||||||
if fromID, e := nodeMap[item.Name]; e {
|
if from, e := nodeMap[item.Name]; e {
|
||||||
edge := Edge{
|
edge := Edge{
|
||||||
From: fromID,
|
From: from.Id,
|
||||||
To: toID,
|
To: to.Id,
|
||||||
}
|
}
|
||||||
if _, e := edgeSet[edge]; !e {
|
if _, e := edgeSet[edge]; !e {
|
||||||
edgeSet[edge] = true
|
edgeSet[edge] = true
|
||||||
|
@ -109,11 +109,12 @@ func prepareEdges(refs Refs, nodeMap NodeMap) []Edge {
|
||||||
|
|
||||||
func prepareNodes(nodeMap NodeMap, apply func(node Node) Node) []Node {
|
func prepareNodes(nodeMap NodeMap, apply func(node Node) Node) []Node {
|
||||||
var nodes []Node
|
var nodes []Node
|
||||||
for name, id := range nodeMap {
|
for _, node := range nodeMap {
|
||||||
nodes = append(nodes, apply(Node{
|
nodes = append(nodes, apply(Node{
|
||||||
Id: id,
|
Id: node.Id,
|
||||||
Label: name,
|
Label: node.Label,
|
||||||
Color: nil,
|
Color: node.Color,
|
||||||
|
Opacity: node.Opacity,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
return nodes
|
return nodes
|
||||||
|
@ -121,18 +122,19 @@ func prepareNodes(nodeMap NodeMap, apply func(node Node) Node) []Node {
|
||||||
|
|
||||||
func (gb *graphBuilder) prepareNodeMap() {
|
func (gb *graphBuilder) prepareNodeMap() {
|
||||||
for key, references := range gb.refs {
|
for key, references := range gb.refs {
|
||||||
gb.addNode(key)
|
gb.addNode(key, "#5e8")
|
||||||
for _, item := range references {
|
for _, item := range references {
|
||||||
gb.addNode(item.Name)
|
gb.addNode(item.Name, "#403")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gb *graphBuilder) addNode(key string) int {
|
func (gb *graphBuilder) addNode(key string, color string) int {
|
||||||
if _, e := gb.nodeMap[key]; !e {
|
if _, e := gb.nodeMap[key]; !e {
|
||||||
gb.nodeMap[key] = gb.nodeCount
|
color := color
|
||||||
|
gb.nodeMap[key] = Node{gb.nodeCount, key, &color, 1}
|
||||||
gb.nodeCount += 1
|
gb.nodeCount += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return gb.nodeMap[key]
|
return gb.nodeMap[key].Id
|
||||||
}
|
}
|
||||||
|
|
16
main.go
16
main.go
|
@ -101,9 +101,10 @@ type indexPage struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
Color *string `json:"color"`
|
Color *string `json:"color"`
|
||||||
|
Opacity float64 `json:"opacity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Edge struct {
|
type Edge struct {
|
||||||
|
@ -818,11 +819,16 @@ func main() {
|
||||||
// Keep a copy of the nodes, buildFromCenter appends to the nodeMap
|
// Keep a copy of the nodes, buildFromCenter appends to the nodeMap
|
||||||
var nodes []string
|
var nodes []string
|
||||||
for k, _ := range gb.nodeMap {
|
for k, _ := range gb.nodeMap {
|
||||||
|
if k == "Daily_Notes" || strings.HasSuffix(k, "Mei_2020") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
nodes = append(nodes, k)
|
nodes = append(nodes, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, node := range nodes {
|
if name != "Daily_Notes" {
|
||||||
err = gb.buildFromCenter(node)
|
for _, node := range nodes {
|
||||||
|
err = gb.buildFromCenter(node)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gb.prepareGraph()
|
err = gb.prepareGraph()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user