mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 00:40:22 +02:00
fix: Remove repeated config calls
This commit is contained in:
@@ -124,7 +124,7 @@ export const setConfig = (conf: MermaidConfig): MermaidConfig => {
|
|||||||
* | --------- | ------------------------- | ----------- | ------------------------------ |
|
* | --------- | ------------------------- | ----------- | ------------------------------ |
|
||||||
* | getConfig | Obtains the currentConfig | Get Request | Any Values from current Config |
|
* | getConfig | Obtains the currentConfig | Get Request | Any Values from current Config |
|
||||||
*
|
*
|
||||||
* **Notes**: Returns **any** the currentConfig
|
* **Notes**: Avoid calling this function repeatedly. Instead, store the result in a variable and use it, and pass it down to function calls.
|
||||||
*
|
*
|
||||||
* @returns The currentConfig
|
* @returns The currentConfig
|
||||||
*/
|
*/
|
||||||
|
@@ -30,7 +30,7 @@ const rect = (parent, node) => {
|
|||||||
// .appendChild(createLabel(node.labelText, node.labelStyle, undefined, true));
|
// .appendChild(createLabel(node.labelText, node.labelStyle, undefined, true));
|
||||||
const text =
|
const text =
|
||||||
node.labelType === 'markdown'
|
node.labelType === 'markdown'
|
||||||
? createText(label, node.labelText, { style: node.labelStyle, useHtmlLabels })
|
? createText(label, node.labelText, { style: node.labelStyle, useHtmlLabels }, siteConfig)
|
||||||
: label.node().appendChild(createLabel(node.labelText, node.labelStyle, undefined, true));
|
: label.node().appendChild(createLabel(node.labelText, node.labelStyle, undefined, true));
|
||||||
|
|
||||||
// Get the size of the label
|
// Get the size of the label
|
||||||
|
@@ -18,15 +18,21 @@ export const clear = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const insertEdgeLabel = (elem, edge) => {
|
export const insertEdgeLabel = (elem, edge) => {
|
||||||
const useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
|
const config = getConfig();
|
||||||
|
const useHtmlLabels = evaluate(config.flowchart.htmlLabels);
|
||||||
// Create the actual text element
|
// Create the actual text element
|
||||||
const labelElement =
|
const labelElement =
|
||||||
edge.labelType === 'markdown'
|
edge.labelType === 'markdown'
|
||||||
? createText(elem, edge.label, {
|
? createText(
|
||||||
style: edge.labelStyle,
|
elem,
|
||||||
useHtmlLabels,
|
edge.label,
|
||||||
addSvgBackground: true,
|
{
|
||||||
})
|
style: edge.labelStyle,
|
||||||
|
useHtmlLabels,
|
||||||
|
addSvgBackground: true,
|
||||||
|
},
|
||||||
|
config
|
||||||
|
)
|
||||||
: createLabel(edge.label, edge.labelStyle);
|
: createLabel(edge.label, edge.labelStyle);
|
||||||
|
|
||||||
// Create outer g, edgeLabel, this will be positioned after graph layout
|
// Create outer g, edgeLabel, this will be positioned after graph layout
|
||||||
|
@@ -6,8 +6,9 @@ import { evaluate, sanitizeText } from '../../diagrams/common/common.js';
|
|||||||
import { decodeEntities } from '../../utils.js';
|
import { decodeEntities } from '../../utils.js';
|
||||||
|
|
||||||
export const labelHelper = async (parent, node, _classes, isNode) => {
|
export const labelHelper = async (parent, node, _classes, isNode) => {
|
||||||
|
const config = getConfig();
|
||||||
let classes;
|
let classes;
|
||||||
const useHtmlLabels = node.useHtmlLabels || evaluate(getConfig().flowchart.htmlLabels);
|
const useHtmlLabels = node.useHtmlLabels || evaluate(config.flowchart.htmlLabels);
|
||||||
if (!_classes) {
|
if (!_classes) {
|
||||||
classes = 'node default';
|
classes = 'node default';
|
||||||
} else {
|
} else {
|
||||||
@@ -35,26 +36,26 @@ export const labelHelper = async (parent, node, _classes, isNode) => {
|
|||||||
let text;
|
let text;
|
||||||
if (node.labelType === 'markdown') {
|
if (node.labelType === 'markdown') {
|
||||||
// text = textNode;
|
// text = textNode;
|
||||||
text = createText(label, sanitizeText(decodeEntities(labelText), getConfig()), {
|
text = createText(
|
||||||
useHtmlLabels,
|
label,
|
||||||
width: node.width || getConfig().flowchart.wrappingWidth,
|
sanitizeText(decodeEntities(labelText), config),
|
||||||
classes: 'markdown-node-label',
|
{
|
||||||
});
|
useHtmlLabels,
|
||||||
|
width: node.width || config.flowchart.wrappingWidth,
|
||||||
|
classes: 'markdown-node-label',
|
||||||
|
},
|
||||||
|
config
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
text = textNode.appendChild(
|
text = textNode.appendChild(
|
||||||
createLabel(
|
createLabel(sanitizeText(decodeEntities(labelText), config), node.labelStyle, false, isNode)
|
||||||
sanitizeText(decodeEntities(labelText), getConfig()),
|
|
||||||
node.labelStyle,
|
|
||||||
false,
|
|
||||||
isNode
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Get the size of the label
|
// Get the size of the label
|
||||||
let bbox = text.getBBox();
|
let bbox = text.getBBox();
|
||||||
const halfPadding = node.padding / 2;
|
const halfPadding = node.padding / 2;
|
||||||
|
|
||||||
if (evaluate(getConfig().flowchart.htmlLabels)) {
|
if (evaluate(config.flowchart.htmlLabels)) {
|
||||||
const div = text.children[0];
|
const div = text.children[0];
|
||||||
const dv = select(text);
|
const dv = select(text);
|
||||||
|
|
||||||
@@ -76,8 +77,8 @@ export const labelHelper = async (parent, node, _classes, isNode) => {
|
|||||||
|
|
||||||
if (noImgText) {
|
if (noImgText) {
|
||||||
// default size if no text
|
// default size if no text
|
||||||
const bodyFontSize = getConfig().fontSize
|
const bodyFontSize = config.fontSize
|
||||||
? getConfig().fontSize
|
? config.fontSize
|
||||||
: window.getComputedStyle(document.body).fontSize;
|
: window.getComputedStyle(document.body).fontSize;
|
||||||
const enlargingFactor = 5;
|
const enlargingFactor = 5;
|
||||||
const width = parseInt(bodyFontSize, 10) * enlargingFactor + 'px';
|
const width = parseInt(bodyFontSize, 10) * enlargingFactor + 'px';
|
||||||
|
@@ -196,11 +196,16 @@ export const drawNode = function (
|
|||||||
// Create the wrapped text element
|
// Create the wrapped text element
|
||||||
const textElem = nodeElem.append('g');
|
const textElem = nodeElem.append('g');
|
||||||
const description = node.descr.replace(/(<br\/*>)/g, '\n');
|
const description = node.descr.replace(/(<br\/*>)/g, '\n');
|
||||||
const newEl = createText(textElem, description, {
|
const newEl = createText(
|
||||||
useHtmlLabels: htmlLabels,
|
textElem,
|
||||||
width: node.width,
|
description,
|
||||||
classes: 'mindmap-node-label',
|
{
|
||||||
});
|
useHtmlLabels: htmlLabels,
|
||||||
|
width: node.width,
|
||||||
|
classes: 'mindmap-node-label',
|
||||||
|
},
|
||||||
|
conf
|
||||||
|
);
|
||||||
|
|
||||||
if (!htmlLabels) {
|
if (!htmlLabels) {
|
||||||
textElem
|
textElem
|
||||||
|
@@ -183,7 +183,7 @@ export const createText = (
|
|||||||
width = 200,
|
width = 200,
|
||||||
addSvgBackground = false,
|
addSvgBackground = false,
|
||||||
} = {},
|
} = {},
|
||||||
config: MermaidConfig = {}
|
config: MermaidConfig
|
||||||
) => {
|
) => {
|
||||||
log.info('createText', text, style, isTitle, classes, useHtmlLabels, isNode, addSvgBackground);
|
log.info('createText', text, style, isTitle, classes, useHtmlLabels, isNode, addSvgBackground);
|
||||||
if (useHtmlLabels) {
|
if (useHtmlLabels) {
|
||||||
|
Reference in New Issue
Block a user