mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-01 18:14:06 +01:00
This commit is contained in:
@@ -192,19 +192,6 @@ export const positionEdgeLabel = (edge, paths) => {
|
||||
}
|
||||
};
|
||||
|
||||
// const getRelationType = function(type) {
|
||||
// switch (type) {
|
||||
// case stateDb.relationType.AGGREGATION:
|
||||
// return 'aggregation';
|
||||
// case stateDb.relationType.EXTENSION:
|
||||
// return 'extension';
|
||||
// case stateDb.relationType.COMPOSITION:
|
||||
// return 'composition';
|
||||
// case stateDb.relationType.DEPENDENCY:
|
||||
// return 'dependency';
|
||||
// }
|
||||
// };
|
||||
|
||||
const outsideNode = (node, point) => {
|
||||
// log.warn('Checking bounds ', node, point);
|
||||
const x = node.x;
|
||||
@@ -415,45 +402,7 @@ export const insertEdge = function (elem, e, edge, clusterDb, diagramType, graph
|
||||
if (edge.fromCluster) {
|
||||
log.info('from cluster abc88', clusterDb[edge.fromCluster]);
|
||||
points = cutPathAtIntersect(points.reverse(), clusterDb[edge.fromCluster].node).reverse();
|
||||
// log.warn('edge', edge);
|
||||
// log.warn('from cluster', clusterDb[edge.fromCluster], points);
|
||||
// const updatedPoints = [];
|
||||
// let lastPointOutside = edge.points[edge.points.length - 1];
|
||||
// let isInside = false;
|
||||
// for (let i = points.length - 1; i >= 0; i--) {
|
||||
// const point = points[i];
|
||||
// const node = clusterDb[edge.fromCluster].node;
|
||||
// log.warn('checking to', edge.fromCluster, point, node);
|
||||
|
||||
// if (!outsideNode(node, point) && !isInside) {
|
||||
// log.warn('inside', edge.fromCluster, point, node);
|
||||
|
||||
// // First point inside the rect
|
||||
// const inter = intersection(node, lastPointOutside, point);
|
||||
// log.warn('intersect', intersection(node, lastPointOutside, point));
|
||||
// let pointPresent = false;
|
||||
// points.forEach(p => {
|
||||
// pointPresent = pointPresent || (p.x === inter.x && p.y === inter.y);
|
||||
// });
|
||||
// // if (!pointPresent) {
|
||||
// if (!points.find(e => e.x === inter.x && e.y === inter.y)) {
|
||||
// updatedPoints.unshift(inter);
|
||||
// log.warn('Adding point -updated = ', updatedPoints);
|
||||
// } else {
|
||||
// log.warn('no intersect', inter, points);
|
||||
// }
|
||||
// // points.push(insterection);
|
||||
// isInside = true;
|
||||
// } else {
|
||||
// // at the outside
|
||||
// // if (!isInside) updatedPoints.unshift(point);
|
||||
// updatedPoints.unshift(point);
|
||||
// log.warn('Outside point', point, updatedPoints);
|
||||
// }
|
||||
// lastPointOutside = point;
|
||||
// }
|
||||
// points = updatedPoints;
|
||||
// points = edge.points;
|
||||
pointsHasChanged = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -277,7 +277,33 @@ export const adjustClustersAndEdges = (graph, depth) => {
|
||||
' --- ',
|
||||
clusterDb[e.w]
|
||||
);
|
||||
if (clusterDb[e.v] || clusterDb[e.w]) {
|
||||
if (clusterDb[e.v] && clusterDb[e.w] && clusterDb[e.v] === clusterDb[e.w]) {
|
||||
log.warn('Fixing and trixing link to self - 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);
|
||||
const specialId = e.w + '---' + e.v;
|
||||
graph.setNode(specialId, {
|
||||
domId: specialId,
|
||||
id: specialId,
|
||||
labelStyle: '',
|
||||
labelText: edge.label,
|
||||
padding: 0,
|
||||
shape: 'labelRect',
|
||||
style: '',
|
||||
});
|
||||
const edge1 = JSON.parse(JSON.stringify(edge));
|
||||
const edge2 = JSON.parse(JSON.stringify(edge));
|
||||
edge1.label = '';
|
||||
edge1.arrowTypeEnd = 'none';
|
||||
edge2.label = '';
|
||||
edge1.fromCluster = e.v;
|
||||
edge2.toCluster = e.v;
|
||||
|
||||
graph.setEdge(v, specialId, edge1, e.name + '-cyclic-special');
|
||||
graph.setEdge(specialId, w, edge2, e.name + '-cyclic-special');
|
||||
} else if (clusterDb[e.v] || clusterDb[e.w]) {
|
||||
log.warn('Fixing and trixing - removing XXX', e.v, e.w, e.name);
|
||||
v = getAnchorId(e.v);
|
||||
w = getAnchorId(e.w);
|
||||
|
||||
@@ -347,6 +347,39 @@ const rect = (parent, node) => {
|
||||
return shapeSvg;
|
||||
};
|
||||
|
||||
const labelRect = (parent, node) => {
|
||||
const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, 'label', true);
|
||||
|
||||
log.trace('Classes = ', node.classes);
|
||||
// add the rect
|
||||
const rect = shapeSvg.insert('rect', ':first-child');
|
||||
|
||||
// Hide the rect we are only after the label
|
||||
const totalWidth = 0;
|
||||
const totalHeight = 0;
|
||||
rect.attr('width', totalWidth).attr('height', totalHeight);
|
||||
shapeSvg.attr('class', 'label edgeLabel');
|
||||
|
||||
if (node.props) {
|
||||
const propKeys = new Set(Object.keys(node.props));
|
||||
if (node.props.borders) {
|
||||
applyNodePropertyBorders(rect, node.props.borders, totalWidth, totalHeight);
|
||||
propKeys.delete('borders');
|
||||
}
|
||||
propKeys.forEach((propKey) => {
|
||||
log.warn(`Unknown node property ${propKey}`);
|
||||
});
|
||||
}
|
||||
|
||||
updateNodeBounds(node, rect);
|
||||
|
||||
node.intersect = function (point) {
|
||||
return intersect.rect(node, point);
|
||||
};
|
||||
|
||||
return shapeSvg;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param rect
|
||||
* @param borders
|
||||
@@ -976,6 +1009,7 @@ const class_box = (parent, node) => {
|
||||
const shapes = {
|
||||
question,
|
||||
rect,
|
||||
labelRect,
|
||||
rectWithTitle,
|
||||
choice,
|
||||
circle,
|
||||
|
||||
@@ -394,6 +394,9 @@ const traverseEdge = (points) => {
|
||||
* @returns {Point} Return result of `transverseEdge`
|
||||
*/
|
||||
const calcLabelPosition = (points) => {
|
||||
if (points.length === 1) {
|
||||
return points[0];
|
||||
}
|
||||
return traverseEdge(points);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user