mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 02:00:43 +00:00
Refactored doLayout signature
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user