mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-02-04 07:13:25 +08:00
Merge pull request #1730 from mermaid-js/1726_graphDef_linkStyle
1726 graph def link style
This commit is contained in:
commit
15f8856f92
@ -324,5 +324,27 @@ end
|
|||||||
{htmlLabels: true, flowchart: {htmlLabels: true}, securityLevel: 'loose'}
|
{htmlLabels: true, flowchart: {htmlLabels: true}, securityLevel: 'loose'}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('59: handle styling of subgraphs and links', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
flowchart TD
|
||||||
|
A[Christmas] ==> D
|
||||||
|
A[Christmas] -->|Get money| B(Go shopping)
|
||||||
|
A[Christmas] ==> C
|
||||||
|
subgraph T ["Test"]
|
||||||
|
A
|
||||||
|
B
|
||||||
|
C
|
||||||
|
end
|
||||||
|
|
||||||
|
classDef Test fill:#F84E68,stroke:#333,color:white;
|
||||||
|
class A,T Test
|
||||||
|
classDef TestSub fill:green;
|
||||||
|
class T TestSub
|
||||||
|
linkStyle 0,1 color:orange, stroke: orange;
|
||||||
|
`,
|
||||||
|
{htmlLabels: true, flowchart: {htmlLabels: true}, securityLevel: 'loose'}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -22,29 +22,40 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>info below</h1>
|
<h1>info below</h1>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div class="mermaid2" style="width: 50%; height: 400px;">
|
<div class="mermaid" style="width: 50%; height: 400px;">
|
||||||
flowchart TD
|
graph TD
|
||||||
subgraph main
|
A[Christmas] ==> D
|
||||||
subgraph subcontainer
|
A[Christmas] -->|Get money| B(Go shopping)
|
||||||
subcontainer-child
|
A[Christmas] ==> C
|
||||||
end
|
subgraph T ["Test"]
|
||||||
subcontainer-child--> subcontainer-sibling
|
A
|
||||||
|
B
|
||||||
|
C
|
||||||
end
|
end
|
||||||
|
classDef Test fill:#F84E68,stroke:#333,color:white;
|
||||||
|
class A,T Test
|
||||||
|
classDef TestSub fill:green;
|
||||||
|
class T TestSub
|
||||||
|
linkStyle 0,1 color:orange, stroke: orange;
|
||||||
</div>
|
</div>
|
||||||
<div class="mermaid" style="width: 50%; height: 400px;">
|
<div class="mermaid" style="width: 50%; height: 400px;">
|
||||||
flowchart TB
|
flowchart TD
|
||||||
b-->B
|
A[Christmas] ==> D
|
||||||
a-->c
|
A[Christmas] -->|Get money| B(Go shopping)
|
||||||
subgraph B
|
A[Christmas] ==> C
|
||||||
c
|
subgraph T ["Test"]
|
||||||
end
|
A
|
||||||
subgraph A
|
|
||||||
a
|
|
||||||
b
|
|
||||||
B
|
B
|
||||||
|
C
|
||||||
end
|
end
|
||||||
|
|
||||||
|
classDef Test fill:#F84E68,stroke:#333,color:white;
|
||||||
|
class A,T Test
|
||||||
|
classDef TestSub fill:green;
|
||||||
|
class T TestSub
|
||||||
|
linkStyle 0,1 color:orange, stroke: orange;
|
||||||
</div>
|
</div>
|
||||||
<div class="mermaid" style="width: 50%; height: 20%;">
|
<div class="mermaid2" style="width: 50%; height: 20%;">
|
||||||
flowchart TB
|
flowchart TB
|
||||||
subgraph A
|
subgraph A
|
||||||
a -->b
|
a -->b
|
||||||
|
@ -10,7 +10,7 @@ const rect = (parent, node) => {
|
|||||||
// Add outer g element
|
// Add outer g element
|
||||||
const shapeSvg = parent
|
const shapeSvg = parent
|
||||||
.insert('g')
|
.insert('g')
|
||||||
.attr('class', 'cluster')
|
.attr('class', 'cluster' + (node.class ? ' ' + node.class : ''))
|
||||||
.attr('id', node.id);
|
.attr('id', node.id);
|
||||||
|
|
||||||
// add the rect
|
// add the rect
|
||||||
|
@ -86,7 +86,8 @@ const createLabel = (_vertexText, style, isTitle, isNode) => {
|
|||||||
label: vertexText.replace(
|
label: vertexText.replace(
|
||||||
/fa[lrsb]?:fa-[\w-]+/g,
|
/fa[lrsb]?:fa-[\w-]+/g,
|
||||||
s => `<i class='${s.replace(':', ' ')}'></i>`
|
s => `<i class='${s.replace(':', ' ')}'></i>`
|
||||||
)
|
),
|
||||||
|
labelStyle: style.replace('fill:', 'color:')
|
||||||
};
|
};
|
||||||
let vertexNode = addHtmlLabel(node);
|
let vertexNode = addHtmlLabel(node);
|
||||||
// vertexNode.parentNode.removeChild(vertexNode);
|
// vertexNode.parentNode.removeChild(vertexNode);
|
||||||
|
@ -387,7 +387,8 @@ export const insertEdge = function(elem, e, edge, clusterDb, diagramType, graph)
|
|||||||
.append('path')
|
.append('path')
|
||||||
.attr('d', lineFunction(lineData))
|
.attr('d', lineFunction(lineData))
|
||||||
.attr('id', edge.id)
|
.attr('id', edge.id)
|
||||||
.attr('class', ' ' + strokeClasses + (edge.classes ? ' ' + edge.classes : ''));
|
.attr('class', ' ' + strokeClasses + (edge.classes ? ' ' + edge.classes : ''))
|
||||||
|
.attr('style', edge.style);
|
||||||
|
|
||||||
// DEBUG code, adds a red circle at each edge coordinate
|
// DEBUG code, adds a red circle at each edge coordinate
|
||||||
// edge.points.forEach(point => {
|
// edge.points.forEach(point => {
|
||||||
|
@ -193,7 +193,7 @@ export const addEdges = function(edges, g) {
|
|||||||
var linkNameStart = 'LS-' + edge.start;
|
var linkNameStart = 'LS-' + edge.start;
|
||||||
var linkNameEnd = 'LE-' + edge.end;
|
var linkNameEnd = 'LE-' + edge.end;
|
||||||
|
|
||||||
const edgeData = {};
|
const edgeData = { style: '', labelStyle: '' };
|
||||||
edgeData.minlen = edge.length || 1;
|
edgeData.minlen = edge.length || 1;
|
||||||
//edgeData.id = 'id' + cnt;
|
//edgeData.id = 'id' + cnt;
|
||||||
|
|
||||||
@ -227,23 +227,12 @@ export const addEdges = function(edges, g) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// logger.info('apa', edgeData, edge);
|
|
||||||
// edgeData.arrowTypeStart = edge.arrowTypeStart;
|
|
||||||
// edgeData.arrowTypeStart = edge.arrowTypeStart;
|
|
||||||
// edgeData.arrowType = edgeData.arrowTypeEnd;
|
|
||||||
// logger.info('apa', edgeData, edge);
|
|
||||||
|
|
||||||
let style = '';
|
let style = '';
|
||||||
let labelStyle = '';
|
let labelStyle = '';
|
||||||
|
|
||||||
if (typeof edge.style !== 'undefined') {
|
|
||||||
const styles = getStylesFromArray(edge.style);
|
|
||||||
style = styles.style;
|
|
||||||
labelStyle = styles.labelStyle;
|
|
||||||
} else {
|
|
||||||
switch (edge.stroke) {
|
switch (edge.stroke) {
|
||||||
case 'normal':
|
case 'normal':
|
||||||
style = 'fill:none';
|
style = 'fill:none;';
|
||||||
if (typeof defaultStyle !== 'undefined') {
|
if (typeof defaultStyle !== 'undefined') {
|
||||||
style = defaultStyle;
|
style = defaultStyle;
|
||||||
}
|
}
|
||||||
@ -256,16 +245,22 @@ export const addEdges = function(edges, g) {
|
|||||||
case 'dotted':
|
case 'dotted':
|
||||||
edgeData.thickness = 'normal';
|
edgeData.thickness = 'normal';
|
||||||
edgeData.pattern = 'dotted';
|
edgeData.pattern = 'dotted';
|
||||||
|
edgeData.style = 'fill:none;stroke-width:2px;stroke-dasharray:3;';
|
||||||
break;
|
break;
|
||||||
case 'thick':
|
case 'thick':
|
||||||
edgeData.thickness = 'thick';
|
edgeData.thickness = 'thick';
|
||||||
edgeData.pattern = 'solid';
|
edgeData.pattern = 'solid';
|
||||||
|
edgeData.style = 'stroke-width: 3.5px;fill:none;';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (typeof edge.style !== 'undefined') {
|
||||||
|
const styles = getStylesFromArray(edge.style);
|
||||||
|
style = styles.style;
|
||||||
|
labelStyle = styles.labelStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeData.style = style;
|
edgeData.style = edgeData.style += style;
|
||||||
edgeData.labelStyle = labelStyle;
|
edgeData.labelStyle = edgeData.labelStyle += labelStyle;
|
||||||
|
|
||||||
if (typeof edge.interpolate !== 'undefined') {
|
if (typeof edge.interpolate !== 'undefined') {
|
||||||
edgeData.curve = interpolateToCurve(edge.interpolate, curveLinear);
|
edgeData.curve = interpolateToCurve(edge.interpolate, curveLinear);
|
||||||
@ -282,21 +277,21 @@ export const addEdges = function(edges, g) {
|
|||||||
} else {
|
} else {
|
||||||
edgeData.arrowheadStyle = 'fill: #333';
|
edgeData.arrowheadStyle = 'fill: #333';
|
||||||
edgeData.labelpos = 'c';
|
edgeData.labelpos = 'c';
|
||||||
|
}
|
||||||
if (getConfig().flowchart.htmlLabels && false) { // eslint-disable-line
|
// if (getConfig().flowchart.htmlLabels && false) {
|
||||||
edgeData.labelType = 'html';
|
// // eslint-disable-line
|
||||||
edgeData.label = `<span id="L-${linkId}" class="edgeLabel L-${linkNameStart}' L-${linkNameEnd}">${edge.text}</span>`;
|
// edgeData.labelType = 'html';
|
||||||
} else {
|
// edgeData.label = `<span id="L-${linkId}" class="edgeLabel L-${linkNameStart}' L-${linkNameEnd}">${edge.text}</span>`;
|
||||||
|
// } else {
|
||||||
edgeData.labelType = 'text';
|
edgeData.labelType = 'text';
|
||||||
edgeData.label = edge.text.replace(common.lineBreakRegex, '\n');
|
edgeData.label = edge.text.replace(common.lineBreakRegex, '\n');
|
||||||
|
|
||||||
if (typeof edge.style === 'undefined') {
|
if (typeof edge.style === 'undefined') {
|
||||||
edgeData.style = edgeData.style || 'stroke: #333; stroke-width: 1.5px;fill:none';
|
edgeData.style = edgeData.style || 'stroke: #333; stroke-width: 1.5px;fill:none;';
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeData.labelStyle = edgeData.labelStyle.replace('color:', 'fill:');
|
edgeData.labelStyle = edgeData.labelStyle.replace('color:', 'fill:');
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
edgeData.id = linkId;
|
edgeData.id = linkId;
|
||||||
edgeData.classes = 'flowchart-link ' + linkNameStart + ' ' + linkNameEnd;
|
edgeData.classes = 'flowchart-link ' + linkNameStart + ' ' + linkNameEnd;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user