mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 18:20:27 +00:00
Stop the rendered graph from dancing.
This commit is contained in:
committed by
David Kaltschmidt
parent
74e8f61da5
commit
91627f8cc3
4332
app/static.go
4332
app/static.go
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,14 @@
|
||||
const dagre = require('dagre');
|
||||
const debug = require('debug')('scope:nodes-layout');
|
||||
const Naming = require('../constants/naming');
|
||||
const _ = require('lodash');
|
||||
|
||||
const MAX_NODES = 100;
|
||||
const g = new dagre.graphlib.Graph({});
|
||||
|
||||
const doLayout = function(nodes, edges, width, height, scale, margins) {
|
||||
let offsetX = 0 + margins.left;
|
||||
let offsetY = 0 + margins.top;
|
||||
const g = new dagre.graphlib.Graph({});
|
||||
|
||||
if (_.size(nodes) > MAX_NODES) {
|
||||
debug('Too many nodes for graph layout engine. Limit: ' + MAX_NODES);
|
||||
@@ -15,21 +16,40 @@ const doLayout = function(nodes, edges, width, height, scale, margins) {
|
||||
}
|
||||
|
||||
// configure node margins
|
||||
|
||||
g.setGraph({
|
||||
nodesep: scale(2.5),
|
||||
ranksep: scale(2.5)
|
||||
});
|
||||
|
||||
// add nodes and edges to layout engine
|
||||
|
||||
// add nodes to the graph if not already there
|
||||
_.each(nodes, function(node) {
|
||||
g.setNode(node.id, {id: node.id, width: scale(0.75), height: scale(0.75)});
|
||||
if (!g.hasNode(node.id)) {
|
||||
g.setNode(node.id, {id: node.id, width: scale(0.75), height: scale(0.75)});
|
||||
}
|
||||
});
|
||||
|
||||
// remove nodes that are no longer there
|
||||
_.each(g.nodes(), function(nodeid) {
|
||||
if (!_.has(nodes, nodeid)) {
|
||||
g.removeNode(nodeid);
|
||||
}
|
||||
});
|
||||
|
||||
// add edges to the graph if not already there
|
||||
_.each(edges, function(edge) {
|
||||
const virtualNodes = edge.source.id === edge.target.id ? 1 : 0;
|
||||
g.setEdge(edge.source.id, edge.target.id, {id: edge.id, minlen: virtualNodes});
|
||||
if (!g.hasEdge(edge.source.id, edge.target.id)) {
|
||||
const virtualNodes = edge.source.id === edge.target.id ? 1 : 0;
|
||||
g.setEdge(edge.source.id, edge.target.id, {id: edge.id, minlen: virtualNodes});
|
||||
}
|
||||
});
|
||||
|
||||
// remoed egdes that are no longer there
|
||||
_.each(g.edges(), function(edgeObj) {
|
||||
const edge = [edgeObj.v, edgeObj.w];
|
||||
const edgeId = edge.join(Naming.EDGE_ID_SEPARATOR);
|
||||
if (!_.has(edges, edgeId)) {
|
||||
g.removeEdge(edgeObj.v, edgeObj.w);
|
||||
}
|
||||
});
|
||||
|
||||
dagre.layout(g);
|
||||
|
||||
Reference in New Issue
Block a user