2018-09-06 13:54:35 +00:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/divan/graphx/layout"
|
|
|
|
"github.com/gopherjs/vecty"
|
|
|
|
"github.com/gopherjs/vecty/elem"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ForceEditor struct {
|
|
|
|
vecty.Core
|
|
|
|
|
|
|
|
config layout.Config
|
2018-09-06 17:07:24 +00:00
|
|
|
|
|
|
|
repelling *ForceInput
|
|
|
|
spring *ForceInput
|
|
|
|
drag *ForceInput
|
2018-09-06 13:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *ForceEditor) Render() vecty.ComponentOrHTML {
|
|
|
|
return elem.Div(
|
|
|
|
elem.Heading3(
|
|
|
|
vecty.Text("Layout forces:"),
|
|
|
|
),
|
|
|
|
elem.HorizontalRule(),
|
|
|
|
elem.Form(
|
|
|
|
vecty.Markup(
|
|
|
|
vecty.Class("pure-form"),
|
|
|
|
),
|
2018-09-06 17:07:24 +00:00
|
|
|
l.repelling,
|
|
|
|
l.spring,
|
|
|
|
l.drag,
|
2018-09-06 13:54:35 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewForceEditor() *ForceEditor {
|
|
|
|
config := layout.DefaultConfig
|
2018-09-06 17:07:24 +00:00
|
|
|
repelling := NewForceInput("Gravity force:", config.Repelling)
|
|
|
|
spring := NewForceInput("Spring force:", config.SpringStiffness)
|
|
|
|
drag := NewForceInput("Drag force:", config.DragCoeff)
|
2018-09-06 13:54:35 +00:00
|
|
|
return &ForceEditor{
|
2018-09-06 17:07:24 +00:00
|
|
|
config: config,
|
|
|
|
repelling: repelling,
|
|
|
|
spring: spring,
|
|
|
|
drag: drag,
|
2018-09-06 13:54:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *ForceEditor) Config() layout.Config {
|
2018-09-06 17:07:24 +00:00
|
|
|
return layout.Config{
|
|
|
|
Repelling: l.repelling.Value(),
|
|
|
|
SpringStiffness: l.spring.Value(),
|
|
|
|
SpringLen: l.config.SpringLen,
|
|
|
|
DragCoeff: l.drag.Value(),
|
|
|
|
}
|
2018-09-06 13:54:35 +00:00
|
|
|
}
|