mirror of
https://github.com/status-im/whispervis.git
synced 2025-02-02 00:15:31 +00:00
Add initial data support
This commit is contained in:
parent
7d30dbec6d
commit
e5e10abf2e
1582
data/3dgrid125.json
Normal file
1582
data/3dgrid125.json
Normal file
File diff suppressed because it is too large
Load Diff
1835
data/net100.json
Normal file
1835
data/net100.json
Normal file
File diff suppressed because it is too large
Load Diff
5647
data/net300.json
Normal file
5647
data/net300.json
Normal file
File diff suppressed because it is too large
Load Diff
37
network.go
Normal file
37
network.go
Normal 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
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user