Browse Source

Add title to graph nodes

single-block-api
Peter Stuifzand 9 months ago
parent
commit
562dadbf4a
  1. 6
      graph.go
  2. 1
      main.go

6
graph.go

@ -80,7 +80,7 @@ func (gb *graphBuilder) RemoveNode(name string) { @@ -80,7 +80,7 @@ func (gb *graphBuilder) RemoveNode(name string) {
}
func (gb *graphBuilder) RemoveNodeWithSuffix(suffix string) {
for k, _ := range gb.nodeMap {
for k := range gb.nodeMap {
if strings.HasSuffix(k, suffix) {
delete(gb.nodeMap, k)
}
@ -141,6 +141,7 @@ func prepareNodes(nodeMap NodeMap, apply func(node Node) Node) []Node { @@ -141,6 +141,7 @@ func prepareNodes(nodeMap NodeMap, apply func(node Node) Node) []Node {
nodes = append(nodes, apply(Node{
Id: node.Id,
Label: node.Label,
Title: node.Title,
Color: node.Color,
Opacity: node.Opacity,
}))
@ -160,7 +161,8 @@ func (gb *graphBuilder) prepareNodeMap() { @@ -160,7 +161,8 @@ func (gb *graphBuilder) prepareNodeMap() {
func (gb *graphBuilder) addNode(key string, color string) int {
if _, e := gb.nodeMap[key]; !e {
color := color
gb.nodeMap[key] = Node{gb.nodeCount, key, &color, 1}
title:= strings.Replace(key, "_", " ", -1)
gb.nodeMap[key] = Node{gb.nodeCount, key, title, &color, 1}
gb.nodeCount += 1
}

1
main.go

@ -146,6 +146,7 @@ type indexPage struct { @@ -146,6 +146,7 @@ type indexPage struct {
type Node struct {
Id int `json:"id"`
Label string `json:"label"`
Title string `json:"title"`
Color *string `json:"color"`
Opacity float64 `json:"opacity"`
}

Loading…
Cancel
Save