Fix blinking node bug

This commit is contained in:
Ivan Danyliuk 2018-10-27 16:04:54 +02:00
parent 161693931e
commit 72ee3b89c9
No known key found for this signature in database
GPG Key ID: 97ED33CE024E1DBF

View File

@ -25,13 +25,15 @@ func (w *WebGLScene) AnimatePropagation(plog *propagation.Log) {
fn := func() { fn := func() {
// blink nodes for this timestamp // blink nodes for this timestamp
for _, idx := range nodes { for _, idx := range nodes {
w.BlinkNode(idx) node := w.nodes[idx]
go time.AfterFunc(delay, func() { w.UnblinkNode(idx) }) w.BlinkNode(node)
go time.AfterFunc(delay, func() { w.UnblinkNode(node) })
} }
// blink links for this timestamp // blink links for this timestamp
for _, idx := range edges { for _, idx := range edges {
w.BlinkEdge(idx) edge := w.lines[idx]
go time.AfterFunc(delay, func() { w.UnblinkEdge(idx) }) w.BlinkEdge(edge)
go time.AfterFunc(delay, func() { w.UnblinkEdge(edge) })
} }
} }
go time.AfterFunc(duration, fn) go time.AfterFunc(duration, fn)
@ -53,10 +55,11 @@ func (w *WebGLScene) AnimateOneStep(plog *propagation.Log, step int) {
} }
// blink nodes for this timestamp // blink nodes for this timestamp
for i, _ := range w.nodes { for i, _ := range w.nodes {
node := w.nodes[i]
if _, ok := nodesToBlink[i]; ok { if _, ok := nodesToBlink[i]; ok {
w.BlinkNode(i) w.BlinkNode(node)
} else { } else {
w.UnblinkNode(i) w.UnblinkNode(node)
} }
} }
@ -65,35 +68,32 @@ func (w *WebGLScene) AnimateOneStep(plog *propagation.Log, step int) {
edgesToBlink[idx] = struct{}{} edgesToBlink[idx] = struct{}{}
} }
for i, _ := range w.lines { for i, _ := range w.lines {
edge := w.lines[i]
if _, ok := edgesToBlink[i]; ok { if _, ok := edgesToBlink[i]; ok {
w.BlinkEdge(i) w.BlinkEdge(edge)
} else { } else {
w.UnblinkEdge(i) w.UnblinkEdge(edge)
} }
} }
} }
// BlinkNode animates a single node blinking. Node specified by its idx. // BlinkNode animates a single node blinking. Node specified by its idx.
// TODO(divan): consider renaming it to Highlight or something. // TODO(divan): consider renaming it to Highlight or something.
func (w *WebGLScene) BlinkNode(id int) { func (w *WebGLScene) BlinkNode(node *Mesh) {
node := w.nodes[id]
node.Set("material", BlinkedNodeMaterial) node.Set("material", BlinkedNodeMaterial)
} }
func (w *WebGLScene) UnblinkNode(id int) { func (w *WebGLScene) UnblinkNode(node *Mesh) {
node := w.nodes[id]
node.Object.Set("material", DefaultNodeMaterial) node.Object.Set("material", DefaultNodeMaterial)
} }
// BlinkEdge animates a single edge blinking. Edge specified by its idx. // BlinkEdge animates a single edge blinking. Edge specified by its idx.
func (w *WebGLScene) BlinkEdge(id int) { func (w *WebGLScene) BlinkEdge(edge *Line) {
edge := w.lines[id]
edge.Set("material", BlinkedEdgeMaterial) edge.Set("material", BlinkedEdgeMaterial)
} }
func (w *WebGLScene) UnblinkEdge(id int) { func (w *WebGLScene) UnblinkEdge(edge *Line) {
node := w.lines[id] edge.Set("material", DefaultEdgeMaterial)
node.Object.Set("material", DefaultEdgeMaterial)
} }
// NewBlinkedEdgeMaterial creates a new default material for the graph blinked edge lines. // NewBlinkedEdgeMaterial creates a new default material for the graph blinked edge lines.