#5237 Fix for diamond intersections with ELK, tweak

This commit is contained in:
Knut Sveidqvist
2024-07-03 14:52:35 +02:00
parent 91670385f5
commit 8db678a039

View File

@@ -652,7 +652,6 @@ export const render = async (data4Layout, svg, element, algorithm) => {
y: startNode.y + startNode.height / 2 + offset.y, y: startNode.y + startNode.height / 2 + offset.y,
width: sw, width: sw,
height: startNode.height, height: startNode.height,
intersection: startNode.intersect,
padding: startNode.padding, padding: startNode.padding,
}, },
startNode.shape === 'diamond' startNode.shape === 'diamond'
@@ -665,13 +664,11 @@ export const render = async (data4Layout, svg, element, algorithm) => {
y: endNode.y + endNode.height / 2 + offset.y, y: endNode.y + endNode.height / 2 + offset.y,
width: ew, width: ew,
height: endNode.height, height: endNode.height,
intersection: endNode.intersect,
padding: endNode.padding, padding: endNode.padding,
}, },
endNode.shape === 'diamond' endNode.shape === 'diamond'
); );
// cutPathAtIntersect(edge.points, endNode);
// }
const paths = insertEdge( const paths = insertEdge(
edgesEl, edgesEl,
edge, edge,
@@ -763,8 +760,8 @@ const diamondIntersection = (bounds, outsidePoint, insidePoint) => {
var x1 = bounds.x; var x1 = bounds.x;
var y1 = bounds.y; var y1 = bounds.y;
const w = bounds.width + bounds.padding; const w = bounds.width; //+ bounds.padding;
const h = bounds.height + bounds.padding; const h = bounds.height; // + bounds.padding;
const s = w + h; const s = w + h;
const polyPoints = [ const polyPoints = [
@@ -812,15 +809,17 @@ const diamondIntersection = (bounds, outsidePoint, insidePoint) => {
return bounds; return bounds;
} }
console.log('UIO intersections', intersections);
if (intersections.length > 1) { if (intersections.length > 1) {
// More intersections, find the one nearest to edge end point // More intersections, find the one nearest to edge end point
intersections.sort(function (p, q) { intersections.sort(function (p, q) {
var pdx = p.x - point.x; var pdx = p.x - outsidePoint.x;
var pdy = p.y - point.y; var pdy = p.y - outsidePoint.y;
var distp = Math.sqrt(pdx * pdx + pdy * pdy); var distp = Math.sqrt(pdx * pdx + pdy * pdy);
var qdx = q.x - point.x; var qdx = q.x - outsidePoint.x;
var qdy = q.y - point.y; var qdy = q.y - outsidePoint.y;
var distq = Math.sqrt(qdx * qdx + qdy * qdy); var distq = Math.sqrt(qdx * qdx + qdy * qdy);
return distp < distq ? -1 : distp === distq ? 0 : 1; return distp < distq ? -1 : distp === distq ? 0 : 1;
@@ -933,14 +932,22 @@ const cutPathAtIntersect = (_points, bounds, isDiamond: boolean) => {
if (!outsideNode(bounds, point) && !isInside) { if (!outsideNode(bounds, point) && !isInside) {
// 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 = !isDiamond let inter;
? intersection(bounds, lastPointOutside, point)
: diamondIntersection(bounds, lastPointOutside, point);
console.log('abc88 inside', point, lastPointOutside, inter); if (isDiamond) {
console.log('abc88 intersection', inter, bounds); let inter2 = diamondIntersection(bounds, lastPointOutside, point);
const distance = Math.sqrt(
(lastPointOutside.x - inter2.x) ** 2 + (lastPointOutside.y - inter2.y) ** 2
);
if (distance > 1) {
inter = inter2;
}
}
if (!inter) {
inter = intersection(bounds, lastPointOutside, point);
}
// // 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;
points.forEach((p) => { points.forEach((p) => {
pointPresent = pointPresent || (p.x === inter.x && p.y === inter.y); pointPresent = pointPresent || (p.x === inter.x && p.y === inter.y);