mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-26 08:24:07 +01:00
adjusted intersection points for half rounded rectangle shape
This commit is contained in:
@@ -39,6 +39,8 @@ export const halfRoundedRectangle = async (parent: SVGAElement, node: Node) => {
|
|||||||
const w = (bbox.width + node.padding) * 1.2;
|
const w = (bbox.width + node.padding) * 1.2;
|
||||||
const h = bbox.height + node.padding;
|
const h = bbox.height + node.padding;
|
||||||
const radius = h / 2;
|
const radius = h / 2;
|
||||||
|
const rx = radius;
|
||||||
|
const ry = radius;
|
||||||
const { cssStyles } = node;
|
const { cssStyles } = node;
|
||||||
|
|
||||||
// @ts-ignore - rough is not typed
|
// @ts-ignore - rough is not typed
|
||||||
@@ -72,6 +74,24 @@ export const halfRoundedRectangle = async (parent: SVGAElement, node: Node) => {
|
|||||||
node.intersect = function (point) {
|
node.intersect = function (point) {
|
||||||
log.info('Pill intersect', node, { radius, point });
|
log.info('Pill intersect', node, { radius, point });
|
||||||
const pos = intersect.rect(node, point);
|
const pos = intersect.rect(node, point);
|
||||||
|
const y = pos.y - (node.y ?? 0);
|
||||||
|
if (
|
||||||
|
ry != 0 &&
|
||||||
|
(Math.abs(y) < (node.height ?? 0) / 2 ||
|
||||||
|
(Math.abs(y) == (node.height ?? 0) / 2 &&
|
||||||
|
Math.abs(pos.x - (node.x ?? 0)) > (node.width ?? 0) / 2 - rx))
|
||||||
|
) {
|
||||||
|
let x = rx * rx * (1 - (y * y) / (ry * ry));
|
||||||
|
if (x != 0) {
|
||||||
|
x = Math.sqrt(x);
|
||||||
|
}
|
||||||
|
x = rx - x;
|
||||||
|
if (point.x - (node.x ?? 0) > 0) {
|
||||||
|
x = -x;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos.x += x;
|
||||||
|
}
|
||||||
return pos;
|
return pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user