Skip to content

Commit

Permalink
#748: class diagram: allow linebreak after last statement; rerender c…
Browse files Browse the repository at this point in the history
…orrectly; allow unassociated classes
  • Loading branch information
monsterkrampe committed Oct 25, 2018
1 parent a499296 commit 15404d4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
18 changes: 13 additions & 5 deletions src/diagrams/class/classDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,24 @@ export const addRelation = function (relation) {
relations.push(relation)
}

export const addMembers = function (className, MembersArr) {
export const addMember = function (className, member) {
const theClass = classes[className]
if (typeof MembersArr === 'string') {
if (MembersArr.substr(-1) === ')') {
theClass.methods.push(MembersArr)
if (typeof member === 'string') {
if (member.substr(-1) === ')') {
theClass.methods.push(member)
} else {
theClass.members.push(MembersArr)
theClass.members.push(member)
}
}
}

export const addMembers = function (className, MembersArr) {
console.log(className, MembersArr)
if (Array.isArray(MembersArr)) {
MembersArr.forEach(member => addMember(className, member))
}
}

export const cleanupLabel = function (label) {
if (label.substring(0, 1) === ':') {
return label.substr(2).trim()
Expand Down Expand Up @@ -82,6 +89,7 @@ export default {
getClasses,
getRelations,
addRelation,
addMember,
addMembers,
cleanupLabel,
lineType,
Expand Down
4 changes: 1 addition & 3 deletions src/diagrams/class/classRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ parser.yy = classDb

const idCache = {}

let classCnt = 0
const conf = {
dividerMargin: 10,
padding: 5,
Expand Down Expand Up @@ -215,7 +214,7 @@ const drawClass = function (elem, classDef) {
}
}

const id = 'classId' + classCnt
const id = 'classId' + classDef.id
const classInfo = {
id: id,
label: classDef.id,
Expand Down Expand Up @@ -284,7 +283,6 @@ const drawClass = function (elem, classDef) {
classInfo.height = classBox.height + conf.padding + 0.5 * conf.dividerMargin

idCache[id] = classInfo
classCnt++
return classInfo
}

Expand Down
7 changes: 4 additions & 3 deletions src/diagrams/class/parser/classDiagram.jison
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ graphConfig

statements
: statement
| statement NEWLINE
| statement NEWLINE statements
;

Expand All @@ -144,8 +145,8 @@ statement
;

classStatement
: CLASS className
| CLASS className STRUCT_START members STRUCT_STOP {/*console.log($2,JSON.stringify($4));*/yy.addMembers($2,$4);}
: CLASS className {yy.addClass($2);}
| CLASS className STRUCT_START members STRUCT_STOP {/*console.log($2,JSON.stringify($4));*/yy.addClass($2);yy.addMembers($2,$4);}
;

members
Expand All @@ -155,7 +156,7 @@ members

methodStatement
: className {/*console.log('Rel found',$1);*/}
| className LABEL {yy.addMembers($1,yy.cleanupLabel($2));}
| className LABEL {yy.addMember($1,yy.cleanupLabel($2));}
| MEMBER {console.warn('Member',$1);}
| SEPARATOR {/*console.log('sep found',$1);*/}
;
Expand Down
57 changes: 30 additions & 27 deletions src/diagrams/class/parser/classDiagram.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 15404d4

Please sign in to comment.