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/README.md b/README.md index 9a7b7d2ee..b7372ce37 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ Future task2 : des4, after des3, 5d ``` classDiagram Class01 <|-- AveryLongClass : Cool +<> Class01 Class03 *-- Class04 Class05 o-- Class06 Class07 .. Class08 @@ -98,6 +99,11 @@ Class01 : size() Class01 : int chimp Class01 : int gorilla Class08 <--> C2: Cool label +class Class10 { + <> + int id + size() +} ``` ![Class diagram](./img/class.png) diff --git a/cypress/integration/rendering/classDiagram.spec.js b/cypress/integration/rendering/classDiagram.spec.js index b80f5d23c..9c0b51581 100644 --- a/cypress/integration/rendering/classDiagram.spec.js +++ b/cypress/integration/rendering/classDiagram.spec.js @@ -1,12 +1,13 @@ /* eslint-env jest */ import { imgSnapshotTest } from '../../helpers/util'; -describe('Sequencediagram', () => { - it('should render a simple class diagrams', () => { +describe('Class diagram', () => { + it('should render a simple class diagram', () => { imgSnapshotTest( ` classDiagram Class01 <|-- AveryLongClass : Cool + <<interface>> Class01 Class03 *-- Class04 Class05 o-- Class06 Class07 .. Class08 @@ -19,6 +20,11 @@ describe('Sequencediagram', () => { Class01 : int chimp Class01 : int gorilla Class08 <--> C2: Cool label + class Class10 { + <<service>> + int id + test() + } `, {} ); diff --git a/cypress/platform/viewer.js b/cypress/platform/viewer.js index b33c76502..ec42fff6a 100644 --- a/cypress/platform/viewer.js +++ b/cypress/platform/viewer.js @@ -1,50 +1,55 @@ -import { Base64 } from 'js-base64' -import mermaid2 from '../../src/mermaid' +import { Base64 } from 'js-base64'; +import mermaid2 from '../../src/mermaid'; /** * ##contentLoaded * Callback function that is called when page is loaded. This functions fetches configuration for mermaid rendering and * calls init for rendering the mermaid diagrams on the page. */ -const contentLoaded = function () { - let pos = document.location.href.indexOf('?graph=') +const contentLoaded = function() { + let pos = document.location.href.indexOf('?graph='); if (pos > 0) { - pos = pos + 7 - const graphBase64 = document.location.href.substr(pos) - const graphObj = JSON.parse(Base64.decode(graphBase64)) + pos = pos + 7; + const graphBase64 = document.location.href.substr(pos); + const graphObj = JSON.parse(Base64.decode(graphBase64)); // const graph = 'hello' - console.log(graphObj) - const div = document.createElement('div') - div.id = 'block' - div.className = 'mermaid' - div.innerHTML = graphObj.code - document.getElementsByTagName('body')[0].appendChild(div) - global.mermaid.initialize(graphObj.mermaid) + console.log(graphObj); + const div = document.createElement('div'); + div.id = 'block'; + div.className = 'mermaid'; + div.innerHTML = graphObj.code; + document.getElementsByTagName('body')[0].appendChild(div); + global.mermaid.initialize(graphObj.mermaid); // console.log('graphObj.mermaid', graphObj.mermaid) - global.mermaid.init() + global.mermaid.init(); } -} -const contentLoadedApi = function () { - let pos = document.location.href.indexOf('?graph=') +}; +const contentLoadedApi = function() { + let pos = document.location.href.indexOf('?graph='); if (pos > 0) { - pos = pos + 7 - const graphBase64 = document.location.href.substr(pos) - const graphObj = JSON.parse(Base64.decode(graphBase64)) + pos = pos + 7; + const graphBase64 = document.location.href.substr(pos); + const graphObj = JSON.parse(Base64.decode(graphBase64)); // const graph = 'hello' - const div = document.createElement('div') - div.id = 'block' - div.className = 'mermaid' + const div = document.createElement('div'); + div.id = 'block'; + div.className = 'mermaid'; // div.innerHTML = graphObj.code - document.getElementsByTagName('body')[0].appendChild(div) - global.mermaid.initialize(graphObj.mermaid) + document.getElementsByTagName('body')[0].appendChild(div); + global.mermaid.initialize(graphObj.mermaid); - mermaid2.render('newid', graphObj.code, (svgCode, bindFunctions) => { - div.innerHTML = svgCode + mermaid2.render( + 'newid', + graphObj.code, + (svgCode, bindFunctions) => { + div.innerHTML = svgCode; - bindFunctions(div) - }, div) + bindFunctions(div); + }, + div + ); } -} +}; if (typeof document !== 'undefined') { /*! @@ -52,15 +57,15 @@ if (typeof document !== 'undefined') { */ window.addEventListener( 'load', - function () { + function() { if (this.location.href.match('xss.html')) { - this.console.log('Using api') - contentLoadedApi() + this.console.log('Using api'); + contentLoadedApi(); } else { - this.console.log('Not using api') - contentLoaded() + this.console.log('Not using api'); + contentLoaded(); } }, false - ) + ); } diff --git a/dist/index.html b/dist/index.html index 027b17213..d6a856f49 100644 --- a/dist/index.html +++ b/dist/index.html @@ -399,6 +399,7 @@ merge newbranch
classDiagram Class01 <|-- AveryLongClass : Cool +<<interface>> Class01 Class03 "0" *-- "0..n" Class04 Class05 "1" o-- "many" Class06 Class07 .. Class08 @@ -411,6 +412,11 @@ Class01 : size() Class01 : int chimp Class01 : int gorilla Class08 <--> C2: Cool label +class Class10 { + <<service>> + int id + size() +}