updated fork Join Shape

This commit is contained in:
omkarht
2024-08-27 14:12:40 +05:30
parent 13719aa694
commit 5e5265c8b0

View File

@@ -1,62 +1,50 @@
import { updateNodeBounds } from './util.js'; import { getNodeClasses, labelHelper, updateNodeBounds } 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 type { SVG } from '$root/diagram-api/types.js'; import type { SVG } from '$root/diagram-api/types.js';
import rough from 'roughjs'; import rough from 'roughjs';
import { solidStateFill } from './handDrawnShapeStyles.js'; import { styles2String, userNodeOverrides } from './handDrawnShapeStyles.js';
import { getConfig } from '$root/diagram-api/diagramAPI.js';
export const forkJoin = (parent: SVG, node: Node, dir: string) => { export const forkJoin = async (parent: SVG, node: Node, dir: string) => {
const { themeVariables } = getConfig(); const { nodeStyles } = styles2String(node);
const { lineColor } = themeVariables; node.label = '';
const shapeSvg = parent const { shapeSvg } = await labelHelper(parent, node, getNodeClasses(node));
.insert('g')
.attr('class', 'node default')
.attr('id', node.domId || node.id);
let width = 70; const { cssStyles } = node;
let height = 10; let width = Math.max(70, node?.width ?? 0);
let height = Math.max(10, node?.height ?? 0);
if (dir === 'LR') { if (dir === 'LR') {
width = 10; width = Math.max(10, node?.width ?? 0);
height = 70; height = Math.max(70, node?.height ?? 0);
} }
const x = (-1 * width) / 2; const x = (-1 * width) / 2;
const y = (-1 * height) / 2; const y = (-1 * height) / 2;
let shape;
if (node.look === 'handDrawn') {
// @ts-ignore TODO: Fix rough typings // @ts-ignore TODO: Fix rough typings
const rc = rough.svg(shapeSvg); const rc = rough.svg(shapeSvg);
const roughNode = rc.rectangle(x, y, width, height, solidStateFill(lineColor)); const options = userNodeOverrides(node, {});
shape = shapeSvg.insert(() => roughNode);
} else { if (node.look !== 'handDrawn') {
shape = shapeSvg options.roughness = 0;
.append('rect') options.fillStyle = 'solid';
.attr('x', x) }
.attr('y', y)
.attr('width', width) const roughNode = rc.rectangle(x, y, width, height, options);
.attr('height', height)
.attr('class', 'fork-join'); const shape = shapeSvg.insert(() => roughNode, ':first-child');
if (cssStyles && node.look !== 'handDrawn') {
shape.selectAll('path').attr('style', cssStyles);
}
if (nodeStyles && node.look !== 'handDrawn') {
shape.selectAll('path').attr('style', nodeStyles);
} }
updateNodeBounds(node, shape); updateNodeBounds(node, shape);
let nodeHeight = 0;
let nodeWidth = 0;
let nodePadding = 10;
if (node.height) {
nodeHeight = node.height;
}
if (node.width) {
nodeWidth = node.width;
}
if (node.padding) {
nodePadding = node.padding;
}
node.height = nodeHeight + nodePadding / 2;
node.width = nodeWidth + nodePadding / 2;
node.intersect = function (point) { node.intersect = function (point) {
return intersect.rect(node, point); return intersect.rect(node, point);
}; };