mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-09 18:39:41 +02:00
Added windowPane
This commit is contained in:
@@ -10,10 +10,16 @@ const newShapesSet1 = [
|
|||||||
'flippedTriangle',
|
'flippedTriangle',
|
||||||
'hourglass',
|
'hourglass',
|
||||||
] as const;
|
] as const;
|
||||||
const newShapesSet2 = ['taggedRect', 'multiRect', 'lightningBolt', 'filledCircle'] as const;
|
const newShapesSet2 = [
|
||||||
|
'taggedRect',
|
||||||
|
'multiRect',
|
||||||
|
'lightningBolt',
|
||||||
|
'filledCircle',
|
||||||
|
'windowPane',
|
||||||
|
] as const;
|
||||||
|
|
||||||
// Aggregate all shape sets into a single array
|
// Aggregate all shape sets into a single array
|
||||||
const newShapesSets = [newShapesSet1, newShapesSet2] as const;
|
const newShapesSets = [['windowPane']] as const;
|
||||||
|
|
||||||
looks.forEach((look) => {
|
looks.forEach((look) => {
|
||||||
directions.forEach((direction) => {
|
directions.forEach((direction) => {
|
||||||
@@ -59,7 +65,7 @@ looks.forEach((look) => {
|
|||||||
imgSnapshotTest(flowchartCode, { look, htmlLabels: false });
|
imgSnapshotTest(flowchartCode, { look, htmlLabels: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip(`with styles`, () => {
|
it(`with styles`, () => {
|
||||||
let flowchartCode = `flowchart ${direction}\n`;
|
let flowchartCode = `flowchart ${direction}\n`;
|
||||||
newShapesSet.forEach((newShape, index) => {
|
newShapesSet.forEach((newShape, index) => {
|
||||||
flowchartCode += ` n${index} --> n${index}${index}@{ shape: ${newShape}, label: 'new shape' }@\n`;
|
flowchartCode += ` n${index} --> n${index}${index}@{ shape: ${newShape}, label: 'new shape' }@\n`;
|
||||||
|
@@ -45,6 +45,7 @@ import { waveEdgedRectangle } from './shapes/waveEdgedRectangle.js';
|
|||||||
import { lightningBolt } from './shapes/lightningBolt.js';
|
import { lightningBolt } from './shapes/lightningBolt.js';
|
||||||
import { filledCircle } from './shapes/filledCircle.js';
|
import { filledCircle } from './shapes/filledCircle.js';
|
||||||
import { multiWaveEdgedRectangle } from './shapes/multiWaveEdgedRectangle.js';
|
import { multiWaveEdgedRectangle } from './shapes/multiWaveEdgedRectangle.js';
|
||||||
|
import { windowPane } from './shapes/windowPane.js';
|
||||||
|
|
||||||
const shapes = {
|
const shapes = {
|
||||||
state,
|
state,
|
||||||
@@ -93,6 +94,7 @@ const shapes = {
|
|||||||
lightningBolt,
|
lightningBolt,
|
||||||
filledCircle,
|
filledCircle,
|
||||||
multiWaveEdgedRectangle,
|
multiWaveEdgedRectangle,
|
||||||
|
windowPane,
|
||||||
};
|
};
|
||||||
|
|
||||||
const nodeElems = new Map();
|
const nodeElems = new Map();
|
||||||
|
@@ -0,0 +1,83 @@
|
|||||||
|
import { labelHelper, getNodeClasses, updateNodeBounds, createPathFromPoints } from './util.js';
|
||||||
|
import type { Node } from '$root/rendering-util/types.d.ts';
|
||||||
|
import {
|
||||||
|
styles2String,
|
||||||
|
userNodeOverrides,
|
||||||
|
} from '$root/rendering-util/rendering-elements/shapes/handDrawnShapeStyles.js';
|
||||||
|
import rough from 'roughjs';
|
||||||
|
import intersect from '../intersect/index.js';
|
||||||
|
|
||||||
|
export const windowPane = async (parent: SVGAElement, node: Node) => {
|
||||||
|
const { labelStyles, nodeStyles } = styles2String(node);
|
||||||
|
node.labelStyle = labelStyles;
|
||||||
|
const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(node));
|
||||||
|
const w = Math.max(bbox.width + (node.padding ?? 0) * 2, node?.width ?? 0);
|
||||||
|
const h = Math.max(bbox.height + (node.padding ?? 0) * 2, node?.height ?? 0);
|
||||||
|
const rectOffset = 5;
|
||||||
|
const x = -w / 2;
|
||||||
|
const y = -h / 2;
|
||||||
|
const { cssStyles } = node;
|
||||||
|
|
||||||
|
// @ts-ignore - rough is not typed
|
||||||
|
const rc = rough.svg(shapeSvg);
|
||||||
|
const options = userNodeOverrides(node, {});
|
||||||
|
|
||||||
|
const outerPathPoints = [
|
||||||
|
{ x: x - rectOffset, y: y - rectOffset },
|
||||||
|
{ x: x - rectOffset, y: y + h },
|
||||||
|
{ x: x + w, y: y + h },
|
||||||
|
{ x: x + w, y: y - rectOffset },
|
||||||
|
];
|
||||||
|
|
||||||
|
const innerPathPoints = [
|
||||||
|
{ x: x - rectOffset, y },
|
||||||
|
{ x: x + w, y },
|
||||||
|
];
|
||||||
|
|
||||||
|
const innerSecondPathPoints = [
|
||||||
|
{ x, y: y - rectOffset },
|
||||||
|
{ x, y: y + h },
|
||||||
|
];
|
||||||
|
|
||||||
|
if (node.look !== 'handdrawn') {
|
||||||
|
options.roughness = 0;
|
||||||
|
options.fillStyle = 'solid';
|
||||||
|
}
|
||||||
|
|
||||||
|
const outerPath = createPathFromPoints(outerPathPoints);
|
||||||
|
const outerNode = rc.path(outerPath, options);
|
||||||
|
const innerPath = createPathFromPoints(innerPathPoints);
|
||||||
|
const innerNode = rc.path(innerPath, options);
|
||||||
|
const innerSecondPath = createPathFromPoints(innerSecondPathPoints);
|
||||||
|
const innerSecondNode = rc.path(innerSecondPath, options);
|
||||||
|
|
||||||
|
const taggedRect = shapeSvg.insert('g', ':first-child');
|
||||||
|
taggedRect.insert(() => innerNode, ':first-child');
|
||||||
|
taggedRect.insert(() => innerSecondNode, ':first-child');
|
||||||
|
taggedRect.insert(() => outerNode, ':first-child');
|
||||||
|
taggedRect.attr('transform', `translate(${rectOffset / 2}, ${rectOffset / 2})`);
|
||||||
|
|
||||||
|
taggedRect.attr('class', 'basic label-container');
|
||||||
|
|
||||||
|
if (cssStyles) {
|
||||||
|
taggedRect.attr('style', cssStyles);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nodeStyles) {
|
||||||
|
taggedRect.attr('style', nodeStyles);
|
||||||
|
}
|
||||||
|
|
||||||
|
label.attr(
|
||||||
|
'transform',
|
||||||
|
`translate(${-(bbox.width / 2) + rectOffset / 2}, ${-(bbox.height / 2) + rectOffset / 2})`
|
||||||
|
);
|
||||||
|
|
||||||
|
updateNodeBounds(node, taggedRect);
|
||||||
|
|
||||||
|
node.intersect = function (point) {
|
||||||
|
const pos = intersect.polygon(node, outerPathPoints, point);
|
||||||
|
return pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
return shapeSvg;
|
||||||
|
};
|
Reference in New Issue
Block a user