Add initial data support
This commit is contained in:
parent
7d30dbec6d
commit
e5e10abf2e
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/divan/graphx/formats"
|
||||
"github.com/divan/graphx/graph"
|
||||
)
|
||||
|
||||
// Network represents network graph and information, used for
|
||||
// for simulation and visualization.
|
||||
type Network struct {
|
||||
Name string
|
||||
Description string
|
||||
Data *graph.Graph
|
||||
|
||||
NodesCount int
|
||||
}
|
||||
|
||||
// LoadNetwork loads network information from the JSON file.
|
||||
// JSON format is specified in graphx/formats package.
|
||||
func LoadNetwork(file string) (*Network, error) {
|
||||
name := path.Base(file)
|
||||
desc := ""
|
||||
|
||||
g, err := formats.FromD3JSON(file)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open '%s': %v", file, err)
|
||||
}
|
||||
|
||||
return &Network{
|
||||
Name: name,
|
||||
Description: desc,
|
||||
Data: g,
|
||||
}, nil
|
||||
}
|
|
@ -11,15 +11,14 @@ import (
|
|||
type NetworkSelector struct {
|
||||
vecty.Core
|
||||
|
||||
description string
|
||||
current *Network
|
||||
networks map[string]*Network
|
||||
value string
|
||||
}
|
||||
|
||||
// NewNetworkSelector creates new NetworkSelector.
|
||||
func NewNetworkSelector(defaultValue string) *NetworkSelector {
|
||||
return &NetworkSelector{
|
||||
value: defaultValue,
|
||||
}
|
||||
func NewNetworkSelector(defaultNet string) *NetworkSelector {
|
||||
return &NetworkSelector{}
|
||||
}
|
||||
|
||||
// Render implements the vecty.Component interface.
|
||||
|
@ -75,22 +74,20 @@ func (n *NetworkSelector) descriptionBlock() *vecty.HTML {
|
|||
vecty.Style("font-style", "italic"),
|
||||
vecty.Style("color", "blue"),
|
||||
),
|
||||
vecty.Text(n.description),
|
||||
vecty.Text(n.current.Description),
|
||||
)
|
||||
}
|
||||
|
||||
// onChange implements handler for select input changed value
|
||||
func (n *NetworkSelector) onChange(e *vecty.Event) {
|
||||
var desc string
|
||||
value := e.Target.Get("value").String()
|
||||
for i := 0; i < e.Target.Length(); i++ {
|
||||
optValue := e.Target.Index(i).Get("value").String()
|
||||
if optValue == value {
|
||||
desc = e.Target.Index(i).Get("description").String()
|
||||
//desc = e.Target.Index(i).Get("description").String()
|
||||
}
|
||||
}
|
||||
|
||||
n.value = value
|
||||
n.description = desc
|
||||
vecty.Rerender(n)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue