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 nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &graphBuilder{
|
gb := &graphBuilder{
|
||||||
refs: refs,
|
refs: refs,
|
||||||
nodeMap: make(NodeMap),
|
nodeMap: make(NodeMap),
|
||||||
nodes: nil,
|
nodes: nil,
|
||||||
edges: 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 {
|
func (gb *graphBuilder) prepareGraph() error {
|
||||||
|
@ -66,7 +71,10 @@ func (gb *graphBuilder) RemoveNodeWithSuffix(suffix string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gb *graphBuilder) buildFromCenter(name string) error {
|
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 {
|
if ref, e := gb.refs[name]; e {
|
||||||
for _, item := range ref {
|
for _, item := range ref {
|
||||||
|
@ -89,9 +97,9 @@ 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 to, e := nodeMap[key]; e {
|
if to, e := nodeMap[key]; e && to.Id >= 0 {
|
||||||
for _, item := range references {
|
for _, item := range references {
|
||||||
if from, e := nodeMap[item.Name]; e {
|
if from, e := nodeMap[item.Name]; e && from.Id >= 0 {
|
||||||
edge := Edge{
|
edge := Edge{
|
||||||
From: from.Id,
|
From: from.Id,
|
||||||
To: to.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 {
|
func prepareNodes(nodeMap NodeMap, apply func(node Node) Node) []Node {
|
||||||
var nodes []Node
|
var nodes []Node
|
||||||
for _, node := range nodeMap {
|
for _, node := range nodeMap {
|
||||||
|
if node.Id < 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
nodes = append(nodes, apply(Node{
|
nodes = append(nodes, apply(Node{
|
||||||
Id: node.Id,
|
Id: node.Id,
|
||||||
Label: node.Label,
|
Label: node.Label,
|
||||||
|
|
12
main.go
12
main.go
|
@ -104,7 +104,7 @@ 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"`
|
Opacity float64 `json:"opacity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Edge struct {
|
type Edge struct {
|
||||||
|
@ -809,6 +809,7 @@ func main() {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
gb.RemoveNode(name)
|
||||||
|
|
||||||
err = gb.buildFromCenter(name)
|
err = gb.buildFromCenter(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -819,16 +820,11 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
if name != "Daily_Notes" {
|
for _, node := range nodes {
|
||||||
for _, node := range nodes {
|
err = gb.buildFromCenter(node)
|
||||||
err = gb.buildFromCenter(node)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gb.prepareGraph()
|
err = gb.prepareGraph()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user