mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-22 17:56:43 +02:00
Updated insertNode to pass optional config
This commit is contained in:
@@ -33,10 +33,11 @@ export const render = async (
|
|||||||
};
|
};
|
||||||
graph.children.push(child);
|
graph.children.push(child);
|
||||||
nodeDb[node.id] = child;
|
nodeDb[node.id] = child;
|
||||||
|
const config = getConfig();
|
||||||
|
|
||||||
// Add the element to the DOM
|
// Add the element to the DOM
|
||||||
if (!node.isGroup) {
|
if (!node.isGroup) {
|
||||||
const childNodeEl = await insertNode(nodeEl, node, node.dir);
|
const childNodeEl = await insertNode(nodeEl, node, { config });
|
||||||
boundingBox = childNodeEl.node().getBBox();
|
boundingBox = childNodeEl.node().getBBox();
|
||||||
child.domId = childNodeEl;
|
child.domId = childNodeEl;
|
||||||
child.width = boundingBox.width;
|
child.width = boundingBox.width;
|
||||||
@@ -50,7 +51,7 @@ export const render = async (
|
|||||||
// @ts-ignore TODO: fix this
|
// @ts-ignore TODO: fix this
|
||||||
const { shapeSvg, bbox } = await labelHelper(nodeEl, node, undefined, true);
|
const { shapeSvg, bbox } = await labelHelper(nodeEl, node, undefined, true);
|
||||||
labelData.width = bbox.width;
|
labelData.width = bbox.width;
|
||||||
labelData.wrappingWidth = getConfig().flowchart!.wrappingWidth;
|
labelData.wrappingWidth = config.flowchart!.wrappingWidth;
|
||||||
// Give some padding for elk
|
// Give some padding for elk
|
||||||
labelData.height = bbox.height - 2;
|
labelData.height = bbox.height - 2;
|
||||||
labelData.labelNode = shapeSvg.node();
|
labelData.labelNode = shapeSvg.node();
|
||||||
|
@@ -87,7 +87,7 @@ const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, sit
|
|||||||
// insertCluster(clusters, graph.node(v));
|
// insertCluster(clusters, graph.node(v));
|
||||||
} else {
|
} else {
|
||||||
log.info('Node - the non recursive path', v, node.id, node);
|
log.info('Node - the non recursive path', v, node.id, node);
|
||||||
await insertNode(nodes, graph.node(v), dir);
|
await insertNode(nodes, graph.node(v), { config: siteConfig });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@@ -124,7 +124,8 @@ async function calculateBlockSize(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the element to the DOM to size it
|
// Add the element to the DOM to size it
|
||||||
const nodeEl = await insertNode(elem, node);
|
const config = getConfig();
|
||||||
|
const nodeEl = await insertNode(elem, node, { config });
|
||||||
const boundingBox = nodeEl.node().getBBox();
|
const boundingBox = nodeEl.node().getBBox();
|
||||||
const obj = db.getBlock(node.id);
|
const obj = db.getBlock(node.id);
|
||||||
obj.size = { width: boundingBox.width, height: boundingBox.height, x: 0, y: 0, node: nodeEl };
|
obj.size = { width: boundingBox.width, height: boundingBox.height, x: 0, y: 0, node: nodeEl };
|
||||||
@@ -138,7 +139,8 @@ export async function insertBlockPositioned(elem: any, block: Block, db: any) {
|
|||||||
// Add the element to the DOM to size it
|
// Add the element to the DOM to size it
|
||||||
const obj = db.getBlock(node.id);
|
const obj = db.getBlock(node.id);
|
||||||
if (obj.type !== 'space') {
|
if (obj.type !== 'space') {
|
||||||
await insertNode(elem, node);
|
const config = getConfig();
|
||||||
|
await insertNode(elem, node, { config });
|
||||||
block.intersect = node?.intersect;
|
block.intersect = node?.intersect;
|
||||||
positionNode(node);
|
positionNode(node);
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { select } from 'd3';
|
import { select } from 'd3';
|
||||||
import { insertNode } from '../dagre-wrapper/nodes.js';
|
import { insertNode } from '../dagre-wrapper/nodes.js';
|
||||||
|
import { getConfig } from '../diagram-api/diagramAPI.js';
|
||||||
|
|
||||||
export const getDiagramElement = (id, securityLevel) => {
|
export const getDiagramElement = (id, securityLevel) => {
|
||||||
let sandboxElement;
|
let sandboxElement;
|
||||||
@@ -22,20 +23,25 @@ export function insertElementsForSize(el, data) {
|
|||||||
const nodesElem = el.insert('g').attr('class', 'nodes');
|
const nodesElem = el.insert('g').attr('class', 'nodes');
|
||||||
el.insert('g').attr('class', 'edges');
|
el.insert('g').attr('class', 'edges');
|
||||||
data.nodes.forEach(async (item) => {
|
data.nodes.forEach(async (item) => {
|
||||||
|
const config = getConfig();
|
||||||
item.shape = 'rect';
|
item.shape = 'rect';
|
||||||
await insertNode(nodesElem, {
|
await insertNode(
|
||||||
...item,
|
nodesElem,
|
||||||
class: 'default flowchart-label',
|
{
|
||||||
labelStyle: '',
|
...item,
|
||||||
x: 0,
|
class: 'default flowchart-label',
|
||||||
y: 0,
|
labelStyle: '',
|
||||||
width: 100,
|
x: 0,
|
||||||
rx: 0,
|
y: 0,
|
||||||
ry: 0,
|
width: 100,
|
||||||
height: 100,
|
rx: 0,
|
||||||
shape: 'rect',
|
ry: 0,
|
||||||
padding: 8,
|
height: 100,
|
||||||
});
|
shape: 'rect',
|
||||||
|
padding: 8,
|
||||||
|
},
|
||||||
|
{ config }
|
||||||
|
);
|
||||||
// Create a new DOM element
|
// Create a new DOM element
|
||||||
// const element = document.createElement('div');
|
// const element = document.createElement('div');
|
||||||
|
|
||||||
|
@@ -125,7 +125,7 @@ const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, sit
|
|||||||
// insertCluster(clusters, graph.node(v));
|
// insertCluster(clusters, graph.node(v));
|
||||||
} else {
|
} else {
|
||||||
log.trace('Node - the non recursive path XAX', v, nodes, graph.node(v), dir);
|
log.trace('Node - the non recursive path XAX', v, nodes, graph.node(v), dir);
|
||||||
await insertNode(nodes, graph.node(v), dir);
|
await insertNode(nodes, graph.node(v), { config: siteConfig });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@@ -9,7 +9,6 @@ import { choice } from './shapes/choice.ts';
|
|||||||
import { note } from './shapes/note.ts';
|
import { note } from './shapes/note.ts';
|
||||||
import { stadium } from './shapes/stadium.js';
|
import { stadium } from './shapes/stadium.js';
|
||||||
import { rectWithTitle } from './shapes/rectWithTitle.js';
|
import { rectWithTitle } from './shapes/rectWithTitle.js';
|
||||||
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
|
||||||
import { subroutine } from './shapes/subroutine.js';
|
import { subroutine } from './shapes/subroutine.js';
|
||||||
import { cylinder } from './shapes/cylinder.js';
|
import { cylinder } from './shapes/cylinder.js';
|
||||||
import { circle } from './shapes/circle.js';
|
import { circle } from './shapes/circle.js';
|
||||||
@@ -229,7 +228,7 @@ export const shapes = {
|
|||||||
|
|
||||||
const nodeElems = new Map();
|
const nodeElems = new Map();
|
||||||
|
|
||||||
export const insertNode = async (elem, node, dir) => {
|
export const insertNode = async (elem, node, config) => {
|
||||||
let newEl;
|
let newEl;
|
||||||
let el;
|
let el;
|
||||||
|
|
||||||
@@ -247,15 +246,15 @@ export const insertNode = async (elem, node, dir) => {
|
|||||||
// Add link when appropriate
|
// Add link when appropriate
|
||||||
if (node.link) {
|
if (node.link) {
|
||||||
let target;
|
let target;
|
||||||
if (getConfig().securityLevel === 'sandbox') {
|
if (config.securityLevel === 'sandbox') {
|
||||||
target = '_top';
|
target = '_top';
|
||||||
} else if (node.linkTarget) {
|
} else if (node.linkTarget) {
|
||||||
target = node.linkTarget || '_blank';
|
target = node.linkTarget || '_blank';
|
||||||
}
|
}
|
||||||
newEl = elem.insert('svg:a').attr('xlink:href', node.link).attr('target', target);
|
newEl = elem.insert('svg:a').attr('xlink:href', node.link).attr('target', target);
|
||||||
el = await shapes[node.shape](newEl, node, dir);
|
el = await shapes[node.shape](newEl, node, config);
|
||||||
} else {
|
} else {
|
||||||
el = await shapes[node.shape](elem, node, dir);
|
el = await shapes[node.shape](elem, node, config);
|
||||||
newEl = el;
|
newEl = el;
|
||||||
}
|
}
|
||||||
if (node.tooltip) {
|
if (node.tooltip) {
|
||||||
|
@@ -5,9 +5,13 @@ import type { SVG } from '../../../diagram-api/types.js';
|
|||||||
import { styles2String, userNodeOverrides } from './handDrawnShapeStyles.js';
|
import { styles2String, userNodeOverrides } from './handDrawnShapeStyles.js';
|
||||||
import rough from 'roughjs';
|
import rough from 'roughjs';
|
||||||
import intersect from '../intersect/index.js';
|
import intersect from '../intersect/index.js';
|
||||||
import { getConfig } from '../../../config.js';
|
import type { MermaidConfig } from '../../../config.type.js';
|
||||||
|
|
||||||
export const filledCircle = (parent: SVG, node: Node) => {
|
export const filledCircle = (
|
||||||
|
parent: SVG,
|
||||||
|
node: Node,
|
||||||
|
{ config: { themeVariables } }: { config: MermaidConfig }
|
||||||
|
) => {
|
||||||
const { labelStyles, nodeStyles } = styles2String(node);
|
const { labelStyles, nodeStyles } = styles2String(node);
|
||||||
node.label = '';
|
node.label = '';
|
||||||
node.labelStyle = labelStyles;
|
node.labelStyle = labelStyles;
|
||||||
@@ -20,7 +24,6 @@ export const filledCircle = (parent: SVG, node: Node) => {
|
|||||||
|
|
||||||
// @ts-ignore - rough is not typed
|
// @ts-ignore - rough is not typed
|
||||||
const rc = rough.svg(shapeSvg);
|
const rc = rough.svg(shapeSvg);
|
||||||
const { themeVariables } = getConfig();
|
|
||||||
const { nodeBorder } = themeVariables;
|
const { nodeBorder } = themeVariables;
|
||||||
const options = userNodeOverrides(node, { fillStyle: 'solid' });
|
const options = userNodeOverrides(node, { fillStyle: 'solid' });
|
||||||
|
|
||||||
|
@@ -6,16 +6,21 @@ import { compileStyles, styles2String, userNodeOverrides } from './handDrawnShap
|
|||||||
import rough from 'roughjs';
|
import rough from 'roughjs';
|
||||||
import intersect from '../intersect/index.js';
|
import intersect from '../intersect/index.js';
|
||||||
import { getIconSVG } from '../../icons.js';
|
import { getIconSVG } from '../../icons.js';
|
||||||
import { getConfig } from '../../../diagram-api/diagramAPI.js';
|
import type { MermaidConfig } from '../../../config.type.js';
|
||||||
|
|
||||||
export const iconCircle = async (parent: SVG, node: Node, dir: string) => {
|
export const iconCircle = async (
|
||||||
const translateHorizontal = dir === 'TB' || dir === 'BT' || dir === 'TD' || dir === 'DT';
|
parent: SVG,
|
||||||
|
node: Node,
|
||||||
|
{ config: { themeVariables, flowchart } }: { config: MermaidConfig }
|
||||||
|
) => {
|
||||||
|
const translateHorizontal =
|
||||||
|
node.dir === 'TB' || node.dir === 'BT' || node.dir === 'TD' || node.dir === 'DT';
|
||||||
const { labelStyles, nodeStyles } = styles2String(node);
|
const { labelStyles, nodeStyles } = styles2String(node);
|
||||||
node.labelStyle = labelStyles;
|
node.labelStyle = labelStyles;
|
||||||
const assetHeight = node.assetHeight ?? 48;
|
const assetHeight = node.assetHeight ?? 48;
|
||||||
const assetWidth = node.assetWidth ?? 48;
|
const assetWidth = node.assetWidth ?? 48;
|
||||||
const iconSize = Math.max(assetHeight, assetWidth);
|
const iconSize = Math.max(assetHeight, assetWidth);
|
||||||
const defaultWidth = getConfig()?.flowchart?.wrappingWidth;
|
const defaultWidth = flowchart?.wrappingWidth;
|
||||||
node.width = Math.max(iconSize, defaultWidth ?? 0);
|
node.width = Math.max(iconSize, defaultWidth ?? 0);
|
||||||
const { shapeSvg, bbox, halfPadding, label } = await labelHelper(
|
const { shapeSvg, bbox, halfPadding, label } = await labelHelper(
|
||||||
parent,
|
parent,
|
||||||
@@ -27,7 +32,6 @@ export const iconCircle = async (parent: SVG, node: Node, dir: string) => {
|
|||||||
const topLabel = node.pos === 't';
|
const topLabel = node.pos === 't';
|
||||||
|
|
||||||
const diameter = iconSize + halfPadding * 2;
|
const diameter = iconSize + halfPadding * 2;
|
||||||
const { themeVariables } = getConfig();
|
|
||||||
const { mainBkg } = themeVariables;
|
const { mainBkg } = themeVariables;
|
||||||
const { stylesMap } = compileStyles(node);
|
const { stylesMap } = compileStyles(node);
|
||||||
|
|
||||||
|
@@ -6,16 +6,20 @@ import { compileStyles, styles2String, userNodeOverrides } from './handDrawnShap
|
|||||||
import rough from 'roughjs';
|
import rough from 'roughjs';
|
||||||
import intersect from '../intersect/index.js';
|
import intersect from '../intersect/index.js';
|
||||||
import { getIconSVG } from '../../icons.js';
|
import { getIconSVG } from '../../icons.js';
|
||||||
import { getConfig } from '../../../diagram-api/diagramAPI.js';
|
|
||||||
import { createRoundedRectPathD } from './roundedRectPath.js';
|
import { createRoundedRectPathD } from './roundedRectPath.js';
|
||||||
|
import type { MermaidConfig } from '../../../config.type.js';
|
||||||
|
|
||||||
export const iconRounded = async (parent: SVG, node: Node) => {
|
export const iconRounded = async (
|
||||||
|
parent: SVG,
|
||||||
|
node: Node,
|
||||||
|
{ config: { themeVariables, flowchart } }: { config: MermaidConfig }
|
||||||
|
) => {
|
||||||
const { labelStyles, nodeStyles } = styles2String(node);
|
const { labelStyles, nodeStyles } = styles2String(node);
|
||||||
node.labelStyle = labelStyles;
|
node.labelStyle = labelStyles;
|
||||||
const assetHeight = node.assetHeight ?? 48;
|
const assetHeight = node.assetHeight ?? 48;
|
||||||
const assetWidth = node.assetWidth ?? 48;
|
const assetWidth = node.assetWidth ?? 48;
|
||||||
const iconSize = Math.max(assetHeight, assetWidth);
|
const iconSize = Math.max(assetHeight, assetWidth);
|
||||||
const defaultWidth = getConfig()?.flowchart?.wrappingWidth;
|
const defaultWidth = flowchart?.wrappingWidth;
|
||||||
node.width = Math.max(iconSize, defaultWidth ?? 0);
|
node.width = Math.max(iconSize, defaultWidth ?? 0);
|
||||||
const { shapeSvg, bbox, halfPadding, label } = await labelHelper(
|
const { shapeSvg, bbox, halfPadding, label } = await labelHelper(
|
||||||
parent,
|
parent,
|
||||||
@@ -28,7 +32,6 @@ export const iconRounded = async (parent: SVG, node: Node) => {
|
|||||||
|
|
||||||
const height = iconSize + halfPadding * 2;
|
const height = iconSize + halfPadding * 2;
|
||||||
const width = iconSize + halfPadding * 2;
|
const width = iconSize + halfPadding * 2;
|
||||||
const { themeVariables } = getConfig();
|
|
||||||
const { mainBkg } = themeVariables;
|
const { mainBkg } = themeVariables;
|
||||||
const { stylesMap } = compileStyles(node);
|
const { stylesMap } = compileStyles(node);
|
||||||
|
|
||||||
@@ -58,7 +61,7 @@ export const iconRounded = async (parent: SVG, node: Node) => {
|
|||||||
const iconHeight = iconBBox.height;
|
const iconHeight = iconBBox.height;
|
||||||
iconElem.attr(
|
iconElem.attr(
|
||||||
'transform',
|
'transform',
|
||||||
`translate(${-iconWidth / 2},${topLabel ? height / 2 - iconHeight + bbox.height / 2 : -height / 2 - bbox.height / 2})`
|
`translate(${-iconWidth / 2},${topLabel ? height / 2 - iconHeight - halfPadding + bbox.height / 2 : -height / 2 + halfPadding - bbox.height / 2})`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,15 +6,19 @@ import { compileStyles, styles2String, userNodeOverrides } from './handDrawnShap
|
|||||||
import rough from 'roughjs';
|
import rough from 'roughjs';
|
||||||
import intersect from '../intersect/index.js';
|
import intersect from '../intersect/index.js';
|
||||||
import { getIconSVG } from '../../icons.js';
|
import { getIconSVG } from '../../icons.js';
|
||||||
import { getConfig } from '../../../diagram-api/diagramAPI.js';
|
import type { MermaidConfig } from '../../../config.type.js';
|
||||||
|
|
||||||
export const iconSquare = async (parent: SVG, node: Node) => {
|
export const iconSquare = async (
|
||||||
|
parent: SVG,
|
||||||
|
node: Node,
|
||||||
|
{ config: { themeVariables, flowchart } }: { config: MermaidConfig }
|
||||||
|
) => {
|
||||||
const { labelStyles, nodeStyles } = styles2String(node);
|
const { labelStyles, nodeStyles } = styles2String(node);
|
||||||
node.labelStyle = labelStyles;
|
node.labelStyle = labelStyles;
|
||||||
const assetHeight = node.assetHeight ?? 48;
|
const assetHeight = node.assetHeight ?? 48;
|
||||||
const assetWidth = node.assetWidth ?? 48;
|
const assetWidth = node.assetWidth ?? 48;
|
||||||
const iconSize = Math.max(assetHeight, assetWidth);
|
const iconSize = Math.max(assetHeight, assetWidth);
|
||||||
const defaultWidth = getConfig()?.flowchart?.wrappingWidth;
|
const defaultWidth = flowchart?.wrappingWidth;
|
||||||
node.width = Math.max(iconSize, defaultWidth ?? 0);
|
node.width = Math.max(iconSize, defaultWidth ?? 0);
|
||||||
const { shapeSvg, bbox, halfPadding, label } = await labelHelper(
|
const { shapeSvg, bbox, halfPadding, label } = await labelHelper(
|
||||||
parent,
|
parent,
|
||||||
@@ -27,7 +31,6 @@ export const iconSquare = async (parent: SVG, node: Node) => {
|
|||||||
|
|
||||||
const height = iconSize + halfPadding * 2;
|
const height = iconSize + halfPadding * 2;
|
||||||
const width = iconSize + halfPadding * 2;
|
const width = iconSize + halfPadding * 2;
|
||||||
const { themeVariables } = getConfig();
|
|
||||||
const { mainBkg } = themeVariables;
|
const { mainBkg } = themeVariables;
|
||||||
const { stylesMap } = compileStyles(node);
|
const { stylesMap } = compileStyles(node);
|
||||||
|
|
||||||
|
@@ -4,13 +4,16 @@ import type { Node } from '../../types.js';
|
|||||||
import type { SVG } from '../../../diagram-api/types.js';
|
import type { SVG } from '../../../diagram-api/types.js';
|
||||||
import rough from 'roughjs';
|
import rough from 'roughjs';
|
||||||
import { solidStateFill, styles2String, userNodeOverrides } from './handDrawnShapeStyles.js';
|
import { solidStateFill, styles2String, userNodeOverrides } from './handDrawnShapeStyles.js';
|
||||||
import { getConfig } from '../../../diagram-api/diagramAPI.js';
|
import type { MermaidConfig } from '../../../config.type.js';
|
||||||
|
|
||||||
export const stateEnd = (parent: SVG, node: Node) => {
|
export const stateEnd = (
|
||||||
|
parent: SVG,
|
||||||
|
node: Node,
|
||||||
|
{ config: { themeVariables } }: { config: MermaidConfig }
|
||||||
|
) => {
|
||||||
const { labelStyles, nodeStyles } = styles2String(node);
|
const { labelStyles, nodeStyles } = styles2String(node);
|
||||||
node.labelStyle = labelStyles;
|
node.labelStyle = labelStyles;
|
||||||
const { cssStyles } = node;
|
const { cssStyles } = node;
|
||||||
const { themeVariables } = getConfig();
|
|
||||||
const { lineColor } = themeVariables;
|
const { lineColor } = themeVariables;
|
||||||
const shapeSvg = parent
|
const shapeSvg = parent
|
||||||
.insert('g')
|
.insert('g')
|
||||||
|
@@ -4,10 +4,13 @@ import type { Node } from '../../types.js';
|
|||||||
import type { SVG } from '../../../diagram-api/types.js';
|
import type { SVG } from '../../../diagram-api/types.js';
|
||||||
import rough from 'roughjs';
|
import rough from 'roughjs';
|
||||||
import { solidStateFill } from './handDrawnShapeStyles.js';
|
import { solidStateFill } from './handDrawnShapeStyles.js';
|
||||||
import { getConfig } from '../../../diagram-api/diagramAPI.js';
|
import type { MermaidConfig } from '../../../config.type.js';
|
||||||
|
|
||||||
export const stateStart = (parent: SVG, node: Node) => {
|
export const stateStart = (
|
||||||
const { themeVariables } = getConfig();
|
parent: SVG,
|
||||||
|
node: Node,
|
||||||
|
{ config: { themeVariables } }: { config: MermaidConfig }
|
||||||
|
) => {
|
||||||
const { lineColor } = themeVariables;
|
const { lineColor } = themeVariables;
|
||||||
|
|
||||||
const shapeSvg = parent
|
const shapeSvg = parent
|
||||||
|
Reference in New Issue
Block a user