whispervis/graph.go

40 lines
852 B
Go
Raw Normal View History

2018-09-11 16:23:37 +03:00
package main
import (
"runtime"
"github.com/gopherjs/vecty"
)
2018-09-19 16:00:53 +03:00
// UpdateGraph starts graph layout simulation.
func (p *Page) UpdateGraph() {
2018-09-11 16:23:37 +03:00
p.loader.Reset()
p.loaded = false
vecty.Rerender(p)
config := p.forceEditor.Config()
2018-09-17 22:11:04 +03:00
p.loader.SetSteps(config.Steps)
for i := 0; i < config.Steps; i++ {
2018-09-11 16:23:37 +03:00
p.layout.UpdatePositions()
p.loader.Inc()
vecty.Rerender(p.loader)
runtime.Gosched()
}
p.loaded = true
2018-09-19 16:00:53 +03:00
// TODO(divan): remove previous objects
2018-09-20 16:30:20 +03:00
p.webgl.RemoveObjects()
2018-09-17 22:11:04 +03:00
p.webgl.CreateObjects(p.layout.Positions(), p.layout.Links())
2018-10-12 22:34:30 +02:00
2018-09-11 16:23:37 +03:00
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.Disable()
}