mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-27 17:04:10 +01:00
Compare commits
1 Commits
fix/mindma
...
fix-edge-d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7d7fe42aa |
5
.changeset/lucky-cases-switch.md
Normal file
5
.changeset/lucky-cases-switch.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'mermaid': patch
|
||||
---
|
||||
|
||||
fix: Allow IDs starting with L, R, T, or B in parser
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
'mermaid': patch
|
||||
---
|
||||
|
||||
fix: Mindmap rendering issue when the number of Level 2 nodes exceeds 11
|
||||
@@ -293,37 +293,5 @@ describe('MindmapDb getData function', () => {
|
||||
expect(edgeA1_aaa.section).toBe(1);
|
||||
expect(edgeA_a2.section).toBe(2);
|
||||
});
|
||||
|
||||
it('should wrap section numbers when there are more than 11 level 2 nodes', () => {
|
||||
db.addNode(0, 'root', 'Example', 0);
|
||||
|
||||
for (let i = 1; i <= 15; i++) {
|
||||
db.addNode(1, `child${i}`, `${i}`, 0);
|
||||
}
|
||||
|
||||
const result = db.getData();
|
||||
|
||||
expect(result.nodes).toHaveLength(16);
|
||||
|
||||
const child1 = result.nodes.find((n) => n.label === '1') as MindmapLayoutNode;
|
||||
const child11 = result.nodes.find((n) => n.label === '11') as MindmapLayoutNode;
|
||||
const child12 = result.nodes.find((n) => n.label === '12') as MindmapLayoutNode;
|
||||
const child13 = result.nodes.find((n) => n.label === '13') as MindmapLayoutNode;
|
||||
const child14 = result.nodes.find((n) => n.label === '14') as MindmapLayoutNode;
|
||||
const child15 = result.nodes.find((n) => n.label === '15') as MindmapLayoutNode;
|
||||
|
||||
expect(child1.section).toBe(0);
|
||||
expect(child11.section).toBe(10);
|
||||
|
||||
expect(child12.section).toBe(0);
|
||||
expect(child13.section).toBe(1);
|
||||
expect(child14.section).toBe(2);
|
||||
expect(child15.section).toBe(3);
|
||||
|
||||
expect(child12.cssClasses).toBe('mindmap-node section-0');
|
||||
expect(child13.cssClasses).toBe('mindmap-node section-1');
|
||||
expect(child14.cssClasses).toBe('mindmap-node section-2');
|
||||
expect(child15.cssClasses).toBe('mindmap-node section-3');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -203,7 +203,7 @@ export class MindmapDB {
|
||||
// For other nodes, inherit parent's section number
|
||||
if (node.children) {
|
||||
for (const [index, child] of node.children.entries()) {
|
||||
const childSectionNumber = node.level === 0 ? index % 11 : sectionNumber;
|
||||
const childSectionNumber = node.level === 0 ? index : sectionNumber;
|
||||
this.assignSections(child, childSectionNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ fragment Statement:
|
||||
;
|
||||
|
||||
fragment LeftPort:
|
||||
':'lhsDir=ARROW_DIRECTION
|
||||
':' lhsDir=ID
|
||||
;
|
||||
|
||||
fragment RightPort:
|
||||
rhsDir=ARROW_DIRECTION':'
|
||||
rhsDir=ID ':'
|
||||
;
|
||||
|
||||
fragment Arrow:
|
||||
@@ -47,6 +47,5 @@ Edge:
|
||||
lhsId=ID lhsGroup?=ARROW_GROUP? Arrow rhsId=ID rhsGroup?=ARROW_GROUP? EOL
|
||||
;
|
||||
|
||||
terminal ARROW_DIRECTION: 'L' | 'R' | 'T' | 'B';
|
||||
terminal ARROW_GROUP: /\{group\}/;
|
||||
terminal ARROW_INTO: /<|>/;
|
||||
|
||||
@@ -19,6 +19,64 @@ describe('architecture', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('should handle services', () => {
|
||||
it('should handle service with icon', () => {
|
||||
const context = `architecture-beta
|
||||
service TH(disk)
|
||||
`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Architecture);
|
||||
expect(result.value.services).toHaveLength(1);
|
||||
expect(result.value.services?.[0].id).toBe('TH');
|
||||
expect(result.value.services?.[0].icon).toBe('disk');
|
||||
});
|
||||
|
||||
it('should handle service with icon starting with arrow direction letters', () => {
|
||||
const context = `architecture-beta
|
||||
service T(disk)
|
||||
service TH(database)
|
||||
service L(server)
|
||||
service R(cloud)
|
||||
service B(internet)
|
||||
service TOP(disk)
|
||||
service LEFT(disk)
|
||||
service RIGHT(disk)
|
||||
service BOTTOM(disk)
|
||||
`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Architecture);
|
||||
expect(result.value.services).toHaveLength(9);
|
||||
});
|
||||
|
||||
it('should handle service with icon and title', () => {
|
||||
const context = `architecture-beta
|
||||
service db(database)[Database]
|
||||
`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Architecture);
|
||||
expect(result.value.services).toHaveLength(1);
|
||||
expect(result.value.services?.[0].id).toBe('db');
|
||||
expect(result.value.services?.[0].icon).toBe('database');
|
||||
expect(result.value.services?.[0].title).toBe('Database');
|
||||
});
|
||||
|
||||
it('should handle service in a group', () => {
|
||||
const context = `architecture-beta
|
||||
group api(cloud)[API]
|
||||
service db(database)[Database] in api
|
||||
`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Architecture);
|
||||
expect(result.value.services).toHaveLength(1);
|
||||
expect(result.value.services?.[0].id).toBe('db');
|
||||
expect(result.value.services?.[0].in).toBe('api');
|
||||
});
|
||||
});
|
||||
|
||||
describe('should handle TitleAndAccessibilities', () => {
|
||||
it.each([
|
||||
`architecture-beta title sample title`,
|
||||
|
||||
Reference in New Issue
Block a user