mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 23:09:49 +02:00
Adding circle node type and class handling
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
|
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||||
<link href="https://fonts.googleapis.com/css?family=Noto+Sans+SC&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Noto+Sans+SC&display=swap" rel="stylesheet">
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@6.9.96/css/materialdesignicons.min.css" rel="stylesheet">
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
/* background: rgb(221, 208, 208); */
|
/* background: rgb(221, 208, 208); */
|
||||||
@@ -93,8 +94,9 @@ mindmap
|
|||||||
Child3(Child 3 has a long wrapped text as well)
|
Child3(Child 3 has a long wrapped text as well)
|
||||||
GrandChild3
|
GrandChild3
|
||||||
GrandChild4
|
GrandChild4
|
||||||
Child4
|
Child4((Child Num 4<br>with<br>wrap text))
|
||||||
GrandChild5
|
GrandChild5[With icon]
|
||||||
|
:::(mdi mdi-numeric-8-circle)
|
||||||
GrandChild6
|
GrandChild6
|
||||||
Child1
|
Child1
|
||||||
GrandChild1
|
GrandChild1
|
||||||
@@ -102,7 +104,9 @@ mindmap
|
|||||||
sc2
|
sc2
|
||||||
sc3
|
sc3
|
||||||
GrandChild2
|
GrandChild2
|
||||||
Child5
|
Child5((Child5))
|
||||||
|
:::disabled
|
||||||
|
|
||||||
GrandChild7
|
GrandChild7
|
||||||
sc1
|
sc1
|
||||||
sc2
|
sc2
|
||||||
|
@@ -1820,7 +1820,7 @@ const config = {
|
|||||||
},
|
},
|
||||||
mindmap: {
|
mindmap: {
|
||||||
useMaxWidth: true,
|
useMaxWidth: true,
|
||||||
padding: 50,
|
padding: 10,
|
||||||
maxNodeWidth: 200,
|
maxNodeWidth: 200,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@@ -28,6 +28,7 @@ export const getMindmap = () => {
|
|||||||
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) => {
|
||||||
|
const conf = getConfig();
|
||||||
const node = {
|
const node = {
|
||||||
id: cnt++,
|
id: cnt++,
|
||||||
nodeId: sanitizeText(id),
|
nodeId: sanitizeText(id),
|
||||||
@@ -37,6 +38,16 @@ export const addNode = (level, id, descr, type) => {
|
|||||||
children: [],
|
children: [],
|
||||||
width: getConfig().mindmap.maxNodeWidth,
|
width: getConfig().mindmap.maxNodeWidth,
|
||||||
};
|
};
|
||||||
|
switch (node.type) {
|
||||||
|
case nodeType.ROUNDED_RECT:
|
||||||
|
node.padding = 2 * conf.mindmap.padding;
|
||||||
|
break;
|
||||||
|
case nodeType.RECT:
|
||||||
|
node.padding = 2 * conf.mindmap.padding;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
node.padding = conf.mindmap.padding;
|
||||||
|
}
|
||||||
const parent = getParent(level);
|
const parent = getParent(level);
|
||||||
if (parent) {
|
if (parent) {
|
||||||
parent.children.push(node);
|
parent.children.push(node);
|
||||||
|
@@ -15,7 +15,7 @@ const genSections = (options) => {
|
|||||||
for (let i = 1; i < 8; i++) {
|
for (let i = 1; 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} rect, .section-${i - 1} path, .section-${i - 1} circle {
|
||||||
fill: ${options['git' + i]};
|
fill: ${options['git' + i]};
|
||||||
}
|
}
|
||||||
.section-${i - 1} text {
|
.section-${i - 1} text {
|
||||||
@@ -31,6 +31,13 @@ const genSections = (options) => {
|
|||||||
stroke: ${options['lineColor' + i]} ;
|
stroke: ${options['lineColor' + i]} ;
|
||||||
stroke-width: 3;
|
stroke-width: 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.disabled, .disabled circle, .disabled text {
|
||||||
|
fill: lightgray;
|
||||||
|
}
|
||||||
|
.disabled text {
|
||||||
|
fill: #efefef;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
return sections;
|
return sections;
|
||||||
|
@@ -78,14 +78,22 @@ const rectBkg = function (elem, node, section, conf) {
|
|||||||
.attr('height', node.height)
|
.attr('height', node.height)
|
||||||
.attr('width', node.width);
|
.attr('width', node.width);
|
||||||
};
|
};
|
||||||
|
const circleBkg = function (elem, node, section, conf) {
|
||||||
|
const r = elem
|
||||||
|
.append('circle')
|
||||||
|
.attr('id', 'node-' + node.id)
|
||||||
|
.attr('class', 'node-bkg node-' + db.type2Str(node.type))
|
||||||
|
.attr('r', node.width / 2);
|
||||||
|
// .attr('width', node.width);
|
||||||
|
};
|
||||||
const roundedRectBkg = function (elem, node, section, conf) {
|
const roundedRectBkg = function (elem, node, section, conf) {
|
||||||
const r = elem
|
const r = elem
|
||||||
.append('rect')
|
.append('rect')
|
||||||
.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('height', node.height)
|
||||||
.attr('rx', conf.mindmap.padding)
|
.attr('rx', node.padding)
|
||||||
.attr('ry', conf.mindmap.padding)
|
.attr('ry', node.padding)
|
||||||
.attr('width', node.width);
|
.attr('width', node.width);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -100,7 +108,9 @@ export const drawNode = function (elem, node, section, conf) {
|
|||||||
const nodeElem = elem.append('g');
|
const nodeElem = elem.append('g');
|
||||||
nodeElem.attr(
|
nodeElem.attr(
|
||||||
'class',
|
'class',
|
||||||
'mindmap-node ' + (section === -1 ? 'section-root' : 'section-' + section)
|
(node.class ? node.class + ' ' : '') +
|
||||||
|
'mindmap-node ' +
|
||||||
|
(section === -1 ? 'section-root' : 'section-' + section)
|
||||||
);
|
);
|
||||||
const bkgElem = nodeElem.append('g');
|
const bkgElem = nodeElem.append('g');
|
||||||
|
|
||||||
@@ -116,12 +126,14 @@ export const drawNode = function (elem, node, section, conf) {
|
|||||||
.attr('text-anchor', 'middle')
|
.attr('text-anchor', 'middle')
|
||||||
.call(wrap, node.width);
|
.call(wrap, node.width);
|
||||||
const bbox = txt.node().getBBox();
|
const bbox = txt.node().getBBox();
|
||||||
node.height = bbox.height + conf.fontSize * 1.1 * 0.5 + conf.mindmap.padding;
|
node.height = bbox.height + conf.fontSize * 1.1 * 0.5 + node.padding;
|
||||||
node.width = bbox.width + 2 * conf.mindmap.padding;
|
node.width = bbox.width + 2 * node.padding;
|
||||||
|
|
||||||
// textElem.attr('transform', 'translate(' + node.width / 2 + ', ' + node.height / 2 + ')');
|
// textElem.attr('transform', 'translate(' + node.width / 2 + ', ' + node.height / 2 + ')');
|
||||||
textElem.attr('transform', 'translate(' + node.width / 2 + ', ' + conf.mindmap.padding / 2 + ')');
|
textElem.attr('transform', 'translate(' + node.width / 2 + ', ' + node.padding / 2 + ')');
|
||||||
|
{
|
||||||
|
/* <i class="mdi mdi-arrange-bring-to-front"></i> */
|
||||||
|
}
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
case db.nodeType.DEFAULT:
|
case db.nodeType.DEFAULT:
|
||||||
defaultBkg(bkgElem, node, section, conf);
|
defaultBkg(bkgElem, node, section, conf);
|
||||||
@@ -133,7 +145,8 @@ export const drawNode = function (elem, node, section, conf) {
|
|||||||
rectBkg(bkgElem, node, section, conf);
|
rectBkg(bkgElem, node, section, conf);
|
||||||
break;
|
break;
|
||||||
case db.nodeType.CIRCLE:
|
case db.nodeType.CIRCLE:
|
||||||
rectBkg(bkgElem, node, section, conf);
|
bkgElem.attr('transform', 'translate(' + node.width / 2 + ', ' + +node.height / 2 + ')');
|
||||||
|
circleBkg(bkgElem, node, section, conf);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// defaultBkg(bkgElem, node, section, conf);
|
// defaultBkg(bkgElem, node, section, conf);
|
||||||
|
Reference in New Issue
Block a user