diff --git a/src/diagrams/classDiagram/classDb.js b/src/diagrams/classDiagram/classDb.js index e69de29bb..f0af6b226 100644 --- a/src/diagrams/classDiagram/classDb.js +++ b/src/diagrams/classDiagram/classDb.js @@ -0,0 +1,67 @@ + +import * as Logger from '../../logger'; +var log = new Logger.Log(); + +var relations = []; +var classes = {}; + +// Functions to be run after graph rendering +var funs = []; +/** + * Function called by parser when a node definition has been found + * @param id + * @param text + * @param type + * @param style + */ +exports.addClass = function (id, text, type, style) { + var txt; + + if(typeof id === 'undefined'){ + return; + } + if(id.trim().length === 0){ + return; + } + + if (typeof vertices[id] === 'undefined') { + vertices[id] = {id: id, styles: [], classes:[]}; + } + if (typeof text !== 'undefined') { + txt = text.trim(); + + // strip quotes if string starts and exnds with a quote + if(txt[0] === '"' && txt[txt.length-1] === '"'){ + txt = txt.substring(1,txt.length-1); + } + + vertices[id].text = txt; + } + if (typeof type !== 'undefined') { + vertices[id].type = type; + } + if (typeof type !== 'undefined') { + vertices[id].type = type; + } + if (typeof style !== 'undefined') { + if (style !== null) { + style.forEach(function (s) { + vertices[id].styles.push(s); + }); + } + } +}; + +exports.addRelation = function (id1, id2, type1, type2, relationTitle1, relationTitle2, title) { + log.debug('Got edge', start, end); + var edge = { + id1: id1, + id2: id2, + type1: type1, + type2: type2, + relationTitle1:relationTitle1, + relationTitle2:relationTitle2, + title:title + }; + relations.push(edge); +}; \ No newline at end of file diff --git a/src/diagrams/classDiagram/parser/classDiagram.jison b/src/diagrams/classDiagram/parser/classDiagram.jison index 6e24d3af2..a9ed67825 100644 --- a/src/diagrams/classDiagram/parser/classDiagram.jison +++ b/src/diagrams/classDiagram/parser/classDiagram.jison @@ -145,12 +145,12 @@ statement classStatement : CLASS className - | CLASS className STRUCT_START members STRUCT_STOP {/*console.log($2);*/} + | CLASS className STRUCT_START members STRUCT_STOP {/*console.log($2,JSON.stringify($4));*/yy.addMembers();} ; members - : MEMBER { return $1; } - | MEMBER members { /*console.log('member: ',$1);*/} + : MEMBER { $$ = [$1]; } + | MEMBER members { $2.push($1);$$=$2;} ; methodStatement diff --git a/src/diagrams/classDiagram/parser/classDiagram.js b/src/diagrams/classDiagram/parser/classDiagram.js index 4602d3f77..11a5e0ab1 100644 --- a/src/diagrams/classDiagram/parser/classDiagram.js +++ b/src/diagrams/classDiagram/parser/classDiagram.js @@ -93,13 +93,13 @@ case 8: /*console.log('Label found',$$[$0]);*/ break; case 12: -/*console.log($$[$0-3]);*/ +console.log($$[$0-3],JSON.stringify($$[$0-1])); break; case 13: - return $$[$0]; + this.$ = [$$[$0]]; break; case 14: - /*console.log('member: ',$$[$0-1]);*/ + $$[$0].push($$[$0-1]);this.$=$$[$0]; break; case 15: /*console.log('Rel found',$$[$0]);*/