mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-21 15:09:39 +02:00
Compare commits
1 Commits
renovate/p
...
bug/2492-f
Author | SHA1 | Date | |
---|---|---|---|
![]() |
81d00bd4e4 |
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
'mermaid': patch
|
|
||||||
---
|
|
||||||
|
|
||||||
fix: Correct viewBox casing and make SVGs responsive
|
|
2
.github/workflows/e2e-timings.yml
vendored
2
.github/workflows/e2e-timings.yml
vendored
@@ -58,7 +58,7 @@ jobs:
|
|||||||
echo "EOF" >> $GITHUB_OUTPUT
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Commit and create pull request
|
- name: Commit and create pull request
|
||||||
uses: peter-evans/create-pull-request@46cdba753c74545733b821043d64bd6925fc4da9
|
uses: peter-evans/create-pull-request@915d841dae6a4f191bb78faf61a257411d7be4d2
|
||||||
with:
|
with:
|
||||||
add-paths: |
|
add-paths: |
|
||||||
cypress/timings.json
|
cypress/timings.json
|
||||||
|
@@ -99,7 +99,6 @@ 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');
|
||||||
cy.get('svg').should('not.have.attr', 'viewbox');
|
|
||||||
|
|
||||||
if (validation) {
|
if (validation) {
|
||||||
cy.get('svg').should(validation);
|
cy.get('svg').should(validation);
|
||||||
|
@@ -266,4 +266,156 @@ describe('[Arrows] when parsing', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Issue #2492: Node names starting with o/x should not be consumed by arrow markers', () => {
|
||||||
|
it('should handle node names starting with "o" after plain arrows', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\ndev---ops;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('dev').id).toBe('dev');
|
||||||
|
expect(vert.get('ops').id).toBe('ops');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('dev');
|
||||||
|
expect(edges[0].end).toBe('ops');
|
||||||
|
expect(edges[0].type).toBe('arrow_open');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle node names starting with "x" after plain arrows', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\ndev---xerxes;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('dev').id).toBe('dev');
|
||||||
|
expect(vert.get('xerxes').id).toBe('xerxes');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('dev');
|
||||||
|
expect(edges[0].end).toBe('xerxes');
|
||||||
|
expect(edges[0].type).toBe('arrow_open');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should still support circle arrows with spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nA --o B;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('A').id).toBe('A');
|
||||||
|
expect(vert.get('B').id).toBe('B');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('A');
|
||||||
|
expect(edges[0].end).toBe('B');
|
||||||
|
expect(edges[0].type).toBe('arrow_circle');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should still support cross arrows with spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nC --x D;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('C').id).toBe('C');
|
||||||
|
expect(vert.get('D').id).toBe('D');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('C');
|
||||||
|
expect(edges[0].end).toBe('D');
|
||||||
|
expect(edges[0].type).toBe('arrow_cross');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support circle arrows to uppercase nodes without spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nA--oB;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('A').id).toBe('A');
|
||||||
|
expect(vert.get('B').id).toBe('B');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('A');
|
||||||
|
expect(edges[0].end).toBe('B');
|
||||||
|
expect(edges[0].type).toBe('arrow_circle');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support cross arrows to uppercase nodes without spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nA--xBar;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('A').id).toBe('A');
|
||||||
|
expect(vert.get('Bar').id).toBe('Bar');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('A');
|
||||||
|
expect(edges[0].end).toBe('Bar');
|
||||||
|
expect(edges[0].type).toBe('arrow_cross');
|
||||||
|
expect(edges[0].stroke).toBe('normal');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle thick arrows with lowercase node names starting with "o"', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nalpha===omega;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('alpha').id).toBe('alpha');
|
||||||
|
expect(vert.get('omega').id).toBe('omega');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('alpha');
|
||||||
|
expect(edges[0].end).toBe('omega');
|
||||||
|
expect(edges[0].type).toBe('arrow_open');
|
||||||
|
expect(edges[0].stroke).toBe('thick');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle dotted arrows with lowercase node names starting with "o"', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nfoo-.-opus;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('foo').id).toBe('foo');
|
||||||
|
expect(vert.get('opus').id).toBe('opus');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('foo');
|
||||||
|
expect(edges[0].end).toBe('opus');
|
||||||
|
expect(edges[0].type).toBe('arrow_open');
|
||||||
|
expect(edges[0].stroke).toBe('dotted');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should still support dotted circle arrows with spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nB -.-o C;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('B').id).toBe('B');
|
||||||
|
expect(vert.get('C').id).toBe('C');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('B');
|
||||||
|
expect(edges[0].end).toBe('C');
|
||||||
|
expect(edges[0].type).toBe('arrow_circle');
|
||||||
|
expect(edges[0].stroke).toBe('dotted');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should still support thick cross arrows with spaces', function () {
|
||||||
|
const res = flow.parser.parse('graph TD;\nC ==x D;');
|
||||||
|
|
||||||
|
const vert = flow.parser.yy.getVertices();
|
||||||
|
const edges = flow.parser.yy.getEdges();
|
||||||
|
|
||||||
|
expect(vert.get('C').id).toBe('C');
|
||||||
|
expect(vert.get('D').id).toBe('D');
|
||||||
|
expect(edges.length).toBe(1);
|
||||||
|
expect(edges[0].start).toBe('C');
|
||||||
|
expect(edges[0].end).toBe('D');
|
||||||
|
expect(edges[0].type).toBe('arrow_cross');
|
||||||
|
expect(edges[0].stroke).toBe('thick');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -152,17 +152,23 @@ that id.
|
|||||||
"," return 'COMMA';
|
"," return 'COMMA';
|
||||||
"*" return 'MULT';
|
"*" return 'MULT';
|
||||||
|
|
||||||
<INITIAL,edgeText>\s*[xo<]?\-\-+[-xo>]\s* { this.popState(); return 'LINK'; }
|
<INITIAL,edgeText>\s*[xo<]?\-\-+[xo>]\s+ { this.popState(); return 'LINK'; }
|
||||||
<INITIAL>\s*[xo<]?\-\-\s* { this.pushState("edgeText"); return 'START_LINK'; }
|
<INITIAL,edgeText>\s*[xo<]?\-\-+[xo>](?=[A-Z]) { this.popState(); return 'LINK'; }
|
||||||
<edgeText>[^-]|\-(?!\-)+ return 'EDGE_TEXT';
|
<INITIAL,edgeText>\s*[xo<]?\-\-+[-]\s* { this.popState(); return 'LINK'; }
|
||||||
|
<INITIAL>\s*[xo<]?\-\-\s* { this.pushState("edgeText"); return 'START_LINK'; }
|
||||||
|
<edgeText>[^-]|\-(?!\-)+ return 'EDGE_TEXT';
|
||||||
|
|
||||||
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[=xo>]\s* { this.popState(); return 'LINK'; }
|
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[xo>]\s+ { this.popState(); return 'LINK'; }
|
||||||
<INITIAL>\s*[xo<]?\=\=\s* { this.pushState("thickEdgeText"); return 'START_LINK'; }
|
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[xo>](?=[A-Z]) { this.popState(); return 'LINK'; }
|
||||||
<thickEdgeText>[^=]|\=(?!=) return 'EDGE_TEXT';
|
<INITIAL,thickEdgeText>\s*[xo<]?\=\=+[=]\s* { this.popState(); return 'LINK'; }
|
||||||
|
<INITIAL>\s*[xo<]?\=\=\s* { this.pushState("thickEdgeText"); return 'START_LINK'; }
|
||||||
|
<thickEdgeText>[^=]|\=(?!=) return 'EDGE_TEXT';
|
||||||
|
|
||||||
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-[xo>]?\s* { this.popState(); return 'LINK'; }
|
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-[xo>]\s+ { this.popState(); return 'LINK'; }
|
||||||
<INITIAL>\s*[xo<]?\-\.\s* { this.pushState("dottedEdgeText"); return 'START_LINK'; }
|
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-[xo>](?=[A-Z]) { this.popState(); return 'LINK'; }
|
||||||
<dottedEdgeText>[^\.]|\.(?!-) return 'EDGE_TEXT';
|
<INITIAL,dottedEdgeText>\s*[xo<]?\-?\.+\-\s* { this.popState(); return 'LINK'; }
|
||||||
|
<INITIAL>\s*[xo<]?\-\.\s* { this.pushState("dottedEdgeText"); return 'START_LINK'; }
|
||||||
|
<dottedEdgeText>[^\.]|\.(?!-) return 'EDGE_TEXT';
|
||||||
|
|
||||||
|
|
||||||
<*>\s*\~\~[\~]+\s* return 'LINK';
|
<*>\s*\~\~[\~]+\s* return 'LINK';
|
||||||
|
@@ -16,7 +16,7 @@ const draw: DrawDefinition = (_text, id, _version, diagram: Diagram) => {
|
|||||||
const svgWidth = bitWidth * bitsPerRow + 2;
|
const svgWidth = bitWidth * bitsPerRow + 2;
|
||||||
const svg: SVG = selectSvgElement(id);
|
const svg: SVG = selectSvgElement(id);
|
||||||
|
|
||||||
svg.attr('viewBox', `0 0 ${svgWidth} ${svgHeight}`);
|
svg.attr('viewbox', `0 0 ${svgWidth} ${svgHeight}`);
|
||||||
configureSvgSize(svg, svgHeight, svgWidth, config.useMaxWidth);
|
configureSvgSize(svg, svgHeight, svgWidth, config.useMaxWidth);
|
||||||
|
|
||||||
for (const [word, packet] of words.entries()) {
|
for (const [word, packet] of words.entries()) {
|
||||||
|
@@ -2,7 +2,6 @@ import type { Diagram } from '../../Diagram.js';
|
|||||||
import type { RadarDiagramConfig } from '../../config.type.js';
|
import type { RadarDiagramConfig } from '../../config.type.js';
|
||||||
import type { DiagramRenderer, DrawDefinition, SVG, SVGGroup } from '../../diagram-api/types.js';
|
import type { DiagramRenderer, DrawDefinition, SVG, SVGGroup } from '../../diagram-api/types.js';
|
||||||
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
|
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
|
||||||
import { configureSvgSize } from '../../setupGraphViewbox.js';
|
|
||||||
import type { RadarDB, RadarAxis, RadarCurve } from './types.js';
|
import type { RadarDB, RadarAxis, RadarCurve } from './types.js';
|
||||||
|
|
||||||
const draw: DrawDefinition = (_text, id, _version, diagram: Diagram) => {
|
const draw: DrawDefinition = (_text, id, _version, diagram: Diagram) => {
|
||||||
@@ -54,9 +53,11 @@ const drawFrame = (svg: SVG, config: Required<RadarDiagramConfig>): SVGGroup =>
|
|||||||
x: config.marginLeft + config.width / 2,
|
x: config.marginLeft + config.width / 2,
|
||||||
y: config.marginTop + config.height / 2,
|
y: config.marginTop + config.height / 2,
|
||||||
};
|
};
|
||||||
configureSvgSize(svg, totalHeight, totalWidth, config.useMaxWidth ?? true);
|
// Initialize the SVG
|
||||||
|
svg
|
||||||
svg.attr('viewBox', `0 0 ${totalWidth} ${totalHeight}`);
|
.attr('viewbox', `0 0 ${totalWidth} ${totalHeight}`)
|
||||||
|
.attr('width', totalWidth)
|
||||||
|
.attr('height', totalHeight);
|
||||||
// g element to center the radar chart
|
// g element to center the radar chart
|
||||||
return svg.append('g').attr('transform', `translate(${center.x}, ${center.y})`);
|
return svg.append('g').attr('transform', `translate(${center.x}, ${center.y})`);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user