This commit is contained in:
parent
e6345edef9
commit
243c5df043
21
graph.go
21
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,
|
||||
|
|
6
main.go
6
main.go
|
@ -809,6 +809,7 @@ func main() {
|
|||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
gb.RemoveNode(name)
|
||||
|
||||
err = gb.buildFromCenter(name)
|
||||
if err != nil {
|
||||
|
@ -819,17 +820,12 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
err = gb.prepareGraph()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue
Block a user