mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
#1295 Fix for edges form clusters
This commit is contained in:
parent
02b19fed27
commit
df2925e51c
@ -82,6 +82,7 @@ const outsideNode = (node, point) => {
|
|||||||
// return { x: insidePoint.x + r, y: insidePoint.y + q };
|
// return { x: insidePoint.x + r, y: insidePoint.y + q };
|
||||||
// };
|
// };
|
||||||
const intersection = (node, outsidePoint, insidePoint) => {
|
const intersection = (node, outsidePoint, insidePoint) => {
|
||||||
|
logger.info('intersection', outsidePoint, insidePoint, node);
|
||||||
const x = node.x;
|
const x = node.x;
|
||||||
const y = node.y;
|
const y = node.y;
|
||||||
|
|
||||||
@ -96,30 +97,31 @@ const intersection = (node, outsidePoint, insidePoint) => {
|
|||||||
|
|
||||||
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);
|
||||||
// if (Math.abs(y - outsidePoint.y) * w > Math.abs(x - outsidePoint.x) * h || false) { // eslint-disable-line
|
if (Math.abs(y - outsidePoint.y) * w > Math.abs(x - outsidePoint.x) * h || false) { // eslint-disable-line
|
||||||
// // Intersection is top or bottom of rect.
|
// Intersection is top or bottom of rect.
|
||||||
|
|
||||||
// r = (R * q) / Q;
|
r = (R * q) / Q;
|
||||||
|
|
||||||
// return {
|
return {
|
||||||
// x: insidePoint.x < outsidePoint.x ? insidePoint.x + r : insidePoint.x - r,
|
x: insidePoint.x < outsidePoint.x ? insidePoint.x + r : insidePoint.x - r,
|
||||||
// y: insidePoint.y + q
|
y: insidePoint.y + q
|
||||||
// };
|
};
|
||||||
// } else {
|
} else {
|
||||||
q = (Q * r) / R;
|
q = (Q * r) / R;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
x: insidePoint.x < outsidePoint.x ? insidePoint.x + r : insidePoint.x - r,
|
x: insidePoint.x < outsidePoint.x ? insidePoint.x + r : insidePoint.x - r,
|
||||||
y: insidePoint.y < outsidePoint.y ? insidePoint.y + q : insidePoint.y - q
|
y: insidePoint.y < outsidePoint.y ? insidePoint.y + q : insidePoint.y - q
|
||||||
};
|
};
|
||||||
// }
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const insertEdge = function(elem, edge, clusterDb) {
|
export const insertEdge = function(elem, edge, clusterDb) {
|
||||||
|
logger.info('\n\n\n\n');
|
||||||
let points = edge.points;
|
let points = edge.points;
|
||||||
if (edge.toCluster) {
|
if (edge.toCluster) {
|
||||||
logger.trace('edge', edge);
|
logger.info('edge', edge);
|
||||||
logger.trace('cluster', clusterDb[edge.toCluster]);
|
logger.info('to cluster', clusterDb[edge.toCluster]);
|
||||||
points = [];
|
points = [];
|
||||||
let lastPointOutside;
|
let lastPointOutside;
|
||||||
let isInside = false;
|
let isInside = false;
|
||||||
@ -144,7 +146,7 @@ export const insertEdge = function(elem, edge, clusterDb) {
|
|||||||
|
|
||||||
if (edge.fromCluster) {
|
if (edge.fromCluster) {
|
||||||
logger.info('edge', edge);
|
logger.info('edge', edge);
|
||||||
logger.info('cluster', clusterDb[edge.toCluster]);
|
logger.info('from cluster', clusterDb[edge.toCluster]);
|
||||||
const updatedPoints = [];
|
const updatedPoints = [];
|
||||||
let lastPointOutside;
|
let lastPointOutside;
|
||||||
let isInside = false;
|
let isInside = false;
|
||||||
@ -157,11 +159,13 @@ export const insertEdge = function(elem, edge, clusterDb) {
|
|||||||
|
|
||||||
// First point inside the rect
|
// First point inside the rect
|
||||||
const insterection = intersection(node, lastPointOutside, point);
|
const insterection = intersection(node, lastPointOutside, point);
|
||||||
logger.info('intersect', inter.rect(node, lastPointOutside));
|
// logger.info('intersect', intersection(node, lastPointOutside, point));
|
||||||
updatedPoints.unshift(insterection);
|
updatedPoints.unshift(insterection);
|
||||||
// points.push(insterection);
|
// points.push(insterection);
|
||||||
isInside = true;
|
isInside = true;
|
||||||
} else {
|
} else {
|
||||||
|
// at the outside
|
||||||
|
logger.info('Outside point', point);
|
||||||
if (!isInside) updatedPoints.unshift(point);
|
if (!isInside) updatedPoints.unshift(point);
|
||||||
}
|
}
|
||||||
lastPointOutside = point;
|
lastPointOutside = point;
|
||||||
@ -169,6 +173,8 @@ export const insertEdge = function(elem, edge, clusterDb) {
|
|||||||
points = updatedPoints;
|
points = updatedPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info('Poibts', points);
|
||||||
|
|
||||||
logger.info('Edge', edge);
|
logger.info('Edge', edge);
|
||||||
|
|
||||||
// The data for our line
|
// The data for our line
|
||||||
|
Loading…
x
Reference in New Issue
Block a user