mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-14 12:59:46 +02:00
Merge branch 'develop' of https://github.com/mermaid-js/mermaid into feature/4653-add_actor-top_class_to_sequence_diagram
This commit is contained in:
@@ -583,4 +583,106 @@ describe('Gantt diagram', () => {
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should render when there's a semicolon in the title", () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
gantt
|
||||||
|
title ;Gantt With a Semicolon in the Title
|
||||||
|
dateFormat YYYY-MM-DD
|
||||||
|
section Section
|
||||||
|
A task :a1, 2014-01-01, 30d
|
||||||
|
Another task :after a1 , 20d
|
||||||
|
section Another
|
||||||
|
Task in sec :2014-01-12 , 12d
|
||||||
|
another task : 24d
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render when there's a semicolon in a section is true", () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
gantt
|
||||||
|
title Gantt Digram
|
||||||
|
dateFormat YYYY-MM-DD
|
||||||
|
section ;Section With a Semicolon
|
||||||
|
A task :a1, 2014-01-01, 30d
|
||||||
|
Another task :after a1 , 20d
|
||||||
|
section Another
|
||||||
|
Task in sec :2014-01-12 , 12d
|
||||||
|
another task : 24d
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render when there's a semicolon in the task data", () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
gantt
|
||||||
|
title Gantt Digram
|
||||||
|
dateFormat YYYY-MM-DD
|
||||||
|
section Section
|
||||||
|
;A task with a semiclon :a1, 2014-01-01, 30d
|
||||||
|
Another task :after a1 , 20d
|
||||||
|
section Another
|
||||||
|
Task in sec :2014-01-12 , 12d
|
||||||
|
another task : 24d
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render when there's a hashtag in the title", () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
gantt
|
||||||
|
title #Gantt With a Hashtag in the Title
|
||||||
|
dateFormat YYYY-MM-DD
|
||||||
|
section Section
|
||||||
|
A task :a1, 2014-01-01, 30d
|
||||||
|
Another task :after a1 , 20d
|
||||||
|
section Another
|
||||||
|
Task in sec :2014-01-12 , 12d
|
||||||
|
another task : 24d
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render when there's a hashtag in a section is true", () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
gantt
|
||||||
|
title Gantt Digram
|
||||||
|
dateFormat YYYY-MM-DD
|
||||||
|
section #Section With a Hashtag
|
||||||
|
A task :a1, 2014-01-01, 30d
|
||||||
|
Another task :after a1 , 20d
|
||||||
|
section Another
|
||||||
|
Task in sec :2014-01-12 , 12d
|
||||||
|
another task : 24d
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render when there's a hashtag in the task data", () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
gantt
|
||||||
|
title Gantt Digram
|
||||||
|
dateFormat YYYY-MM-DD
|
||||||
|
section Section
|
||||||
|
#A task with a hashtag :a1, 2014-01-01, 30d
|
||||||
|
Another task :after a1 , 20d
|
||||||
|
section Another
|
||||||
|
Task in sec :2014-01-12 , 12d
|
||||||
|
another task : 24d
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -805,6 +805,34 @@ context('Sequence diagram', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
context('links', () => {
|
context('links', () => {
|
||||||
|
it('should support actor links', () => {
|
||||||
|
renderGraph(
|
||||||
|
`
|
||||||
|
sequenceDiagram
|
||||||
|
link Alice: Dashboard @ https://dashboard.contoso.com/alice
|
||||||
|
link Alice: Wiki @ https://wiki.contoso.com/alice
|
||||||
|
link John: Dashboard @ https://dashboard.contoso.com/john
|
||||||
|
link John: Wiki @ https://wiki.contoso.com/john
|
||||||
|
Alice->>John: Hello John<br/>
|
||||||
|
John-->>Alice: Great<br/><br/>day!
|
||||||
|
`,
|
||||||
|
{ securityLevel: 'loose' }
|
||||||
|
);
|
||||||
|
cy.get('#actor0_popup').should((popupMenu) => {
|
||||||
|
const style = popupMenu.attr('style');
|
||||||
|
expect(style).to.undefined;
|
||||||
|
});
|
||||||
|
cy.get('#root-0').click();
|
||||||
|
cy.get('#actor0_popup').should((popupMenu) => {
|
||||||
|
const style = popupMenu.attr('style');
|
||||||
|
expect(style).to.match(/^display: block;$/);
|
||||||
|
});
|
||||||
|
cy.get('#root-0').click();
|
||||||
|
cy.get('#actor0_popup').should((popupMenu) => {
|
||||||
|
const style = popupMenu.attr('style');
|
||||||
|
expect(style).to.match(/^display: none;$/);
|
||||||
|
});
|
||||||
|
});
|
||||||
it('should support actor links and properties EXPERIMENTAL: USE WITH CAUTION', () => {
|
it('should support actor links and properties EXPERIMENTAL: USE WITH CAUTION', () => {
|
||||||
//Be aware that the syntax for "properties" is likely to be changed.
|
//Be aware that the syntax for "properties" is likely to be changed.
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
|
@@ -30,6 +30,21 @@
|
|||||||
</pre>
|
</pre>
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
|
<pre class="mermaid">
|
||||||
|
gantt
|
||||||
|
title #; Gantt Diagrams Allow Semicolons and Hashtags #;!
|
||||||
|
accTitle: A simple sample gantt diagram
|
||||||
|
accDescr: 2 sections with 2 tasks each, from 2014
|
||||||
|
dateFormat YYYY-MM-DD
|
||||||
|
section #;Section
|
||||||
|
#;A task :a1, 2014-01-01, 30d
|
||||||
|
#;Another task :after a1 , 20d
|
||||||
|
section #;Another
|
||||||
|
Task in sec :2014-01-12 , 12d
|
||||||
|
another task : 24d
|
||||||
|
</pre>
|
||||||
|
<hr />
|
||||||
|
|
||||||
<pre class="mermaid">
|
<pre class="mermaid">
|
||||||
gantt
|
gantt
|
||||||
title Airworks roadmap
|
title Airworks roadmap
|
||||||
|
@@ -23,6 +23,10 @@
|
|||||||
participant Alice
|
participant Alice
|
||||||
participant Bob
|
participant Bob
|
||||||
participant John as John<br />Second Line
|
participant John as John<br />Second Line
|
||||||
|
link Alice: Dashboard @ https://dashboard.contoso.com/alice
|
||||||
|
link Alice: Wiki @ https://wiki.contoso.com/alice
|
||||||
|
link John: Dashboard @ https://dashboard.contoso.com/john
|
||||||
|
link John: Wiki @ https://wiki.contoso.com/john
|
||||||
autonumber 10 10
|
autonumber 10 10
|
||||||
rect rgb(200, 220, 100)
|
rect rgb(200, 220, 100)
|
||||||
rect rgb(200, 255, 200)
|
rect rgb(200, 255, 200)
|
||||||
@@ -62,6 +66,26 @@
|
|||||||
</pre>
|
</pre>
|
||||||
<hr />
|
<hr />
|
||||||
<pre class="mermaid">
|
<pre class="mermaid">
|
||||||
|
---
|
||||||
|
title: With forced menus
|
||||||
|
config:
|
||||||
|
sequence:
|
||||||
|
forceMenus: true
|
||||||
|
---
|
||||||
|
sequenceDiagram
|
||||||
|
participant Alice
|
||||||
|
participant John
|
||||||
|
link Alice: Dashboard @ https://dashboard.contoso.com/alice
|
||||||
|
link Alice: Wiki @ https://wiki.contoso.com/alice
|
||||||
|
link John: Dashboard @ https://dashboard.contoso.com/john
|
||||||
|
link John: Wiki @ https://wiki.contoso.com/john
|
||||||
|
Alice->>John: Hello John, how are you?
|
||||||
|
John-->>Alice: Great!
|
||||||
|
Alice-)John: See you later!
|
||||||
|
</pre
|
||||||
|
>
|
||||||
|
<hr />
|
||||||
|
<pre class="mermaid">
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
accTitle: Sequence diagram title is here
|
accTitle: Sequence diagram title is here
|
||||||
accDescr: Hello friends
|
accDescr: Hello friends
|
||||||
|
@@ -27,11 +27,10 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili
|
|||||||
|
|
||||||
\%\%(?!\{)*[^\n]* /* skip comments */
|
\%\%(?!\{)*[^\n]* /* skip comments */
|
||||||
[^\}]\%\%*[^\n]* /* skip comments */
|
[^\}]\%\%*[^\n]* /* skip comments */
|
||||||
\%\%*[^\n]*[\n]* /* do nothing */
|
\%\%*[^\n]*[\n]* /* do nothing */
|
||||||
|
|
||||||
[\n]+ return 'NL';
|
[\n]+ return 'NL';
|
||||||
\s+ /* skip whitespace */
|
\s+ /* skip whitespace */
|
||||||
\#[^\n]* /* skip comments */
|
|
||||||
\%%[^\n]* /* skip comments */
|
\%%[^\n]* /* skip comments */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -86,10 +85,10 @@ weekday\s+friday return 'weekday_friday'
|
|||||||
weekday\s+saturday return 'weekday_saturday'
|
weekday\s+saturday return 'weekday_saturday'
|
||||||
weekday\s+sunday return 'weekday_sunday'
|
weekday\s+sunday return 'weekday_sunday'
|
||||||
\d\d\d\d"-"\d\d"-"\d\d return 'date';
|
\d\d\d\d"-"\d\d"-"\d\d return 'date';
|
||||||
"title"\s[^#\n;]+ return 'title';
|
"title"\s[^\n]+ return 'title';
|
||||||
"accDescription"\s[^#\n;]+ return 'accDescription'
|
"accDescription"\s[^#\n;]+ return 'accDescription'
|
||||||
"section"\s[^#:\n;]+ return 'section';
|
"section"\s[^\n]+ return 'section';
|
||||||
[^#:\n;]+ return 'taskTxt';
|
[^:\n]+ return 'taskTxt';
|
||||||
":"[^#\n;]+ return 'taskData';
|
":"[^#\n;]+ return 'taskData';
|
||||||
":" return ':';
|
":" return ':';
|
||||||
<<EOF>> return 'EOF';
|
<<EOF>> return 'EOF';
|
||||||
|
@@ -28,8 +28,12 @@ describe('when parsing a gantt diagram it', function () {
|
|||||||
});
|
});
|
||||||
it('should handle a title definition', function () {
|
it('should handle a title definition', function () {
|
||||||
const str = 'gantt\ndateFormat yyyy-mm-dd\ntitle Adding gantt diagram functionality to mermaid';
|
const str = 'gantt\ndateFormat yyyy-mm-dd\ntitle Adding gantt diagram functionality to mermaid';
|
||||||
|
const semi = 'gantt\ndateFormat yyyy-mm-dd\ntitle ;Gantt diagram titles support semicolons';
|
||||||
|
const hash = 'gantt\ndateFormat yyyy-mm-dd\ntitle #Gantt diagram titles support hashtags';
|
||||||
|
|
||||||
expect(parserFnConstructor(str)).not.toThrow();
|
expect(parserFnConstructor(str)).not.toThrow();
|
||||||
|
expect(parserFnConstructor(semi)).not.toThrow();
|
||||||
|
expect(parserFnConstructor(hash)).not.toThrow();
|
||||||
});
|
});
|
||||||
it('should handle an excludes definition', function () {
|
it('should handle an excludes definition', function () {
|
||||||
const str =
|
const str =
|
||||||
@@ -53,7 +57,23 @@ describe('when parsing a gantt diagram it', function () {
|
|||||||
'excludes weekdays 2019-02-01\n' +
|
'excludes weekdays 2019-02-01\n' +
|
||||||
'section Documentation';
|
'section Documentation';
|
||||||
|
|
||||||
|
const semi =
|
||||||
|
'gantt\n' +
|
||||||
|
'dateFormat yyyy-mm-dd\n' +
|
||||||
|
'title Adding gantt diagram functionality to mermaid\n' +
|
||||||
|
'excludes weekdays 2019-02-01\n' +
|
||||||
|
'section ;Documentation';
|
||||||
|
|
||||||
|
const hash =
|
||||||
|
'gantt\n' +
|
||||||
|
'dateFormat yyyy-mm-dd\n' +
|
||||||
|
'title Adding gantt diagram functionality to mermaid\n' +
|
||||||
|
'excludes weekdays 2019-02-01\n' +
|
||||||
|
'section #Documentation';
|
||||||
|
|
||||||
expect(parserFnConstructor(str)).not.toThrow();
|
expect(parserFnConstructor(str)).not.toThrow();
|
||||||
|
expect(parserFnConstructor(semi)).not.toThrow();
|
||||||
|
expect(parserFnConstructor(hash)).not.toThrow();
|
||||||
});
|
});
|
||||||
it('should handle multiline section titles with different line breaks', function () {
|
it('should handle multiline section titles with different line breaks', function () {
|
||||||
const str =
|
const str =
|
||||||
@@ -73,7 +93,23 @@ describe('when parsing a gantt diagram it', function () {
|
|||||||
'section Documentation\n' +
|
'section Documentation\n' +
|
||||||
'Design jison grammar:des1, 2014-01-01, 2014-01-04';
|
'Design jison grammar:des1, 2014-01-01, 2014-01-04';
|
||||||
|
|
||||||
|
const semi =
|
||||||
|
'gantt\n' +
|
||||||
|
'dateFormat YYYY-MM-DD\n' +
|
||||||
|
'title Adding gantt diagram functionality to mermaid\n' +
|
||||||
|
'section Documentation\n' +
|
||||||
|
';Design jison grammar:des1, 2014-01-01, 2014-01-04';
|
||||||
|
|
||||||
|
const hash =
|
||||||
|
'gantt\n' +
|
||||||
|
'dateFormat YYYY-MM-DD\n' +
|
||||||
|
'title Adding gantt diagram functionality to mermaid\n' +
|
||||||
|
'section Documentation\n' +
|
||||||
|
'#Design jison grammar:des1, 2014-01-01, 2014-01-04';
|
||||||
|
|
||||||
expect(parserFnConstructor(str)).not.toThrow();
|
expect(parserFnConstructor(str)).not.toThrow();
|
||||||
|
expect(parserFnConstructor(semi)).not.toThrow();
|
||||||
|
expect(parserFnConstructor(hash)).not.toThrow();
|
||||||
|
|
||||||
const tasks = parser.yy.getTasks();
|
const tasks = parser.yy.getTasks();
|
||||||
|
|
||||||
|
@@ -11,22 +11,6 @@ export const drawRect = function (elem, rectData) {
|
|||||||
return svgDrawCommon.drawRect(elem, rectData);
|
return svgDrawCommon.drawRect(elem, rectData);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addPopupInteraction = (id, actorCnt) => {
|
|
||||||
addFunction(() => {
|
|
||||||
const arr = document.querySelectorAll(id);
|
|
||||||
// This will be the case when running in sandboxed mode
|
|
||||||
if (arr.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
arr[0].addEventListener('mouseover', function () {
|
|
||||||
popupMenuUpFunc('actor' + actorCnt + '_popup');
|
|
||||||
});
|
|
||||||
arr[0].addEventListener('mouseout', function () {
|
|
||||||
popupMenuDownFunc('actor' + actorCnt + '_popup');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const drawPopup = function (elem, actor, minMenuWidth, textAttrs, forceMenus) {
|
export const drawPopup = function (elem, actor, minMenuWidth, textAttrs, forceMenus) {
|
||||||
if (actor.links === undefined || actor.links === null || Object.keys(actor.links).length === 0) {
|
if (actor.links === undefined || actor.links === null || Object.keys(actor.links).length === 0) {
|
||||||
return { height: 0, width: 0 };
|
return { height: 0, width: 0 };
|
||||||
@@ -45,7 +29,6 @@ export const drawPopup = function (elem, actor, minMenuWidth, textAttrs, forceMe
|
|||||||
g.attr('id', 'actor' + actorCnt + '_popup');
|
g.attr('id', 'actor' + actorCnt + '_popup');
|
||||||
g.attr('class', 'actorPopupMenu');
|
g.attr('class', 'actorPopupMenu');
|
||||||
g.attr('display', displayValue);
|
g.attr('display', displayValue);
|
||||||
addPopupInteraction('#actor' + actorCnt + '_popup', actorCnt);
|
|
||||||
var actorClass = '';
|
var actorClass = '';
|
||||||
if (rectData.class !== undefined) {
|
if (rectData.class !== undefined) {
|
||||||
actorClass = ' ' + rectData.class;
|
actorClass = ' ' + rectData.class;
|
||||||
@@ -91,36 +74,14 @@ export const drawPopup = function (elem, actor, minMenuWidth, textAttrs, forceMe
|
|||||||
return { height: rectData.height + linkY, width: menuWidth };
|
return { height: rectData.height + linkY, width: menuWidth };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const popupMenu = function (popid) {
|
const popupMenuToggle = function (popid) {
|
||||||
return (
|
return (
|
||||||
"var pu = document.getElementById('" +
|
"var pu = document.getElementById('" +
|
||||||
popid +
|
popid +
|
||||||
"'); if (pu != null) { pu.style.display = 'block'; }"
|
"'); if (pu != null) { pu.style.display = pu.style.display == 'block' ? 'none' : 'block'; }"
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const popdownMenu = function (popid) {
|
|
||||||
return (
|
|
||||||
"var pu = document.getElementById('" +
|
|
||||||
popid +
|
|
||||||
"'); if (pu != null) { pu.style.display = 'none'; }"
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const popupMenuUpFunc = function (popupId) {
|
|
||||||
var pu = document.getElementById(popupId);
|
|
||||||
if (pu != null) {
|
|
||||||
pu.style.display = 'block';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const popupMenuDownFunc = function (popupId) {
|
|
||||||
var pu = document.getElementById(popupId);
|
|
||||||
if (pu != null) {
|
|
||||||
pu.style.display = 'none';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const drawText = function (elem, textData) {
|
export const drawText = function (elem, textData) {
|
||||||
let prevTextHeight = 0;
|
let prevTextHeight = 0;
|
||||||
let textHeight = 0;
|
let textHeight = 0;
|
||||||
@@ -330,6 +291,9 @@ const drawActorTypeParticipant = function (elem, actor, conf, isFooter) {
|
|||||||
|
|
||||||
if (!isFooter) {
|
if (!isFooter) {
|
||||||
actorCnt++;
|
actorCnt++;
|
||||||
|
if (Object.keys(actor.links || {}).length && !conf.forceMenus) {
|
||||||
|
g.attr('onclick', popupMenuToggle(`actor${actorCnt}_popup`)).attr('cursor', 'pointer');
|
||||||
|
}
|
||||||
g.append('line')
|
g.append('line')
|
||||||
.attr('id', 'actor' + actorCnt)
|
.attr('id', 'actor' + actorCnt)
|
||||||
.attr('x1', center)
|
.attr('x1', center)
|
||||||
@@ -346,7 +310,6 @@ const drawActorTypeParticipant = function (elem, actor, conf, isFooter) {
|
|||||||
|
|
||||||
if (actor.links != null) {
|
if (actor.links != null) {
|
||||||
g.attr('id', 'root-' + actorCnt);
|
g.attr('id', 'root-' + actorCnt);
|
||||||
addPopupInteraction('#root-' + actorCnt, actorCnt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1061,8 +1024,6 @@ export default {
|
|||||||
insertClockIcon,
|
insertClockIcon,
|
||||||
getTextObj,
|
getTextObj,
|
||||||
getNoteRect,
|
getNoteRect,
|
||||||
popupMenu,
|
|
||||||
popdownMenu,
|
|
||||||
fixLifeLineHeights,
|
fixLifeLineHeights,
|
||||||
sanitizeUrl,
|
sanitizeUrl,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user