Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Mindmap to TS #5247

Merged
merged 24 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"codedoc",
"codemia",
"colour",
"colours",
"commitlint",
"cpettitt",
"customizability",
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,10 @@
},
"nyc": {
"report-dir": "coverage/cypress"
},
"pnpm": {
"patchedDependencies": {
"cytoscape@3.28.1": "patches/cytoscape@3.28.1.patch"
}
}
}
7 changes: 1 addition & 6 deletions packages/mermaid-example-diagram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@
},
"dependencies": {
"@braintree/sanitize-url": "^6.0.1",
"cytoscape": "^3.23.0",
"cytoscape-cose-bilkent": "^4.1.0",
"cytoscape-fcose": "^2.1.0",
"d3": "^7.0.0",
"khroma": "^2.0.0",
"non-layered-tidy-tree-layout": "^2.0.2"
"khroma": "^2.0.0"
},
"devDependencies": {
"@types/cytoscape": "^3.19.9",
"concurrently": "^8.0.0",
"rimraf": "^5.0.0",
"mermaid": "workspace:*"
Expand Down
3 changes: 1 addition & 2 deletions packages/mermaid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@
"@braintree/sanitize-url": "^6.0.1",
"@types/d3-scale": "^4.0.3",
"@types/d3-scale-chromatic": "^3.0.0",
"cytoscape": "^3.23.0",
"cytoscape": "^3.28.1",
"cytoscape-cose-bilkent": "^4.1.0",
"cytoscape-fcose": "^2.1.0",
"d3": "^7.4.0",
"d3-sankey": "^0.12.3",
"dagre-d3-es": "7.0.10",
Expand Down
19 changes: 10 additions & 9 deletions packages/mermaid/src/diagrams/mindmap/mindmap-definition.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// @ts-ignore: JISON doesn't support types
import mindmapParser from './parser/mindmap.jison';
import * as mindmapDb from './mindmapDb.js';
import mindmapRenderer from './mindmapRenderer.js';
import mindmapStyles from './styles.js';
import parser from './parser/mindmap.jison';
import db from './mindmapDb.js';
import renderer from './mindmapRenderer.js';
import styles from './styles.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';

export const diagram = {
db: mindmapDb,
renderer: mindmapRenderer,
parser: mindmapParser,
styles: mindmapStyles,
export const diagram: DiagramDefinition = {
db,
renderer,
parser,
styles,
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-expect-error No types available for JISON
import { parser as mindmap } from './parser/mindmap.jison';
import * as mindmapDB from './mindmapDb.js';
import mindmapDB from './mindmapDb.js';
// Todo fix utils functions for tests
import { setLogLevel } from '../../diagram-api/diagramAPI.js';

Expand All @@ -11,15 +12,15 @@ describe('when parsing a mindmap ', function () {
});
describe('hiearchy', function () {
it('MMP-1 should handle a simple root definition abc122', function () {
let str = `mindmap
const str = `mindmap
root`;

mindmap.parse(str);
// console.log('Time for checks', mindmap.yy.getMindmap().descr);
expect(mindmap.yy.getMindmap().descr).toEqual('root');
});
it('MMP-2 should handle a hierachial mindmap definition', function () {
let str = `mindmap
const str = `mindmap
root
child1
child2
Expand All @@ -34,7 +35,7 @@ describe('when parsing a mindmap ', function () {
});

it('3 should handle a simple root definition with a shape and without an id abc123', function () {
let str = `mindmap
const str = `mindmap
(root)`;

mindmap.parse(str);
Expand All @@ -43,7 +44,7 @@ describe('when parsing a mindmap ', function () {
});

it('MMP-4 should handle a deeper hierachial mindmap definition', function () {
let str = `mindmap
const str = `mindmap
root
child1
leaf1
Expand All @@ -58,40 +59,27 @@ describe('when parsing a mindmap ', function () {
expect(mm.children[1].descr).toEqual('child2');
});
it('5 Multiple roots are illegal', function () {
let str = `mindmap
const str = `mindmap
root
fakeRoot`;

try {
mindmap.parse(str);
// Fail test if above expression doesn't throw anything.
expect(true).toBe(false);
} catch (e) {
expect(e.message).toBe(
'There can be only one root. No parent could be found for ("fakeRoot")'
);
}
expect(() => mindmap.parse(str)).toThrow(
'There can be only one root. No parent could be found for ("fakeRoot")'
);
});
it('MMP-6 real root in wrong place', function () {
let str = `mindmap
const str = `mindmap
root
fakeRoot
realRootWrongPlace`;

try {
mindmap.parse(str);
// Fail test if above expression doesn't throw anything.
expect(true).toBe(false);
} catch (e) {
expect(e.message).toBe(
'There can be only one root. No parent could be found for ("fakeRoot")'
);
}
expect(() => mindmap.parse(str)).toThrow(
'There can be only one root. No parent could be found for ("fakeRoot")'
);
});
});
describe('nodes', function () {
it('MMP-7 should handle an id and type for a node definition', function () {
let str = `mindmap
const str = `mindmap
root[The root]
`;

Expand All @@ -102,7 +90,7 @@ describe('when parsing a mindmap ', function () {
expect(mm.type).toEqual(mindmap.yy.nodeType.RECT);
});
it('MMP-8 should handle an id and type for a node definition', function () {
let str = `mindmap
const str = `mindmap
root
theId(child1)`;

Expand All @@ -116,7 +104,7 @@ describe('when parsing a mindmap ', function () {
expect(child.type).toEqual(mindmap.yy.nodeType.ROUNDED_RECT);
});
it('MMP-9 should handle an id and type for a node definition', function () {
let str = `mindmap
const str = `mindmap
root
theId(child1)`;

Expand All @@ -130,7 +118,7 @@ root
expect(child.type).toEqual(mindmap.yy.nodeType.ROUNDED_RECT);
});
it('MMP-10 multiple types (circle)', function () {
let str = `mindmap
const str = `mindmap
root((the root))
`;

Expand All @@ -142,7 +130,7 @@ root
});

it('MMP-11 multiple types (cloud)', function () {
let str = `mindmap
const str = `mindmap
root)the root(
`;

Expand All @@ -153,7 +141,7 @@ root
expect(mm.type).toEqual(mindmap.yy.nodeType.CLOUD);
});
it('MMP-12 multiple types (bang)', function () {
let str = `mindmap
const str = `mindmap
root))the root((
`;

Expand All @@ -165,7 +153,7 @@ root
});

it('MMP-12-a multiple types (hexagon)', function () {
let str = `mindmap
const str = `mindmap
root{{the root}}
`;

Expand All @@ -178,7 +166,7 @@ root
});
describe('decorations', function () {
it('MMP-13 should be possible to set an icon for the node', function () {
let str = `mindmap
const str = `mindmap
root[The root]
::icon(bomb)
`;
Expand All @@ -192,7 +180,7 @@ root
expect(mm.icon).toEqual('bomb');
});
it('MMP-14 should be possible to set classes for the node', function () {
let str = `mindmap
const str = `mindmap
root[The root]
:::m-4 p-8
`;
Expand All @@ -206,7 +194,7 @@ root
expect(mm.class).toEqual('m-4 p-8');
});
it('MMP-15 should be possible to set both classes and icon for the node', function () {
let str = `mindmap
const str = `mindmap
root[The root]
:::m-4 p-8
::icon(bomb)
Expand All @@ -222,7 +210,7 @@ root
expect(mm.icon).toEqual('bomb');
});
it('MMP-16 should be possible to set both classes and icon for the node', function () {
let str = `mindmap
const str = `mindmap
root[The root]
::icon(bomb)
:::m-4 p-8
Expand All @@ -240,7 +228,7 @@ root
});
describe('descriptions', function () {
it('MMP-17 should be possible to use node syntax in the descriptions', function () {
let str = `mindmap
const str = `mindmap
root["String containing []"]
`;
mindmap.parse(str);
Expand All @@ -249,7 +237,7 @@ root
expect(mm.descr).toEqual('String containing []');
});
it('MMP-18 should be possible to use node syntax in the descriptions in children', function () {
let str = `mindmap
const str = `mindmap
root["String containing []"]
child1["String containing ()"]
`;
Expand All @@ -261,7 +249,7 @@ root
expect(mm.children[0].descr).toEqual('String containing ()');
});
it('MMP-19 should be possible to have a child after a class assignment', function () {
let str = `mindmap
const str = `mindmap
root(Root)
Child(Child)
:::hot
Expand All @@ -281,7 +269,7 @@ root
});
});
it('MMP-20 should be possible to have meaningless empty rows in a mindmap abc124', function () {
let str = `mindmap
const str = `mindmap
root(Root)
Child(Child)
a(a)
Expand All @@ -300,7 +288,7 @@ root
expect(child.children[1].nodeId).toEqual('b');
});
it('MMP-21 should be possible to have comments in a mindmap', function () {
let str = `mindmap
const str = `mindmap
root(Root)
Child(Child)
a(a)
Expand All @@ -321,7 +309,7 @@ root
});

it('MMP-22 should be possible to have comments at the end of a line', function () {
let str = `mindmap
const str = `mindmap
root(Root)
Child(Child)
a(a) %% This is a comment
Expand All @@ -339,7 +327,7 @@ root
expect(child.children[1].nodeId).toEqual('b');
});
it('MMP-23 Rows with only spaces should not interfere', function () {
let str = 'mindmap\nroot\n A\n \n\n B';
const str = 'mindmap\nroot\n A\n \n\n B';
mindmap.parse(str);
const mm = mindmap.yy.getMindmap();
expect(mm.nodeId).toEqual('root');
Expand All @@ -351,7 +339,7 @@ root
expect(child2.nodeId).toEqual('B');
});
it('MMP-24 Handle rows above the mindmap declarations', function () {
let str = '\n \nmindmap\nroot\n A\n \n\n B';
const str = '\n \nmindmap\nroot\n A\n \n\n B';
mindmap.parse(str);
const mm = mindmap.yy.getMindmap();
expect(mm.nodeId).toEqual('root');
Expand All @@ -363,7 +351,7 @@ root
expect(child2.nodeId).toEqual('B');
});
it('MMP-25 Handle rows above the mindmap declarations, no space', function () {
let str = '\n\n\nmindmap\nroot\n A\n \n\n B';
const str = '\n\n\nmindmap\nroot\n A\n \n\n B';
mindmap.parse(str);
const mm = mindmap.yy.getMindmap();
expect(mm.nodeId).toEqual('root');
Expand Down