Add initial data support

This commit is contained in:
Ivan Danyliuk 2018-09-18 17:35:16 +03:00
parent 7d30dbec6d
commit e5e10abf2e
No known key found for this signature in database
GPG Key ID: 97ED33CE024E1DBF
5 changed files with 9108 additions and 10 deletions

1582
data/3dgrid125.json Normal file

File diff suppressed because it is too large Load Diff

1835
data/net100.json Normal file

File diff suppressed because it is too large Load Diff

5647
data/net300.json Normal file

File diff suppressed because it is too large Load Diff

37
network.go Normal file
View File

@ -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
}

View File

@ -11,15 +11,14 @@ import (
type NetworkSelector struct {
vecty.Core
description string
value 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)
}