Files
weave-scope/client/app/scripts/components/explorer.js
David Kaltschmidt 7d1ee40a2b Fixed lint errors in all js files
- Also added linter configuration, and make linter fail on error
- fixing ES6 errors and added ES6 transformer
- gulp target to try local build
- linted gulpfile
- cant hook into gulp lint yet, because gulp does currently not support
  ES6 which some rules demand, since gulp cant transpile itself, we have a
  chicken and egg problem.
- ES6 transpiler for test runner
- removed old linter config
- adapted editorconfig to reflect linter config
2015-05-28 15:07:13 +00:00

88 lines
2.1 KiB
JavaScript

const React = require('react');
const _ = require('lodash');
const NodesChart = require('../charts/nodes-chart');
const NodeDetails = require('./node-details');
const marginBottom = 64;
const marginTop = 64;
const marginLeft = 36;
const marginRight = 36;
const Explorer = React.createClass({
getInitialState: function() {
return {
layout: 'solar',
width: window.innerWidth - marginLeft - marginRight,
height: window.innerHeight - marginBottom - marginTop
};
},
componentDidMount: function() {
window.addEventListener('resize', this.handleResize);
},
componentWillUnmount: function() {
window.removeEventListener('resize', this.handleResize);
},
getSubTopology: function(topology) {
const subTopology = {};
const nodeSet = [];
_.each(this.props.expandedNodes, function(nodeId) {
if (topology[nodeId]) {
subTopology[nodeId] = topology[nodeId];
nodeSet = _.union(subTopology[nodeId].adjacency, nodeSet);
_.each(subTopology[nodeId].adjacency, function(adjacentId) {
const node = _.assign({}, topology[adjacentId]);
subTopology[adjacentId] = node;
});
}
});
// weed out edges
_.each(subTopology, function(node) {
node.adjacency = _.intersection(node.adjacency, nodeSet);
});
return subTopology;
},
render: function() {
const subTopology = this.getSubTopology(this.props.nodes);
return (
<div id="explorer">
<NodeDetails details={this.props.details} />
<div className="graph">
<NodesChart
layout={this.state.layout}
nodes={subTopology}
highlightedNodes={this.props.expandedNodes}
width={this.state.width}
height={this.state.height}
context="explorer"
/>
</div>
</div>
);
},
setDimensions: function() {
this.setState({
height: window.innerHeight - marginBottom - marginTop,
width: window.innerWidth - marginLeft - marginRight
});
},
handleResize: function() {
this.setDimensions();
}
});
module.exports = Explorer;