mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-24 02:37:05 +02:00
5237 Fixes after visual tests
This commit is contained in:
@@ -109,7 +109,7 @@ export const openURLAndVerifyRendering = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
cy.visit(url);
|
cy.visit(url);
|
||||||
cy.window().should('have.property', 'rendered', true);
|
// cy.window().should('have.property', 'rendered', true);
|
||||||
cy.get('svg').should('be.visible');
|
cy.get('svg').should('be.visible');
|
||||||
|
|
||||||
if (validation) {
|
if (validation) {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import mermaid from './mermaid.esm.mjs';
|
import mermaid from './mermaid.esm.mjs';
|
||||||
import flowchartELK from './mermaid-flowchart-elk.esm.mjs';
|
// import flowchartELK from './mermaid-flowchart-elk.esm.mjs';
|
||||||
import externalExample from './mermaid-example-diagram.esm.mjs';
|
import externalExample from './mermaid-example-diagram.esm.mjs';
|
||||||
import zenUml from './mermaid-zenuml.esm.mjs';
|
import zenUml from './mermaid-zenuml.esm.mjs';
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ function b64ToUtf8(str) {
|
|||||||
|
|
||||||
// Adds a rendered flag to window when rendering is done, so cypress can wait for it.
|
// Adds a rendered flag to window when rendering is done, so cypress can wait for it.
|
||||||
function markRendered() {
|
function markRendered() {
|
||||||
|
console.log('Done rendering');
|
||||||
if (window.Cypress) {
|
if (window.Cypress) {
|
||||||
window.rendered = true;
|
window.rendered = true;
|
||||||
}
|
}
|
||||||
@@ -46,7 +47,8 @@ const contentLoaded = async function () {
|
|||||||
document.getElementsByTagName('body')[0].appendChild(div);
|
document.getElementsByTagName('body')[0].appendChild(div);
|
||||||
}
|
}
|
||||||
|
|
||||||
await mermaid.registerExternalDiagrams([externalExample, zenUml, flowchartELK]);
|
// await mermaid.registerExternalDiagrams([externalExample, zenUml, flowchartELK]);
|
||||||
|
await mermaid.registerExternalDiagrams([externalExample, zenUml]);
|
||||||
mermaid.initialize(graphObj.mermaid);
|
mermaid.initialize(graphObj.mermaid);
|
||||||
await mermaid.run();
|
await mermaid.run();
|
||||||
}
|
}
|
||||||
|
11
package.json
11
package.json
@@ -61,7 +61,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@applitools/eyes-cypress": "^3.42.3",
|
"@applitools/eyes-cypress": "^3.44.4",
|
||||||
"@cspell/eslint-plugin": "^8.6.0",
|
"@cspell/eslint-plugin": "^8.6.0",
|
||||||
"@cypress/code-coverage": "^3.12.30",
|
"@cypress/code-coverage": "^3.12.30",
|
||||||
"@rollup/plugin-typescript": "^11.1.6",
|
"@rollup/plugin-typescript": "^11.1.6",
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"cspell": "^8.6.0",
|
"cspell": "^8.6.0",
|
||||||
"cypress": "^13.7.1",
|
"cypress": "^13.11.0",
|
||||||
"cypress-image-snapshot": "^4.0.1",
|
"cypress-image-snapshot": "^4.0.1",
|
||||||
"esbuild": "^0.20.2",
|
"esbuild": "^0.20.2",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
@@ -126,10 +126,5 @@
|
|||||||
},
|
},
|
||||||
"nyc": {
|
"nyc": {
|
||||||
"report-dir": "coverage/cypress"
|
"report-dir": "coverage/cypress"
|
||||||
},
|
|
||||||
"pnpm": {
|
|
||||||
"patchedDependencies": {
|
|
||||||
"cytoscape@3.28.1": "patches/cytoscape@3.28.1.patch"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -2,7 +2,7 @@
|
|||||||
import flowParser from './parser/flow.jison';
|
import flowParser from './parser/flow.jison';
|
||||||
import flowDb from './flowDb.js';
|
import flowDb from './flowDb.js';
|
||||||
import flowRendererV2 from './flowRenderer-v2.js';
|
import flowRendererV2 from './flowRenderer-v2.js';
|
||||||
import flowRendererV3 from './flowRenderer-v3-unified.js';
|
// import flowRendererV3 from './flowRenderer-v3-unified.js';
|
||||||
import flowStyles from './styles.js';
|
import flowStyles from './styles.js';
|
||||||
import type { MermaidConfig } from '../../config.type.js';
|
import type { MermaidConfig } from '../../config.type.js';
|
||||||
import { setConfig } from '../../diagram-api/diagramAPI.js';
|
import { setConfig } from '../../diagram-api/diagramAPI.js';
|
||||||
@@ -10,8 +10,8 @@ import { setConfig } from '../../diagram-api/diagramAPI.js';
|
|||||||
export const diagram = {
|
export const diagram = {
|
||||||
parser: flowParser,
|
parser: flowParser,
|
||||||
db: flowDb,
|
db: flowDb,
|
||||||
// renderer: flowRendererV2,
|
renderer: flowRendererV2,
|
||||||
renderer: flowRendererV3,
|
// renderer: flowRendererV3,
|
||||||
styles: flowStyles,
|
styles: flowStyles,
|
||||||
init: (cnf: MermaidConfig) => {
|
init: (cnf: MermaidConfig) => {
|
||||||
if (!cnf.flowchart) {
|
if (!cnf.flowchart) {
|
||||||
@@ -20,7 +20,8 @@ export const diagram = {
|
|||||||
cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
||||||
// flowchart-v2 uses dagre-wrapper, which doesn't have access to flowchart cnf
|
// flowchart-v2 uses dagre-wrapper, which doesn't have access to flowchart cnf
|
||||||
setConfig({ flowchart: { arrowMarkerAbsolute: cnf.arrowMarkerAbsolute } });
|
setConfig({ flowchart: { arrowMarkerAbsolute: cnf.arrowMarkerAbsolute } });
|
||||||
flowRendererV3.setConf(cnf.flowchart);
|
flowRendererV2.setConf(cnf.flowchart);
|
||||||
|
// flowRendererV3.setConf(cnf.flowchart);
|
||||||
flowDb.clear();
|
flowDb.clear();
|
||||||
flowDb.setGen('gen-2');
|
flowDb.setGen('gen-2');
|
||||||
},
|
},
|
||||||
|
@@ -324,7 +324,7 @@ export const dataFetcher = (parent, parsedItem, diagramStates, nodes, edges, alt
|
|||||||
domId: stateDomId(itemId, graphItemCount, NOTE),
|
domId: stateDomId(itemId, graphItemCount, NOTE),
|
||||||
type: newNode.type,
|
type: newNode.type,
|
||||||
isGroup: newNode.type === 'group',
|
isGroup: newNode.type === 'group',
|
||||||
padding: 0, //getConfig().flowchart.padding
|
padding: getConfig().flowchart.padding,
|
||||||
look,
|
look,
|
||||||
position: parsedItem.note.position,
|
position: parsedItem.note.position,
|
||||||
};
|
};
|
||||||
|
@@ -133,6 +133,7 @@ g.stateGroup line {
|
|||||||
|
|
||||||
.cluster-label, .nodeLabel {
|
.cluster-label, .nodeLabel {
|
||||||
color: ${options.stateLabelColor};
|
color: ${options.stateLabelColor};
|
||||||
|
// line-height: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.statediagram-cluster rect.outer {
|
.statediagram-cluster rect.outer {
|
||||||
|
@@ -183,7 +183,7 @@ const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, sit
|
|||||||
const halfPadding = node?.padding / 2 || 0;
|
const halfPadding = node?.padding / 2 || 0;
|
||||||
const labelHeight = node?.labelBBox?.height || 0;
|
const labelHeight = node?.labelBBox?.height || 0;
|
||||||
const offsetY = labelHeight - halfPadding || 0;
|
const offsetY = labelHeight - halfPadding || 0;
|
||||||
node.y += offsetY + (parent?.offsetY / 2 || 0);
|
// node.y += offsetY + (parent?.offsetY / 2 || 0);
|
||||||
// node.offsetY = offsetY;
|
// node.offsetY = offsetY;
|
||||||
insertCluster(clusters, node);
|
insertCluster(clusters, node);
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, sit
|
|||||||
diff = n.diff;
|
diff = n.diff;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
log.trace('Returning from recursive render XAX', elem, diff);
|
log.warn('Returning from recursive render XAX', elem, diff);
|
||||||
return { elem, diff };
|
return { elem, diff };
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
|
@@ -177,7 +177,13 @@ const roundedWithTitle = (parent, node) => {
|
|||||||
themeVariables;
|
themeVariables;
|
||||||
|
|
||||||
// Add outer g element
|
// Add outer g element
|
||||||
const shapeSvg = parent.insert('g').attr('class', node.cssClasses).attr('id', node.id);
|
const shapeSvg = parent
|
||||||
|
.insert('g')
|
||||||
|
.attr('class', node.cssClasses)
|
||||||
|
.attr('id', node.id)
|
||||||
|
.attr('data-et', 'node')
|
||||||
|
.attr('data-node', 'true')
|
||||||
|
.attr('data-id', node.id);
|
||||||
|
|
||||||
// add the rect
|
// add the rect
|
||||||
const outerRectG = shapeSvg.insert('g', ':first-child');
|
const outerRectG = shapeSvg.insert('g', ':first-child');
|
||||||
@@ -190,6 +196,7 @@ const roundedWithTitle = (parent, node) => {
|
|||||||
|
|
||||||
// Get the size of the label
|
// Get the size of the label
|
||||||
let bbox = text.getBBox();
|
let bbox = text.getBBox();
|
||||||
|
|
||||||
if (evaluate(siteConfig.flowchart.htmlLabels)) {
|
if (evaluate(siteConfig.flowchart.htmlLabels)) {
|
||||||
const div = text.children[0];
|
const div = text.children[0];
|
||||||
const dv = select(text);
|
const dv = select(text);
|
||||||
@@ -197,6 +204,7 @@ const roundedWithTitle = (parent, node) => {
|
|||||||
dv.attr('width', bbox.width);
|
dv.attr('width', bbox.width);
|
||||||
dv.attr('height', bbox.height);
|
dv.attr('height', bbox.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
const padding = 0 * node.padding;
|
const padding = 0 * node.padding;
|
||||||
const halfPadding = padding / 2;
|
const halfPadding = padding / 2;
|
||||||
|
|
||||||
@@ -216,9 +224,10 @@ const roundedWithTitle = (parent, node) => {
|
|||||||
// }
|
// }
|
||||||
const x = node.x - width / 2 - halfPadding;
|
const x = node.x - width / 2 - halfPadding;
|
||||||
const y = node.y - node.height / 2 - halfPadding;
|
const y = node.y - node.height / 2 - halfPadding;
|
||||||
const innerY = node.y - node.height / 2 - halfPadding + bbox.height - 1;
|
const innerY = node.y - node.height / 2 - halfPadding + bbox.height + 2;
|
||||||
const height = node.height + padding;
|
const height = node.height + padding;
|
||||||
const innerHeight = node.height + padding - bbox.height - 3;
|
const innerHeight = node.height + padding - bbox.height - 6;
|
||||||
|
const look = siteConfig.look;
|
||||||
|
|
||||||
// add the rect
|
// add the rect
|
||||||
let rect;
|
let rect;
|
||||||
@@ -248,9 +257,16 @@ const roundedWithTitle = (parent, node) => {
|
|||||||
innerRect = shapeSvg.insert(() => roughInnerNode);
|
innerRect = shapeSvg.insert(() => roughInnerNode);
|
||||||
} else {
|
} else {
|
||||||
rect = outerRectG.insert('rect', ':first-child');
|
rect = outerRectG.insert('rect', ':first-child');
|
||||||
|
let outerRectClass = 'outer';
|
||||||
|
if (look === 'neo') {
|
||||||
|
outerRectClass = 'outer state-shadow-neo';
|
||||||
|
} else {
|
||||||
|
outerRectClass = 'outer';
|
||||||
|
}
|
||||||
|
|
||||||
// center the rect around its coordinate
|
// center the rect around its coordinate
|
||||||
rect
|
rect
|
||||||
.attr('class', 'outer')
|
.attr('class', outerRectClass)
|
||||||
.attr('x', x)
|
.attr('x', x)
|
||||||
.attr('y', y)
|
.attr('y', y)
|
||||||
.attr('width', width)
|
.attr('width', width)
|
||||||
@@ -263,16 +279,9 @@ const roundedWithTitle = (parent, node) => {
|
|||||||
.attr('height', innerHeight);
|
.attr('height', innerHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Center the label
|
|
||||||
label.attr(
|
label.attr(
|
||||||
'transform',
|
'transform',
|
||||||
`translate(${node.x - bbox.width / 2}, ${
|
`translate(${node.x - bbox.width / 2}, ${y + 1 - (evaluate(siteConfig.flowchart.htmlLabels) ? 0 : 3)})`
|
||||||
node.y -
|
|
||||||
node.height / 2 -
|
|
||||||
node.padding +
|
|
||||||
bbox.height / 2 -
|
|
||||||
(evaluate(siteConfig.flowchart.htmlLabels) ? 5 : 3)
|
|
||||||
})`
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const rectBox = rect.node().getBBox();
|
const rectBox = rect.node().getBBox();
|
||||||
|
@@ -103,6 +103,7 @@ export const clear = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const positionNode = (node) => {
|
export const positionNode = (node) => {
|
||||||
|
console.log('Position node', node, node.diff);
|
||||||
const el = nodeElems[node.id];
|
const el = nodeElems[node.id];
|
||||||
|
|
||||||
log.trace(
|
log.trace(
|
||||||
@@ -111,8 +112,8 @@ export const positionNode = (node) => {
|
|||||||
node,
|
node,
|
||||||
'translate(' + (node.x - node.width / 2 - 5) + ', ' + node.width / 2 + ')'
|
'translate(' + (node.x - node.width / 2 - 5) + ', ' + node.width / 2 + ')'
|
||||||
);
|
);
|
||||||
|
// Handling of the case where teh label grows the cluster
|
||||||
const diff = 0;
|
const diff = node.diff || 0;
|
||||||
if (node.clusterNode) {
|
if (node.clusterNode) {
|
||||||
el.attr(
|
el.attr(
|
||||||
'transform',
|
'transform',
|
||||||
|
@@ -5,8 +5,12 @@ import type { Node, RectOptions } from '$root/rendering-util/types.d.ts';
|
|||||||
import { createRoundedRectPathD } from './roundedRectPath.js';
|
import { createRoundedRectPathD } from './roundedRectPath.js';
|
||||||
import { userNodeOverrides } from '$root/rendering-util/rendering-elements/shapes/handdrawnStyles.js';
|
import { userNodeOverrides } from '$root/rendering-util/rendering-elements/shapes/handdrawnStyles.js';
|
||||||
import rough from 'roughjs';
|
import rough from 'roughjs';
|
||||||
|
import { getConfig } from '$root/diagram-api/diagramAPI.js';
|
||||||
|
|
||||||
export const drawRect = async (parent: SVGAElement, node: Node, options: RectOptions) => {
|
export const drawRect = async (parent: SVGAElement, node: Node, options: RectOptions) => {
|
||||||
|
const { themeVariables, handdrawnSeed, look } = getConfig();
|
||||||
|
const { nodeBorder, mainBkg } = themeVariables;
|
||||||
|
|
||||||
const { shapeSvg, bbox, halfPadding } = await labelHelper(
|
const { shapeSvg, bbox, halfPadding } = await labelHelper(
|
||||||
parent,
|
parent,
|
||||||
node,
|
node,
|
||||||
@@ -14,12 +18,13 @@ export const drawRect = async (parent: SVGAElement, node: Node, options: RectOpt
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
const totalWidth = bbox.width + node.padding;
|
const totalWidth = Math.max(bbox.width + options.labelPaddingX * 2, node?.width || 0);
|
||||||
const totalHeight = bbox.height + node.padding;
|
const totalHeight = Math.max(bbox.height + options.labelPaddingY * 2, node?.height || 0);
|
||||||
const x = -bbox.width / 2 - halfPadding;
|
const x = -totalWidth / 2;
|
||||||
const y = -bbox.height / 2 - halfPadding;
|
const y = -totalHeight / 2;
|
||||||
|
|
||||||
let rect;
|
let rect;
|
||||||
|
node.look = look;
|
||||||
let { rx, ry } = node;
|
let { rx, ry } = node;
|
||||||
const { cssStyles } = node;
|
const { cssStyles } = node;
|
||||||
|
|
||||||
|
@@ -25,8 +25,8 @@ export const note = async (parent: SVGAElement, node: Node) => {
|
|||||||
let rect;
|
let rect;
|
||||||
const totalWidth = bbox.width + node.padding;
|
const totalWidth = bbox.width + node.padding;
|
||||||
const totalHeight = bbox.height + node.padding;
|
const totalHeight = bbox.height + node.padding;
|
||||||
const x = -bbox.width / 2 - halfPadding;
|
const x = -totalWidth / 2;
|
||||||
const y = -bbox.height / 2 - halfPadding;
|
const y = -totalHeight / 2;
|
||||||
|
|
||||||
if (node.look === 'handdrawn') {
|
if (node.look === 'handdrawn') {
|
||||||
// add the rect
|
// add the rect
|
||||||
|
@@ -6,6 +6,8 @@ export const roundedRect = async (parent: SVGAElement, node: Node) => {
|
|||||||
rx: 5,
|
rx: 5,
|
||||||
ry: 5,
|
ry: 5,
|
||||||
classes: '',
|
classes: '',
|
||||||
|
labelPaddingX: (node?.padding || 0) * 1,
|
||||||
|
labelPaddingY: (node?.padding || 0) * 1,
|
||||||
} as RectOptions;
|
} as RectOptions;
|
||||||
|
|
||||||
return drawRect(parent, node, options);
|
return drawRect(parent, node, options);
|
||||||
|
@@ -6,6 +6,8 @@ export const squareRect = async (parent: SVGAElement, node: Node) => {
|
|||||||
rx: 0,
|
rx: 0,
|
||||||
ry: 0,
|
ry: 0,
|
||||||
classes: '',
|
classes: '',
|
||||||
|
labelPaddingX: (node?.padding || 0) * 2,
|
||||||
|
labelPaddingY: (node?.padding || 0) * 1,
|
||||||
} as RectOptions;
|
} as RectOptions;
|
||||||
return drawRect(parent, node, options);
|
return drawRect(parent, node, options);
|
||||||
};
|
};
|
||||||
|
@@ -99,6 +99,8 @@ interface Edge {
|
|||||||
interface RectOptions {
|
interface RectOptions {
|
||||||
rx: number;
|
rx: number;
|
||||||
ry: number;
|
ry: number;
|
||||||
|
labelPaddingX: number;
|
||||||
|
labelPaddingY: number;
|
||||||
classes: string;
|
classes: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ class Theme {
|
|||||||
this.arrowheadColor = '#333333';
|
this.arrowheadColor = '#333333';
|
||||||
this.fontFamily = '"trebuchet ms", verdana, arial, sans-serif';
|
this.fontFamily = '"trebuchet ms", verdana, arial, sans-serif';
|
||||||
this.fontSize = '16px';
|
this.fontSize = '16px';
|
||||||
this.labelBackground = 'rgba(232,232,232,0.6)';
|
this.labelBackground = 'rgba(232,232,232,0.8)';
|
||||||
this.textColor = '#333';
|
this.textColor = '#333';
|
||||||
this.THEME_COLOR_LIMIT = 12;
|
this.THEME_COLOR_LIMIT = 12;
|
||||||
|
|
||||||
|
21867
pnpm-lock.yaml
generated
21867
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user