Add weights
This commit is contained in:
parent
48cf8ee564
commit
a5dd8d5987
35
node.go
35
node.go
|
@ -6,8 +6,9 @@ import (
|
|||
|
||||
// Node represents single node information to be used in Graph.
|
||||
type Node struct {
|
||||
ID_ string `json:"id"`
|
||||
Group_ int `json:"group"`
|
||||
ID_ string `json:"id"`
|
||||
Group_ int `json:"group"`
|
||||
Weight_ int `json:"weight"`
|
||||
|
||||
meta *Metadata
|
||||
}
|
||||
|
@ -16,8 +17,9 @@ type Node struct {
|
|||
func NewNode(id, name string) *Node {
|
||||
meta := NewMetadata(name)
|
||||
return &Node{
|
||||
ID_: id,
|
||||
Group_: clientGroup(meta),
|
||||
ID_: id,
|
||||
Group_: group(meta),
|
||||
Weight_: weight(meta),
|
||||
|
||||
meta: meta,
|
||||
}
|
||||
|
@ -28,8 +30,8 @@ func (n *Node) IsClient() bool {
|
|||
return n.meta.Name == "StatusIM"
|
||||
}
|
||||
|
||||
// clientGroup returns group id based in server type.
|
||||
func clientGroup(meta *Metadata) int {
|
||||
// group returns group id based in server type.
|
||||
func group(meta *Metadata) int {
|
||||
switch meta.Name {
|
||||
case "StatusIM":
|
||||
return 1
|
||||
|
@ -42,6 +44,20 @@ func clientGroup(meta *Metadata) int {
|
|||
return 3
|
||||
}
|
||||
|
||||
// weight returns weight based in server type.
|
||||
func weight(meta *Metadata) int {
|
||||
switch meta.Name {
|
||||
case "StatusIM":
|
||||
return 1
|
||||
case "Statusd":
|
||||
return 2
|
||||
default:
|
||||
return 1
|
||||
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
// ClusterNode represents single cluster node information.
|
||||
type ClusterNode struct {
|
||||
IP string
|
||||
|
@ -72,11 +88,16 @@ func (n *Node) ID() string {
|
|||
return n.ID_
|
||||
}
|
||||
|
||||
// Group returns group of the node. Satisfies graph.Node interface.
|
||||
// Group returns group of the node. Satisfies graph.GroupedNode interface.
|
||||
func (n *Node) Group() int {
|
||||
return n.Group_
|
||||
}
|
||||
|
||||
// Weight returns group of the node. Satisfies graph.WeightedNode interface.
|
||||
func (n *Node) Weight() int {
|
||||
return n.Weight_
|
||||
}
|
||||
|
||||
// Link represents link between two nodes.
|
||||
type Link struct {
|
||||
FromID, ToID string
|
||||
|
|
|
@ -111,6 +111,7 @@ var initGraph = function () {
|
|||
autoColorNodes(graphData.nodes);
|
||||
graphData.nodes.forEach((node, idx) => {
|
||||
let val = valAccessor(node) || 1;
|
||||
console.log(node);
|
||||
if (!nodeGeometries.hasOwnProperty(val)) {
|
||||
nodeGeometries[val] = NewEthereumGeometry(val);
|
||||
}
|
||||
|
@ -278,7 +279,7 @@ function onMouseMove( event ) {
|
|||
canvas.addEventListener( 'mousemove', onMouseMove, false );
|
||||
|
||||
},{"./js/colors.js":2,"./js/ethereum.js":3,"./js/keys.js":4,"./js/shitty_hacks.js":5,"./js/stats.js":6,"dat.gui":68,"stats-js":70}],2:[function(require,module,exports){
|
||||
var schemePaired = require('d3-scale-chromatic').schemePaired;
|
||||
var schemePaired = require('d3-scale-chromatic').schemeSet1;
|
||||
var tinyColor = require('tinycolor2');
|
||||
|
||||
const colorStr2Hex = str => isNaN(str) ? parseInt(tinyColor(str).toHex(), 16) : str;
|
||||
|
|
|
@ -110,6 +110,7 @@ var initGraph = function () {
|
|||
autoColorNodes(graphData.nodes);
|
||||
graphData.nodes.forEach((node, idx) => {
|
||||
let val = valAccessor(node) || 1;
|
||||
console.log(node);
|
||||
if (!nodeGeometries.hasOwnProperty(val)) {
|
||||
nodeGeometries[val] = NewEthereumGeometry(val);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var schemePaired = require('d3-scale-chromatic').schemePaired;
|
||||
var schemePaired = require('d3-scale-chromatic').schemeSet1;
|
||||
var tinyColor = require('tinycolor2');
|
||||
|
||||
const colorStr2Hex = str => isNaN(str) ? parseInt(tinyColor(str).toHex(), 16) : str;
|
||||
|
|
4
ws.go
4
ws.go
|
@ -138,8 +138,8 @@ func (ws *WSServer) refresh(ctx context.Context) error {
|
|||
log.Printf("Loaded graph: %d nodes, %d links\n", len(g.Nodes()), len(g.Links()))
|
||||
|
||||
log.Printf("Initializing layout...")
|
||||
repelling := layout.NewGravityForce(-10.0, layout.BarneHutMethod)
|
||||
springs := layout.NewSpringForce(0.02, 5.0, layout.ForEachLink)
|
||||
repelling := layout.NewGravityForce(-25.0, layout.BarneHutMethod)
|
||||
springs := layout.NewSpringForce(0.02, 15.0, layout.ForEachLink)
|
||||
drag := layout.NewDragForce(0.8, layout.ForEachNode)
|
||||
l := layout.New(g, repelling, springs, drag)
|
||||
|
||||
|
|
Loading…
Reference in New Issue