mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-09 05:54:07 +01:00
Change logger to log
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import intersectRect from './intersect/intersect-rect';
|
||||
import { logger } from '../logger';
|
||||
import { log } from '../logger';
|
||||
import createLabel from './createLabel';
|
||||
import { select } from 'd3';
|
||||
import { getConfig } from '../config';
|
||||
|
||||
const rect = (parent, node) => {
|
||||
logger.trace('Creating subgraph rect for ', node.id, node);
|
||||
log.trace('Creating subgraph rect for ', node.id, node);
|
||||
|
||||
// Add outer g element
|
||||
const shapeSvg = parent
|
||||
@@ -37,7 +37,7 @@ const rect = (parent, node) => {
|
||||
const padding = 0 * node.padding;
|
||||
const halfPadding = padding / 2;
|
||||
|
||||
logger.trace('Data ', node, JSON.stringify(node));
|
||||
log.trace('Data ', node, JSON.stringify(node));
|
||||
// center the rect around its coordinate
|
||||
rect
|
||||
.attr('style', node.style)
|
||||
@@ -208,7 +208,7 @@ const shapes = { rect, roundedWithTitle, noteGroup, divider };
|
||||
let clusterElems = {};
|
||||
|
||||
export const insertCluster = (elem, node) => {
|
||||
logger.trace('Inserting cluster');
|
||||
log.trace('Inserting cluster');
|
||||
const shape = node.shape || 'rect';
|
||||
clusterElems[node.id] = shapes[shape](elem, node);
|
||||
};
|
||||
@@ -225,7 +225,7 @@ export const clear = () => {
|
||||
};
|
||||
|
||||
export const positionCluster = node => {
|
||||
logger.info('Position cluster');
|
||||
log.info('Position cluster');
|
||||
const el = clusterElems[node.id];
|
||||
|
||||
el.attr('transform', 'translate(' + node.x + ', ' + node.y + ')');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { select } from 'd3';
|
||||
import { logger } from '../logger'; // eslint-disable-line
|
||||
import { log } from '../logger'; // eslint-disable-line
|
||||
// let vertexNode;
|
||||
// if (getConfig().flowchart.htmlLabels) {
|
||||
// // TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that?
|
||||
@@ -80,7 +80,7 @@ const createLabel = (_vertexText, style, isTitle, isNode) => {
|
||||
if (getConfig().flowchart.htmlLabels) {
|
||||
// TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that?
|
||||
vertexText = vertexText.replace(/\\n|\n/g, '<br />');
|
||||
logger.info('vertexText' + vertexText);
|
||||
log.info('vertexText' + vertexText);
|
||||
const node = {
|
||||
isNode,
|
||||
label: vertexText.replace(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { logger } from '../logger'; // eslint-disable-line
|
||||
import { log } from '../logger'; // eslint-disable-line
|
||||
import createLabel from './createLabel';
|
||||
import { line, curveBasis, select } from 'd3';
|
||||
import { getConfig } from '../config';
|
||||
@@ -104,7 +104,7 @@ export const insertEdgeLabel = (elem, edge) => {
|
||||
};
|
||||
|
||||
export const positionEdgeLabel = (edge, paths) => {
|
||||
logger.info('Moving label', edge.id, edge.label, edgeLabels[edge.id]);
|
||||
log.info('Moving label', edge.id, edge.label, edgeLabels[edge.id]);
|
||||
let path = paths.updatedPath ? paths.updatedPath : paths.originalPath;
|
||||
if (edge.label) {
|
||||
const el = edgeLabels[edge.id];
|
||||
@@ -113,7 +113,7 @@ export const positionEdgeLabel = (edge, paths) => {
|
||||
if (path) {
|
||||
// // debugger;
|
||||
const pos = utils.calcLabelPosition(path);
|
||||
logger.info('Moving label from (', x, ',', y, ') to (', pos.x, ',', pos.y, ')');
|
||||
log.info('Moving label from (', x, ',', y, ') to (', pos.x, ',', pos.y, ')');
|
||||
// x = pos.x;
|
||||
// y = pos.y;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ export const positionEdgeLabel = (edge, paths) => {
|
||||
// };
|
||||
|
||||
const outsideNode = (node, point) => {
|
||||
// logger.warn('Checking bounds ', node, point);
|
||||
// log.warn('Checking bounds ', node, point);
|
||||
const x = node.x;
|
||||
const y = node.y;
|
||||
const dx = Math.abs(point.x - x);
|
||||
@@ -199,7 +199,7 @@ const outsideNode = (node, point) => {
|
||||
};
|
||||
|
||||
export const intersection = (node, outsidePoint, insidePoint) => {
|
||||
logger.warn('intersection calc o:', outsidePoint, ' i:', insidePoint, node);
|
||||
log.warn('intersection calc o:', outsidePoint, ' i:', insidePoint, node);
|
||||
const x = node.x;
|
||||
const y = node.y;
|
||||
|
||||
@@ -221,7 +221,7 @@ export const intersection = (node, outsidePoint, insidePoint) => {
|
||||
outsidePoint.y === edges.y1 ||
|
||||
outsidePoint.y === edges.y2
|
||||
) {
|
||||
logger.warn('calc equals on edge');
|
||||
log.warn('calc equals on edge');
|
||||
return outsidePoint;
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ export const intersection = (node, outsidePoint, insidePoint) => {
|
||||
x: insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : insidePoint.x - r,
|
||||
y: insidePoint.y < outsidePoint.y ? insidePoint.y + Q - q : insidePoint.y - q
|
||||
};
|
||||
logger.warn(`topp/bott calc, Q ${Q}, q ${q}, R ${R}, r ${r}`, res);
|
||||
log.warn(`topp/bott calc, Q ${Q}, q ${q}, R ${R}, r ${r}`, res);
|
||||
|
||||
return res;
|
||||
} else {
|
||||
@@ -252,7 +252,7 @@ export const intersection = (node, outsidePoint, insidePoint) => {
|
||||
r = x - w - outsidePoint.x;
|
||||
}
|
||||
let q = (q = (Q * r) / R);
|
||||
logger.warn(`sides calc, Q ${Q}, q ${q}, R ${R}, r ${r}`, {
|
||||
log.warn(`sides calc, Q ${Q}, q ${q}, R ${R}, r ${r}`, {
|
||||
x: insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : insidePoint.x + dx - w,
|
||||
y: insidePoint.y < outsidePoint.y ? insidePoint.y + q : insidePoint.y - q
|
||||
});
|
||||
@@ -274,7 +274,7 @@ export const insertEdge = function(elem, e, edge, clusterDb, diagramType, graph)
|
||||
if (head.intersect && tail.intersect) {
|
||||
points = points.slice(1, edge.points.length - 1);
|
||||
points.unshift(tail.intersect(points[0]));
|
||||
logger.info(
|
||||
log.info(
|
||||
'Last point',
|
||||
points[points.length - 1],
|
||||
head,
|
||||
@@ -283,8 +283,8 @@ export const insertEdge = function(elem, e, edge, clusterDb, diagramType, graph)
|
||||
points.push(head.intersect(points[points.length - 1]));
|
||||
}
|
||||
if (edge.toCluster) {
|
||||
logger.trace('edge', edge);
|
||||
logger.trace('to cluster', clusterDb[edge.toCluster]);
|
||||
log.trace('edge', edge);
|
||||
log.trace('to cluster', clusterDb[edge.toCluster]);
|
||||
points = [];
|
||||
let lastPointOutside;
|
||||
let isInside = false;
|
||||
@@ -292,7 +292,7 @@ export const insertEdge = function(elem, e, edge, clusterDb, diagramType, graph)
|
||||
const node = clusterDb[edge.toCluster].node;
|
||||
|
||||
if (!outsideNode(node, point) && !isInside) {
|
||||
logger.trace('inside', edge.toCluster, point, lastPointOutside);
|
||||
log.trace('inside', edge.toCluster, point, lastPointOutside);
|
||||
|
||||
// First point inside the rect
|
||||
const inter = intersection(node, lastPointOutside, point);
|
||||
@@ -305,7 +305,7 @@ export const insertEdge = function(elem, e, edge, clusterDb, diagramType, graph)
|
||||
if (!points.find(e => e.x === inter.x && e.y === inter.y)) {
|
||||
points.push(inter);
|
||||
} else {
|
||||
logger.warn('no intersect', inter, points);
|
||||
log.warn('no intersect', inter, points);
|
||||
}
|
||||
isInside = true;
|
||||
} else {
|
||||
@@ -317,8 +317,8 @@ export const insertEdge = function(elem, e, edge, clusterDb, diagramType, graph)
|
||||
}
|
||||
|
||||
if (edge.fromCluster) {
|
||||
logger.trace('edge', edge);
|
||||
logger.warn('from cluster', clusterDb[edge.fromCluster]);
|
||||
log.trace('edge', edge);
|
||||
log.warn('from cluster', clusterDb[edge.fromCluster]);
|
||||
const updatedPoints = [];
|
||||
let lastPointOutside;
|
||||
let isInside = false;
|
||||
@@ -327,17 +327,17 @@ export const insertEdge = function(elem, e, edge, clusterDb, diagramType, graph)
|
||||
const node = clusterDb[edge.fromCluster].node;
|
||||
|
||||
if (!outsideNode(node, point) && !isInside) {
|
||||
logger.warn('inside', edge.fromCluster, point, node);
|
||||
log.warn('inside', edge.fromCluster, point, node);
|
||||
|
||||
// First point inside the rect
|
||||
const insterection = intersection(node, lastPointOutside, point);
|
||||
// logger.trace('intersect', intersection(node, lastPointOutside, point));
|
||||
// log.trace('intersect', intersection(node, lastPointOutside, point));
|
||||
updatedPoints.unshift(insterection);
|
||||
// points.push(insterection);
|
||||
isInside = true;
|
||||
} else {
|
||||
// at the outside
|
||||
logger.trace('Outside point', point);
|
||||
log.trace('Outside point', point);
|
||||
if (!isInside) updatedPoints.unshift(point);
|
||||
}
|
||||
lastPointOutside = point;
|
||||
@@ -412,8 +412,8 @@ export const insertEdge = function(elem, e, edge, clusterDb, diagramType, graph)
|
||||
url = url.replace(/\(/g, '\\(');
|
||||
url = url.replace(/\)/g, '\\)');
|
||||
}
|
||||
logger.info('arrowTypeStart', edge.arrowTypeStart);
|
||||
logger.info('arrowTypeEnd', edge.arrowTypeEnd);
|
||||
log.info('arrowTypeStart', edge.arrowTypeStart);
|
||||
log.info('arrowTypeEnd', edge.arrowTypeEnd);
|
||||
|
||||
switch (edge.arrowTypeStart) {
|
||||
case 'arrow_cross':
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { intersection } from './edges';
|
||||
import { setLogLevel, logger } from '../logger';
|
||||
import { setLogLevel, log } from '../logger';
|
||||
|
||||
describe('Graphlib decorations', () => {
|
||||
let node;
|
||||
|
||||
@@ -12,21 +12,21 @@ import {
|
||||
import { insertNode, positionNode, clear as clearNodes, setNodeElem } from './nodes';
|
||||
import { insertCluster, clear as clearClusters } from './clusters';
|
||||
import { insertEdgeLabel, positionEdgeLabel, insertEdge, clear as clearEdges } from './edges';
|
||||
import { logger } from '../logger';
|
||||
import { log } from '../logger';
|
||||
|
||||
const recursiveRender = (_elem, graph, diagramtype, parentCluster) => {
|
||||
logger.info('Graph in recursive render: XXX', graphlib.json.write(graph), parentCluster);
|
||||
log.info('Graph in recursive render: XXX', graphlib.json.write(graph), parentCluster);
|
||||
const dir = graph.graph().rankdir;
|
||||
logger.warn('Dir in recursive render - dir:', dir);
|
||||
log.warn('Dir in recursive render - dir:', dir);
|
||||
|
||||
const elem = _elem.insert('g').attr('class', 'root'); // eslint-disable-line
|
||||
if (!graph.nodes()) {
|
||||
logger.info('No nodes found for', graph);
|
||||
log.info('No nodes found for', graph);
|
||||
} else {
|
||||
logger.info('Recursive render XXX', graph.nodes());
|
||||
log.info('Recursive render XXX', graph.nodes());
|
||||
}
|
||||
if (graph.edges().length > 0) {
|
||||
logger.info('Recursive edges', graph.edge(graph.edges()[0]));
|
||||
log.info('Recursive edges', graph.edge(graph.edges()[0]));
|
||||
}
|
||||
const clusters = elem.insert('g').attr('class', 'clusters'); // eslint-disable-line
|
||||
const edgePaths = elem.insert('g').attr('class', 'edgePaths');
|
||||
@@ -40,32 +40,32 @@ const recursiveRender = (_elem, graph, diagramtype, parentCluster) => {
|
||||
if (typeof parentCluster !== 'undefined') {
|
||||
const data = JSON.parse(JSON.stringify(parentCluster.clusterData));
|
||||
// data.clusterPositioning = true;
|
||||
logger.info('Setting data for cluster XXX (', v, ') ', data, parentCluster);
|
||||
log.info('Setting data for cluster XXX (', v, ') ', data, parentCluster);
|
||||
graph.setNode(parentCluster.id, data);
|
||||
if (!graph.parent(v)) {
|
||||
logger.warn('Setting parent', v, parentCluster.id);
|
||||
log.warn('Setting parent', v, parentCluster.id);
|
||||
graph.setParent(v, parentCluster.id, data);
|
||||
}
|
||||
}
|
||||
logger.info('(Insert) Node XXX' + v + ': ' + JSON.stringify(graph.node(v)));
|
||||
log.info('(Insert) Node XXX' + v + ': ' + JSON.stringify(graph.node(v)));
|
||||
if (node && node.clusterNode) {
|
||||
// const children = graph.children(v);
|
||||
logger.info('Cluster identified', v, node, graph.node(v));
|
||||
log.info('Cluster identified', v, node, graph.node(v));
|
||||
const newEl = recursiveRender(nodes, node.graph, diagramtype, graph.node(v));
|
||||
updateNodeBounds(node, newEl);
|
||||
setNodeElem(newEl, node);
|
||||
|
||||
logger.warn('Recursive render complete', newEl, node);
|
||||
log.warn('Recursive render complete', newEl, node);
|
||||
} else {
|
||||
if (graph.children(v).length > 0) {
|
||||
// This is a cluster but not to be rendered recusively
|
||||
// Render as before
|
||||
logger.info('Cluster - the non recursive path XXX', v, node.id, node, graph);
|
||||
logger.info(findNonClusterChild(node.id, graph));
|
||||
log.info('Cluster - the non recursive path XXX', v, node.id, node, graph);
|
||||
log.info(findNonClusterChild(node.id, graph));
|
||||
clusterDb[node.id] = { id: findNonClusterChild(node.id, graph), node };
|
||||
// insertCluster(clusters, graph.node(v));
|
||||
} else {
|
||||
logger.info('Node - the non recursive path', v, node.id, node);
|
||||
log.info('Node - the non recursive path', v, node.id, node);
|
||||
insertNode(nodes, graph.node(v), dir);
|
||||
}
|
||||
}
|
||||
@@ -77,37 +77,28 @@ const recursiveRender = (_elem, graph, diagramtype, parentCluster) => {
|
||||
// TODO: pick optimal child in the cluster to us as link anchor
|
||||
graph.edges().forEach(function(e) {
|
||||
const edge = graph.edge(e.v, e.w, e.name);
|
||||
logger.info('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(e));
|
||||
logger.info('Edge ' + e.v + ' -> ' + e.w + ': ', e, ' ', JSON.stringify(graph.edge(e)));
|
||||
log.info('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(e));
|
||||
log.info('Edge ' + e.v + ' -> ' + e.w + ': ', e, ' ', JSON.stringify(graph.edge(e)));
|
||||
|
||||
// Check if link is either from or to a cluster
|
||||
logger.info(
|
||||
'Fix',
|
||||
clusterDb,
|
||||
'ids:',
|
||||
e.v,
|
||||
e.w,
|
||||
'Translateing: ',
|
||||
clusterDb[e.v],
|
||||
clusterDb[e.w]
|
||||
);
|
||||
log.info('Fix', clusterDb, 'ids:', e.v, e.w, 'Translateing: ', clusterDb[e.v], clusterDb[e.w]);
|
||||
insertEdgeLabel(edgeLabels, edge);
|
||||
});
|
||||
|
||||
graph.edges().forEach(function(e) {
|
||||
logger.info('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(e));
|
||||
log.info('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(e));
|
||||
});
|
||||
logger.info('#############################################');
|
||||
logger.info('### Layout ###');
|
||||
logger.info('#############################################');
|
||||
logger.info(graph);
|
||||
log.info('#############################################');
|
||||
log.info('### Layout ###');
|
||||
log.info('#############################################');
|
||||
log.info(graph);
|
||||
dagre.layout(graph);
|
||||
logger.info('Graph after layout:', graphlib.json.write(graph));
|
||||
log.info('Graph after layout:', graphlib.json.write(graph));
|
||||
// Move the nodes to the correct place
|
||||
sortNodesByHierarchy(graph).forEach(function(v) {
|
||||
const node = graph.node(v);
|
||||
logger.info('Position ' + v + ': ' + JSON.stringify(graph.node(v)));
|
||||
logger.info(
|
||||
log.info('Position ' + v + ': ' + JSON.stringify(graph.node(v)));
|
||||
log.info(
|
||||
'Position ' + v + ': (' + node.x,
|
||||
',' + node.y,
|
||||
') width: ',
|
||||
@@ -135,7 +126,7 @@ const recursiveRender = (_elem, graph, diagramtype, parentCluster) => {
|
||||
// Move the edge labels to the correct place after layout
|
||||
graph.edges().forEach(function(e) {
|
||||
const edge = graph.edge(e);
|
||||
logger.info('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(edge), edge);
|
||||
log.info('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(edge), edge);
|
||||
|
||||
const paths = insertEdge(edgePaths, e, edge, clusterDb, diagramtype, graph);
|
||||
positionEdgeLabel(edge, paths);
|
||||
@@ -151,10 +142,10 @@ export const render = (elem, graph, markers, diagramtype, id) => {
|
||||
clearClusters();
|
||||
clearGraphlib();
|
||||
|
||||
logger.warn('Graph at first:', graphlib.json.write(graph));
|
||||
log.warn('Graph at first:', graphlib.json.write(graph));
|
||||
adjustClustersAndEdges(graph);
|
||||
logger.warn('Graph after:', graphlib.json.write(graph));
|
||||
// logger.warn('Graph ever after:', graphlib.json.write(graph.node('A').graph));
|
||||
log.warn('Graph after:', graphlib.json.write(graph));
|
||||
// log.warn('Graph ever after:', graphlib.json.write(graph.node('A').graph));
|
||||
recursiveRender(elem, graph, diagramtype);
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Setup arrow head and define the marker. The result is appended to the svg.
|
||||
*/
|
||||
|
||||
import { logger } from '../logger';
|
||||
import { log } from '../logger';
|
||||
|
||||
// Only add the number of markers that the diagram needs
|
||||
const insertMarkers = (elem, markerArray, type, id) => {
|
||||
@@ -12,7 +12,7 @@ const insertMarkers = (elem, markerArray, type, id) => {
|
||||
};
|
||||
|
||||
const extension = (elem, type, id) => {
|
||||
logger.trace('Making markers for ', id);
|
||||
log.trace('Making markers for ', id);
|
||||
elem
|
||||
.append('defs')
|
||||
.append('marker')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Decorates with functions required by mermaids dagre-wrapper.
|
||||
*/
|
||||
import { logger } from '../logger';
|
||||
import { log } from '../logger';
|
||||
import graphlib from 'graphlib';
|
||||
|
||||
export let clusterDb = {};
|
||||
@@ -17,7 +17,7 @@ export const clear = () => {
|
||||
const isDecendant = (id, ancenstorId) => {
|
||||
// if (id === ancenstorId) return true;
|
||||
|
||||
logger.debug(
|
||||
log.debug(
|
||||
'In isDecendant',
|
||||
ancenstorId,
|
||||
' ',
|
||||
@@ -31,17 +31,17 @@ const isDecendant = (id, ancenstorId) => {
|
||||
};
|
||||
|
||||
const edgeInCluster = (edge, clusterId) => {
|
||||
logger.info('Decendants of ', clusterId, ' is ', decendants[clusterId]);
|
||||
logger.info('Edge is ', edge);
|
||||
log.info('Decendants of ', clusterId, ' is ', decendants[clusterId]);
|
||||
log.info('Edge is ', edge);
|
||||
// Edges to/from the cluster is not in the cluster, they are in the parent
|
||||
if (edge.v === clusterId) return false;
|
||||
if (edge.w === clusterId) return false;
|
||||
|
||||
if (!decendants[clusterId]) {
|
||||
logger.debug('Tilt, ', clusterId, ',not in decendants');
|
||||
log.debug('Tilt, ', clusterId, ',not in decendants');
|
||||
return false;
|
||||
}
|
||||
logger.info('Here ');
|
||||
log.info('Here ');
|
||||
|
||||
if (decendants[clusterId].indexOf(edge.v) >= 0) return true;
|
||||
if (isDecendant(edge.v, clusterId)) return true;
|
||||
@@ -52,7 +52,7 @@ const edgeInCluster = (edge, clusterId) => {
|
||||
};
|
||||
|
||||
const copy = (clusterId, graph, newGraph, rootId) => {
|
||||
logger.warn(
|
||||
log.warn(
|
||||
'Copying children of ',
|
||||
clusterId,
|
||||
'root',
|
||||
@@ -68,26 +68,26 @@ const copy = (clusterId, graph, newGraph, rootId) => {
|
||||
nodes.push(clusterId);
|
||||
}
|
||||
|
||||
logger.warn('Copying (nodes) clusterId', clusterId, 'nodes', nodes);
|
||||
log.warn('Copying (nodes) clusterId', clusterId, 'nodes', nodes);
|
||||
|
||||
nodes.forEach(node => {
|
||||
if (graph.children(node).length > 0) {
|
||||
copy(node, graph, newGraph, rootId);
|
||||
} else {
|
||||
const data = graph.node(node);
|
||||
logger.info('cp ', node, ' to ', rootId, ' with parent ', clusterId); //,node, data, ' parent is ', clusterId);
|
||||
log.info('cp ', node, ' to ', rootId, ' with parent ', clusterId); //,node, data, ' parent is ', clusterId);
|
||||
newGraph.setNode(node, data);
|
||||
if (rootId !== graph.parent(node)) {
|
||||
logger.warn('Setting parent', node, graph.parent(node));
|
||||
log.warn('Setting parent', node, graph.parent(node));
|
||||
newGraph.setParent(node, graph.parent(node));
|
||||
}
|
||||
|
||||
if (clusterId !== rootId && node !== clusterId) {
|
||||
logger.debug('Setting parent', node, clusterId);
|
||||
log.debug('Setting parent', node, clusterId);
|
||||
newGraph.setParent(node, clusterId);
|
||||
} else {
|
||||
logger.info('In copy ', clusterId, 'root', rootId, 'data', graph.node(clusterId), rootId);
|
||||
logger.debug(
|
||||
log.info('In copy ', clusterId, 'root', rootId, 'data', graph.node(clusterId), rootId);
|
||||
log.debug(
|
||||
'Not Setting parent for node=',
|
||||
node,
|
||||
'cluster!==rootId',
|
||||
@@ -97,19 +97,19 @@ const copy = (clusterId, graph, newGraph, rootId) => {
|
||||
);
|
||||
}
|
||||
const edges = graph.edges(node);
|
||||
logger.debug('Copying Edges', edges);
|
||||
log.debug('Copying Edges', edges);
|
||||
edges.forEach(edge => {
|
||||
logger.info('Edge', edge);
|
||||
log.info('Edge', edge);
|
||||
const data = graph.edge(edge.v, edge.w, edge.name);
|
||||
logger.info('Edge data', data, rootId);
|
||||
log.info('Edge data', data, rootId);
|
||||
try {
|
||||
// Do not copy edges in and out of the root cluster, they belong to the parent graph
|
||||
if (edgeInCluster(edge, rootId)) {
|
||||
logger.info('Copying as ', edge.v, edge.w, data, edge.name);
|
||||
log.info('Copying as ', edge.v, edge.w, data, edge.name);
|
||||
newGraph.setEdge(edge.v, edge.w, data, edge.name);
|
||||
logger.info('newGraph edges ', newGraph.edges(), newGraph.edge(newGraph.edges()[0]));
|
||||
log.info('newGraph edges ', newGraph.edges(), newGraph.edge(newGraph.edges()[0]));
|
||||
} else {
|
||||
logger.info(
|
||||
log.info(
|
||||
'Skipping copy of edge ',
|
||||
edge.v,
|
||||
'-->',
|
||||
@@ -121,16 +121,16 @@ const copy = (clusterId, graph, newGraph, rootId) => {
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
log.error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
logger.debug('Removing node', node);
|
||||
log.debug('Removing node', node);
|
||||
graph.removeNode(node);
|
||||
});
|
||||
};
|
||||
export const extractDecendants = (id, graph) => {
|
||||
// logger.debug('Extracting ', id);
|
||||
// log.debug('Extracting ', id);
|
||||
const children = graph.children(id);
|
||||
let res = [].concat(children);
|
||||
|
||||
@@ -149,14 +149,14 @@ export const extractDecendants = (id, graph) => {
|
||||
*/
|
||||
export const validate = graph => {
|
||||
const edges = graph.edges();
|
||||
logger.trace('Edges: ', edges);
|
||||
log.trace('Edges: ', edges);
|
||||
for (let i = 0; i < edges.length; i++) {
|
||||
if (graph.children(edges[i].v).length > 0) {
|
||||
logger.trace('The node ', edges[i].v, ' is part of and edge even though it has children');
|
||||
log.trace('The node ', edges[i].v, ' is part of and edge even though it has children');
|
||||
return false;
|
||||
}
|
||||
if (graph.children(edges[i].w).length > 0) {
|
||||
logger.trace('The node ', edges[i].w, ' is part of and edge even though it has children');
|
||||
log.trace('The node ', edges[i].w, ' is part of and edge even though it has children');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -170,18 +170,18 @@ export const validate = graph => {
|
||||
*/
|
||||
export const findNonClusterChild = (id, graph) => {
|
||||
// const node = graph.node(id);
|
||||
logger.trace('Searching', id);
|
||||
log.trace('Searching', id);
|
||||
// const children = graph.children(id).reverse();
|
||||
const children = graph.children(id); //.reverse();
|
||||
logger.trace('Searching children of id ', id, children);
|
||||
log.trace('Searching children of id ', id, children);
|
||||
if (children.length < 1) {
|
||||
logger.trace('This is a valid node', id);
|
||||
log.trace('This is a valid node', id);
|
||||
return id;
|
||||
}
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
const _id = findNonClusterChild(children[i], graph);
|
||||
if (_id) {
|
||||
logger.trace('Found replacement for', id, ' => ', _id);
|
||||
log.trace('Found replacement for', id, ' => ', _id);
|
||||
return _id;
|
||||
}
|
||||
}
|
||||
@@ -205,17 +205,17 @@ const getAnchorId = id => {
|
||||
|
||||
export const adjustClustersAndEdges = (graph, depth) => {
|
||||
if (!graph || depth > 10) {
|
||||
logger.debug('Opting out, no graph ');
|
||||
log.debug('Opting out, no graph ');
|
||||
return;
|
||||
} else {
|
||||
logger.debug('Opting in, graph ');
|
||||
log.debug('Opting in, graph ');
|
||||
}
|
||||
// Go through the nodes and for each cluster found, save a replacment node, this can be used when
|
||||
// faking a link to a cluster
|
||||
graph.nodes().forEach(function(id) {
|
||||
const children = graph.children(id);
|
||||
if (children.length > 0) {
|
||||
logger.warn(
|
||||
log.warn(
|
||||
'Cluster identified',
|
||||
id,
|
||||
' Replacement id in edges: ',
|
||||
@@ -231,9 +231,9 @@ export const adjustClustersAndEdges = (graph, depth) => {
|
||||
const children = graph.children(id);
|
||||
const edges = graph.edges();
|
||||
if (children.length > 0) {
|
||||
logger.debug('Cluster identified', id, decendants);
|
||||
log.debug('Cluster identified', id, decendants);
|
||||
edges.forEach(edge => {
|
||||
// logger.debug('Edge, decendants: ', edge, decendants[id]);
|
||||
// log.debug('Edge, decendants: ', edge, decendants[id]);
|
||||
|
||||
// Check if any edge leaves the cluster (not the actual cluster, thats a link from the box)
|
||||
if (edge.v !== id && edge.w !== id) {
|
||||
@@ -245,14 +245,14 @@ export const adjustClustersAndEdges = (graph, depth) => {
|
||||
|
||||
// d1 xor d2 - if either d1 is true and d2 is false or the other way around
|
||||
if (d1 ^ d2) {
|
||||
logger.warn('Edge: ', edge, ' leaves cluster ', id);
|
||||
logger.warn('Decendants of XXX ', id, ': ', decendants[id]);
|
||||
log.warn('Edge: ', edge, ' leaves cluster ', id);
|
||||
log.warn('Decendants of XXX ', id, ': ', decendants[id]);
|
||||
clusterDb[id].externalConnections = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.debug('Not a cluster ', id, decendants);
|
||||
log.debug('Not a cluster ', id, decendants);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -260,13 +260,13 @@ export const adjustClustersAndEdges = (graph, depth) => {
|
||||
// in the cluster inorder to fake the edge
|
||||
graph.edges().forEach(function(e) {
|
||||
const edge = graph.edge(e);
|
||||
logger.warn('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(e));
|
||||
logger.warn('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(graph.edge(e)));
|
||||
log.warn('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(e));
|
||||
log.warn('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(graph.edge(e)));
|
||||
|
||||
let v = e.v;
|
||||
let w = e.w;
|
||||
// Check if link is either from or to a cluster
|
||||
logger.warn(
|
||||
log.warn(
|
||||
'Fix XXX',
|
||||
clusterDb,
|
||||
'ids:',
|
||||
@@ -278,20 +278,20 @@ export const adjustClustersAndEdges = (graph, depth) => {
|
||||
clusterDb[e.w]
|
||||
);
|
||||
if (clusterDb[e.v] || clusterDb[e.w]) {
|
||||
logger.warn('Fixing and trixing - removing XXX', e.v, e.w, e.name);
|
||||
log.warn('Fixing and trixing - removing XXX', e.v, e.w, e.name);
|
||||
v = getAnchorId(e.v);
|
||||
w = getAnchorId(e.w);
|
||||
graph.removeEdge(e.v, e.w, e.name);
|
||||
if (v !== e.v) edge.fromCluster = e.v;
|
||||
if (w !== e.w) edge.toCluster = e.w;
|
||||
logger.warn('Fix Replacing with XXX', v, w, e.name);
|
||||
log.warn('Fix Replacing with XXX', v, w, e.name);
|
||||
graph.setEdge(v, w, edge, e.name);
|
||||
}
|
||||
});
|
||||
logger.warn('Adjusted Graph', graphlib.json.write(graph));
|
||||
log.warn('Adjusted Graph', graphlib.json.write(graph));
|
||||
extractor(graph, 0);
|
||||
|
||||
logger.trace(clusterDb);
|
||||
log.trace(clusterDb);
|
||||
|
||||
// Remove references to extracted cluster
|
||||
// graph.edges().forEach(edge => {
|
||||
@@ -302,9 +302,9 @@ export const adjustClustersAndEdges = (graph, depth) => {
|
||||
};
|
||||
|
||||
export const extractor = (graph, depth) => {
|
||||
logger.warn('extractor - ', depth, graphlib.json.write(graph), graph.children('D'));
|
||||
log.warn('extractor - ', depth, graphlib.json.write(graph), graph.children('D'));
|
||||
if (depth > 10) {
|
||||
logger.error('Bailing out');
|
||||
log.error('Bailing out');
|
||||
return;
|
||||
}
|
||||
// For clusters without incoming and/or outgoing edges, create a new cluster-node
|
||||
@@ -319,16 +319,16 @@ export const extractor = (graph, depth) => {
|
||||
}
|
||||
|
||||
if (!hasChildren) {
|
||||
logger.debug('Done, no node has children', graph.nodes());
|
||||
log.debug('Done, no node has children', graph.nodes());
|
||||
return;
|
||||
}
|
||||
// const clusters = Object.keys(clusterDb);
|
||||
// clusters.forEach(clusterId => {
|
||||
logger.debug('Nodes = ', nodes, depth);
|
||||
log.debug('Nodes = ', nodes, depth);
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
const node = nodes[i];
|
||||
|
||||
logger.debug(
|
||||
log.debug(
|
||||
'Extracting node',
|
||||
node,
|
||||
clusterDb,
|
||||
@@ -343,7 +343,7 @@ export const extractor = (graph, depth) => {
|
||||
// that it still is in the game
|
||||
if (!clusterDb[node]) {
|
||||
// Skip if the node is not a cluster
|
||||
logger.debug('Not a cluster', node, depth);
|
||||
log.debug('Not a cluster', node, depth);
|
||||
// break;
|
||||
} else if (
|
||||
!clusterDb[node].externalConnections &&
|
||||
@@ -351,7 +351,7 @@ export const extractor = (graph, depth) => {
|
||||
graph.children(node) &&
|
||||
graph.children(node).length > 0
|
||||
) {
|
||||
logger.warn(
|
||||
log.warn(
|
||||
'Cluster without external connections, without a parent and with children',
|
||||
node,
|
||||
depth
|
||||
@@ -375,7 +375,7 @@ export const extractor = (graph, depth) => {
|
||||
return {};
|
||||
});
|
||||
|
||||
logger.warn('Old graph before copy', graphlib.json.write(graph));
|
||||
log.warn('Old graph before copy', graphlib.json.write(graph));
|
||||
copy(node, graph, clusterGraph, node);
|
||||
graph.setNode(node, {
|
||||
clusterNode: true,
|
||||
@@ -384,10 +384,10 @@ export const extractor = (graph, depth) => {
|
||||
labelText: clusterDb[node].labelText,
|
||||
graph: clusterGraph
|
||||
});
|
||||
logger.warn('New graph after copy node: (', node, ')', graphlib.json.write(clusterGraph));
|
||||
logger.debug('Old graph after copy', graphlib.json.write(graph));
|
||||
log.warn('New graph after copy node: (', node, ')', graphlib.json.write(clusterGraph));
|
||||
log.debug('Old graph after copy', graphlib.json.write(graph));
|
||||
} else {
|
||||
logger.warn(
|
||||
log.warn(
|
||||
'Cluster ** ',
|
||||
node,
|
||||
' **not meeting the criteria !externalConnections:',
|
||||
@@ -399,16 +399,16 @@ export const extractor = (graph, depth) => {
|
||||
graph.children('D'),
|
||||
depth
|
||||
);
|
||||
logger.debug(clusterDb);
|
||||
log.debug(clusterDb);
|
||||
}
|
||||
}
|
||||
|
||||
nodes = graph.nodes();
|
||||
logger.warn('New list of nodes', nodes);
|
||||
log.warn('New list of nodes', nodes);
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
const node = nodes[i];
|
||||
const data = graph.node(node);
|
||||
logger.warn(' Now next level', node, data);
|
||||
log.warn(' Now next level', node, data);
|
||||
if (data.clusterNode) {
|
||||
extractor(data.graph, depth + 1);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import graphlib from 'graphlib';
|
||||
import dagre from 'dagre';
|
||||
import { validate, adjustClustersAndEdges, extractDecendants, sortNodesByHierarchy } from './mermaid-graphlib';
|
||||
import { setLogLevel, logger } from '../logger';
|
||||
import { setLogLevel, log } from '../logger';
|
||||
|
||||
describe('Graphlib decorations', () => {
|
||||
let g;
|
||||
@@ -65,7 +65,7 @@ describe('Graphlib decorations', () => {
|
||||
g.setEdge('C1', 'C2');
|
||||
|
||||
adjustClustersAndEdges(g);
|
||||
logger.info(g.edges())
|
||||
log.info(g.edges())
|
||||
expect(validate(g)).toBe(true);
|
||||
});
|
||||
|
||||
@@ -92,7 +92,7 @@ describe('Graphlib decorations', () => {
|
||||
g.setEdge('C1', 'c', { name: 'C1-external-link' });
|
||||
|
||||
adjustClustersAndEdges(g);
|
||||
logger.info(g.nodes())
|
||||
log.info(g.nodes())
|
||||
expect(g.nodes().length).toBe(2);
|
||||
expect(validate(g)).toBe(true);
|
||||
});
|
||||
@@ -114,9 +114,9 @@ describe('Graphlib decorations', () => {
|
||||
// g.setEdge('a', 'b', { name: 'C1-internal-link' });
|
||||
g.setEdge('C1', 'C2', { name: 'C1-external-link' });
|
||||
|
||||
logger.info(g.nodes())
|
||||
log.info(g.nodes())
|
||||
adjustClustersAndEdges(g);
|
||||
logger.info(g.nodes())
|
||||
log.info(g.nodes())
|
||||
expect(g.nodes().length).toBe(2);
|
||||
expect(validate(g)).toBe(true);
|
||||
});
|
||||
@@ -133,9 +133,9 @@ describe('Graphlib decorations', () => {
|
||||
g.setParent('a', 'C1');
|
||||
g.setEdge('C1', 'b', { data: 'link1' }, '1');
|
||||
|
||||
// logger.info(g.edges())
|
||||
// log.info(g.edges())
|
||||
adjustClustersAndEdges(g);
|
||||
logger.info(g.edges())
|
||||
log.info(g.edges())
|
||||
expect(g.nodes()).toEqual(['b', 'C1']);
|
||||
expect(g.edges().length).toBe(1);
|
||||
expect(validate(g)).toBe(true);
|
||||
@@ -160,9 +160,9 @@ describe('Graphlib decorations', () => {
|
||||
g.setEdge('C1', 'b', { data: 'link1' }, '1');
|
||||
g.setEdge('C1', 'c', { data: 'link2' }, '2');
|
||||
|
||||
logger.info(g.node('C1'))
|
||||
log.info(g.node('C1'))
|
||||
adjustClustersAndEdges(g);
|
||||
logger.info(g.edges())
|
||||
log.info(g.edges())
|
||||
expect(g.nodes()).toEqual(['b', 'c', 'C1']);
|
||||
expect(g.nodes().length).toBe(3);
|
||||
expect(g.edges().length).toBe(2);
|
||||
@@ -198,7 +198,7 @@ describe('Graphlib decorations', () => {
|
||||
g.setEdge('A', 'B', { data: 'link1' }, '1');
|
||||
g.setEdge('A', 'C', { data: 'link2' }, '2');
|
||||
|
||||
// logger.info(g.edges())
|
||||
// log.info(g.edges())
|
||||
adjustClustersAndEdges(g);
|
||||
expect(g.nodes()).toEqual(['A', 'B', 'C']);
|
||||
expect(g.edges().length).toBe(2);
|
||||
@@ -228,10 +228,10 @@ describe('Graphlib decorations', () => {
|
||||
g.setParent('d', 'D');
|
||||
g.setParent('D', 'C');
|
||||
|
||||
// logger.info('Graph before', g.node('D'))
|
||||
// logger.info('Graph before', graphlib.json.write(g))
|
||||
// log.info('Graph before', g.node('D'))
|
||||
// log.info('Graph before', graphlib.json.write(g))
|
||||
adjustClustersAndEdges(g);
|
||||
// logger.info('Graph after', graphlib.json.write(g), g.node('C').graph)
|
||||
// log.info('Graph after', graphlib.json.write(g), g.node('C').graph)
|
||||
|
||||
const CGraph = g.node('C').graph;
|
||||
const DGraph = CGraph.node('D').graph;
|
||||
@@ -274,10 +274,10 @@ describe('Graphlib decorations', () => {
|
||||
g.setEdge('A', 'B', { data: 'link1' }, '1');
|
||||
g.setEdge('A', 'C', { data: 'link2' }, '2');
|
||||
|
||||
logger.info('Graph before', g.node('D'))
|
||||
logger.info('Graph before', graphlib.json.write(g))
|
||||
log.info('Graph before', g.node('D'))
|
||||
log.info('Graph before', graphlib.json.write(g))
|
||||
adjustClustersAndEdges(g);
|
||||
logger.trace('Graph after', graphlib.json.write(g))
|
||||
log.trace('Graph after', graphlib.json.write(g))
|
||||
expect(g.nodes()).toEqual(['C', 'B', 'A']);
|
||||
expect(g.nodes().length).toBe(3);
|
||||
expect(g.edges().length).toBe(2);
|
||||
@@ -285,14 +285,14 @@ describe('Graphlib decorations', () => {
|
||||
const AGraph = g.node('A').graph;
|
||||
const BGraph = g.node('B').graph;
|
||||
const CGraph = g.node('C').graph;
|
||||
// logger.info(CGraph.nodes());
|
||||
// log.info(CGraph.nodes());
|
||||
const DGraph = CGraph.node('D').graph;
|
||||
// logger.info('DG', CGraph.children('D'));
|
||||
// log.info('DG', CGraph.children('D'));
|
||||
|
||||
logger.info('A', AGraph.nodes());
|
||||
log.info('A', AGraph.nodes());
|
||||
expect(AGraph.nodes().length).toBe(1);
|
||||
expect(AGraph.nodes()).toEqual(['a']);
|
||||
logger.trace('Nodes', BGraph.nodes())
|
||||
log.trace('Nodes', BGraph.nodes())
|
||||
expect(BGraph.nodes().length).toBe(1);
|
||||
expect(BGraph.nodes()).toEqual(['b']);
|
||||
expect(CGraph.nodes()).toEqual(['D']);
|
||||
@@ -330,11 +330,11 @@ describe('Graphlib decorations', () => {
|
||||
g.setEdge('c', 'd', { data: 'link2' }, '2');
|
||||
g.setEdge('d', 'e', { data: 'link2' }, '2');
|
||||
|
||||
logger.info('Graph before', graphlib.json.write(g))
|
||||
log.info('Graph before', graphlib.json.write(g))
|
||||
adjustClustersAndEdges(g);
|
||||
const bGraph = g.node('b').graph;
|
||||
// logger.trace('Graph after', graphlib.json.write(g))
|
||||
logger.info('Graph after', graphlib.json.write(bGraph));
|
||||
// log.trace('Graph after', graphlib.json.write(g))
|
||||
log.info('Graph after', graphlib.json.write(bGraph));
|
||||
expect(bGraph.nodes().length).toBe(3);
|
||||
expect(bGraph.edges().length).toBe(2);
|
||||
});
|
||||
@@ -356,13 +356,13 @@ describe('Graphlib decorations', () => {
|
||||
g.setParent('c', 'b');
|
||||
g.setParent('e', 'c');
|
||||
|
||||
logger.info('Graph before', graphlib.json.write(g))
|
||||
log.info('Graph before', graphlib.json.write(g))
|
||||
adjustClustersAndEdges(g);
|
||||
const aGraph = g.node('a').graph;
|
||||
const bGraph = aGraph.node('b').graph;
|
||||
logger.info('Graph after', graphlib.json.write(aGraph));
|
||||
log.info('Graph after', graphlib.json.write(aGraph));
|
||||
const cGraph = bGraph.node('c').graph;
|
||||
// logger.trace('Graph after', graphlib.json.write(g))
|
||||
// log.trace('Graph after', graphlib.json.write(g))
|
||||
expect(aGraph.nodes().length).toBe(1);
|
||||
expect(bGraph.nodes().length).toBe(1);
|
||||
expect(cGraph.nodes().length).toBe(1);
|
||||
@@ -385,12 +385,12 @@ flowchart TB
|
||||
const exportedGraph = JSON.parse('{"options":{"directed":true,"multigraph":true,"compound":true},"nodes":[{"v":"A","value":{"labelStyle":"","shape":"rect","labelText":"A","rx":0,"ry":0,"class":"default","style":"","id":"A","width":500,"type":"group","padding":15}},{"v":"B","value":{"labelStyle":"","shape":"rect","labelText":"B","rx":0,"ry":0,"class":"default","style":"","id":"B","width":500,"type":"group","padding":15},"parent":"A"},{"v":"b","value":{"labelStyle":"","shape":"rect","labelText":"b","rx":0,"ry":0,"class":"default","style":"","id":"b","padding":15},"parent":"A"},{"v":"c","value":{"labelStyle":"","shape":"rect","labelText":"c","rx":0,"ry":0,"class":"default","style":"","id":"c","padding":15},"parent":"B"},{"v":"a","value":{"labelStyle":"","shape":"rect","labelText":"a","rx":0,"ry":0,"class":"default","style":"","id":"a","padding":15},"parent":"A"}],"edges":[{"v":"b","w":"B","name":"1","value":{"minlen":1,"arrowhead":"normal","arrowTypeStart":"arrow_open","arrowTypeEnd":"arrow_point","thickness":"normal","pattern":"solid","style":"fill:none","labelStyle":"","arrowheadStyle":"fill: #333","labelpos":"c","labelType":"text","label":"","id":"L-b-B","classes":"flowchart-link LS-b LE-B"}},{"v":"a","w":"c","name":"2","value":{"minlen":1,"arrowhead":"normal","arrowTypeStart":"arrow_open","arrowTypeEnd":"arrow_point","thickness":"normal","pattern":"solid","style":"fill:none","labelStyle":"","arrowheadStyle":"fill: #333","labelpos":"c","labelType":"text","label":"","id":"L-a-c","classes":"flowchart-link LS-a LE-c"}}],"value":{"rankdir":"TB","nodesep":50,"ranksep":50,"marginx":8,"marginy":8}}');
|
||||
const gr = graphlib.json.read(exportedGraph)
|
||||
|
||||
logger.info('Graph before', graphlib.json.write(gr))
|
||||
log.info('Graph before', graphlib.json.write(gr))
|
||||
adjustClustersAndEdges(gr);
|
||||
const aGraph = gr.node('A').graph;
|
||||
const bGraph = aGraph.node('B').graph;
|
||||
logger.info('Graph after', graphlib.json.write(aGraph));
|
||||
// logger.trace('Graph after', graphlib.json.write(g))
|
||||
log.info('Graph after', graphlib.json.write(aGraph));
|
||||
// log.trace('Graph after', graphlib.json.write(g))
|
||||
expect(aGraph.parent('c')).toBe('B');
|
||||
expect(aGraph.parent('B')).toBe(undefined);
|
||||
});
|
||||
@@ -438,7 +438,7 @@ describe('extractDecendants', function () {
|
||||
g.setEdge('A', 'B', { data: 'link1' }, '1');
|
||||
g.setEdge('A', 'C', { data: 'link2' }, '2');
|
||||
|
||||
// logger.info(g.edges())
|
||||
// log.info(g.edges())
|
||||
const d1 = extractDecendants('A',g)
|
||||
const d2 = extractDecendants('B',g)
|
||||
const d3 = extractDecendants('C',g)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { select } from 'd3';
|
||||
import { logger } from '../logger'; // eslint-disable-line
|
||||
import { log } from '../logger'; // eslint-disable-line
|
||||
import { labelHelper, updateNodeBounds, insertPolygonShape } from './shapes/util';
|
||||
import { getConfig } from '../config';
|
||||
import intersect from './intersect/index.js';
|
||||
@@ -20,12 +20,12 @@ const question = (parent, node) => {
|
||||
{ x: 0, y: -s / 2 }
|
||||
];
|
||||
|
||||
logger.info('Question main (Circle)');
|
||||
log.info('Question main (Circle)');
|
||||
|
||||
const questionElem = insertPolygonShape(shapeSvg, s, s, points);
|
||||
updateNodeBounds(node, questionElem);
|
||||
node.intersect = function(point) {
|
||||
logger.warn('Intersect called');
|
||||
log.warn('Intersect called');
|
||||
return intersect.polygon(node, points, point);
|
||||
};
|
||||
|
||||
@@ -255,7 +255,7 @@ const cylinder = (parent, node) => {
|
||||
const rect = (parent, node) => {
|
||||
const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, 'node ' + node.classes, true);
|
||||
|
||||
logger.trace('Classes = ', node.classes);
|
||||
log.trace('Classes = ', node.classes);
|
||||
// add the rect
|
||||
const rect = shapeSvg.insert('rect', ':first-child');
|
||||
|
||||
@@ -300,7 +300,7 @@ const rectWithTitle = (parent, node) => {
|
||||
const label = shapeSvg.insert('g').attr('class', 'label');
|
||||
|
||||
const text2 = node.labelText.flat();
|
||||
logger.info('Label text', text2[0]);
|
||||
log.info('Label text', text2[0]);
|
||||
|
||||
const text = label.node().appendChild(createLabel(text2[0], node.labelStyle, true, true));
|
||||
let bbox;
|
||||
@@ -311,7 +311,7 @@ const rectWithTitle = (parent, node) => {
|
||||
dv.attr('width', bbox.width);
|
||||
dv.attr('height', bbox.height);
|
||||
}
|
||||
logger.info('Text 2', text2);
|
||||
log.info('Text 2', text2);
|
||||
const textRows = text2.slice(1, text2.length);
|
||||
let titleBox = text.getBBox();
|
||||
const descr = label
|
||||
@@ -326,7 +326,7 @@ const rectWithTitle = (parent, node) => {
|
||||
dv.attr('height', bbox.height);
|
||||
}
|
||||
// bbox = label.getBBox();
|
||||
// logger.info(descr);
|
||||
// log.info(descr);
|
||||
const halfPadding = node.padding / 2;
|
||||
select(descr).attr(
|
||||
'transform',
|
||||
@@ -416,12 +416,12 @@ const circle = (parent, node) => {
|
||||
.attr('width', bbox.width + node.padding)
|
||||
.attr('height', bbox.height + node.padding);
|
||||
|
||||
logger.info('Circle main');
|
||||
log.info('Circle main');
|
||||
|
||||
updateNodeBounds(node, circle);
|
||||
|
||||
node.intersect = function(point) {
|
||||
logger.info('Circle intersect', node, bbox.width / 2 + halfPadding, point);
|
||||
log.info('Circle intersect', node, bbox.width / 2 + halfPadding, point);
|
||||
return intersect.circle(node, bbox.width / 2 + halfPadding, point);
|
||||
};
|
||||
|
||||
@@ -729,7 +729,7 @@ const class_box = (parent, node) => {
|
||||
// }
|
||||
// bbox = labelContainer.getBBox();
|
||||
|
||||
// logger.info('Text 2', text2);
|
||||
// log.info('Text 2', text2);
|
||||
// const textRows = text2.slice(1, text2.length);
|
||||
// let titleBox = text.getBBox();
|
||||
// const descr = label
|
||||
@@ -744,7 +744,7 @@ const class_box = (parent, node) => {
|
||||
// dv.attr('height', bbox.height);
|
||||
// }
|
||||
// // bbox = label.getBBox();
|
||||
// // logger.info(descr);
|
||||
// // log.info(descr);
|
||||
// select(descr).attr(
|
||||
// 'transform',
|
||||
// 'translate( ' +
|
||||
@@ -859,7 +859,7 @@ export const clear = () => {
|
||||
|
||||
export const positionNode = node => {
|
||||
const el = nodeElems[node.id];
|
||||
logger.trace(
|
||||
log.trace(
|
||||
'Transforming node',
|
||||
node,
|
||||
'translate(' + (node.x - node.width / 2 - 5) + ', ' + (node.y - node.height / 2 - 5) + ')'
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Setup arrow head and define the marker. The result is appended to the svg.
|
||||
*/
|
||||
|
||||
// import { logger } from '../logger';
|
||||
// import { log } from '../logger';
|
||||
|
||||
// Only add the number of markers that the diagram needs
|
||||
const insertPatterns = (elem, patternArray, type, id) => {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { updateNodeBounds, labelHelper } from './util';
|
||||
import { logger } from '../../logger'; // eslint-disable-line
|
||||
import { log } from '../../logger'; // eslint-disable-line
|
||||
import intersect from '../intersect/index.js';
|
||||
|
||||
const note = (parent, node) => {
|
||||
const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, 'node ' + node.classes, true);
|
||||
|
||||
logger.info('Classes = ', node.classes);
|
||||
log.info('Classes = ', node.classes);
|
||||
// add the rect
|
||||
const rect = shapeSvg.insert('rect', ':first-child');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user