Skip to content

Commit

Permalink
Support passing in node size for nodes in a global graph. Stop trying…
Browse files Browse the repository at this point in the history
… to figure out which node in the entry node for sizing.
  • Loading branch information
jrsquared committed Nov 28, 2016
1 parent fc9ebf3 commit 5a115a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/global/globalNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import NodeViewDetailed from '../base/nodeViewDetailed';
class GlobalNode extends Node {
constructor (node) {
super(node, 'global');
this.size = 120;
this.size = node.size || 120;
this.refreshLoaded();
}

Expand Down
12 changes: 5 additions & 7 deletions src/layouts/ringCenterLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
*/
import _ from 'lodash';

function updatePosition (node, nodeCount, nodeIndex, orbitSize, nodeSize) {
function updatePosition (node, nodeCount, nodeIndex, orbitSize) {
const rotationAdjustment = nodeCount % 2 === 0 ? Math.PI / 4 : (5 / 6) * Math.PI;
node.size = nodeSize;
const adjustment = (((2 * Math.PI) * nodeIndex) / nodeCount) + rotationAdjustment;
node.updatePosition({
x: ((orbitSize / 2) * Math.cos(adjustment)),
y: ((orbitSize / 2) * Math.sin(adjustment))
});
}

function positionNodes (nodes, orbitSize, nodeSize) {
function positionNodes (nodes, orbitSize) {
let nodeIndex = 0;
const nodeCount = Object.keys(nodes).length - 1;

Expand All @@ -40,9 +39,8 @@ function positionNodes (nodes, orbitSize, nodeSize) {
const node = nodeMap[nodeName];
if (!node.isEntryNode()) {
nodeIndex++;
updatePosition(node, nodeCount, nodeIndex, orbitSize, nodeSize);
updatePosition(node, nodeCount, nodeIndex, orbitSize);
} else {
node.size = nodeSize * 1.25;
node.updatePosition({ x: 0, y: 0 });
}
});
Expand Down Expand Up @@ -74,11 +72,11 @@ class RingCenterLayout {

if (Object.keys(graph.nodes).length > 0) {
// Position the nodes based on the current orbitSize
positionNodes(graph.nodes, orbitSize, nodeSize);
positionNodes(graph.nodes, orbitSize);
// Now that the nodes are positioned, adjust orbit size accordingly so the nodes all fit
orbitSize = recalculateOrbitSize(graph.nodes, maxDimension, nodeSize);
// Position again with the proper orbitSize
positionNodes(graph.nodes, orbitSize, nodeSize);
positionNodes(graph.nodes, orbitSize);
centerNodesVertically(graph.nodes);
}

Expand Down

0 comments on commit 5a115a2

Please sign in to comment.