mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-24 17:59:39 +02:00
add line interpolation to linkStyle in flowchart
This commit is contained in:
@@ -151,23 +151,22 @@ exports.addVertices = function (vert, g) {
|
||||
*/
|
||||
exports.addEdges = function (edges, g) {
|
||||
var cnt=0;
|
||||
var aHead;
|
||||
|
||||
var defaultStyle;
|
||||
if(typeof edges.defaultStyle !== 'undefined'){
|
||||
defaultStyle = edges.defaultStyle.toString().replace(/,/g , ';');
|
||||
|
||||
}
|
||||
|
||||
edges.forEach(function (edge) {
|
||||
cnt++;
|
||||
var edgeData = {};
|
||||
|
||||
// Set link type for rendering
|
||||
if(edge.type === 'arrow_open'){
|
||||
aHead = 'none';
|
||||
edgeData.arrowhead = 'none';
|
||||
}
|
||||
else{
|
||||
aHead = 'normal';
|
||||
edgeData.arrowhead = 'normal';
|
||||
}
|
||||
|
||||
var style = '';
|
||||
@@ -194,32 +193,38 @@ exports.addEdges = function (edges, g) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
edgeData.style = style;
|
||||
|
||||
if (typeof edge.interpolate !== 'undefined') {
|
||||
edgeData.lineInterpolate = edge.interpolate;
|
||||
} else {
|
||||
if (typeof edges.defaultInterpolate !== 'undefined') {
|
||||
edgeData.lineInterpolate = edges.defaultInterpolate;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the edge to the graph
|
||||
if (typeof edge.text === 'undefined') {
|
||||
if(typeof edge.style === 'undefined'){
|
||||
g.setEdge(edge.start, edge.end,{ style: style, arrowhead: aHead},cnt);
|
||||
}else{
|
||||
g.setEdge(edge.start, edge.end, {
|
||||
style: style, arrowheadStyle: 'fill: #333', arrowhead: aHead
|
||||
},cnt);
|
||||
if (typeof edge.style !== 'undefined') {
|
||||
edgeData.arrowheadStyle = 'fill: #333';
|
||||
}
|
||||
}
|
||||
// Edge with text
|
||||
else {
|
||||
var edgeText = edge.text.replace(/<br>/g, '\n');
|
||||
if(typeof edge.style === 'undefined'){
|
||||
if (conf.htmlLabels){
|
||||
g.setEdge(edge.start, edge.end,{labelType: 'html',style: style, labelpos:'c', label: '<span class="edgeLabel">'+edge.text+'</span>', arrowheadStyle: 'fill: #333', arrowhead: aHead},cnt);
|
||||
}else{
|
||||
g.setEdge(edge.start, edge.end,{labelType: 'text', style: 'stroke: #333; stroke-width: 1.5px;fill:none', labelpos:'c', label: edgeText, arrowheadStyle: 'fill: #333', arrowhead: aHead},cnt);
|
||||
} else {
|
||||
edgeData.arrowheadStyle = 'fill: #333';
|
||||
if(typeof edge.style === 'undefined') {
|
||||
edgeData.labelpos = 'c';
|
||||
if (conf.htmlLabels) {
|
||||
edgeData.labelType = 'html';
|
||||
edgeData.label = '<span class="edgeLabel">'+edge.text+'</span>';
|
||||
} else {
|
||||
edgeData.labelType = 'text';
|
||||
edgeData.style = 'stroke: #333; stroke-width: 1.5px;fill:none';
|
||||
edgeData.label = edge.text.replace(/<br>/g, '\n');
|
||||
}
|
||||
}else{
|
||||
g.setEdge(edge.start, edge.end, {
|
||||
labelType: 'text', style: style, arrowheadStyle: 'fill: #333', label: edgeText, arrowhead: aHead
|
||||
},cnt);
|
||||
} else {
|
||||
edgeData.label = edge.text.replace(/<br>/g, '\n');
|
||||
}
|
||||
}
|
||||
// Add the edge to the graph
|
||||
g.setEdge(edge.start, edge.end, edgeData, cnt);
|
||||
});
|
||||
};
|
||||
|
||||
|
@@ -86,6 +86,20 @@ exports.addLink = function (start, end, type, linktext) {
|
||||
}
|
||||
edges.push(edge);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates a link's line interpolation algorithm
|
||||
* @param pos
|
||||
* @param interpolate
|
||||
*/
|
||||
exports.updateLinkInterpolate = function (pos, interp) {
|
||||
if(pos === 'default'){
|
||||
edges.defaultInterpolate = interp;
|
||||
}else{
|
||||
edges[pos].interpolate = interp;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates a link with a style
|
||||
* @param pos
|
||||
|
@@ -16,6 +16,7 @@
|
||||
"style" return 'STYLE';
|
||||
"default" return 'DEFAULT';
|
||||
"linkStyle" return 'LINKSTYLE';
|
||||
"interpolate" return 'INTERPOLATE';
|
||||
"classDef" return 'CLASSDEF';
|
||||
"class" return 'CLASS';
|
||||
"click" return 'CLICK';
|
||||
@@ -412,6 +413,14 @@ linkStyleStatement
|
||||
{$$ = $1;yy.updateLink($3,$5);}
|
||||
| LINKSTYLE SPACE NUM SPACE stylesOpt
|
||||
{$$ = $1;yy.updateLink($3,$5);}
|
||||
| LINKSTYLE SPACE DEFAULT SPACE INTERPOLATE SPACE alphaNum SPACE stylesOpt
|
||||
{$$ = $1;yy.updateLinkInterpolate($3,$7);yy.updateLink($3,$9);}
|
||||
| LINKSTYLE SPACE NUM SPACE INTERPOLATE SPACE alphaNum SPACE stylesOpt
|
||||
{$$ = $1;yy.updateLinkInterpolate($3,$7);yy.updateLink($3,$9);}
|
||||
| LINKSTYLE SPACE DEFAULT SPACE INTERPOLATE SPACE alphaNum
|
||||
{$$ = $1;yy.updateLinkInterpolate($3,$7);}
|
||||
| LINKSTYLE SPACE NUM SPACE INTERPOLATE SPACE alphaNum
|
||||
{$$ = $1;yy.updateLinkInterpolate($3,$7);}
|
||||
;
|
||||
|
||||
commentStatement: PCT PCT commentText;
|
||||
|
File diff suppressed because one or more lines are too long
@@ -455,6 +455,58 @@ describe('when parsing ',function(){
|
||||
expect(edges[0].type).toBe('arrow');
|
||||
});
|
||||
|
||||
it('should handle line interpolation default definitions',function(){
|
||||
var res = flow.parser.parse('graph TD\n' +
|
||||
'A-->B\n' +
|
||||
'linkStyle default interpolate basis');
|
||||
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
|
||||
|
||||
expect(edges.defaultInterpolate).toBe('basis');
|
||||
});
|
||||
|
||||
it('should handle line interpolation numbered definitions',function(){
|
||||
var res = flow.parser.parse('graph TD\n' +
|
||||
'A-->B\n' +
|
||||
'A-->C\n' +
|
||||
'linkStyle 0 interpolate basis\n' +
|
||||
'linkStyle 1 interpolate cardinal');
|
||||
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
|
||||
expect(edges[0].interpolate).toBe('basis');
|
||||
expect(edges[1].interpolate).toBe('cardinal');
|
||||
});
|
||||
|
||||
it('should handle line interpolation default with style',function(){
|
||||
var res = flow.parser.parse('graph TD\n' +
|
||||
'A-->B\n' +
|
||||
'linkStyle default interpolate basis stroke-width:1px;');
|
||||
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
|
||||
|
||||
expect(edges.defaultInterpolate).toBe('basis');
|
||||
});
|
||||
|
||||
it('should handle line interpolation numbered with style',function(){
|
||||
var res = flow.parser.parse('graph TD\n' +
|
||||
'A-->B\n' +
|
||||
'A-->C\n' +
|
||||
'linkStyle 0 interpolate basis stroke-width:1px;\n' +
|
||||
'linkStyle 1 interpolate cardinal stroke-width:1px;');
|
||||
|
||||
var vert = flow.parser.yy.getVertices();
|
||||
var edges = flow.parser.yy.getEdges();
|
||||
|
||||
expect(edges[0].interpolate).toBe('basis');
|
||||
expect(edges[1].interpolate).toBe('cardinal');
|
||||
});
|
||||
|
||||
describe('it should handle interaction, ',function(){
|
||||
|
||||
it('it should be possible to use click to a callback',function(){
|
||||
|
Reference in New Issue
Block a user