mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-07 17:46:44 +02:00
Updated with cloud and bang shapes
This commit is contained in:
@@ -38,6 +38,32 @@ root[root]
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Blang and cloud shape', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`mindmap
|
||||||
|
root))bang((
|
||||||
|
::icon(mdi mdi-fire)
|
||||||
|
a))Another bang((
|
||||||
|
::icon(mdi mdi-fire)
|
||||||
|
a)A cloud(
|
||||||
|
::icon(mdi mdi-fire)
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Blang and cloud shape with icons', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`mindmap
|
||||||
|
root))bang((
|
||||||
|
|
||||||
|
a))Another bang((
|
||||||
|
a)A cloud(
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('braches', () => {
|
it('braches', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`mindmap
|
`mindmap
|
||||||
|
@@ -97,14 +97,15 @@ mindmap
|
|||||||
</div>
|
</div>
|
||||||
<div class="mermaid2" style="width: 50%;">
|
<div class="mermaid2" style="width: 50%;">
|
||||||
mindmap
|
mindmap
|
||||||
root[
|
root))
|
||||||
The root where the things
|
The root where the things
|
||||||
hap<br/>
|
hap<br/>
|
||||||
hap<br/>
|
hap<br/>
|
||||||
pen!
|
pen!
|
||||||
]
|
((
|
||||||
|
::icon(mdi mdi-alarm)
|
||||||
Child1
|
Child1
|
||||||
child2[
|
child2)
|
||||||
Child2<br/>
|
Child2<br/>
|
||||||
The second<br/>
|
The second<br/>
|
||||||
The second<br/>
|
The second<br/>
|
||||||
@@ -113,7 +114,7 @@ mindmap
|
|||||||
The second<br/>
|
The second<br/>
|
||||||
The second<br/>
|
The second<br/>
|
||||||
The second<br/>
|
The second<br/>
|
||||||
]
|
(
|
||||||
Other
|
Other
|
||||||
Child3
|
Child3
|
||||||
GrandChild1
|
GrandChild1
|
||||||
@@ -125,10 +126,10 @@ mindmap
|
|||||||
</div>
|
</div>
|
||||||
<div class="mermaid" style="width: 100%;">
|
<div class="mermaid" style="width: 100%;">
|
||||||
mindmap
|
mindmap
|
||||||
root))TheRoot)
|
root))I am a bang((
|
||||||
Child1)"Child1"(
|
::icon(mdi mdi-alarm)
|
||||||
Child2-)"Child2"(-
|
Child1)"Bang"(
|
||||||
Child3(-"Child3"-)
|
::icon(mdi mdi-alarm)
|
||||||
</div>
|
</div>
|
||||||
<div class="mermaid2" style="width: 100%;">
|
<div class="mermaid2" style="width: 100%;">
|
||||||
mindmap
|
mindmap
|
||||||
|
@@ -49,8 +49,6 @@ Root
|
|||||||
C
|
C
|
||||||
```
|
```
|
||||||
|
|
||||||
)sdlfkjlsd(
|
|
||||||
|
|
||||||
In this way we can use a text outline to generate a hierarchical mindmap.
|
In this way we can use a text outline to generate a hierarchical mindmap.
|
||||||
|
|
||||||
## Different shapes
|
## Different shapes
|
||||||
@@ -76,7 +74,18 @@ mindmap
|
|||||||
mindmap
|
mindmap
|
||||||
id((I am a circle))
|
id((I am a circle))
|
||||||
```
|
```
|
||||||
|
### Bang
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
mindmap
|
||||||
|
id))I am a bang((
|
||||||
|
```
|
||||||
|
### Cloud
|
||||||
|
|
||||||
|
```mermaid-example
|
||||||
|
mindmap
|
||||||
|
id)I am a cloud(
|
||||||
|
```
|
||||||
### Default
|
### Default
|
||||||
|
|
||||||
```mermaid-example
|
```mermaid-example
|
||||||
|
@@ -85,7 +85,6 @@ const detectType = function (text, cnf) {
|
|||||||
const k = Object.keys(detectors);
|
const k = Object.keys(detectors);
|
||||||
for (let i = 0; i < k.length; i++) {
|
for (let i = 0; i < k.length; i++) {
|
||||||
const key = k[i];
|
const key = k[i];
|
||||||
console.log('Detecting type for', key);
|
|
||||||
const dia = detectors[key];
|
const dia = detectors[key];
|
||||||
if (dia && dia.detector(text)) {
|
if (dia && dia.detector(text)) {
|
||||||
return key;
|
return key;
|
||||||
|
@@ -24,7 +24,6 @@ const getParent = function (level) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getMindmap = () => {
|
export const getMindmap = () => {
|
||||||
console.log('getMindmap', nodes[0]);
|
|
||||||
return nodes.length > 0 ? nodes[0] : null;
|
return nodes.length > 0 ? nodes[0] : null;
|
||||||
};
|
};
|
||||||
export const addNode = (level, id, descr, type) => {
|
export const addNode = (level, id, descr, type) => {
|
||||||
@@ -80,15 +79,17 @@ export const nodeType = {
|
|||||||
ROUNDED_RECT: 1,
|
ROUNDED_RECT: 1,
|
||||||
RECT: 2,
|
RECT: 2,
|
||||||
CIRCLE: 3,
|
CIRCLE: 3,
|
||||||
|
CLOUD: 4,
|
||||||
|
BANG: 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getType = (startStr, endStr) => {
|
export const getType = (startStr, endStr) => {
|
||||||
console.log('In get type', startStr, endStr);
|
log.debug('In get type', startStr, endStr);
|
||||||
switch (startStr) {
|
switch (startStr) {
|
||||||
case '[':
|
case '[':
|
||||||
return nodeType.RECT;
|
return nodeType.RECT;
|
||||||
case '(':
|
case '(':
|
||||||
return nodeType.ROUNDED_RECT;
|
return endStr === ')' ? nodeType.ROUNDED_RECT : nodeType.CLOUD;
|
||||||
case '((':
|
case '((':
|
||||||
return nodeType.CIRCLE;
|
return nodeType.CIRCLE;
|
||||||
case ')':
|
case ')':
|
||||||
@@ -105,7 +106,6 @@ export const setElementForId = (id, element) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const decorateNode = (decoration) => {
|
export const decorateNode = (decoration) => {
|
||||||
console.log('decorateNode', decoration);
|
|
||||||
const node = nodes[nodes.length - 1];
|
const node = nodes[nodes.length - 1];
|
||||||
if (decoration && decoration.icon) {
|
if (decoration && decoration.icon) {
|
||||||
node.icon = sanitizeText(decoration.icon);
|
node.icon = sanitizeText(decoration.icon);
|
||||||
|
@@ -67,7 +67,7 @@ function transpose(mindmap) {
|
|||||||
}
|
}
|
||||||
/** @param {object} mindmap */
|
/** @param {object} mindmap */
|
||||||
function bottomToUp(mindmap) {
|
function bottomToUp(mindmap) {
|
||||||
console.log('bottomToUp', mindmap);
|
log.debug('bottomToUp', mindmap);
|
||||||
eachNode(mindmap.result, (node) => {
|
eachNode(mindmap.result, (node) => {
|
||||||
// node.y = node.y - (node.y - bb.top) * 2 - node.height;
|
// node.y = node.y - (node.y - bb.top) * 2 - node.height;
|
||||||
node.y = node.y - (node.y - 0) * 2 - node.height;
|
node.y = node.y - (node.y - 0) * 2 - node.height;
|
||||||
@@ -76,7 +76,6 @@ function bottomToUp(mindmap) {
|
|||||||
}
|
}
|
||||||
/** @param {object} mindmap The mindmap hierarchy */
|
/** @param {object} mindmap The mindmap hierarchy */
|
||||||
function rightToLeft(mindmap) {
|
function rightToLeft(mindmap) {
|
||||||
console.log('bottomToUp', mindmap);
|
|
||||||
eachNode(mindmap.result, (node) => {
|
eachNode(mindmap.result, (node) => {
|
||||||
// node.y = node.y - (node.y - bb.top) * 2 - node.height;
|
// node.y = node.y - (node.y - bb.top) * 2 - node.height;
|
||||||
node.x = node.x - (node.x - 0) * 2 - node.width;
|
node.x = node.x - (node.x - 0) * 2 - node.width;
|
||||||
@@ -90,7 +89,7 @@ function rightToLeft(mindmap) {
|
|||||||
* @param conf
|
* @param conf
|
||||||
*/
|
*/
|
||||||
function layout(mindmap, dir, conf) {
|
function layout(mindmap, dir, conf) {
|
||||||
const bb = new BoundingBox(80, 80);
|
const bb = new BoundingBox(30, 60);
|
||||||
|
|
||||||
const layout = new Layout(bb);
|
const layout = new Layout(bb);
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
@@ -114,7 +113,7 @@ function layout(mindmap, dir, conf) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const dirFromIndex = (index) => {
|
const dirFromIndex = (index) => {
|
||||||
const dirNum = index % 4;
|
const dirNum = (index + 2) % 4;
|
||||||
switch (dirNum) {
|
switch (dirNum) {
|
||||||
case 0:
|
case 0:
|
||||||
return 'LR';
|
return 'LR';
|
||||||
@@ -197,14 +196,6 @@ function layoutMindmap(node, conf) {
|
|||||||
|
|
||||||
// Merge the trees into a single tree
|
// Merge the trees into a single tree
|
||||||
const result = mergeTrees(node, trees);
|
const result = mergeTrees(node, trees);
|
||||||
|
|
||||||
// return layout(node, 'BT', conf);
|
|
||||||
// const res = layout(node, 'BT', conf);
|
|
||||||
// res.result.children = [];
|
|
||||||
// trees.forEach((tree) => {
|
|
||||||
// res.result.children.push(tree.result);
|
|
||||||
// });
|
|
||||||
console.log('Trees', trees);
|
|
||||||
eachNode;
|
eachNode;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@@ -267,9 +258,7 @@ export const draw = (text, id, version, diagObj) => {
|
|||||||
|
|
||||||
// Next step is to layout the mindmap, giving each node a position
|
// Next step is to layout the mindmap, giving each node a position
|
||||||
|
|
||||||
console.log('Before', mm);
|
|
||||||
const positionedMindmap = layoutMindmap(mm, conf);
|
const positionedMindmap = layoutMindmap(mm, conf);
|
||||||
console.log(positionedMindmap);
|
|
||||||
|
|
||||||
// After this we can draw, first the edges and the then nodes with the correct position
|
// After this we can draw, first the edges and the then nodes with the correct position
|
||||||
drawEdges(edgesElem, positionedMindmap, null, 0, -1, conf);
|
drawEdges(edgesElem, positionedMindmap, null, 0, -1, conf);
|
||||||
|
@@ -15,7 +15,9 @@ const genSections = (options) => {
|
|||||||
for (let i = 0; i < 8; i++) {
|
for (let i = 0; i < 8; i++) {
|
||||||
const sw = '' + (17 - 3 * i);
|
const sw = '' + (17 - 3 * i);
|
||||||
sections += `
|
sections += `
|
||||||
.section-${i - 1} rect, .section-${i - 1} path, .section-${i - 1} circle {
|
.section-${i - 1} rect, .section-${i - 1} path, .section-${i - 1} circle, .section-${
|
||||||
|
i - 1
|
||||||
|
} path {
|
||||||
fill: ${options['git' + i]};
|
fill: ${options['git' + i]};
|
||||||
}
|
}
|
||||||
.section-${i - 1} text {
|
.section-${i - 1} text {
|
||||||
|
@@ -79,24 +79,69 @@ const rectBkg = function (elem, node, section, conf) {
|
|||||||
.attr('width', node.width);
|
.attr('width', node.width);
|
||||||
};
|
};
|
||||||
const cloudBkg = function (elem, node, section, conf) {
|
const cloudBkg = function (elem, node, section, conf) {
|
||||||
const r = elem
|
const rd = 5;
|
||||||
.append('rect')
|
const r = elem;
|
||||||
|
const w = node.width;
|
||||||
|
const h = node.height;
|
||||||
|
const r0 = 0.1 * w;
|
||||||
|
const r1 = 0.15 * w;
|
||||||
|
const r2 = 0.25 * w;
|
||||||
|
const r3 = 0.35 * w;
|
||||||
|
const r4 = 0.2 * w;
|
||||||
|
const p = elem
|
||||||
|
.append('path')
|
||||||
.attr('id', 'node-' + node.id)
|
.attr('id', 'node-' + node.id)
|
||||||
.attr('class', 'node-bkg node-' + db.type2Str(node.type))
|
.attr('class', 'node-bkg node-' + db.type2Str(node.type))
|
||||||
.attr('height', node.height)
|
.attr(
|
||||||
.attr('rx', node.padding)
|
'd',
|
||||||
.attr('ry', node.padding)
|
`M0 0 a${r1},${r1} 0 0,1 ${w * 0.25},${-1 * w * 0.1}
|
||||||
.attr('width', node.width);
|
a${r3},${r3} 1 0,1 ${w * 0.4},${-1 * w * 0.1}
|
||||||
|
a${r2},${r2} 1 0,1 ${w * 0.35},${1 * w * 0.2}
|
||||||
|
|
||||||
|
a${r1},${r1} 1 0,1 ${w * 0.15},${1 * h * 0.35}
|
||||||
|
a${r4},${r4} 1 0,1 ${-1 * w * 0.15},${1 * h * 0.65}
|
||||||
|
|
||||||
|
a${r2},${r1} 1 0,1 ${-1 * w * 0.25},${w * 0.15}
|
||||||
|
a${r3},${r3} 1 0,1 ${-1 * w * 0.5},${0}
|
||||||
|
a${r1},${r1} 1 0,1 ${-1 * w * 0.25},${-1 * w * 0.15}
|
||||||
|
|
||||||
|
a${r1},${r1} 1 0,1 ${-1 * w * 0.1},${-1 * h * 0.35}
|
||||||
|
a${r4},${r4} 1 0,1 ${w * 0.1},${-1 * h * 0.65}
|
||||||
|
|
||||||
|
H0 V0 Z`
|
||||||
|
);
|
||||||
};
|
};
|
||||||
const bangBkg = function (elem, node, section, conf) {
|
const bangBkg = function (elem, node, section, conf) {
|
||||||
const r = elem
|
const rd = 5;
|
||||||
.append('rect')
|
const w = node.width;
|
||||||
|
const h = node.height;
|
||||||
|
const r = 0.15 * w;
|
||||||
|
const p = elem
|
||||||
|
.append('path')
|
||||||
.attr('id', 'node-' + node.id)
|
.attr('id', 'node-' + node.id)
|
||||||
.attr('class', 'node-bkg node-' + db.type2Str(node.type))
|
.attr('class', 'node-bkg node-' + db.type2Str(node.type))
|
||||||
.attr('height', node.height)
|
.attr(
|
||||||
.attr('rx', node.padding)
|
'd',
|
||||||
.attr('ry', node.padding)
|
`M0 0 a${r},${r} 1 0,0 ${w * 0.25},${-1 * h * 0.1}
|
||||||
.attr('width', node.width);
|
a${r},${r} 1 0,0 ${w * 0.25},${0}
|
||||||
|
a${r},${r} 1 0,0 ${w * 0.25},${0}
|
||||||
|
a${r},${r} 1 0,0 ${w * 0.25},${1 * h * 0.1}
|
||||||
|
|
||||||
|
a${r},${r} 1 0,0 ${w * 0.15},${1 * h * 0.33}
|
||||||
|
a${r * 0.8},${r * 0.8} 1 0,0 ${0},${1 * h * 0.34}
|
||||||
|
a${r},${r} 1 0,0 ${-1 * w * 0.15},${1 * h * 0.33}
|
||||||
|
|
||||||
|
a${r},${r} 1 0,0 ${-1 * w * 0.25},${h * 0.15}
|
||||||
|
a${r},${r} 1 0,0 ${-1 * w * 0.25},${0}
|
||||||
|
a${r},${r} 1 0,0 ${-1 * w * 0.25},${0}
|
||||||
|
a${r},${r} 1 0,0 ${-1 * w * 0.25},${-1 * h * 0.15}
|
||||||
|
|
||||||
|
a${r},${r} 1 0,0 ${-1 * w * 0.1},${-1 * h * 0.33}
|
||||||
|
a${r * 0.8},${r * 0.8} 1 0,0 ${0},${-1 * h * 0.34}
|
||||||
|
a${r},${r} 1 0,0 ${w * 0.1},${-1 * h * 0.33}
|
||||||
|
|
||||||
|
H0 V0 Z`
|
||||||
|
);
|
||||||
};
|
};
|
||||||
const circleBkg = function (elem, node, section, conf) {
|
const circleBkg = function (elem, node, section, conf) {
|
||||||
const r = elem
|
const r = elem
|
||||||
|
Reference in New Issue
Block a user