Merge remote-tracking branch 'MERMAID/develop' into docs/3418_auto_generated_comment_html_files

This commit is contained in:
Ashley Engelund (weedySeaDragon @ github) 2022-09-07 06:52:02 -07:00
commit b534a5c2ff
16 changed files with 104 additions and 107 deletions

View File

@ -17,15 +17,6 @@
* Traditional Object.assign would have clobbered foo in config_0 with foo in config_1. If src is a
* destructured array of objects and dst is not an array, assignWithDepth will apply each element
* of src to dst in order.
* @param dst
* @param src
* @param config
* @param dst
* @param src
* @param config
* @param dst
* @param src
* @param config
* @param {any} dst - The destination of the merge
* @param {any} src - The source object(s) to merge into destination
* @param {{ depth: number; clobber: boolean }} [config={ depth: 2, clobber: false }] - Depth: depth

View File

@ -163,9 +163,9 @@ export const validate = (graph) => {
};
/**
* Finds a child that is not a cluster. When faking a edge between a node and a cluster.
* Finds a child that is not a cluster. When faking an edge between a node and a cluster.
*
* @param {Finds a} id
* @param id
* @param {any} graph
*/
export const findNonClusterChild = (id, graph) => {
@ -235,7 +235,7 @@ export const adjustClustersAndEdges = (graph, depth) => {
edges.forEach((edge) => {
// log.debug('Edge, decendants: ', edge, decendants[id]);
// Check if any edge leaves the cluster (not the actual cluster, thats a link from the box)
// Check if any edge leaves the cluster (not the actual cluster, that's a link from the box)
if (edge.v !== id && edge.w !== id) {
// Any edge where either the one of the nodes is decending to the cluster but not the other
// if (decendants[id].indexOf(edge.v) < 0 && decendants[id].indexOf(edge.w) < 0) {

View File

@ -568,10 +568,9 @@ function drawInsideBoundary(diagram, parentBoundaryAlias, parentBounds, currentB
/**
* Draws a sequenceDiagram in the tag with id: id based on the graph definition in text.
*
* @param {any} text
* @param _text
* @param {any} _text
* @param {any} id
* @param _version
* @param {any} _version
* @param diagObj
*/
export const draw = function (_text, id, _version, diagObj) {

View File

@ -142,8 +142,7 @@ const insertMarkers = function (elem) {
*
* @param {string} text
* @param {string} id
* @param version
* @param _version
* @param {any} _version
* @param diagObj
*/
export const draw = function (text, id, _version, diagObj) {

View File

@ -32,7 +32,7 @@ export const setConf = function (cnf) {
* @param groupNode The svg group node for the entity
* @param entityTextNode The svg node for the entity label text
* @param attributes An array of attributes defined for the entity (each attribute has a type and a name)
* @returns The bounding box of the entity, after attributes have been added
* @returns {object} The bounding box of the entity, after attributes have been added. The bounding box has a .width and .height
*/
const drawAttributes = (groupNode, entityTextNode, attributes) => {
const heightPadding = conf.entityPadding / 3; // Padding internal to attribute boxes
@ -307,7 +307,7 @@ const drawAttributes = (groupNode, entityTextNode, attributes) => {
* @param svgNode The svg node that contains the diagram
* @param entities The entities to be drawn
* @param graph The graph that contains the vertex and edge definitions post-layout
* @returns The first entity that was inserted
* @returns {object} The first entity that was inserted
*/
const drawEntities = function (svgNode, entities, graph) {
const keys = Object.keys(entities);
@ -545,7 +545,6 @@ const drawRelationshipFromLayout = function (svg, rel, g, insert, diagObj) {
* @param text The text of the diagram
* @param id The unique id of the DOM node that contains the diagram
* @param _version
* @param diag
* @param diagObj
*/
export const draw = function (text, id, _version, diagObj) {

View File

@ -25,7 +25,6 @@ export const setConf = function (cnf) {
* @param g The graph that is to be drawn.
* @param svgId
* @param root
* @param doc
* @param _doc
* @param diagObj
*/

View File

@ -348,6 +348,21 @@ describe('when parsing a gitGraph', function () {
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
});
it('should allow branch names starting with numbers', function () {
const str = `gitGraph:
commit
%% branch names starting with numbers are not recommended, but are supported by git
branch 1.0.1
`;
parser.parse(str);
const commits = parser.yy.getCommits();
expect(Object.keys(commits).length).toBe(1);
expect(parser.yy.getCurrentBranch()).toBe('1.0.1');
expect(parser.yy.getDirection()).toBe('LR');
expect(Object.keys(parser.yy.getBranches()).length).toBe(2);
});
it('should handle new branch checkout', function () {
const str = `gitGraph:
commit

View File

@ -290,13 +290,13 @@ const drawCommits = (svg, commits, modifyGraph) => {
};
/**
* Detect if there are other commits between commit1s x-position and commit2s x-position on the same
* Detect if there are other commits between commit1's x-position and commit2's x-position on the same
* branch as commit2.
*
* @param {any} commit1
* @param {any} commit2
* @param allCommits
* @returns
* @returns {boolean} if there are commits between commit1's x-position and commit2's x-position
*/
const hasOverlappingCommits = (commit1, commit2, allCommits) => {
const commit1Pos = commitPos[commit2.id];
@ -322,7 +322,7 @@ const hasOverlappingCommits = (commit1, commit2, allCommits) => {
* @param {any} y1
* @param {any} y2
* @param {any} _depth
* @returns
* @returns {number} y value between y1 and y2
*/
const findLane = (y1, y2, _depth) => {
const depth = _depth || 0;
@ -347,7 +347,7 @@ const findLane = (y1, y2, _depth) => {
};
/**
* This function draw the lines between the commits. They were arrows initially.
* Draw the lines between the commits. They were arrows initially.
*
* @param {any} svg
* @param {any} commit1
@ -453,12 +453,10 @@ const drawArrows = (svg, commits) => {
};
/**
* This function adds the branches and the branches' labels to the svg.
* Adds the branches and the branches' labels to the svg.
*
* @param svg
* @param commitid
* @param branches
* @param direction
*/
const drawBranches = (svg, branches) => {
const gitGraphConfig = getConfig().gitGraph;
@ -510,10 +508,6 @@ const drawBranches = (svg, branches) => {
};
/**
* @param svg
* @param commit
* @param direction
* @param branchColor
* @param txt
* @param id
* @param ver

View File

@ -33,7 +33,6 @@ accDescr\s*"{"\s* { this.begin("ac
<acc_descr_multiline>[\}] { this.popState(); }
<acc_descr_multiline>[^\}]* return "acc_descr_multiline_value";
(\r?\n)+ /*{console.log('New line');return 'NL';}*/ return 'NL';
\s+ /* skip all whitespace */
\#[^\n]* /* skip comments */
\%%[^\n]* /* skip comments */
"gitGraph" return 'GG';
@ -61,9 +60,10 @@ accDescr\s*"{"\s* { this.begin("ac
["] this.begin("string");
<string>["] this.popState();
<string>[^"]* return 'STR';
[0-9]+ return 'NUM';
[a-zA-Z][-_\./a-zA-Z0-9]*[-_a-zA-Z0-9] return 'ID';
[0-9]+(?=\s|$) return 'NUM';
\w[-\./\w]*[-\w] return 'ID'; // only a subset of https://git-scm.com/docs/git-check-ref-format
<<EOF>> return 'EOF';
\s+ /* skip all whitespace */ // lowest priority so we can use lookaheads in earlier regex
/lex

View File

@ -1,4 +1,5 @@
import * as mindmapDB from './mindmapDb';
import { setLogLevel } from '../../logger';
describe('when parsing a mindmap ', function () {
let mindmap;
@ -6,9 +7,10 @@ describe('when parsing a mindmap ', function () {
mindmap = require('./parser/mindmap').parser;
mindmap.yy = require('./mindmapDb');
mindmap.yy.clear();
setLogLevel('trace');
});
describe('hiearchy', function () {
it('should handle a simple root definition', function () {
it('MMP-1 should handle a simple root definition abc122', function () {
let str = `mindmap
root`;
@ -16,7 +18,7 @@ describe('when parsing a mindmap ', function () {
// console.log('Time for checks', mindmap.yy.getMindmap().descr);
expect(mindmap.yy.getMindmap().descr).toEqual('root');
});
it('should handle a hierachial mindmap definition', function () {
it('MMP-2 should handle a hierachial mindmap definition', function () {
let str = `mindmap
root
child1
@ -31,7 +33,7 @@ describe('when parsing a mindmap ', function () {
expect(mm.children[1].descr).toEqual('child2');
});
it('should handle a simple root definition with a shape and without an id abc123', function () {
it('3 should handle a simple root definition with a shape and without an id abc123', function () {
let str = `mindmap
(root)`;
@ -40,7 +42,7 @@ describe('when parsing a mindmap ', function () {
expect(mindmap.yy.getMindmap().descr).toEqual('root');
});
it('should handle a deeper hierachial mindmap definition', function () {
it('MMP-4 should handle a deeper hierachial mindmap definition', function () {
let str = `mindmap
root
child1
@ -55,7 +57,7 @@ describe('when parsing a mindmap ', function () {
expect(mm.children[0].children[0].descr).toEqual('leaf1');
expect(mm.children[1].descr).toEqual('child2');
});
it('Multiple roots are illegal', function () {
it('5 Multiple roots are illegal', function () {
let str = `mindmap
root
fakeRoot`;
@ -70,7 +72,7 @@ describe('when parsing a mindmap ', function () {
);
}
});
it('real root in wrong place', function () {
it('MMP-6 real root in wrong place', function () {
let str = `mindmap
root
fakeRoot
@ -88,7 +90,7 @@ describe('when parsing a mindmap ', function () {
});
});
describe('nodes', function () {
it('should handle an id and type for a node definition', function () {
it('MMP-7 should handle an id and type for a node definition', function () {
let str = `mindmap
root[The root]
`;
@ -99,7 +101,7 @@ describe('when parsing a mindmap ', function () {
expect(mm.descr).toEqual('The root');
expect(mm.type).toEqual(mindmap.yy.nodeType.RECT);
});
it('should handle an id and type for a node definition', function () {
it('MMP-8 should handle an id and type for a node definition', function () {
let str = `mindmap
root
theId(child1)`;
@ -113,7 +115,7 @@ describe('when parsing a mindmap ', function () {
expect(child.nodeId).toEqual('theId');
expect(child.type).toEqual(mindmap.yy.nodeType.ROUNDED_RECT);
});
it('should handle an id and type for a node definition', function () {
it('MMP-9 should handle an id and type for a node definition', function () {
let str = `mindmap
root
theId(child1)`;
@ -127,10 +129,10 @@ root
expect(child.nodeId).toEqual('theId');
expect(child.type).toEqual(mindmap.yy.nodeType.ROUNDED_RECT);
});
it('mutiple types (circle)', function () {
it('MMP-10 mutiple types (circle)', function () {
let str = `mindmap
root((the root))
`;
`;
mindmap.parse(str);
const mm = mindmap.yy.getMindmap();
@ -139,7 +141,7 @@ root
expect(mm.type).toEqual(mindmap.yy.nodeType.CIRCLE);
});
it('mutiple types (cloud)', function () {
it('MMP-11 mutiple types (cloud)', function () {
let str = `mindmap
root)the root(
`;
@ -150,7 +152,7 @@ root
expect(mm.children.length).toEqual(0);
expect(mm.type).toEqual(mindmap.yy.nodeType.CLOUD);
});
it('mutiple types (bang)', function () {
it('MMP-12 mutiple types (bang)', function () {
let str = `mindmap
root))the root((
`;
@ -163,7 +165,7 @@ root
});
});
describe('decorations', function () {
it('should be possible to set an icon for the node', function () {
it('MMP-13 should be possible to set an icon for the node', function () {
let str = `mindmap
root[The root]
::icon(bomb)
@ -177,7 +179,7 @@ root
expect(mm.type).toEqual(mindmap.yy.nodeType.RECT);
expect(mm.icon).toEqual('bomb');
});
it('should be possible to set classes for the node', function () {
it('MMP-14 should be possible to set classes for the node', function () {
let str = `mindmap
root[The root]
:::m-4 p-8
@ -191,7 +193,7 @@ root
expect(mm.type).toEqual(mindmap.yy.nodeType.RECT);
expect(mm.class).toEqual('m-4 p-8');
});
it('should be possible to set both classes and icon for the node', function () {
it('MMP-15 should be possible to set both classes and icon for the node', function () {
let str = `mindmap
root[The root]
:::m-4 p-8
@ -207,7 +209,7 @@ root
expect(mm.class).toEqual('m-4 p-8');
expect(mm.icon).toEqual('bomb');
});
it('should be possible to set both classes and icon for the node', function () {
it('MMP-16 should be possible to set both classes and icon for the node', function () {
let str = `mindmap
root[The root]
::icon(bomb)
@ -225,7 +227,7 @@ root
});
});
describe('descriptions', function () {
it('should be possible to use node syntax in the descriptions', function () {
it('MMP-17 should be possible to use node syntax in the descriptions', function () {
let str = `mindmap
root["String containing []"]
`;
@ -234,7 +236,7 @@ root
expect(mm.nodeId).toEqual('root');
expect(mm.descr).toEqual('String containing []');
});
it('should be possible to use node syntax in the descriptions in children', function () {
it('MMP-18 should be possible to use node syntax in the descriptions in children', function () {
let str = `mindmap
root["String containing []"]
child1["String containing ()"]
@ -246,7 +248,7 @@ root
expect(mm.children.length).toEqual(1);
expect(mm.children[0].descr).toEqual('String containing ()');
});
it('should be possible to have a child after a class assignment', function () {
it('MMP-19 should be possible to have a child after a class assignment', function () {
let str = `mindmap
root(Root)
Child(Child)
@ -266,7 +268,7 @@ root
expect(child.children[1].nodeId).toEqual('b');
});
});
it('should be possible to have meaningless empty rows in a mindmap abc124', function () {
it('MMP-20 should be possible to have meaningless empty rows in a mindmap abc124', function () {
let str = `mindmap
root(Root)
Child(Child)
@ -285,7 +287,7 @@ root
expect(child.children.length).toEqual(2);
expect(child.children[1].nodeId).toEqual('b');
});
it('should be possible to have comments in a mindmap', function () {
it('MMP-21 should be possible to have comments in a mindmap', function () {
let str = `mindmap
root(Root)
Child(Child)
@ -306,7 +308,7 @@ root
expect(child.children[1].nodeId).toEqual('b');
});
it('should be possible to have comments at the end of a line', function () {
it('MMP-22 should be possible to have comments at the end of a line', function () {
let str = `mindmap
root(Root)
Child(Child)

View File

@ -1,6 +1,6 @@
/** Created by knut on 15-01-14. */
import { sanitizeText, getConfig } from '../../diagram-api/diagramAPI';
import { log } from '../../logger';
import { log as _log } from '../../logger';
let nodes = [];
let cnt = 0;
@ -25,7 +25,7 @@ export const getMindmap = () => {
return nodes.length > 0 ? nodes[0] : null;
};
export const addNode = (level, id, descr, type) => {
console.info('addNode', level, id, descr, type);
log.info('addNode', level, id, descr, type);
const conf = getConfig();
const node = {
id: cnt++,
@ -132,7 +132,8 @@ export const type2Str = (type) => {
return 'no-border';
}
};
// Expose logger to grammar
export const log = _log;
export const getNodeById = (id) => nodes[id];
export const getElementById = (id) => elements[id];
// export default {

View File

@ -22,7 +22,6 @@ function drawNodes(svg, mindmap, section, conf) {
}
/**
* @param {any} svg The svg element to draw the diagram onto
* @param edgesElem
* @param mindmap
* @param parent
@ -149,8 +148,6 @@ const mergeTrees = (node, trees) => {
/**
* @param node
* @param isRoot
* @param parent
* @param conf
*/
function layoutMindmap(node, conf) {
@ -201,7 +198,6 @@ function layoutMindmap(node, conf) {
}
/**
* @param node
* @param isRoot
* @param conf
*/
function positionNodes(node, conf) {

View File

@ -17,20 +17,21 @@
%%
\s*\%\%.*\n {console.log('Found comment',yytext);}
\s*\%\%.* {yy.log.trace('Found comment',yytext);}
// \%\%[^\n]*\n /* skip comments */
"mindmap" return 'MINDMAP';
":::" { this.begin('CLASS'); }
<CLASS>.+ { this.popState();return 'CLASS'; }
<CLASS>\n { this.popState();}
[\n\s]*"::icon(" { this.begin('ICON'); }
[\n]+ /* return 'NL'; */
// [\s]*"::icon(" { this.begin('ICON'); }
"::icon(" { yy.log.trace('Begin icon');this.begin('ICON'); }
[\n]+ return 'NL';
<ICON>[^\)]+ { return 'ICON'; }
<ICON>\) {this.popState();}
"-)" { console.log('Exploding node'); this.begin('NODE');return 'NODE_DSTART'; }
"(-" { console.log('Cloud'); this.begin('NODE');return 'NODE_DSTART'; }
"))" { console.log('Explosion Bang'); this.begin('NODE');return 'NODE_DSTART'; }
")" { console.log('Cloud Bang'); this.begin('NODE');return 'NODE_DSTART'; }
<ICON>\) {yy.log.trace('end icon');this.popState();}
"-)" { yy.log.trace('Exploding node'); this.begin('NODE');return 'NODE_DSTART'; }
"(-" { yy.log.trace('Cloud'); this.begin('NODE');return 'NODE_DSTART'; }
"))" { yy.log.trace('Explosion Bang'); this.begin('NODE');return 'NODE_DSTART'; }
")" { yy.log.trace('Cloud Bang'); this.begin('NODE');return 'NODE_DSTART'; }
"((" { this.begin('NODE');return 'NODE_DSTART'; }
"(" { this.begin('NODE');return 'NODE_DSTART'; }
"[" { this.begin('NODE');return 'NODE_DSTART'; }
@ -38,18 +39,18 @@
// !(-\() return 'NODE_ID';
[^\(\[\n\-\)]+ return 'NODE_ID';
<<EOF>> return 'EOF';
<NODE>["] { console.log('Starting NSTR');this.begin("NSTR");}
<NSTR>[^"]+ { console.log('description:', yytext); return "NODE_DESCR";}
<NODE>["] { yy.log.trace('Starting NSTR');this.begin("NSTR");}
<NSTR>[^"]+ { yy.log.trace('description:', yytext); return "NODE_DESCR";}
<NSTR>["] {this.popState();}
<NODE>[\)]\) {this.popState();console.log('node end ))');return "NODE_DEND";}
<NODE>[\)] {this.popState();console.log('node end )');return "NODE_DEND";}
<NODE>[\]] {this.popState();console.log('node end ...');return "NODE_DEND";}
<NODE>"(-" {this.popState();console.log('node end (-');return "NODE_DEND";}
<NODE>"-)" {this.popState();console.log('node end (-');return "NODE_DEND";}
<NODE>"((" {this.popState();console.log('node end ((');return "NODE_DEND";}
<NODE>"(" {this.popState();console.log('node end ((');return "NODE_DEND";}
<NODE>[^\)\]\(]+ { console.log('Long description:', yytext); return 'NODE_DESCR';}
<NODE>.+(?!\(\() { console.log('Long description:', yytext); return 'NODE_DESCR';}
<NODE>[\)]\) {this.popState();yy.log.trace('node end ))');return "NODE_DEND";}
<NODE>[\)] {this.popState();yy.log.trace('node end )');return "NODE_DEND";}
<NODE>[\]] {this.popState();yy.log.trace('node end ...',yytext);return "NODE_DEND";}
<NODE>"(-" {this.popState();yy.log.trace('node end (-');return "NODE_DEND";}
<NODE>"-)" {this.popState();yy.log.trace('node end (-');return "NODE_DEND";}
<NODE>"((" {this.popState();yy.log.trace('node end ((');return "NODE_DEND";}
<NODE>"(" {this.popState();yy.log.trace('node end ((');return "NODE_DEND";}
<NODE>[^\)\]\(]+ { yy.log.trace('Long description:', yytext); return 'NODE_DESCR';}
<NODE>.+(?!\(\() { yy.log.trace('Long description:', yytext); return 'NODE_DESCR';}
// [\[] return 'NODE_START';
// .+ return 'TXT' ;
@ -62,29 +63,33 @@
start
// %{ : info document 'EOF' { return yy; } }
: MINDMAP document { return yy; }
| MINDMAP NL document { return yy; }
| SPACELIST MINDMAP document { return yy; }
;
stop
: NL {yy.log.trace('Stop NL ');}
| EOF {yy.log.trace('Stop EOF ');}
| stop NL {yy.log.trace('Stop NL2 ');}
| stop EOF {yy.log.trace('Stop EOF2 ');}
;
document
: document line
| line
;
line
: statement { }
: document statement stop
| statement stop
;
statement
: SPACELIST node { yy.addNode($1.length, $2.id, $2.descr, $2.type); }
| SPACELIST ICON { yy.decorateNode({icon: $2}); }
| SPACELIST EOF
| SPACELIST NL
| node { console.log($1.id);yy.addNode(0, $1.id, $1.descr, $1.type); }
: SPACELIST node { yy.log.trace('Node: ',$2.id);yy.addNode($1.length, $2.id, $2.descr, $2.type); }
| SPACELIST ICON { yy.log.trace('Icon: ',$2);yy.decorateNode({icon: $2}); }
| SPACELIST CLASS { yy.decorateNode({class: $2}); }
| node { yy.log.trace('Node: ',$1.id);yy.addNode(0, $1.id, $1.descr, $1.type); }
| ICON { yy.decorateNode({icon: $1}); }
| SPACELIST CLASS { yy.decorateNode({class: $2}); }
| CLASS { yy.decorateNode({class: $1}); }
| EOF
| CLASS { yy.decorateNode({class: $1}); }
| SPACELIST
;
node
:nodeWithId
|nodeWithoutId
@ -92,12 +97,12 @@ node
nodeWithoutId
: NODE_DSTART NODE_DESCR NODE_DEND
{ console.log("node found ..", $1); $$ = { id: $2, descr: $2, type: yy.getType($1, $3) }; }
{ yy.log.trace("node found ..", $1); $$ = { id: $2, descr: $2, type: yy.getType($1, $3) }; }
;
nodeWithId
: NODE_ID { $$ = { id: $1, descr: $1, type: yy.nodeType.DEFAULT }; }
| NODE_ID NODE_DSTART NODE_DESCR NODE_DEND
{ console.log("node found ..", $1); $$ = { id: $1, descr: $3, type: yy.getType($2, $4) }; }
{ yy.log.trace("node found ..", $1); $$ = { id: $1, descr: $3, type: yy.getType($2, $4) }; }
;
%%

View File

@ -326,7 +326,7 @@ const boundMessage = function (diagram, msgModel) {
*
* @param {any} diagram - The parent of the message element
* @param {any} msgModel - The model containing fields describing a message
* @param {float} lineStarty - The Y coordinate at which the message line starts
* @param {number} lineStarty - The Y coordinate at which the message line starts
* @param diagObj
*/
const drawMessage = function (diagram, msgModel, lineStarty, diagObj) {
@ -582,8 +582,7 @@ function adjustLoopHeightForWrap(loopWidths, msg, preMargin, postMargin, addLoop
/**
* Draws a sequenceDiagram in the tag with id: id based on the graph definition in text.
*
* @param {any} text The text of the diagram
* @param _text
* @param {any} _text The text of the diagram
* @param {any} id The id of the diagram which will be used as a DOM element id¨
* @param {any} _version Mermaid version from package.json
* @param {any} diagObj A stanard diagram containing the db and the text and type etc of the diagram

View File

@ -66,9 +66,9 @@ export const drawSimpleState = (g, stateDef) => {
/**
* Draws a state with descriptions
*
* @param {any} g
* @param {any} g The d3 svg object to add the state to
* @param {any} stateDef
* @returns
* @returns {any} The d3 svg state
*/
export const drawDescrState = (g, stateDef) => {
const addTspan = function (textEl, txt, isFirst) {

View File

@ -37,8 +37,6 @@ export const calculateSvgSizeAttrs = function (height, width, useMaxWidth) {
* @param {SVGSVGElement} svgElem The SVG Element to configure
* @param {number} height The height of the SVG
* @param {number} width The width of the SVG
* @param tx
* @param ty
* @param {boolean} useMaxWidth Whether or not to use max-width and set width to 100%
*/
export const configureSvgSize = function (svgElem, height, width, useMaxWidth) {