From 96735dd5435017db898de2bacd8ef1b1a3251b97 Mon Sep 17 00:00:00 2001 From: Christian Klemm Date: Fri, 4 Oct 2019 21:09:49 +0200 Subject: [PATCH 1/9] Added rendering for annotations --- .gitignore | 1 + src/diagrams/class/classDb.js | 3 ++- src/diagrams/class/classRenderer.js | 29 ++++++++++++++++++++++++++--- src/themes/class.scss | 4 ++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index afceb98c0..74ecd58ff 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules/ coverage/ +.idea/ dist/*.js dist/*.map diff --git a/src/diagrams/class/classDb.js b/src/diagrams/class/classDb.js index 94ec0e21e..b364d9987 100644 --- a/src/diagrams/class/classDb.js +++ b/src/diagrams/class/classDb.js @@ -15,7 +15,8 @@ export const addClass = function(id) { classes[id] = { id: id, methods: [], - members: [] + members: [], + annotations: [] }; } }; diff --git a/src/diagrams/class/classRenderer.js b/src/diagrams/class/classRenderer.js index 37a6629ae..b4344e459 100644 --- a/src/diagrams/class/classRenderer.js +++ b/src/diagrams/class/classRenderer.js @@ -261,9 +261,26 @@ const drawClass = function(elem, classDef) { .attr('class', 'classGroup'); const title = g .append('text') - .attr('x', conf.padding) .attr('y', conf.textHeight + conf.padding) - .text(classDef.id); + .attr('x', 0); + + // TODO: remove testing code + classDef.annotations = ['interface', 'injected']; + + // add annotations + let isFirst = true; + classDef.annotations.forEach(function(member) { + const titleText2 = title.append('tspan').text('«' + member + '»'); + if (!isFirst) titleText2.attr('dy', conf.textHeight); + isFirst = false; + }); + + // add class title + title + .append('tspan') + .text(classDef.id) + .attr('class', 'title') + .attr('dy', conf.textHeight); const titleHeight = title.node().getBBox().height; @@ -280,7 +297,7 @@ const drawClass = function(elem, classDef) { .attr('fill', 'white') .attr('class', 'classText'); - let isFirst = true; + isFirst = true; classDef.members.forEach(function(member) { addTspan(members, member, isFirst); isFirst = false; @@ -315,6 +332,12 @@ const drawClass = function(elem, classDef) { .attr('width', classBox.width + 2 * conf.padding) .attr('height', classBox.height + conf.padding + 0.5 * conf.dividerMargin); + // Center title + title.node().childNodes.forEach(function(x) { + console.dir(x.getBBox()); + x.setAttribute('x', (classBox.width + 2 * conf.padding - x.getBBox().width) / 2); + }); + membersLine.attr('x2', classBox.width + 2 * conf.padding); methodsLine.attr('x2', classBox.width + 2 * conf.padding); diff --git a/src/themes/class.scss b/src/themes/class.scss index 5e7de9150..86893cf09 100644 --- a/src/themes/class.scss +++ b/src/themes/class.scss @@ -3,6 +3,10 @@ g.classGroup text { stroke: none; font-family: 'trebuchet ms', verdana, arial; font-size: 10px; + + .title { + font-weight: bolder; + } } g.classGroup rect { From 912e850db496a2c4a7e39e701dec48529f7cd5d9 Mon Sep 17 00:00:00 2001 From: Christian Klemm Date: Fri, 4 Oct 2019 21:49:02 +0200 Subject: [PATCH 2/9] added grammar --- README.md | 1 + dist/index.html | 1 + src/diagrams/class/classDb.js | 5 +++++ src/diagrams/class/classRenderer.js | 11 ++++------- src/diagrams/class/parser/classDiagram.jison | 8 +++++++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 44a6a2c19..ec6b243ef 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ Class01 : size() Class01 : int chimp Class01 : int gorilla Class08 <--> C2: Cool label +<> Class01 ``` ![Class diagram](./img/class.png) diff --git a/dist/index.html b/dist/index.html index 027b17213..d5e7ba0a0 100644 --- a/dist/index.html +++ b/dist/index.html @@ -411,6 +411,7 @@ Class01 : size() Class01 : int chimp Class01 : int gorilla Class08 <--> C2: Cool label +<<interface>> Class01