diff --git a/graph.go b/graph.go index 6cc613c..406df30 100644 --- a/graph.go +++ b/graph.go @@ -32,12 +32,17 @@ func NewGraphBuilder(mp PagesRepository) (*graphBuilder, error) { return nil, err } - return &graphBuilder{ + gb := &graphBuilder{ refs: refs, nodeMap: make(NodeMap), nodes: nil, edges: nil, - }, nil + } + gb.nodeMap["Daily_Notes"] = Node{Id: -1} + gb.nodeMap["TODO"] = Node{Id: -1} + gb.nodeMap["DONE"] = Node{Id: -1} + gb.nodeMap["Projects"] = Node{Id: -1} + return gb, nil } func (gb *graphBuilder) prepareGraph() error { @@ -66,7 +71,10 @@ func (gb *graphBuilder) RemoveNodeWithSuffix(suffix string) { } func (gb *graphBuilder) buildFromCenter(name string) error { - _ = gb.addNode(name, "#ef2929") + id := gb.addNode(name, "#ef2929") + if id < 0 { + return nil + } if ref, e := gb.refs[name]; e { for _, item := range ref { @@ -89,9 +97,9 @@ func prepareEdges(refs Refs, nodeMap NodeMap) []Edge { var edges []Edge edgeSet := make(map[Edge]bool) for key, references := range refs { - if to, e := nodeMap[key]; e { + if to, e := nodeMap[key]; e && to.Id >= 0 { for _, item := range references { - if from, e := nodeMap[item.Name]; e { + if from, e := nodeMap[item.Name]; e && from.Id >= 0 { edge := Edge{ From: from.Id, To: to.Id, @@ -110,6 +118,9 @@ func prepareEdges(refs Refs, nodeMap NodeMap) []Edge { func prepareNodes(nodeMap NodeMap, apply func(node Node) Node) []Node { var nodes []Node for _, node := range nodeMap { + if node.Id < 0 { + continue + } nodes = append(nodes, apply(Node{ Id: node.Id, Label: node.Label, diff --git a/main.go b/main.go index bc95e8a..48b84b8 100644 --- a/main.go +++ b/main.go @@ -104,7 +104,7 @@ type Node struct { Id int `json:"id"` Label string `json:"label"` Color *string `json:"color"` - Opacity float64 `json:"opacity"` + Opacity float64 `json:"opacity"` } type Edge struct { @@ -809,6 +809,7 @@ func main() { http.Error(w, err.Error(), 500) return } + gb.RemoveNode(name) err = gb.buildFromCenter(name) if err != nil { @@ -819,16 +820,11 @@ func main() { // Keep a copy of the nodes, buildFromCenter appends to the nodeMap var nodes []string for k, _ := range gb.nodeMap { - if k == "Daily_Notes" || strings.HasSuffix(k, "Mei_2020") { - continue - } nodes = append(nodes, k) } - if name != "Daily_Notes" { - for _, node := range nodes { - err = gb.buildFromCenter(node) - } + for _, node := range nodes { + err = gb.buildFromCenter(node) } err = gb.prepareGraph()