Merge pull request #1204 from GDFaber/bug/1196_keep_flowchart_label_text_when_style_is_applied

Keep flowchart node label text (if already defined) when a style is applied
This commit is contained in:
Knut Sveidqvist
2020-01-15 18:27:48 +01:00
committed by GitHub
4 changed files with 41 additions and 1 deletions

View File

@@ -52,7 +52,7 @@ export const addVertex = function(_id, text, type, style, classes) {
vertices[id].text = txt;
} else {
if (!vertices[id].text) {
if (typeof vertices[id].text === 'undefined') {
vertices[id].text = _id;
}
}

View File

@@ -86,6 +86,17 @@ describe('[Style] when parsing', () => {
expect(vert['T'].styles[1]).toBe('border:1px solid red');
});
it('should keep node label text (if already defined) when a style is applied', function() {
const res = flow.parser.parse('graph TD;A(( ));B((Test));C;style A background:#fff;style D border:1px solid red;');
const vert = flow.parser.yy.getVertices();
expect(vert['A'].text).toBe('');
expect(vert['B'].text).toBe('Test');
expect(vert['C'].text).toBe('C');
expect(vert['D'].text).toBe('D');
});
it('should be possible to declare a class', function() {
const res = flow.parser.parse(
'graph TD;classDef exClass background:#bbb,border:1px solid red;'