Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes process-by-name layout with ./foo and /foo nodes #948

Merged
merged 2 commits into from
Feb 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 39 additions & 28 deletions client/app/scripts/charts/nodes-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ const RANK_SEPARATION_FACTOR = 2.5;
let layoutRuns = 0;
let layoutRunsTrivial = 0;

function graphNodeId(id) {
return id.replace('.', '<DOT>');
}

function fromGraphNodeId(encodedId) {
return encodedId.replace('<DOT>', '.');
}

/**
* Layout engine runner
* After the layout engine run nodes and edges have x-y-coordinates. Engine is
Expand Down Expand Up @@ -52,37 +60,36 @@ function runLayoutEngine(graph, imNodes, imEdges, opts) {

// add nodes to the graph if not already there
nodes.forEach(node => {
if (!graph.hasNode(node.get('id'))) {
graph.setNode(node.get('id'), {
id: node.get('id'),
const gNodeId = graphNodeId(node.get('id'));
if (!graph.hasNode(gNodeId)) {
graph.setNode(gNodeId, {
width: nodeWidth,
height: nodeHeight
});
}
});

// remove nodes that are no longer there or are 0-degree nodes
graph.nodes().forEach(nodeid => {
if (!nodes.has(nodeid) || nodes.get(nodeid).get('degree') === 0) {
graph.removeNode(nodeid);
graph.nodes().forEach(gNodeId => {
const nodeId = fromGraphNodeId(gNodeId);
if (!nodes.has(nodeId) || nodes.get(nodeId).get('degree') === 0) {
graph.removeNode(gNodeId);
}
});

// add edges to the graph if not already there
edges.forEach(edge => {
if (!graph.hasEdge(edge.get('source'), edge.get('target'))) {
const virtualNodes = edge.get('source') === edge.get('target') ? 1 : 0;
graph.setEdge(
edge.get('source'),
edge.get('target'),
{id: edge.get('id'), minlen: virtualNodes}
);
const s = graphNodeId(edge.get('source'));
const t = graphNodeId(edge.get('target'));
if (!graph.hasEdge(s, t)) {
const virtualNodes = s === t ? 1 : 0;
graph.setEdge(s, t, {id: edge.get('id'), minlen: virtualNodes});
}
});

// remove edges that are no longer there
graph.edges().forEach(edgeObj => {
const edge = [edgeObj.v, edgeObj.w];
const edge = [fromGraphNodeId(edgeObj.v), fromGraphNodeId(edgeObj.w)];
const edgeId = edge.join(EDGE_ID_SEPARATOR);
if (!edges.has(edgeId)) {
graph.removeEdge(edgeObj.v, edgeObj.w);
Expand All @@ -94,30 +101,34 @@ function runLayoutEngine(graph, imNodes, imEdges, opts) {

// apply coordinates to nodes and edges

graph.nodes().forEach(id => {
const graphNode = graph.node(id);
nodes = nodes.setIn([id, 'x'], graphNode.x);
nodes = nodes.setIn([id, 'y'], graphNode.y);
graph.nodes().forEach(gNodeId => {
const graphNode = graph.node(gNodeId);
const nodeId = fromGraphNodeId(gNodeId);
nodes = nodes.setIn([nodeId, 'x'], graphNode.x);
nodes = nodes.setIn([nodeId, 'y'], graphNode.y);
});

graph.edges().forEach(id => {
const graphEdge = graph.edge(id);
const edge = edges.get(graphEdge.id);
const points = graphEdge.points;
graph.edges().forEach(graphEdge => {
const graphEdgeMeta = graph.edge(graphEdge);
const edge = edges.get(graphEdgeMeta.id);
const points = graphEdgeMeta.points;

// set beginning and end points to node coordinates to ignore node bounding box
const source = nodes.get(edge.get('source'));
const target = nodes.get(edge.get('target'));
const source = nodes.get(fromGraphNodeId(edge.get('source')));
const target = nodes.get(fromGraphNodeId(edge.get('target')));
points[0] = {x: source.get('x'), y: source.get('y')};
points[points.length - 1] = {x: target.get('x'), y: target.get('y')};

edges = edges.setIn([graphEdge.id, 'points'], points);
edges = edges.setIn([graphEdgeMeta.id, 'points'], points);
});

// return object with the width and height of layout
layout.nodes = nodes;
layout.edges = edges;
return layout;
return {
width: layout.width,
height: layout.height,
nodes,
edges
};
}

/**
Expand Down