Refactored doLayout signature

This commit is contained in:
David Kaltschmidt
2015-10-27 11:27:52 +00:00
parent 3d08b15430
commit e4da515fa1
3 changed files with 18 additions and 16 deletions

View File

@@ -34,7 +34,7 @@ describe('NodesLayout', () => {
it('lays out initial nodeset', () => {
const nodes = nodeSets.initial4.nodes;
const edges = nodeSets.initial4.edges;
NodesLayout.doLayout(nodes, edges, width, height, scale, margins, topologyId);
NodesLayout.doLayout(nodes, edges);
expect(nodes.n1.x).toBeLessThan(nodes.n2.x);
expect(nodes.n1.y).toEqual(nodes.n2.y);

View File

@@ -428,17 +428,16 @@ const NodesChart = React.createClass({
const nodeSize = expanse / 3; // single node should fill a third of the screen
const normalizedNodeSize = nodeSize / Math.sqrt(n); // assuming rectangular layout
const nodeScale = this.state.nodeScale.range([0, normalizedNodeSize]);
const options = {
width: props.width,
height: props.height,
scale: nodeScale,
margins: MARGINS,
topologyId: this.props.topologyId
};
const timedLayouter = timely(NodesLayout.doLayout);
const graph = timedLayouter(
nodes,
edges,
props.width,
props.height,
nodeScale,
MARGINS,
this.props.topologyId
);
const graph = timedLayouter(nodes, edges, options);
debug('graph layout took ' + timedLayouter.time + 'ms');

View File

@@ -6,7 +6,14 @@ const _ = require('lodash');
const MAX_NODES = 100;
const topologyGraphs = {};
const doLayout = function(nodes, edges, width, height, scale, margins, topologyId) {
export function doLayout(nodes, edges, opts) {
const options = opts || {};
const margins = options.margins || {top: 0, left: 0};
const width = options.width || 800;
const height = options.height || width / 2;
const scale = options.scale || (val => val * 2);
const topologyId = options.topologyId || 'noId';
let offsetX = 0 + margins.left;
let offsetY = 0 + margins.top;
let graph;
@@ -101,8 +108,4 @@ const doLayout = function(nodes, edges, width, height, scale, margins, topologyI
// return object with the width and height of layout
return layout;
};
module.exports = {
doLayout: doLayout
};
}