-
Notifications
You must be signed in to change notification settings - Fork 5
/
graph.go
49 lines (40 loc) · 1.1 KB
/
graph.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"runtime"
"github.com/gopherjs/vecty"
)
// UpdateGraph starts graph layout simulation.
func (p *Page) UpdateGraph() {
p.loader.Reset()
p.loaded = false
vecty.Rerender(p)
config := p.forceEditor.Config()
p.loader.SetSteps(config.Steps)
for i := 0; i < config.Steps; i++ {
p.layout.UpdatePositions()
p.loader.Inc()
vecty.Rerender(p.loader)
runtime.Gosched()
}
p.loaded = true
p.RecreateObjects()
}
// RecreateObjects removes (if any) objects from the WebGL scene,
// and creates all new objects based on current data and positions.
// It doesn't do any calculations of changes to the layout or graph data.
func (p *Page) RecreateObjects() {
p.loaded = true
p.loader.Reset()
p.webgl.RemoveObjects()
p.webgl.CreateObjects(p.layout.Positions(), p.layout.Links())
vecty.Rerender(p)
}
// ApplyForces applies current forces to the objects, and runs
// a single simulation run to update positions.
func (p *Page) ApplyForces() {
fc := p.forceEditor.Config()
p.layout.SetConfig(fc.Config)
p.layout.UpdatePositions()
p.webgl.updatePositions()
p.webgl.rt.EnableRendering()
}