Files
weave-scope/client/app/scripts/utils/layouter-utils.js
Filip Barl 0869d26ec4 Moved highlighted nodes/edges info to selectors (#2584)
* Use selector for highlighted nodes.

* Use selector for highlighted edges.
2017-06-14 11:11:59 +02:00

37 lines
1.1 KiB
JavaScript

import { Map as makeMap } from 'immutable';
import { EDGE_ID_SEPARATOR } from '../constants/naming';
export function getNodesFromEdgeId(edgeId) {
return edgeId.split(EDGE_ID_SEPARATOR);
}
export function constructEdgeId(source, target) {
return [source, target].join(EDGE_ID_SEPARATOR);
}
// Constructs the edges for the layout engine from the nodes' adjacency table.
// We don't collapse edge pairs (A->B, B->A) here as we want to let the layout
// engine decide how to handle bidirectional edges.
export function initEdgesFromNodes(nodes) {
let edges = makeMap();
nodes.forEach((node, nodeId) => {
(node.get('adjacency') || []).forEach((adjacentId) => {
const source = nodeId;
const target = adjacentId;
if (nodes.has(target)) {
// The direction source->target is important since dagre takes
// directionality into account when calculating the layout.
const edgeId = constructEdgeId(source, target);
const edge = makeMap({ id: edgeId, value: 1, source, target });
edges = edges.set(edgeId, edge);
}
});
});
return edges;
}