#1196 Keep flowchart node label text (if already defined) when a style is applied

This commit is contained in:
Marc Faber
2020-01-14 23:37:30 +01:00
parent eade3d0a2d
commit b1bfdec473
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;'