Jack Mallers
7 years ago
4 changed files with 4 additions and 252 deletions
@ -1,169 +0,0 @@ |
|||||
import { findDOMNode } from 'react-dom' |
|
||||
import React, { Component } from 'react' |
|
||||
import PropTypes from 'prop-types' |
|
||||
import { ForceGraph, ForceGraphNode, ForceGraphLink } from 'react-vis-force' |
|
||||
import { FaCircle } from 'react-icons/lib/fa' |
|
||||
import Isvg from 'react-inlinesvg' |
|
||||
import LoadingBolt from 'components/LoadingBolt' |
|
||||
import bitcoinIcon from 'icons/skinny_bitcoin.svg' |
|
||||
import styles from './NetworkGraph.scss' |
|
||||
|
|
||||
class NetworkGraph extends Component { |
|
||||
constructor(props) { |
|
||||
super(props) |
|
||||
this.state = { |
|
||||
ready: false |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
componentWillMount() { |
|
||||
setTimeout(() => { |
|
||||
this.setState({ ready: true }) |
|
||||
}, 10000) |
|
||||
} |
|
||||
|
|
||||
render() { |
|
||||
const { ready } = this.state |
|
||||
const { |
|
||||
network: { nodes, edges, selectedChannel, networkLoading }, |
|
||||
selectedPeerPubkeys, |
|
||||
selectedChannelIds, |
|
||||
currentRouteChanIds, |
|
||||
identity_pubkey |
|
||||
} = this.props |
|
||||
|
|
||||
if ((!nodes.length || !edges.length) || networkLoading) { |
|
||||
return ( |
|
||||
<section className={styles.network}> |
|
||||
<div className={styles.networkLoading}> |
|
||||
<h1>loading network graph</h1> |
|
||||
</div> |
|
||||
</section> |
|
||||
) |
|
||||
} |
|
||||
|
|
||||
return ( |
|
||||
<section className={styles.network}> |
|
||||
<ForceGraph |
|
||||
id='map' |
|
||||
simulationOptions={ |
|
||||
{ |
|
||||
height: 800, |
|
||||
width: 800, |
|
||||
strength: { |
|
||||
charge: -750 |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
labelAttr='label' |
|
||||
opacityFactor={1} |
|
||||
zoomOptions={{ minScale: 0.1, maxScale: 5, scale: 0.2 }} |
|
||||
zoom |
|
||||
highlightDependencies |
|
||||
ref={(el) => { |
|
||||
console.log('el: ', el) |
|
||||
this.fg = el |
|
||||
}} |
|
||||
> |
|
||||
{ |
|
||||
nodes.map(node => |
|
||||
<ForceGraphNode |
|
||||
id={node.pub_key} |
|
||||
r={25} |
|
||||
label={node.pub_key} |
|
||||
key={node.pub_key} |
|
||||
node={{ id: node.pub_key }} |
|
||||
strokeWidth={2.5} |
|
||||
className={`${styles.node} ${identity_pubkey === node.pub_key && styles.owner} ${selectedPeerPubkeys.includes(node.pub_key) && styles.peer}`} |
|
||||
/> |
|
||||
) |
|
||||
} |
|
||||
{ |
|
||||
edges.map(edge => { |
|
||||
return ( |
|
||||
<ForceGraphLink |
|
||||
id={edge.channel_id} |
|
||||
className={selectedChannelIds.includes(edge.channel_id) && styles.activeEdge} |
|
||||
key={edge.channel_id} |
|
||||
link={{ source: edge.node1_pub, target: edge.node2_pub }} |
|
||||
stroke='silver' |
|
||||
strokeWidth='5' |
|
||||
/> |
|
||||
) |
|
||||
}) |
|
||||
} |
|
||||
|
|
||||
{ |
|
||||
currentRouteChanIds.map((chan_id) => { |
|
||||
const line = document.getElementById(chan_id) |
|
||||
|
|
||||
if (!line) { return } |
|
||||
const x1 = line.x1.baseVal.value |
|
||||
const x2 = line.x2.baseVal.value |
|
||||
const y1 = line.y1.baseVal.value |
|
||||
const y2 = line.y2.baseVal.value |
|
||||
|
|
||||
return ( |
|
||||
<circle id={`circle-${chan_id}`} r="10" cx={x1} cy={y1} fill="#FFDC53" zoomable /> |
|
||||
) |
|
||||
}) |
|
||||
} |
|
||||
|
|
||||
{ |
|
||||
currentRouteChanIds.map((chan_id) => { |
|
||||
const line = document.getElementById(chan_id) |
|
||||
|
|
||||
if (!line) { return } |
|
||||
const x1 = line.x1.baseVal.value |
|
||||
const x2 = line.x2.baseVal.value |
|
||||
const y1 = line.y1.baseVal.value |
|
||||
const y2 = line.y2.baseVal.value |
|
||||
|
|
||||
return ( |
|
||||
<animate |
|
||||
xlinkHref={`#circle-${chan_id}`} |
|
||||
attributeName="cx" |
|
||||
from={x1} |
|
||||
to={x2} |
|
||||
dur="1s" |
|
||||
fill="freeze" |
|
||||
repeatCount="indefinite" |
|
||||
/> |
|
||||
) |
|
||||
}) |
|
||||
} |
|
||||
{ |
|
||||
currentRouteChanIds.map((chan_id) => { |
|
||||
const line = document.getElementById(chan_id) |
|
||||
|
|
||||
if (!line) { return } |
|
||||
const x1 = line.x1.baseVal.value |
|
||||
const x2 = line.x2.baseVal.value |
|
||||
const y1 = line.y1.baseVal.value |
|
||||
const y2 = line.y2.baseVal.value |
|
||||
|
|
||||
return ( |
|
||||
<animate |
|
||||
xlinkHref={`#circle-${chan_id}`} |
|
||||
attributeName="cy" |
|
||||
from={y1} |
|
||||
to={y2} |
|
||||
dur="1s" |
|
||||
fill="freeze" |
|
||||
repeatCount="indefinite" |
|
||||
/> |
|
||||
) |
|
||||
}) |
|
||||
} |
|
||||
</ForceGraph> |
|
||||
</section> |
|
||||
) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
NetworkGraph.propTypes = { |
|
||||
network: PropTypes.object.isRequired, |
|
||||
identity_pubkey: PropTypes.string.isRequired |
|
||||
} |
|
||||
|
|
||||
export default NetworkGraph |
|
@ -1,75 +0,0 @@ |
|||||
@import '../../variables.scss'; |
|
||||
|
|
||||
@keyframes dash { |
|
||||
to { |
|
||||
stroke-dashoffset: 1000; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
@keyframes fadein { |
|
||||
0% { background: $white; } |
|
||||
50% { background: lighten($secondary, 50%); } |
|
||||
100% { background: $secondary; animation-fill-mode:forwards; } |
|
||||
} |
|
||||
|
|
||||
.networkLoading { |
|
||||
position: absolute; |
|
||||
top: 0; |
|
||||
left: 0; |
|
||||
width: 70%; |
|
||||
height: 100vh; |
|
||||
animation: fadein 0.5s; |
|
||||
animation-timing-function:linear; |
|
||||
animation-fill-mode: forwards; |
|
||||
animation-iteration-count: infinite; |
|
||||
// visibility: hidden; |
|
||||
|
|
||||
&.active { |
|
||||
// visibility: visible; |
|
||||
} |
|
||||
|
|
||||
h1 { |
|
||||
font-size: 22px; |
|
||||
text-align: center; |
|
||||
margin-top: calc(50% - 22px); |
|
||||
animation: color-change 1s infinite; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
.network { |
|
||||
width: 100%; |
|
||||
height: 100vh; |
|
||||
animation: fadein 0.5s; |
|
||||
animation-timing-function:linear; |
|
||||
animation-fill-mode: forwards; |
|
||||
animation-iteration-count: 1; |
|
||||
} |
|
||||
|
|
||||
.node { |
|
||||
stroke-width: 2 !important; |
|
||||
animation: color-change 1s infinite; |
|
||||
fill: #353535; |
|
||||
|
|
||||
&.owner { |
|
||||
fill: #FFFFFF; |
|
||||
} |
|
||||
|
|
||||
&.peer { |
|
||||
fill: #5589F3; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
.activeEdge { |
|
||||
opacity: 1; |
|
||||
stroke: #88D4A2; |
|
||||
stroke-width: 5; |
|
||||
stroke-dasharray: 100; |
|
||||
animation: dash 2.5s infinite linear; |
|
||||
} |
|
||||
|
|
||||
.network { |
|
||||
display: inline-block; |
|
||||
vertical-align: top; |
|
||||
height: 100vh; |
|
||||
width: 70%; |
|
||||
} |
|
Loading…
Reference in new issue