diff --git a/client/app/scripts/charts/__tests__/node-layout-test.js b/client/app/scripts/charts/__tests__/node-layout-test.js index a6d8d3cf2..a8799bd6f 100644 --- a/client/app/scripts/charts/__tests__/node-layout-test.js +++ b/client/app/scripts/charts/__tests__/node-layout-test.js @@ -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); diff --git a/client/app/scripts/charts/nodes-chart.js b/client/app/scripts/charts/nodes-chart.js index 7fb918129..945554a94 100644 --- a/client/app/scripts/charts/nodes-chart.js +++ b/client/app/scripts/charts/nodes-chart.js @@ -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'); diff --git a/client/app/scripts/charts/nodes-layout.js b/client/app/scripts/charts/nodes-layout.js index 5ee720f5b..a86247991 100644 --- a/client/app/scripts/charts/nodes-layout.js +++ b/client/app/scripts/charts/nodes-layout.js @@ -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 -}; +}