mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
#5237 Fix for issue with edges from clusters
This commit is contained in:
parent
a35e62db14
commit
fef433e844
@ -237,7 +237,7 @@ const outsideNode = (node, point) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const intersection = (node, outsidePoint, insidePoint) => {
|
export const intersection = (node, outsidePoint, insidePoint) => {
|
||||||
log.warn(`intersection calc abc89:
|
log.debug(`intersection calc abc89:
|
||||||
outsidePoint: ${JSON.stringify(outsidePoint)}
|
outsidePoint: ${JSON.stringify(outsidePoint)}
|
||||||
insidePoint : ${JSON.stringify(insidePoint)}
|
insidePoint : ${JSON.stringify(insidePoint)}
|
||||||
node : x:${node.x} y:${node.y} w:${node.width} h:${node.height}`);
|
node : x:${node.x} y:${node.y} w:${node.width} h:${node.height}`);
|
||||||
@ -250,26 +250,9 @@ export const intersection = (node, outsidePoint, insidePoint) => {
|
|||||||
let r = insidePoint.x < outsidePoint.x ? w - dx : w + dx;
|
let r = insidePoint.x < outsidePoint.x ? w - dx : w + dx;
|
||||||
const h = node.height / 2;
|
const h = node.height / 2;
|
||||||
|
|
||||||
// const edges = {
|
|
||||||
// x1: x - w,
|
|
||||||
// x2: x + w,
|
|
||||||
// y1: y - h,
|
|
||||||
// y2: y + h
|
|
||||||
// };
|
|
||||||
|
|
||||||
// if (
|
|
||||||
// outsidePoint.x === edges.x1 ||
|
|
||||||
// outsidePoint.x === edges.x2 ||
|
|
||||||
// outsidePoint.y === edges.y1 ||
|
|
||||||
// outsidePoint.y === edges.y2
|
|
||||||
// ) {
|
|
||||||
// log.warn('abc89 calc equals on edge', outsidePoint, edges);
|
|
||||||
// return outsidePoint;
|
|
||||||
// }
|
|
||||||
|
|
||||||
const Q = Math.abs(outsidePoint.y - insidePoint.y);
|
const Q = Math.abs(outsidePoint.y - insidePoint.y);
|
||||||
const R = Math.abs(outsidePoint.x - insidePoint.x);
|
const R = Math.abs(outsidePoint.x - insidePoint.x);
|
||||||
// log.warn();
|
|
||||||
if (Math.abs(y - outsidePoint.y) * w > Math.abs(x - outsidePoint.x) * h) {
|
if (Math.abs(y - outsidePoint.y) * w > Math.abs(x - outsidePoint.x) * h) {
|
||||||
// Intersection is top or bottom of rect.
|
// Intersection is top or bottom of rect.
|
||||||
let q = insidePoint.y < outsidePoint.y ? outsidePoint.y - h - y : y - h - outsidePoint.y;
|
let q = insidePoint.y < outsidePoint.y ? outsidePoint.y - h - y : y - h - outsidePoint.y;
|
||||||
@ -279,10 +262,10 @@ export const intersection = (node, outsidePoint, insidePoint) => {
|
|||||||
y: insidePoint.y < outsidePoint.y ? insidePoint.y + Q - q : insidePoint.y - Q + q,
|
y: insidePoint.y < outsidePoint.y ? insidePoint.y + Q - q : insidePoint.y - Q + q,
|
||||||
};
|
};
|
||||||
|
|
||||||
// if (r === 0) {
|
if (r === 0) {
|
||||||
// res.x = outsidePoint.x;
|
res.x = outsidePoint.x;
|
||||||
// res.y = outsidePoint.y;
|
res.y = outsidePoint.y;
|
||||||
// }
|
}
|
||||||
if (R === 0) {
|
if (R === 0) {
|
||||||
res.x = outsidePoint.x;
|
res.x = outsidePoint.x;
|
||||||
}
|
}
|
||||||
@ -290,7 +273,7 @@ export const intersection = (node, outsidePoint, insidePoint) => {
|
|||||||
res.y = outsidePoint.y;
|
res.y = outsidePoint.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.warn(`abc89 top/bot calc, Q ${Q}, q ${q}, R ${R}, r ${r}`, res, 'apa');
|
log.debug(`abc89 topp/bott calc, Q ${Q}, q ${q}, R ${R}, r ${r}`, res); // cspell: disable-line
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
@ -307,7 +290,7 @@ export const intersection = (node, outsidePoint, insidePoint) => {
|
|||||||
let _x = insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : insidePoint.x - R + r;
|
let _x = insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : insidePoint.x - R + r;
|
||||||
// let _x = insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : outsidePoint.x + r;
|
// let _x = insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : outsidePoint.x + r;
|
||||||
let _y = insidePoint.y < outsidePoint.y ? insidePoint.y + q : insidePoint.y - q;
|
let _y = insidePoint.y < outsidePoint.y ? insidePoint.y + q : insidePoint.y - q;
|
||||||
log.warn(`sides calc abc89, Q ${Q}, q ${q}, R ${R}, r ${r}`, { _x, _y });
|
log.debug(`sides calc abc89, Q ${Q}, q ${q}, R ${R}, r ${r}`, { _x, _y });
|
||||||
if (r === 0) {
|
if (r === 0) {
|
||||||
_x = outsidePoint.x;
|
_x = outsidePoint.x;
|
||||||
_y = outsidePoint.y;
|
_y = outsidePoint.y;
|
||||||
@ -344,8 +327,8 @@ const cutPathAtIntersect = (_points, boundaryNode) => {
|
|||||||
// First point inside the rect found
|
// First point inside the rect found
|
||||||
// Calc the intersection coord between the point anf the last point outside the rect
|
// Calc the intersection coord between the point anf the last point outside the rect
|
||||||
const inter = intersection(boundaryNode, lastPointOutside, point);
|
const inter = intersection(boundaryNode, lastPointOutside, point);
|
||||||
log.warn('abc88 inside', point, lastPointOutside, inter);
|
log.debug('abc88 inside', point, lastPointOutside, inter);
|
||||||
log.warn('abc88 intersection', inter, boundaryNode);
|
log.debug('abc88 intersection', inter, boundaryNode);
|
||||||
|
|
||||||
// // Check case where the intersection is the same as the last point
|
// // Check case where the intersection is the same as the last point
|
||||||
let pointPresent = false;
|
let pointPresent = false;
|
||||||
@ -370,7 +353,7 @@ const cutPathAtIntersect = (_points, boundaryNode) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
log.warn('abc88 returning points', points);
|
log.debug('returning points', points);
|
||||||
return points;
|
return points;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -482,14 +465,23 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
|
|||||||
const tail = startNode;
|
const tail = startNode;
|
||||||
var head = endNode;
|
var head = endNode;
|
||||||
|
|
||||||
log.info('abc88 InsertEdge XBX: ', points, edge.start, id);
|
log.info(
|
||||||
|
'abc88 InsertEdge Start: ',
|
||||||
|
edge.start,
|
||||||
|
'-->',
|
||||||
|
edge.end,
|
||||||
|
JSON.stringify(points, null, 2)
|
||||||
|
);
|
||||||
if (head.intersect && tail.intersect) {
|
if (head.intersect && tail.intersect) {
|
||||||
// log.info('abc88 InsertEdge SPLIT: 0.5', points);
|
// log.info('abc88 InsertEdge: 0.5', edge.start, '-->', edge.end, JSON.stringify(points));
|
||||||
points = points.slice(1, edge.points.length - 1);
|
points = points.slice(1, edge.points.length - 1);
|
||||||
// log.info('abc88 InsertEdge SPLIT: 0.7', points);
|
// log.info('abc88 InsertEdge APA12: 0.7', edge.start, '-->', edge.end, JSON.stringify(points));
|
||||||
points.unshift(tail.intersect(points[0]));
|
points.unshift(tail.intersect(points[0]));
|
||||||
log.info(
|
log.debug(
|
||||||
'Last point abc88',
|
'Last point APA12',
|
||||||
|
edge.start,
|
||||||
|
'-->',
|
||||||
|
edge.end,
|
||||||
points[points.length - 1],
|
points[points.length - 1],
|
||||||
head,
|
head,
|
||||||
head.intersect(points[points.length - 1])
|
head.intersect(points[points.length - 1])
|
||||||
@ -505,8 +497,9 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (edge.fromCluster) {
|
if (edge.fromCluster) {
|
||||||
log.info('from cluster abc88', clusterDb[edge.fromCluster]);
|
log.debug('from cluster abc88', clusterDb[edge.fromCluster], JSON.stringify(points, null, 2));
|
||||||
points = cutPathAtIntersect(points.reverse(), clusterDb[edge.fromCluster].node).reverse();
|
points = cutPathAtIntersect(points.reverse(), clusterDb[edge.fromCluster].node).reverse();
|
||||||
|
// log.info('from cluster abc88 fixed', JSON.stringify(points, null, 2));
|
||||||
|
|
||||||
pointsHasChanged = true;
|
pointsHasChanged = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user