mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-02-04 07:13:25 +08:00
updated odd shape
This commit is contained in:
parent
13719aa694
commit
3715254a78
@ -1,4 +1,4 @@
|
|||||||
import { labelHelper, updateNodeBounds, getNodeClasses } from './util.js';
|
import { labelHelper, updateNodeBounds, getNodeClasses, createPathFromPoints } from './util.js';
|
||||||
import intersect from '../intersect/index.js';
|
import intersect from '../intersect/index.js';
|
||||||
import type { Node } from '$root/rendering-util/types.d.ts';
|
import type { Node } from '$root/rendering-util/types.d.ts';
|
||||||
import {
|
import {
|
||||||
@ -6,18 +6,6 @@ import {
|
|||||||
userNodeOverrides,
|
userNodeOverrides,
|
||||||
} from '$root/rendering-util/rendering-elements/shapes/handDrawnShapeStyles.js';
|
} from '$root/rendering-util/rendering-elements/shapes/handDrawnShapeStyles.js';
|
||||||
import rough from 'roughjs';
|
import rough from 'roughjs';
|
||||||
import { insertPolygonShape } from './insertPolygonShape.js';
|
|
||||||
|
|
||||||
export const createPolygonPathD = (x: number, y: number, width: number, height: number): string => {
|
|
||||||
return [
|
|
||||||
`M${x - height / 2},${y}`,
|
|
||||||
`L${x + width},${y}`,
|
|
||||||
`L${x + width},${y - height}`,
|
|
||||||
`L${x - height / 2},${y - height}`,
|
|
||||||
`L${x},${y - height / 2}`,
|
|
||||||
'Z',
|
|
||||||
].join(' ');
|
|
||||||
};
|
|
||||||
|
|
||||||
export const rect_left_inv_arrow = async (
|
export const rect_left_inv_arrow = async (
|
||||||
parent: SVGAElement,
|
parent: SVGAElement,
|
||||||
@ -25,44 +13,50 @@ export const rect_left_inv_arrow = async (
|
|||||||
): Promise<SVGAElement> => {
|
): Promise<SVGAElement> => {
|
||||||
const { labelStyles, nodeStyles } = styles2String(node);
|
const { labelStyles, nodeStyles } = styles2String(node);
|
||||||
node.labelStyle = labelStyles;
|
node.labelStyle = labelStyles;
|
||||||
const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
|
const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(node));
|
||||||
|
|
||||||
const w = bbox.width + node.padding;
|
const w = bbox.width + node.padding;
|
||||||
const h = bbox.height + node.padding;
|
const h = bbox.height + node.padding;
|
||||||
|
|
||||||
|
const x = -w / 2;
|
||||||
|
const y = -h / 2;
|
||||||
|
const notch = y / 2;
|
||||||
|
|
||||||
const points = [
|
const points = [
|
||||||
{ x: -h / 2, y: 0 },
|
{ x: x + notch, y },
|
||||||
{ x: w, y: 0 },
|
{ x: x, y: 0 },
|
||||||
{ x: w, y: -h },
|
{ x: x + notch, y: -y },
|
||||||
{ x: -h / 2, y: -h },
|
{ x: -x, y: -y },
|
||||||
{ x: 0, y: -h / 2 },
|
{ x: -x, y },
|
||||||
];
|
];
|
||||||
|
|
||||||
let polygon;
|
|
||||||
const { cssStyles } = node;
|
const { cssStyles } = node;
|
||||||
|
// @ts-ignore - rough is not typed
|
||||||
|
const rc = rough.svg(shapeSvg);
|
||||||
|
const options = userNodeOverrides(node, {});
|
||||||
|
|
||||||
if (node.look === 'handDrawn') {
|
if (node.look !== 'handDrawn') {
|
||||||
// @ts-ignore - rough is not typed
|
options.roughness = 0;
|
||||||
const rc = rough.svg(shapeSvg);
|
options.fillStyle = 'solid';
|
||||||
const options = userNodeOverrides(node, {});
|
|
||||||
const pathData = createPolygonPathD(0, 0, w, h);
|
|
||||||
const roughNode = rc.path(pathData, options);
|
|
||||||
|
|
||||||
polygon = shapeSvg
|
|
||||||
.insert(() => roughNode, ':first-child')
|
|
||||||
.attr('transform', `translate(${-w / 2}, ${h / 2})`);
|
|
||||||
if (cssStyles) {
|
|
||||||
polygon.attr('style', cssStyles);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
polygon = insertPolygonShape(shapeSvg, w, h, points);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pathData = createPathFromPoints(points);
|
||||||
|
const roughNode = rc.path(pathData, options);
|
||||||
|
|
||||||
|
const polygon = shapeSvg.insert(() => roughNode, ':first-child');
|
||||||
|
|
||||||
|
if (cssStyles) {
|
||||||
|
polygon.attr('style', cssStyles);
|
||||||
|
}
|
||||||
if (nodeStyles) {
|
if (nodeStyles) {
|
||||||
polygon.attr('style', nodeStyles);
|
polygon.attr('style', nodeStyles);
|
||||||
}
|
}
|
||||||
node.width = w + h;
|
|
||||||
node.height = h;
|
|
||||||
|
|
||||||
|
polygon.attr('transform', `translate(${-notch / 2},0)`);
|
||||||
|
label.attr(
|
||||||
|
'transform',
|
||||||
|
`translate(${-w / 2 + -notch / 2 + (node.padding ?? 0) / 2},${-h / 2 + (node.padding ?? 0) / 2})`
|
||||||
|
);
|
||||||
updateNodeBounds(node, polygon);
|
updateNodeBounds(node, polygon);
|
||||||
|
|
||||||
node.intersect = function (point) {
|
node.intersect = function (point) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user