Skip to content

Commit

Permalink
Improve performance for FocusedGraph by not creating duplicate focuse…
Browse files Browse the repository at this point in the history
…d nodes…
  • Loading branch information
jrsquared committed Nov 11, 2016
1 parent ef18fd2 commit 90c1c17
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/focused/focusedTrafficGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,24 @@ class FocusedTrafficGraph extends TrafficGraph {
}

manipulateState (state, parentState) {
// set up the focused node
const thisNode = _.cloneDeep(state);
delete thisNode.renderer;
thisNode.focused = true;

// manipulate nodes and connections based on parent graph
state.connections = _.filter(parentState.connections, connection => connection.source === state.name || connection.target === state.name);
state.nodes = _.uniq(_.reduce(state.connections, (acc, connection) => {
state.nodes = _.uniqBy(_.reduce(state.connections, (acc, connection) => {
acc.push(_.clone(_.find(parentState.nodes, { name: connection.source })));
acc.push(_.clone(_.find(parentState.nodes, { name: connection.target })));
return acc;
}, []));
}, []), 'name');

// replace focused node
_.remove(state.nodes, node => node.name === thisNode.name);
state.nodes.push(thisNode);

// clean up new state
state.nodes.forEach(node => delete node.renderer);
state.maxVolume = state.maxVolume || _.get(this.parentGraph, ['volume', 'max'], 0);
}
Expand Down

0 comments on commit 90c1c17

Please sign in to comment.