mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-28 15:16:22 +01:00
Compare commits
2 Commits
fix-7214-h
...
fix/align-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a325ae8f3 | ||
|
|
bc53201551 |
@@ -1,5 +0,0 @@
|
||||
---
|
||||
'mermaid': patch
|
||||
---
|
||||
|
||||
fix: Ensure block diagram hexagon blocks respect column spanning syntax
|
||||
@@ -404,18 +404,6 @@ describe('Block diagram', () => {
|
||||
a
|
||||
b
|
||||
a --- b
|
||||
`,
|
||||
{}
|
||||
);
|
||||
});
|
||||
|
||||
it('BL32: hexagon shape block should span correctly', () => {
|
||||
imgSnapshotTest(
|
||||
`block-beta
|
||||
columns 3
|
||||
A1{{"Opening tag"}} space A3{{"Closing tag"}}
|
||||
B1["<tagname>"] B2["content"] B3["</tagname>"]
|
||||
C{{"Element"}}:3
|
||||
`,
|
||||
{}
|
||||
);
|
||||
|
||||
@@ -96,9 +96,9 @@ const hexagon = async (parent, node) => {
|
||||
);
|
||||
|
||||
const f = 4;
|
||||
const h = node.positioned ? node.height : bbox.height + node.padding;
|
||||
const h = bbox.height + node.padding;
|
||||
const m = h / f;
|
||||
const w = node.positioned ? node.width : bbox.width + 2 * m + node.padding;
|
||||
const w = bbox.width + 2 * m + node.padding;
|
||||
const points = [
|
||||
{ x: m, y: 0 },
|
||||
{ x: w - m, y: 0 },
|
||||
|
||||
@@ -19,7 +19,7 @@ function applyStyle(dom, styleFn) {
|
||||
}
|
||||
}
|
||||
|
||||
async function addHtmlSpan(
|
||||
export async function addHtmlSpan(
|
||||
element,
|
||||
node,
|
||||
width,
|
||||
|
||||
@@ -1,56 +1,9 @@
|
||||
import { select } from 'd3';
|
||||
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||
import common, {
|
||||
evaluate,
|
||||
hasKatex,
|
||||
renderKatexSanitized,
|
||||
sanitizeText,
|
||||
} from '../../diagrams/common/common.js';
|
||||
import { evaluate } from '../../diagrams/common/common.js';
|
||||
import { log } from '../../logger.js';
|
||||
import { decodeEntities } from '../../utils.js';
|
||||
|
||||
/**
|
||||
* @param dom
|
||||
* @param styleFn
|
||||
*/
|
||||
function applyStyle(dom, styleFn) {
|
||||
if (styleFn) {
|
||||
dom.attr('style', styleFn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} node
|
||||
* @returns {Promise<SVGForeignObjectElement>} Node
|
||||
*/
|
||||
async function addHtmlLabel(node) {
|
||||
const fo = select(document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject'));
|
||||
const div = fo.append('xhtml:div');
|
||||
|
||||
const config = getConfig();
|
||||
let label = node.label;
|
||||
if (node.label && hasKatex(node.label)) {
|
||||
label = await renderKatexSanitized(node.label.replace(common.lineBreakRegex, '\n'), config);
|
||||
}
|
||||
const labelClass = node.isNode ? 'nodeLabel' : 'edgeLabel';
|
||||
const labelSpan =
|
||||
'<span class="' +
|
||||
labelClass +
|
||||
'" ' +
|
||||
(node.labelStyle ? 'style="' + node.labelStyle + '"' : '') + // codeql [js/html-constructed-from-input] : false positive
|
||||
'>' +
|
||||
label +
|
||||
'</span>';
|
||||
div.html(sanitizeText(labelSpan, config));
|
||||
|
||||
applyStyle(div, node.labelStyle);
|
||||
div.style('display', 'inline-block');
|
||||
div.style('padding-right', '1px');
|
||||
// Fix for firefox
|
||||
div.style('white-space', 'nowrap');
|
||||
div.attr('xmlns', 'http://www.w3.org/1999/xhtml');
|
||||
return fo.node();
|
||||
}
|
||||
import { addHtmlSpan } from '../createText.js';
|
||||
/**
|
||||
* @param _vertexText
|
||||
* @param style
|
||||
@@ -65,7 +18,6 @@ const createLabel = async (_vertexText, style, isTitle, isNode) => {
|
||||
}
|
||||
|
||||
if (evaluate(getConfig().flowchart.htmlLabels)) {
|
||||
// TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that?
|
||||
vertexText = vertexText.replace(/\\n|\n/g, '<br />');
|
||||
log.info('vertexText' + vertexText);
|
||||
const node = {
|
||||
@@ -76,8 +28,10 @@ const createLabel = async (_vertexText, style, isTitle, isNode) => {
|
||||
),
|
||||
labelStyle: style ? style.replace('fill:', 'color:') : style,
|
||||
};
|
||||
let vertexNode = await addHtmlLabel(node);
|
||||
// vertexNode.parentNode.removeChild(vertexNode);
|
||||
const config = getConfig();
|
||||
const width = config.flowchart?.wrappingWidth || 200;
|
||||
const tempContainer = select(document.createElementNS('http://www.w3.org/2000/svg', 'g'));
|
||||
const vertexNode = await addHtmlSpan(tempContainer, node, width, '', false, config);
|
||||
return vertexNode;
|
||||
} else {
|
||||
const svgLabel = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
||||
|
||||
Reference in New Issue
Block a user