Replace require with import

This commit is contained in:
Tyler Long 2017-09-10 21:23:04 +08:00
parent c9442653e9
commit a7d79baf00
36 changed files with 693 additions and 838 deletions

View File

@ -5,7 +5,7 @@ import { jsConfig } from './webpack.config.base'
const webpackConfig = jsConfig() const webpackConfig = jsConfig()
module.exports = function (config) { export default function (config) {
config.set({ config.set({
// base path that will be used to resolve all patterns (eg. files, exclude) // base path that will be used to resolve all patterns (eg. files, exclude)

View File

@ -4,17 +4,15 @@ import which from 'which'
import parseArgs from 'minimist' import parseArgs from 'minimist'
import semver from 'semver' import semver from 'semver'
import path from 'path' import path from 'path'
import { exec } from 'child_process'
import phantom from 'phantomjs'
var exec = require('child_process').exec import pkg from '../package.json'
var PHANTOM_VERSION = '^2.1.0' var PHANTOM_VERSION = '^2.1.15'
var info = chalk.blue.bold var info = chalk.blue.bold
module.exports = (function () {
return new Cli()
}())
function Cli (options) { function Cli (options) {
this.options = { this.options = {
alias: { alias: {
@ -63,9 +61,7 @@ function Cli (options) {
Cli.prototype.parse = function (argv, next) { Cli.prototype.parse = function (argv, next) {
this.errors = [] // clear errors this.errors = [] // clear errors
var options = parseArgs(argv, this.options) var options = parseArgs(argv, this.options)
if (options.version) { if (options.version) {
var pkg = require('../package.json')
this.message = '' + pkg.version this.message = '' + pkg.version
next(null, this.message) next(null, this.message)
} else if (options.help) { } else if (options.help) {
@ -151,10 +147,8 @@ function createCheckPhantom (_phantomPath) {
return function checkPhantom (_next) { return function checkPhantom (_next) {
var next = _next || function () { } var next = _next || function () { }
var err var err
if (typeof phantomPath === 'undefined') { if (typeof phantomPath === 'undefined') {
try { try {
var phantom = require('phantomjs')
phantomPath = phantom.path phantomPath = phantom.path
} catch (e) { } catch (e) {
try { try {
@ -195,3 +189,9 @@ function createCheckPhantom (_phantomPath) {
}) })
} }
} }
const cli = (function () {
return new Cli()
}())
export default cli

View File

@ -1,12 +1,9 @@
import path from 'path' import path from 'path'
import mkdirp from 'mkdirp' import mkdirp from 'mkdirp'
import { spawn } from 'child_process'
var spawn = require('child_process').spawn
var phantomscript = path.join(__dirname, 'phantomscript.js') var phantomscript = path.join(__dirname, 'phantomscript.js')
module.exports = { process: processMermaid }
function processMermaid (files, _options, _next) { function processMermaid (files, _options, _next) {
var options = _options || {} var options = _options || {}
var outputDir = options.outputDir || process.cwd() var outputDir = options.outputDir || process.cwd()
@ -41,3 +38,5 @@ function processMermaid (files, _options, _next) {
phantom.stdout.pipe(process.stdout) phantom.stdout.pipe(process.stdout)
}) })
} }
export default { process: processMermaid }

View File

@ -14,7 +14,7 @@ classes = {
* @param type * @param type
* @param style * @param style
*/ */
exports.addClass = function (id) { export const addClass = function (id) {
if (typeof classes[id] === 'undefined') { if (typeof classes[id] === 'undefined') {
classes[id] = { classes[id] = {
id: id, id: id,
@ -24,31 +24,30 @@ exports.addClass = function (id) {
} }
} }
exports.clear = function () { export const clear = function () {
relations = [] relations = []
classes = {} classes = {}
} }
module.exports.getClass = function (id) { export const getClass = function (id) {
return classes[id] return classes[id]
} }
module.exports.getClasses = function () { export const getClasses = function () {
return classes return classes
} }
module.exports.getRelations = function () { export const getRelations = function () {
return relations return relations
} }
exports.addRelation = function (relation) { export const addRelation = function (relation) {
logger.warn('Adding relation: ' + JSON.stringify(relation)) logger.warn('Adding relation: ' + JSON.stringify(relation))
module.exports.addClass(relation.id1) addClass(relation.id1)
module.exports.addClass(relation.id2) addClass(relation.id2)
relations.push(relation) relations.push(relation)
} }
exports.addMembers = function (className, MembersArr) { export const addMembers = function (className, MembersArr) {
var theClass = classes[className] var theClass = classes[className]
if (typeof MembersArr === 'string') { if (typeof MembersArr === 'string') {
if (MembersArr.substr(-1) === ')') { if (MembersArr.substr(-1) === ')') {
@ -59,7 +58,7 @@ exports.addMembers = function (className, MembersArr) {
} }
} }
exports.cleanupLabel = function (label) { export const cleanupLabel = function (label) {
if (label.substring(0, 1) === ':') { if (label.substring(0, 1) === ':') {
return label.substr(2).trim() return label.substr(2).trim()
} else { } else {
@ -67,12 +66,12 @@ exports.cleanupLabel = function (label) {
} }
} }
exports.lineType = { export const lineType = {
LINE: 0, LINE: 0,
DOTTED_LINE: 1 DOTTED_LINE: 1
} }
exports.relationType = { export const relationType = {
AGGREGATION: 0, AGGREGATION: 0,
EXTENSION: 1, EXTENSION: 1,
COMPOSITION: 2, COMPOSITION: 2,

View File

@ -1,11 +1,11 @@
/* eslint-env jasmine */ /* eslint-env jasmine */
import { parser } from './parser/classDiagram'
import classDb from './classDb'
describe('class diagram, ', function () { describe('class diagram, ', function () {
describe('when parsing an info graph it', function () { describe('when parsing an info graph it', function () {
var cd, cDDb
beforeEach(function () { beforeEach(function () {
cd = require('./parser/classDiagram').parser parser.yy = classDb
cDDb = require('./classDb')
cd.yy = cDDb
}) })
it('should handle relation definitions', function () { it('should handle relation definitions', function () {
@ -16,7 +16,7 @@ describe('class diagram, ', function () {
'Class07 .. Class08\n' + 'Class07 .. Class08\n' +
'Class09 -- Class1' 'Class09 -- Class1'
cd.parse(str) parser.parse(str)
}) })
it('should handle relation definition of different types and directions', function () { it('should handle relation definition of different types and directions', function () {
var str = 'classDiagram\n' + var str = 'classDiagram\n' +
@ -26,7 +26,7 @@ describe('class diagram, ', function () {
'Class17 ..|> Class18\n' + 'Class17 ..|> Class18\n' +
'Class19 <--* Class20' 'Class19 <--* Class20'
cd.parse(str) parser.parse(str)
}) })
it('should handle cardinality and labels', function () { it('should handle cardinality and labels', function () {
@ -35,7 +35,7 @@ describe('class diagram, ', function () {
'Class03 o-- Class04 : aggregation\n' + 'Class03 o-- Class04 : aggregation\n' +
'Class05 --> "1" Class06' 'Class05 --> "1" Class06'
cd.parse(str) parser.parse(str)
}) })
it('should handle class definitions', function () { it('should handle class definitions', function () {
var str = 'classDiagram\n' + var str = 'classDiagram\n' +
@ -44,7 +44,7 @@ describe('class diagram, ', function () {
'Car *-- Wheel : have 4 >\n' + 'Car *-- Wheel : have 4 >\n' +
'Car -- Person : < owns' 'Car -- Person : < owns'
cd.parse(str) parser.parse(str)
}) })
it('should handle method statements', function () { it('should handle method statements', function () {
@ -54,7 +54,7 @@ describe('class diagram, ', function () {
'ArrayList : Object[] elementData\n' + 'ArrayList : Object[] elementData\n' +
'ArrayList : size()' 'ArrayList : size()'
cd.parse(str) parser.parse(str)
}) })
it('should handle parsing of method statements grouped by brackets', function () { it('should handle parsing of method statements grouped by brackets', function () {
var str = 'classDiagram\n' + var str = 'classDiagram\n' +
@ -68,7 +68,7 @@ describe('class diagram, ', function () {
' departureTime : Date\n' + ' departureTime : Date\n' +
'}' '}'
cd.parse(str) parser.parse(str)
}) })
it('should handle parsing of separators', function () { it('should handle parsing of separators', function () {
@ -100,87 +100,84 @@ describe('class diagram, ', function () {
'String password\n' + 'String password\n' +
'}' '}'
cd.parse(str) parser.parse(str)
}) })
}) })
describe('when fetching data from an classDiagram graph it', function () { describe('when fetching data from an classDiagram graph it', function () {
var cd, cDDb
beforeEach(function () { beforeEach(function () {
cd = require('./parser/classDiagram').parser parser.yy = classDb
cDDb = require('./classDb') parser.yy.clear()
cd.yy = cDDb
cd.yy.clear()
}) })
it('should handle relation definitions EXTENSION', function () { it('should handle relation definitions EXTENSION', function () {
var str = 'classDiagram\n' + var str = 'classDiagram\n' +
'Class01 <|-- Class02' 'Class01 <|-- Class02'
cd.parse(str) parser.parse(str)
var relations = cd.yy.getRelations() var relations = parser.yy.getRelations()
expect(cd.yy.getClass('Class01').id).toBe('Class01') expect(parser.yy.getClass('Class01').id).toBe('Class01')
expect(cd.yy.getClass('Class02').id).toBe('Class02') expect(parser.yy.getClass('Class02').id).toBe('Class02')
expect(relations[0].relation.type1).toBe(cDDb.relationType.EXTENSION) expect(relations[0].relation.type1).toBe(classDb.relationType.EXTENSION)
expect(relations[0].relation.type2).toBe('none') expect(relations[0].relation.type2).toBe('none')
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE) expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE)
}) })
it('should handle relation definitions AGGREGATION and dotted line', function () { it('should handle relation definitions AGGREGATION and dotted line', function () {
var str = 'classDiagram\n' + var str = 'classDiagram\n' +
'Class01 o.. Class02' 'Class01 o.. Class02'
cd.parse(str) parser.parse(str)
var relations = cd.yy.getRelations() var relations = parser.yy.getRelations()
expect(cd.yy.getClass('Class01').id).toBe('Class01') expect(parser.yy.getClass('Class01').id).toBe('Class01')
expect(cd.yy.getClass('Class02').id).toBe('Class02') expect(parser.yy.getClass('Class02').id).toBe('Class02')
expect(relations[0].relation.type1).toBe(cDDb.relationType.AGGREGATION) expect(relations[0].relation.type1).toBe(classDb.relationType.AGGREGATION)
expect(relations[0].relation.type2).toBe('none') expect(relations[0].relation.type2).toBe('none')
expect(relations[0].relation.lineType).toBe(cDDb.lineType.DOTTED_LINE) expect(relations[0].relation.lineType).toBe(classDb.lineType.DOTTED_LINE)
}) })
it('should handle relation definitions COMPOSITION on both sides', function () { it('should handle relation definitions COMPOSITION on both sides', function () {
var str = 'classDiagram\n' + var str = 'classDiagram\n' +
'Class01 *--* Class02' 'Class01 *--* Class02'
cd.parse(str) parser.parse(str)
var relations = cd.yy.getRelations() var relations = parser.yy.getRelations()
expect(cd.yy.getClass('Class01').id).toBe('Class01') expect(parser.yy.getClass('Class01').id).toBe('Class01')
expect(cd.yy.getClass('Class02').id).toBe('Class02') expect(parser.yy.getClass('Class02').id).toBe('Class02')
expect(relations[0].relation.type1).toBe(cDDb.relationType.COMPOSITION) expect(relations[0].relation.type1).toBe(classDb.relationType.COMPOSITION)
expect(relations[0].relation.type2).toBe(cDDb.relationType.COMPOSITION) expect(relations[0].relation.type2).toBe(classDb.relationType.COMPOSITION)
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE) expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE)
}) })
it('should handle relation definitions no types', function () { it('should handle relation definitions no types', function () {
var str = 'classDiagram\n' + var str = 'classDiagram\n' +
'Class01 -- Class02' 'Class01 -- Class02'
cd.parse(str) parser.parse(str)
var relations = cd.yy.getRelations() var relations = parser.yy.getRelations()
expect(cd.yy.getClass('Class01').id).toBe('Class01') expect(parser.yy.getClass('Class01').id).toBe('Class01')
expect(cd.yy.getClass('Class02').id).toBe('Class02') expect(parser.yy.getClass('Class02').id).toBe('Class02')
expect(relations[0].relation.type1).toBe('none') expect(relations[0].relation.type1).toBe('none')
expect(relations[0].relation.type2).toBe('none') expect(relations[0].relation.type2).toBe('none')
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE) expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE)
}) })
it('should handle relation definitions with type only on right side', function () { it('should handle relation definitions with type only on right side', function () {
var str = 'classDiagram\n' + var str = 'classDiagram\n' +
'Class01 --|> Class02' 'Class01 --|> Class02'
cd.parse(str) parser.parse(str)
var relations = cd.yy.getRelations() var relations = parser.yy.getRelations()
expect(cd.yy.getClass('Class01').id).toBe('Class01') expect(parser.yy.getClass('Class01').id).toBe('Class01')
expect(cd.yy.getClass('Class02').id).toBe('Class02') expect(parser.yy.getClass('Class02').id).toBe('Class02')
expect(relations[0].relation.type1).toBe('none') expect(relations[0].relation.type1).toBe('none')
expect(relations[0].relation.type2).toBe(cDDb.relationType.EXTENSION) expect(relations[0].relation.type2).toBe(classDb.relationType.EXTENSION)
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE) expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE)
}) })
it('should handle multiple classes and relation definitions', function () { it('should handle multiple classes and relation definitions', function () {
@ -191,21 +188,21 @@ describe('class diagram, ', function () {
'Class07 .. Class08\n' + 'Class07 .. Class08\n' +
'Class09 -- Class10' 'Class09 -- Class10'
cd.parse(str) parser.parse(str)
var relations = cd.yy.getRelations() var relations = parser.yy.getRelations()
expect(cd.yy.getClass('Class01').id).toBe('Class01') expect(parser.yy.getClass('Class01').id).toBe('Class01')
expect(cd.yy.getClass('Class10').id).toBe('Class10') expect(parser.yy.getClass('Class10').id).toBe('Class10')
expect(relations.length).toBe(5) expect(relations.length).toBe(5)
expect(relations[0].relation.type1).toBe(cDDb.relationType.EXTENSION) expect(relations[0].relation.type1).toBe(classDb.relationType.EXTENSION)
expect(relations[0].relation.type2).toBe('none') expect(relations[0].relation.type2).toBe('none')
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE) expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE)
expect(relations[3].relation.type1).toBe('none') expect(relations[3].relation.type1).toBe('none')
expect(relations[3].relation.type2).toBe('none') expect(relations[3].relation.type2).toBe('none')
expect(relations[3].relation.lineType).toBe(cDDb.lineType.DOTTED_LINE) expect(relations[3].relation.lineType).toBe(classDb.lineType.DOTTED_LINE)
}) })
}) })
}) })

View File

@ -1,12 +1,12 @@
import dagre from 'dagre-layout' import dagre from 'dagre-layout'
import cDDb from './classDb' import classDb from './classDb'
import d3 from '../../d3' import d3 from '../../d3'
import { logger } from '../../logger' import { logger } from '../../logger'
var cd = require('./parser/classDiagram').parser import { parser } from './parser/classDiagram'
cd.yy = cDDb parser.yy = classDb
var idCache var idCache
idCache = {} idCache = {}
@ -125,13 +125,13 @@ var edgeCount = 0
var drawEdge = function (elem, path, relation) { var drawEdge = function (elem, path, relation) {
var getRelationType = function (type) { var getRelationType = function (type) {
switch (type) { switch (type) {
case cDDb.relationType.AGGREGATION: case classDb.relationType.AGGREGATION:
return 'aggregation' return 'aggregation'
case cDDb.relationType.EXTENSION: case classDb.relationType.EXTENSION:
return 'extension' return 'extension'
case cDDb.relationType.COMPOSITION: case classDb.relationType.COMPOSITION:
return 'composition' return 'composition'
case cDDb.relationType.DEPENDENCY: case classDb.relationType.DEPENDENCY:
return 'dependency' return 'dependency'
} }
} }
@ -291,7 +291,7 @@ var drawClass = function (elem, classDef) {
return classInfo return classInfo
} }
module.exports.setConf = function (cnf) { export const setConf = function (cnf) {
var keys = Object.keys(cnf) var keys = Object.keys(cnf)
keys.forEach(function (key) { keys.forEach(function (key) {
@ -303,9 +303,9 @@ module.exports.setConf = function (cnf) {
* @param text * @param text
* @param id * @param id
*/ */
module.exports.draw = function (text, id) { export const draw = function (text, id) {
cd.yy.clear() parser.yy.clear()
cd.parse(text) parser.parse(text)
logger.info('Rendering diagram ' + text) logger.info('Rendering diagram ' + text)
@ -328,7 +328,7 @@ module.exports.draw = function (text, id) {
return {} return {}
}) })
var classes = cDDb.getClasses() var classes = classDb.getClasses()
var keys = Object.keys(classes) var keys = Object.keys(classes)
var i var i
for (i = 0; i < keys.length; i++) { for (i = 0; i < keys.length; i++) {
@ -341,7 +341,7 @@ module.exports.draw = function (text, id) {
logger.info('Org height: ' + node.height) logger.info('Org height: ' + node.height)
} }
var relations = cDDb.getRelations() var relations = classDb.getRelations()
relations.forEach(function (relation) { relations.forEach(function (relation) {
logger.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation)) logger.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation))
g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), { relation: relation }) g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), { relation: relation })

View File

@ -1,19 +1,20 @@
import { parser } from './parser/example'
import exampleDb from './exampleDb'
/* eslint-env jasmine */ /* eslint-env jasmine */
describe('when parsing an info graph it', function () { describe('when parsing an info graph it', function () {
var ex
beforeEach(function () { beforeEach(function () {
ex = require('./parser/example').parser parser.yy = exampleDb
ex.yy = require('./exampleDb')
}) })
it('should handle an info definition', function () { it('should handle an info definition', function () {
var str = 'info\nsay: hello' var str = 'info\nsay: hello'
ex.parse(str) parser.parse(str)
}) })
it('should handle an showMessage statement definition', function () { it('should handle an showMessage statement definition', function () {
var str = 'info\nshowInfo' var str = 'info\nshowInfo'
ex.parse(str) parser.parse(str)
}) })
}) })

View File

@ -3,19 +3,19 @@ import { logger } from '../../logger'
var message = '' var message = ''
var info = false var info = false
exports.setMessage = function (txt) { export const setMessage = function (txt) {
logger.debug('Setting message to: ' + txt) logger.debug('Setting message to: ' + txt)
message = txt message = txt
} }
exports.getMessage = function () { export const getMessage = function () {
return message return message
} }
exports.setInfo = function (inf) { export const setInfo = function (inf) {
info = inf info = inf
} }
exports.getInfo = function () { export const getInfo = function () {
return info return info
} }

View File

@ -9,7 +9,7 @@ import { logger } from '../../logger'
* @param text * @param text
* @param id * @param id
*/ */
exports.draw = function (txt, id, ver) { export const draw = function (txt, id, ver) {
var parser var parser
parser = exampleParser.parser parser = exampleParser.parser
parser.yy = db parser.yy = db

View File

@ -7,7 +7,7 @@ import { logger } from '../../logger'
var conf = { var conf = {
} }
module.exports.setConf = function (cnf) { export const setConf = function (cnf) {
var keys = Object.keys(cnf) var keys = Object.keys(cnf)
var i var i
for (i = 0; i < keys.length; i++) { for (i = 0; i < keys.length; i++) {
@ -20,7 +20,7 @@ module.exports.setConf = function (cnf) {
* @param vert Object containing the vertices. * @param vert Object containing the vertices.
* @param g The graph that is to be drawn. * @param g The graph that is to be drawn.
*/ */
module.exports.addVertices = function (vert, g) { export const addVertices = function (vert, g) {
var keys = Object.keys(vert) var keys = Object.keys(vert)
var styleFromStyleArr = function (styleStr, arr) { var styleFromStyleArr = function (styleStr, arr) {
@ -135,7 +135,7 @@ module.exports.addVertices = function (vert, g) {
* @param {Object} edges The edges to add to the graph * @param {Object} edges The edges to add to the graph
* @param {Object} g The graph object * @param {Object} g The graph object
*/ */
module.exports.addEdges = function (edges, g) { export const addEdges = function (edges, g) {
var cnt = 0 var cnt = 0
var defaultStyle var defaultStyle
@ -215,7 +215,7 @@ module.exports.addEdges = function (edges, g) {
* Returns the all the styles from classDef statements in the graph definition. * Returns the all the styles from classDef statements in the graph definition.
* @returns {object} classDef styles * @returns {object} classDef styles
*/ */
module.exports.getClasses = function (text, isDot) { export const getClasses = function (text, isDot) {
var parser var parser
graph.clear() graph.clear()
if (isDot) { if (isDot) {
@ -246,7 +246,7 @@ module.exports.getClasses = function (text, isDot) {
* @param text * @param text
* @param id * @param id
*/ */
module.exports.draw = function (text, id, isDot) { export const draw = function (text, id, isDot) {
logger.debug('Drawing flowchart') logger.debug('Drawing flowchart')
var parser var parser
graph.clear() graph.clear()
@ -310,8 +310,8 @@ module.exports.draw = function (text, id, isDot) {
g.setParent(subG.nodes[j], subG.id) g.setParent(subG.nodes[j], subG.id)
} }
} }
module.exports.addVertices(vert, g) addVertices(vert, g)
module.exports.addEdges(edges, g) addEdges(edges, g)
// Create the renderer // Create the renderer
var Render = dagreD3.render var Render = dagreD3.render

View File

@ -18,7 +18,7 @@ var funs = []
* @param type * @param type
* @param style * @param style
*/ */
exports.addVertex = function (id, text, type, style) { export const addVertex = function (id, text, type, style) {
var txt var txt
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
@ -63,7 +63,7 @@ exports.addVertex = function (id, text, type, style) {
* @param type * @param type
* @param linktext * @param linktext
*/ */
exports.addLink = function (start, end, type, linktext) { export const addLink = function (start, end, type, linktext) {
logger.info('Got edge...', start, end) logger.info('Got edge...', start, end)
var edge = { start: start, end: end, type: undefined, text: '' } var edge = { start: start, end: end, type: undefined, text: '' }
linktext = type.text linktext = type.text
@ -89,7 +89,7 @@ exports.addLink = function (start, end, type, linktext) {
* @param pos * @param pos
* @param interpolate * @param interpolate
*/ */
exports.updateLinkInterpolate = function (pos, interp) { export const updateLinkInterpolate = function (pos, interp) {
if (pos === 'default') { if (pos === 'default') {
edges.defaultInterpolate = interp edges.defaultInterpolate = interp
} else { } else {
@ -102,7 +102,7 @@ exports.updateLinkInterpolate = function (pos, interp) {
* @param pos * @param pos
* @param style * @param style
*/ */
exports.updateLink = function (pos, style) { export const updateLink = function (pos, style) {
if (pos === 'default') { if (pos === 'default') {
edges.defaultStyle = style edges.defaultStyle = style
} else { } else {
@ -113,7 +113,7 @@ exports.updateLink = function (pos, style) {
} }
} }
exports.addClass = function (id, style) { export const addClass = function (id, style) {
if (typeof classes[id] === 'undefined') { if (typeof classes[id] === 'undefined') {
classes[id] = { id: id, styles: [] } classes[id] = { id: id, styles: [] }
} }
@ -131,7 +131,7 @@ exports.addClass = function (id, style) {
* Called by parser when a graph definition is found, stores the direction of the chart. * Called by parser when a graph definition is found, stores the direction of the chart.
* @param dir * @param dir
*/ */
exports.setDirection = function (dir) { export const setDirection = function (dir) {
direction = dir direction = dir
} }
@ -139,7 +139,7 @@ exports.setDirection = function (dir) {
* Called by parser when a graph definition is found, stores the direction of the chart. * Called by parser when a graph definition is found, stores the direction of the chart.
* @param dir * @param dir
*/ */
exports.setClass = function (id, className) { export const setClass = function (id, className) {
if (id.indexOf(',') > 0) { if (id.indexOf(',') > 0) {
id.split(',').forEach(function (id2) { id.split(',').forEach(function (id2) {
if (typeof vertices[id2] !== 'undefined') { if (typeof vertices[id2] !== 'undefined') {
@ -190,7 +190,7 @@ var setLink = function (id, linkStr) {
}) })
} }
} }
exports.getTooltip = function (id) { export const getTooltip = function (id) {
return tooltips[id] return tooltips[id]
} }
@ -198,7 +198,7 @@ exports.getTooltip = function (id) {
* Called by parser when a graph definition is found, stores the direction of the chart. * Called by parser when a graph definition is found, stores the direction of the chart.
* @param dir * @param dir
*/ */
exports.setClickEvent = function (id, functionName, link, tooltip) { export const setClickEvent = function (id, functionName, link, tooltip) {
if (id.indexOf(',') > 0) { if (id.indexOf(',') > 0) {
id.split(',').forEach(function (id2) { id.split(',').forEach(function (id2) {
setTooltip(id2, tooltip) setTooltip(id2, tooltip)
@ -212,19 +212,19 @@ exports.setClickEvent = function (id, functionName, link, tooltip) {
} }
} }
exports.bindFunctions = function (element) { export const bindFunctions = function (element) {
funs.forEach(function (fun) { funs.forEach(function (fun) {
fun(element) fun(element)
}) })
} }
exports.getDirection = function () { export const getDirection = function () {
return direction return direction
} }
/** /**
* Retrieval function for fetching the found nodes after parsing has completed. * Retrieval function for fetching the found nodes after parsing has completed.
* @returns {{}|*|vertices} * @returns {{}|*|vertices}
*/ */
exports.getVertices = function () { export const getVertices = function () {
return vertices return vertices
} }
@ -232,7 +232,7 @@ exports.getVertices = function () {
* Retrieval function for fetching the found links after parsing has completed. * Retrieval function for fetching the found links after parsing has completed.
* @returns {{}|*|edges} * @returns {{}|*|edges}
*/ */
exports.getEdges = function () { export const getEdges = function () {
return edges return edges
} }
@ -240,7 +240,7 @@ exports.getEdges = function () {
* Retrieval function for fetching the found class definitions after parsing has completed. * Retrieval function for fetching the found class definitions after parsing has completed.
* @returns {{}|*|classes} * @returns {{}|*|classes}
*/ */
exports.getClasses = function () { export const getClasses = function () {
return classes return classes
} }
@ -287,7 +287,7 @@ funs.push(setupToolTips)
/** /**
* Clears the internal graph db so that a new graph can be parsed. * Clears the internal graph db so that a new graph can be parsed.
*/ */
exports.clear = function () { export const clear = function () {
vertices = {} vertices = {}
classes = {} classes = {}
edges = [] edges = []
@ -301,14 +301,14 @@ exports.clear = function () {
* *
* @returns {string} * @returns {string}
*/ */
exports.defaultStyle = function () { export const defaultStyle = function () {
return 'fill:#ffa;stroke: #f66; stroke-width: 3px; stroke-dasharray: 5, 5;fill:#ffa;stroke: #666;' return 'fill:#ffa;stroke: #f66; stroke-width: 3px; stroke-dasharray: 5, 5;fill:#ffa;stroke: #666;'
} }
/** /**
* Clears the internal graph db so that a new graph can be parsed. * Clears the internal graph db so that a new graph can be parsed.
*/ */
exports.addSubGraph = function (list, title) { export const addSubGraph = function (list, title) {
function uniq (a) { function uniq (a) {
var prims = { 'boolean': {}, 'number': {}, 'string': {} } var prims = { 'boolean': {}, 'number': {}, 'string': {} }
var objs = [] var objs = []
@ -343,7 +343,7 @@ var getPosForId = function (id) {
} }
var secCount = -1 var secCount = -1
var posCrossRef = [] var posCrossRef = []
var indexNodes = function (id, pos) { var indexNodes2 = function (id, pos) {
var nodes = subGraphs[pos].nodes var nodes = subGraphs[pos].nodes
secCount = secCount + 1 secCount = secCount + 1
if (secCount > 2000) { if (secCount > 2000) {
@ -364,7 +364,7 @@ var indexNodes = function (id, pos) {
var childPos = getPosForId(nodes[count]) var childPos = getPosForId(nodes[count])
// Ignore regular nodes (pos will be -1) // Ignore regular nodes (pos will be -1)
if (childPos >= 0) { if (childPos >= 0) {
var res = indexNodes(id, childPos) var res = indexNodes2(id, childPos)
if (res.result) { if (res.result) {
return { return {
result: true, result: true,
@ -383,16 +383,16 @@ var indexNodes = function (id, pos) {
} }
} }
exports.getDepthFirstPos = function (pos) { export const getDepthFirstPos = function (pos) {
return posCrossRef[pos] return posCrossRef[pos]
} }
exports.indexNodes = function () { export const indexNodes = function () {
secCount = -1 secCount = -1
if (subGraphs.length > 0) { if (subGraphs.length > 0) {
indexNodes('none', subGraphs.length - 1, 0) indexNodes2('none', subGraphs.length - 1, 0)
} }
} }
exports.getSubGraphs = function () { export const getSubGraphs = function () {
return subGraphs return subGraphs
} }

View File

@ -1,9 +1,9 @@
import graph from '../graphDb' import graphDb from '../graphDb'
import flow from './flow' import flow from './flow'
describe('when parsing ', function () { describe('when parsing ', function () {
beforeEach(function () { beforeEach(function () {
flow.parser.yy = require('../graphDb') flow.parser.yy = graphDb
flow.parser.yy.clear() flow.parser.yy.clear()
}) })
@ -469,42 +469,42 @@ describe('when parsing ', function () {
describe('it should handle interaction, ', function () { describe('it should handle interaction, ', function () {
it('it should be possible to use click to a callback', function () { it('it should be possible to use click to a callback', function () {
spyOn(graph, 'setClickEvent') spyOn(graphDb, 'setClickEvent')
var res = flow.parser.parse('graph TD\nA-->B\nclick A callback') var res = flow.parser.parse('graph TD\nA-->B\nclick A callback')
var vert = flow.parser.yy.getVertices() var vert = flow.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flow.parser.yy.getEdges()
expect(graph.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, undefined) expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, undefined)
}) })
it('it should be possible to use click to a callback with toolip', function () { it('it should be possible to use click to a callback with toolip', function () {
spyOn(graph, 'setClickEvent') spyOn(graphDb, 'setClickEvent')
var res = flow.parser.parse('graph TD\nA-->B\nclick A callback "tooltip"') var res = flow.parser.parse('graph TD\nA-->B\nclick A callback "tooltip"')
var vert = flow.parser.yy.getVertices() var vert = flow.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flow.parser.yy.getEdges()
expect(graph.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, 'tooltip') expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', 'callback', undefined, 'tooltip')
}) })
it('should handle interaction - click to a link', function () { it('should handle interaction - click to a link', function () {
spyOn(graph, 'setClickEvent') spyOn(graphDb, 'setClickEvent')
var res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html"') var res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html"')
var vert = flow.parser.yy.getVertices() var vert = flow.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flow.parser.yy.getEdges()
expect(graph.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', undefined) expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', undefined)
}) })
it('should handle interaction - click to a link with tooltip', function () { it('should handle interaction - click to a link with tooltip', function () {
spyOn(graph, 'setClickEvent') spyOn(graphDb, 'setClickEvent')
var res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html" "tooltip"') var res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html" "tooltip"')
var vert = flow.parser.yy.getVertices() var vert = flow.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flow.parser.yy.getEdges()
expect(graph.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', 'tooltip') expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', 'tooltip')
}) })
}) })

View File

@ -1,30 +1,31 @@
/* eslint-env jasmine */ /* eslint-env jasmine */
import { parser } from './parser/gantt'
import ganttDb from './ganttDb'
describe('when parsing a gantt diagram it', function () { describe('when parsing a gantt diagram it', function () {
var gantt
beforeEach(function () { beforeEach(function () {
gantt = require('./parser/gantt').parser parser.yy = ganttDb
gantt.yy = require('./ganttDb')
}) })
it('should handle an dateFormat definition', function () { it('should handle an dateFormat definition', function () {
var str = 'gantt\ndateFormat yyyy-mm-dd' var str = 'gantt\ndateFormat yyyy-mm-dd'
gantt.parse(str) parser.parse(str)
}) })
it('should handle an dateFormat definition', function () { it('should handle an dateFormat definition', function () {
var str = 'gantt\ndateFormat yyyy-mm-dd\ntitle Adding gantt diagram functionality to mermaid' var str = 'gantt\ndateFormat yyyy-mm-dd\ntitle Adding gantt diagram functionality to mermaid'
gantt.parse(str) parser.parse(str)
}) })
it('should handle an dateFormat definition', function () { it('should handle an dateFormat definition', function () {
var str = 'gantt\ndateFormat yyyy-mm-dd\ntitle Adding gantt diagram functionality to mermaid' var str = 'gantt\ndateFormat yyyy-mm-dd\ntitle Adding gantt diagram functionality to mermaid'
gantt.parse(str) parser.parse(str)
}) })
it('should handle an section definition', function () { it('should handle an section definition', function () {
var str = 'gantt\ndateFormat yyyy-mm-dd\ntitle Adding gantt diagram functionality to mermaid' var str = 'gantt\ndateFormat yyyy-mm-dd\ntitle Adding gantt diagram functionality to mermaid'
gantt.parse(str) parser.parse(str)
}) })
/** /**
* Beslutsflöde inligt nedan. Obs bla bla bla * Beslutsflöde inligt nedan. Obs bla bla bla
@ -44,6 +45,6 @@ describe('when parsing a gantt diagram it', function () {
'section Documentation\n' + 'section Documentation\n' +
'Design jison grammar:des1, 2014-01-01, 2014-01-04' 'Design jison grammar:des1, 2014-01-01, 2014-01-04'
gantt.parse(str) parser.parse(str)
}) })
}) })

View File

@ -7,7 +7,7 @@ var sections = []
var tasks = [] var tasks = []
var currentSection = '' var currentSection = ''
module.exports.clear = function () { export const clear = function () {
sections = [] sections = []
tasks = [] tasks = []
currentSection = '' currentSection = ''
@ -18,27 +18,27 @@ module.exports.clear = function () {
rawTasks = [] rawTasks = []
} }
module.exports.setDateFormat = function (txt) { export const setDateFormat = function (txt) {
dateFormat = txt dateFormat = txt
} }
module.exports.getDateFormat = function () { export const getDateFormat = function () {
return dateFormat return dateFormat
} }
module.exports.setTitle = function (txt) { export const setTitle = function (txt) {
title = txt title = txt
} }
module.exports.getTitle = function () { export const getTitle = function () {
return title return title
} }
module.exports.addSection = function (txt) { export const addSection = function (txt) {
currentSection = txt currentSection = txt
sections.push(txt) sections.push(txt)
} }
module.exports.getTasks = function () { export const getTasks = function () {
var allItemsPricessed = compileTasks() var allItemsPricessed = compileTasks()
var maxDepth = 10 var maxDepth = 10
var iterationCount = 0 var iterationCount = 0
@ -60,7 +60,7 @@ var getStartDate = function (prevTime, dateFormat, str) {
var afterStatement = re.exec(str.trim()) var afterStatement = re.exec(str.trim())
if (afterStatement !== null) { if (afterStatement !== null) {
var task = module.exports.findTaskById(afterStatement[1]) var task = findTaskById(afterStatement[1])
if (typeof task === 'undefined') { if (typeof task === 'undefined') {
var dt = new Date() var dt = new Date()
@ -150,7 +150,7 @@ var compileData = function (prevTask, dataStr) {
var data = ds.split(',') var data = ds.split(',')
var task = {} var task = {}
var df = module.exports.getDateFormat() var df = getDateFormat()
// Get tags like active, done cand crit // Get tags like active, done cand crit
var matchFound = true var matchFound = true
@ -263,7 +263,7 @@ var lastTask
var lastTaskID var lastTaskID
var rawTasks = [] var rawTasks = []
var taskDb = {} var taskDb = {}
module.exports.addTask = function (descr, data) { export const addTask = function (descr, data) {
var rawTask = { var rawTask = {
section: currentSection, section: currentSection,
type: currentSection, type: currentSection,
@ -287,12 +287,12 @@ module.exports.addTask = function (descr, data) {
taskDb[rawTask.id] = pos - 1 taskDb[rawTask.id] = pos - 1
} }
module.exports.findTaskById = function (id) { export const findTaskById = function (id) {
var pos = taskDb[id] var pos = taskDb[id]
return rawTasks[pos] return rawTasks[pos]
} }
module.exports.addTaskOrg = function (descr, data) { export const addTaskOrg = function (descr, data) {
var newTask = { var newTask = {
section: currentSection, section: currentSection,
type: currentSection, type: currentSection,
@ -311,14 +311,14 @@ module.exports.addTaskOrg = function (descr, data) {
} }
var compileTasks = function () { var compileTasks = function () {
var df = module.exports.getDateFormat() var df = getDateFormat()
var compileTask = function (pos) { var compileTask = function (pos) {
var task = rawTasks[pos] var task = rawTasks[pos]
var startTime = '' var startTime = ''
switch (rawTasks[pos].raw.startTime.type) { switch (rawTasks[pos].raw.startTime.type) {
case 'prevTaskEnd': case 'prevTaskEnd':
var prevTask = module.exports.findTaskById(task.prevTaskId) var prevTask = findTaskById(task.prevTaskId)
task.startTime = prevTask.endTime task.startTime = prevTask.endTime
break break
case 'getStartDate': case 'getStartDate':

View File

@ -1,68 +1,67 @@
/* eslint-env jasmine */ /* eslint-env jasmine */
describe('when using the ganttDb', function () { import moment from 'moment'
var gDb import ganttDb from './ganttDb'
var moment = require('moment')
describe('when using the ganttDb', function () {
beforeEach(function () { beforeEach(function () {
gDb = require('./ganttDb') ganttDb.clear()
gDb.clear()
}) })
it('should handle an fixed dates', function () { it('should handle an fixed dates', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2013-01-12') ganttDb.addTask('test1', 'id1,2013-01-01,2013-01-12')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate())
expect(tasks[0].endTime).toEqual(moment('2013-01-12', 'YYYY-MM-DD').toDate()) expect(tasks[0].endTime).toEqual(moment('2013-01-12', 'YYYY-MM-DD').toDate())
expect(tasks[0].id).toEqual('id1') expect(tasks[0].id).toEqual('id1')
expect(tasks[0].task).toEqual('test1') expect(tasks[0].task).toEqual('test1')
}) })
it('should handle duration (days) instead of fixed date to determine end date', function () { it('should handle duration (days) instead of fixed date to determine end date', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2d') ganttDb.addTask('test1', 'id1,2013-01-01,2d')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate())
expect(tasks[0].endTime).toEqual(moment('2013-01-03', 'YYYY-MM-DD').toDate()) expect(tasks[0].endTime).toEqual(moment('2013-01-03', 'YYYY-MM-DD').toDate())
expect(tasks[0].id).toEqual('id1') expect(tasks[0].id).toEqual('id1')
expect(tasks[0].task).toEqual('test1') expect(tasks[0].task).toEqual('test1')
}) })
it('should handle duration (hours) instead of fixed date to determine end date', function () { it('should handle duration (hours) instead of fixed date to determine end date', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2h') ganttDb.addTask('test1', 'id1,2013-01-01,2h')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate())
expect(tasks[0].endTime).toEqual(moment('2013-01-01 2:00', 'YYYY-MM-DD hh:mm').toDate()) expect(tasks[0].endTime).toEqual(moment('2013-01-01 2:00', 'YYYY-MM-DD hh:mm').toDate())
expect(tasks[0].id).toEqual('id1') expect(tasks[0].id).toEqual('id1')
expect(tasks[0].task).toEqual('test1') expect(tasks[0].task).toEqual('test1')
}) })
it('should handle duration (minutes) instead of fixed date to determine end date', function () { it('should handle duration (minutes) instead of fixed date to determine end date', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2m') ganttDb.addTask('test1', 'id1,2013-01-01,2m')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate())
expect(tasks[0].endTime).toEqual(moment('2013-01-01 00:02', 'YYYY-MM-DD hh:mm').toDate()) expect(tasks[0].endTime).toEqual(moment('2013-01-01 00:02', 'YYYY-MM-DD hh:mm').toDate())
expect(tasks[0].id).toEqual('id1') expect(tasks[0].id).toEqual('id1')
expect(tasks[0].task).toEqual('test1') expect(tasks[0].task).toEqual('test1')
}) })
it('should handle duration (seconds) instead of fixed date to determine end date', function () { it('should handle duration (seconds) instead of fixed date to determine end date', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2s') ganttDb.addTask('test1', 'id1,2013-01-01,2s')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate())
expect(tasks[0].endTime).toEqual(moment('2013-01-01 00:00:02', 'YYYY-MM-DD hh:mm:ss').toDate()) expect(tasks[0].endTime).toEqual(moment('2013-01-01 00:00:02', 'YYYY-MM-DD hh:mm:ss').toDate())
expect(tasks[0].id).toEqual('id1') expect(tasks[0].id).toEqual('id1')
expect(tasks[0].task).toEqual('test1') expect(tasks[0].task).toEqual('test1')
}) })
it('should handle duration (weeks) instead of fixed date to determine end date', function () { it('should handle duration (weeks) instead of fixed date to determine end date', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2w') ganttDb.addTask('test1', 'id1,2013-01-01,2w')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate())
expect(tasks[0].endTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) expect(tasks[0].endTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate())
expect(tasks[0].id).toEqual('id1') expect(tasks[0].id).toEqual('id1')
@ -70,12 +69,12 @@ describe('when using the ganttDb', function () {
}) })
it('should handle relative start date based on id', function () { it('should handle relative start date based on id', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2w') ganttDb.addTask('test1', 'id1,2013-01-01,2w')
gDb.addTask('test2', 'id2,after id1,1d') ganttDb.addTask('test2', 'id2,after id1,1d')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate())
expect(tasks[1].id).toEqual('id2') expect(tasks[1].id).toEqual('id2')
@ -83,21 +82,21 @@ describe('when using the ganttDb', function () {
}) })
it('should handle relative start date based on id when id is invalid', function () { it('should handle relative start date based on id when id is invalid', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2w') ganttDb.addTask('test1', 'id1,2013-01-01,2w')
gDb.addTask('test2', 'id2,after id3,1d') ganttDb.addTask('test2', 'id2,after id3,1d')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[1].startTime).toEqual(new Date((new Date()).setHours(0, 0, 0, 0))) expect(tasks[1].startTime).toEqual(new Date((new Date()).setHours(0, 0, 0, 0)))
expect(tasks[1].id).toEqual('id2') expect(tasks[1].id).toEqual('id2')
expect(tasks[1].task).toEqual('test2') expect(tasks[1].task).toEqual('test2')
}) })
it('should handle fixed dates without id', function () { it('should handle fixed dates without id', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', '2013-01-01,2013-01-12') ganttDb.addTask('test1', '2013-01-01,2013-01-12')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate())
expect(tasks[0].endTime).toEqual(moment('2013-01-12', 'YYYY-MM-DD').toDate()) expect(tasks[0].endTime).toEqual(moment('2013-01-12', 'YYYY-MM-DD').toDate())
expect(tasks[0].id).toEqual('task1') expect(tasks[0].id).toEqual('task1')
@ -105,10 +104,10 @@ describe('when using the ganttDb', function () {
}) })
it('should handle duration instead of a fixed date to determine end date without id', function () { it('should handle duration instead of a fixed date to determine end date without id', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', '2013-01-01,4d') ganttDb.addTask('test1', '2013-01-01,4d')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate()) expect(tasks[0].startTime).toEqual(moment('2013-01-01', 'YYYY-MM-DD').toDate())
expect(tasks[0].endTime).toEqual(moment('2013-01-05', 'YYYY-MM-DD').toDate()) expect(tasks[0].endTime).toEqual(moment('2013-01-05', 'YYYY-MM-DD').toDate())
expect(tasks[0].id).toEqual('task1') expect(tasks[0].id).toEqual('task1')
@ -116,24 +115,24 @@ describe('when using the ganttDb', function () {
}) })
it('should handle relative start date of a fixed date to determine end date without id', function () { it('should handle relative start date of a fixed date to determine end date without id', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2w') ganttDb.addTask('test1', 'id1,2013-01-01,2w')
gDb.addTask('test2', 'after id1,1d') ganttDb.addTask('test2', 'after id1,1d')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate())
expect(tasks[1].id).toEqual('task1') expect(tasks[1].id).toEqual('task1')
expect(tasks[1].task).toEqual('test2') expect(tasks[1].task).toEqual('test2')
}) })
it('should handle a new task with only an end date as definition', function () { it('should handle a new task with only an end date as definition', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2w') ganttDb.addTask('test1', 'id1,2013-01-01,2w')
gDb.addTask('test2', '2013-01-26') ganttDb.addTask('test2', '2013-01-26')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate())
expect(tasks[1].endTime).toEqual(moment('2013-01-26', 'YYYY-MM-DD').toDate()) expect(tasks[1].endTime).toEqual(moment('2013-01-26', 'YYYY-MM-DD').toDate())
@ -141,12 +140,12 @@ describe('when using the ganttDb', function () {
expect(tasks[1].task).toEqual('test2') expect(tasks[1].task).toEqual('test2')
}) })
it('should handle a new task with only an end date as definition', function () { it('should handle a new task with only an end date as definition', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2w') ganttDb.addTask('test1', 'id1,2013-01-01,2w')
gDb.addTask('test2', '2d') ganttDb.addTask('test2', '2d')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate())
expect(tasks[1].endTime).toEqual(moment('2013-01-17', 'YYYY-MM-DD').toDate()) expect(tasks[1].endTime).toEqual(moment('2013-01-17', 'YYYY-MM-DD').toDate())
@ -154,14 +153,14 @@ describe('when using the ganttDb', function () {
expect(tasks[1].task).toEqual('test2') expect(tasks[1].task).toEqual('test2')
}) })
it('should handle relative start date based on id regardless of sections', function () { it('should handle relative start date based on id regardless of sections', function () {
gDb.setDateFormat('YYYY-MM-DD') ganttDb.setDateFormat('YYYY-MM-DD')
gDb.addSection('testa1') ganttDb.addSection('testa1')
gDb.addTask('test1', 'id1,2013-01-01,2w') ganttDb.addTask('test1', 'id1,2013-01-01,2w')
gDb.addTask('test2', 'id2,after id3,1d') ganttDb.addTask('test2', 'id2,after id3,1d')
gDb.addSection('testa2') ganttDb.addSection('testa2')
gDb.addTask('test3', 'id3,after id1,2d') ganttDb.addTask('test3', 'id3,after id1,2d')
var tasks = gDb.getTasks() var tasks = ganttDb.getTasks()
expect(tasks[1].startTime).toEqual(moment('2013-01-17', 'YYYY-MM-DD').toDate()) expect(tasks[1].startTime).toEqual(moment('2013-01-17', 'YYYY-MM-DD').toDate())
expect(tasks[1].endTime).toEqual(moment('2013-01-18', 'YYYY-MM-DD').toDate()) expect(tasks[1].endTime).toEqual(moment('2013-01-18', 'YYYY-MM-DD').toDate())

View File

@ -1,9 +1,11 @@
import moment from 'moment' import moment from 'moment'
import { parser } from './parser/gantt'
import ganttDb from './ganttDb'
import d3 from '../../d3' import d3 from '../../d3'
var gantt = require('./parser/gantt').parser
gantt.yy = require('./ganttDb') parser.yy = ganttDb
var daysInChart var daysInChart
var conf = { var conf = {
@ -17,7 +19,7 @@ var conf = {
fontSize: 11, fontSize: 11,
fontFamily: '"Open-Sans", "sans-serif"' fontFamily: '"Open-Sans", "sans-serif"'
} }
module.exports.setConf = function (cnf) { export const setConf = function (cnf) {
var keys = Object.keys(cnf) var keys = Object.keys(cnf)
keys.forEach(function (key) { keys.forEach(function (key) {
@ -25,9 +27,9 @@ module.exports.setConf = function (cnf) {
}) })
} }
var w var w
module.exports.draw = function (text, id) { export const draw = function (text, id) {
gantt.yy.clear() parser.yy.clear()
gantt.parse(text) parser.parse(text)
var elem = document.getElementById(id) var elem = document.getElementById(id)
w = elem.parentElement.offsetWidth w = elem.parentElement.offsetWidth
@ -40,7 +42,7 @@ module.exports.draw = function (text, id) {
w = conf.useWidth w = conf.useWidth
} }
var taskArray = gantt.yy.getTasks() var taskArray = parser.yy.getTasks()
// Set height based on number of tasks // Set height based on number of tasks
var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding
@ -85,7 +87,7 @@ module.exports.draw = function (text, id) {
} }
svg.append('text') svg.append('text')
.text(gantt.yy.getTitle()) .text(parser.yy.getTitle())
.attr('x', w / 2) .attr('x', w / 2)
.attr('y', conf.titleTopMargin) .attr('y', conf.titleTopMargin)
.attr('class', 'titleText') .attr('class', 'titleText')

View File

@ -46,11 +46,11 @@ function isReachableFrom (currentCommit, otherCommit) {
return false return false
} }
module.exports.setDirection = function (dir) { export const setDirection = function (dir) {
direction = dir direction = dir
} }
var options = {} var options = {}
module.exports.setOptions = function (rawOptString) { export const setOptions = function (rawOptString) {
logger.debug('options str', rawOptString) logger.debug('options str', rawOptString)
rawOptString = rawOptString && rawOptString.trim() rawOptString = rawOptString && rawOptString.trim()
rawOptString = rawOptString || '{}' rawOptString = rawOptString || '{}'
@ -61,11 +61,11 @@ module.exports.setOptions = function (rawOptString) {
} }
} }
module.exports.getOptions = function () { export const getOptions = function () {
return options return options
} }
module.exports.commit = function (msg) { export const commit = function (msg) {
var commit = { var commit = {
id: getId(), id: getId(),
message: msg, message: msg,
@ -78,12 +78,12 @@ module.exports.commit = function (msg) {
logger.debug('in pushCommit ' + commit.id) logger.debug('in pushCommit ' + commit.id)
} }
module.exports.branch = function (name) { export const branch = function (name) {
branches[name] = head != null ? head.id : null branches[name] = head != null ? head.id : null
logger.debug('in createBranch') logger.debug('in createBranch')
} }
module.exports.merge = function (otherBranch) { export const merge = function (otherBranch) {
var currentCommit = commits[branches[curBranch]] var currentCommit = commits[branches[curBranch]]
var otherCommit = commits[branches[otherBranch]] var otherCommit = commits[branches[otherBranch]]
if (isReachableFrom(currentCommit, otherCommit)) { if (isReachableFrom(currentCommit, otherCommit)) {
@ -109,14 +109,14 @@ module.exports.merge = function (otherBranch) {
logger.debug('in mergeBranch') logger.debug('in mergeBranch')
} }
module.exports.checkout = function (branch) { export const checkout = function (branch) {
logger.debug('in checkout') logger.debug('in checkout')
curBranch = branch curBranch = branch
var id = branches[curBranch] var id = branches[curBranch]
head = commits[id] head = commits[id]
} }
module.exports.reset = function (commitRef) { export const reset = function (commitRef) {
logger.debug('in reset', commitRef) logger.debug('in reset', commitRef)
var ref = commitRef.split(':')[0] var ref = commitRef.split(':')[0]
var parentCount = parseInt(commitRef.split(':')[1]) var parentCount = parseInt(commitRef.split(':')[1])
@ -173,13 +173,13 @@ function prettyPrintCommitHistory (commitArr) {
prettyPrintCommitHistory(commitArr) prettyPrintCommitHistory(commitArr)
} }
module.exports.prettyPrint = function () { export const prettyPrint = function () {
logger.debug(commits) logger.debug(commits)
var node = module.exports.getCommitsArray()[0] var node = getCommitsArray()[0]
prettyPrintCommitHistory([node]) prettyPrintCommitHistory([node])
} }
module.exports.clear = function () { export const clear = function () {
commits = {} commits = {}
head = null head = null
branches = { 'master': head } branches = { 'master': head }
@ -187,22 +187,22 @@ module.exports.clear = function () {
seq = 0 seq = 0
} }
module.exports.getBranchesAsObjArray = function () { export const getBranchesAsObjArray = function () {
const branchArr = _.map(branches, function (value, key) { const branchArr = _.map(branches, function (value, key) {
return { 'name': key, 'commit': commits[value] } return { 'name': key, 'commit': commits[value] }
}) })
return branchArr return branchArr
} }
module.exports.getBranches = function () { return branches } export const getBranches = function () { return branches }
module.exports.getCommits = function () { return commits } export const getCommits = function () { return commits }
module.exports.getCommitsArray = function () { export const getCommitsArray = function () {
var commitArr = Object.keys(commits).map(function (key) { var commitArr = Object.keys(commits).map(function (key) {
return commits[key] return commits[key]
}) })
commitArr.forEach(function (o) { logger.debug(o.id) }) commitArr.forEach(function (o) { logger.debug(o.id) })
return _.orderBy(commitArr, ['seq'], ['desc']) return _.orderBy(commitArr, ['seq'], ['desc'])
} }
module.exports.getCurrentBranch = function () { return curBranch } export const getCurrentBranch = function () { return curBranch }
module.exports.getDirection = function () { return direction } export const getDirection = function () { return direction }
module.exports.getHead = function () { return head } export const getHead = function () { return head }

View File

@ -1,7 +1,6 @@
/* eslint-env jasmine */ /* eslint-env jasmine */
import ast from './gitGraphAst' import ast from './gitGraphAst'
import { parser } from './parser/gitGraph'
var parser = require('./parser/gitGraph').parser
describe('when parsing a gitGraph', function () { describe('when parsing a gitGraph', function () {
beforeEach(function () { beforeEach(function () {

View File

@ -26,7 +26,7 @@ var config = {
} }
} }
var apiConfig = {} var apiConfig = {}
exports.setConf = function (c) { export const setConf = function (c) {
apiConfig = c apiConfig = c
} }
@ -235,7 +235,7 @@ function renderLines (svg, commit, direction, branchColor) {
} }
} }
exports.draw = function (txt, id, ver) { export const draw = function (txt, id, ver) {
try { try {
var parser var parser
parser = gitGraphParser.parser parser = gitGraphParser.parser

View File

@ -5,7 +5,7 @@ var messages = []
var notes = [] var notes = []
var title = '' var title = ''
module.exports.addActor = function (id, name, description) { export const addActor = function (id, name, description) {
// Don't allow description nulling // Don't allow description nulling
var old = actors[id] var old = actors[id]
if (old && name === old.name && description == null) return if (old && name === old.name && description == null) return
@ -16,38 +16,38 @@ module.exports.addActor = function (id, name, description) {
actors[id] = { name: name, description: description } actors[id] = { name: name, description: description }
} }
module.exports.addMessage = function (idFrom, idTo, message, answer) { export const addMessage = function (idFrom, idTo, message, answer) {
messages.push({ from: idFrom, to: idTo, message: message, answer: answer }) messages.push({ from: idFrom, to: idTo, message: message, answer: answer })
} }
module.exports.addSignal = function (idFrom, idTo, message, messageType) { export const addSignal = function (idFrom, idTo, message, messageType) {
logger.debug('Adding message from=' + idFrom + ' to=' + idTo + ' message=' + message + ' type=' + messageType) logger.debug('Adding message from=' + idFrom + ' to=' + idTo + ' message=' + message + ' type=' + messageType)
messages.push({ from: idFrom, to: idTo, message: message, type: messageType }) messages.push({ from: idFrom, to: idTo, message: message, type: messageType })
} }
module.exports.getMessages = function () { export const getMessages = function () {
return messages return messages
} }
module.exports.getActors = function () { export const getActors = function () {
return actors return actors
} }
module.exports.getActor = function (id) { export const getActor = function (id) {
return actors[id] return actors[id]
} }
module.exports.getActorKeys = function () { export const getActorKeys = function () {
return Object.keys(actors) return Object.keys(actors)
} }
module.exports.getTitle = function () { export const getTitle = function () {
return title return title
} }
module.exports.clear = function () { export const clear = function () {
actors = {} actors = {}
messages = [] messages = []
} }
module.exports.LINETYPE = { export const LINETYPE = {
SOLID: 0, SOLID: 0,
DOTTED: 1, DOTTED: 1,
NOTE: 2, NOTE: 2,
@ -69,85 +69,85 @@ module.exports.LINETYPE = {
PAR_END: 21 PAR_END: 21
} }
module.exports.ARROWTYPE = { export const ARROWTYPE = {
FILLED: 0, FILLED: 0,
OPEN: 1 OPEN: 1
} }
module.exports.PLACEMENT = { export const PLACEMENT = {
LEFTOF: 0, LEFTOF: 0,
RIGHTOF: 1, RIGHTOF: 1,
OVER: 2 OVER: 2
} }
module.exports.addNote = function (actor, placement, message) { export const addNote = function (actor, placement, message) {
var note = { actor: actor, placement: placement, message: message } var note = { actor: actor, placement: placement, message: message }
// Coerce actor into a [to, from, ...] array // Coerce actor into a [to, from, ...] array
var actors = [].concat(actor, actor) var actors = [].concat(actor, actor)
notes.push(note) notes.push(note)
messages.push({ from: actors[0], to: actors[1], message: message, type: module.exports.LINETYPE.NOTE, placement: placement }) messages.push({ from: actors[0], to: actors[1], message: message, type: LINETYPE.NOTE, placement: placement })
} }
module.exports.setTitle = function (titleText) { export const setTitle = function (titleText) {
title = titleText title = titleText
} }
module.exports.apply = function (param) { export const apply = function (param) {
if (param instanceof Array) { if (param instanceof Array) {
param.forEach(function (item) { param.forEach(function (item) {
module.exports.apply(item) apply(item)
}) })
} else { } else {
switch (param.type) { switch (param.type) {
case 'addActor': case 'addActor':
module.exports.addActor(param.actor, param.actor, param.description) addActor(param.actor, param.actor, param.description)
break break
case 'activeStart': case 'activeStart':
module.exports.addSignal(param.actor, undefined, undefined, param.signalType) addSignal(param.actor, undefined, undefined, param.signalType)
break break
case 'activeEnd': case 'activeEnd':
module.exports.addSignal(param.actor, undefined, undefined, param.signalType) addSignal(param.actor, undefined, undefined, param.signalType)
break break
case 'addNote': case 'addNote':
module.exports.addNote(param.actor, param.placement, param.text) addNote(param.actor, param.placement, param.text)
break break
case 'addMessage': case 'addMessage':
module.exports.addSignal(param.from, param.to, param.msg, param.signalType) addSignal(param.from, param.to, param.msg, param.signalType)
break break
case 'loopStart': case 'loopStart':
module.exports.addSignal(undefined, undefined, param.loopText, param.signalType) addSignal(undefined, undefined, param.loopText, param.signalType)
break break
case 'loopEnd': case 'loopEnd':
module.exports.addSignal(undefined, undefined, undefined, param.signalType) addSignal(undefined, undefined, undefined, param.signalType)
break break
case 'optStart': case 'optStart':
module.exports.addSignal(undefined, undefined, param.optText, param.signalType) addSignal(undefined, undefined, param.optText, param.signalType)
break break
case 'optEnd': case 'optEnd':
module.exports.addSignal(undefined, undefined, undefined, param.signalType) addSignal(undefined, undefined, undefined, param.signalType)
break break
case 'altStart': case 'altStart':
module.exports.addSignal(undefined, undefined, param.altText, param.signalType) addSignal(undefined, undefined, param.altText, param.signalType)
break break
case 'else': case 'else':
module.exports.addSignal(undefined, undefined, param.altText, param.signalType) addSignal(undefined, undefined, param.altText, param.signalType)
break break
case 'altEnd': case 'altEnd':
module.exports.addSignal(undefined, undefined, undefined, param.signalType) addSignal(undefined, undefined, undefined, param.signalType)
break break
case 'setTitle': case 'setTitle':
module.exports.setTitle(param.text) setTitle(param.text)
break break
case 'parStart': case 'parStart':
module.exports.addSignal(undefined, undefined, param.parText, param.signalType) addSignal(undefined, undefined, param.parText, param.signalType)
break break
case 'and': case 'and':
module.exports.addSignal(undefined, undefined, param.parText, param.signalType) addSignal(undefined, undefined, param.parText, param.signalType)
break break
case 'parEnd': case 'parEnd':
module.exports.addSignal(undefined, undefined, undefined, param.signalType) addSignal(undefined, undefined, undefined, param.signalType)
break break
} }
} }

View File

@ -1,5 +1,7 @@
/* eslint-env jasmine */ /* eslint-env jasmine */
var sq = require('./parser/sequenceDiagram').parser import { parser } from './parser/sequenceDiagram'
import sequenceDb from './sequenceDb'
import MyModuleInjector from 'inject-loader!./sequenceRenderer' // eslint-disable-line import/no-webpack-loader-syntax
var NewD3 var NewD3
@ -11,8 +13,8 @@ var d3 = {
return new NewD3() return new NewD3()
} }
} }
const MyModuleInjector = require('inject-loader!./sequenceRenderer') // eslint-disable-line import/no-webpack-loader-syntax
var sd = MyModuleInjector({ var renderer = MyModuleInjector({
'../../d3': d3 '../../d3': d3
}) })
@ -26,8 +28,8 @@ function addConf (conf, key, value) {
var str var str
describe('when parsing a sequenceDiagram', function () { describe('when parsing a sequenceDiagram', function () {
beforeEach(function () { beforeEach(function () {
sq.yy = require('./sequenceDb') parser.yy = sequenceDb
sq.yy.clear() parser.yy.clear()
}) })
it('it should handle a sequenceDiagram defintion', function () { it('it should handle a sequenceDiagram defintion', function () {
str = 'sequenceDiagram\n' + str = 'sequenceDiagram\n' +
@ -35,12 +37,12 @@ describe('when parsing a sequenceDiagram', function () {
'Note right of Bob: Bob thinks\n' + 'Note right of Bob: Bob thinks\n' +
'Bob-->Alice: I am good thanks!' 'Bob-->Alice: I am good thanks!'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(3) expect(messages.length).toBe(3)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -53,13 +55,13 @@ describe('when parsing a sequenceDiagram', function () {
'Note right of Bob: Bob thinks\n' + 'Note right of Bob: Bob thinks\n' +
'Bob-->Alice: I am good thanks!' 'Bob-->Alice: I am good thanks!'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
var title = sq.yy.getTitle() var title = parser.yy.getTitle()
expect(messages.length).toBe(3) expect(messages.length).toBe(3)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -71,12 +73,12 @@ describe('when parsing a sequenceDiagram', function () {
'Alice->Bob:Hello Bob, how are - you?\n' + 'Alice->Bob:Hello Bob, how are - you?\n' +
'Bob-->Alice: I am good thanks!' 'Bob-->Alice: I am good thanks!'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(2) expect(messages.length).toBe(2)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -89,14 +91,14 @@ describe('when parsing a sequenceDiagram', function () {
'A->B:Hello Bob, how are you?\n' + 'A->B:Hello Bob, how are you?\n' +
'B-->A: I am good thanks!' 'B-->A: I am good thanks!'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(Object.keys(actors)).toEqual(['A', 'B']) expect(Object.keys(actors)).toEqual(['A', 'B'])
expect(actors.A.description).toBe('Alice') expect(actors.A.description).toBe('Alice')
expect(actors.B.description).toBe('Bob') expect(actors.B.description).toBe('Bob')
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(2) expect(messages.length).toBe(2)
expect(messages[0].from).toBe('A') expect(messages[0].from).toBe('A')
expect(messages[1].from).toBe('B') expect(messages[1].from).toBe('B')
@ -105,57 +107,57 @@ describe('when parsing a sequenceDiagram', function () {
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'Alice-xBob:Hello Bob, how are you?' 'Alice-xBob:Hello Bob, how are you?'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
expect(actors.Bob.description).toBe('Bob') expect(actors.Bob.description).toBe('Bob')
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(1) expect(messages.length).toBe(1)
expect(messages[0].type).toBe(sq.yy.LINETYPE.SOLID_CROSS) expect(messages[0].type).toBe(parser.yy.LINETYPE.SOLID_CROSS)
}) })
it('it should handle in async dotted messages', function () { it('it should handle in async dotted messages', function () {
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'Alice--xBob:Hello Bob, how are you?' 'Alice--xBob:Hello Bob, how are you?'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
expect(actors.Bob.description).toBe('Bob') expect(actors.Bob.description).toBe('Bob')
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(1) expect(messages.length).toBe(1)
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED_CROSS) expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED_CROSS)
}) })
it('it should handle in arrow messages', function () { it('it should handle in arrow messages', function () {
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'Alice->>Bob:Hello Bob, how are you?' 'Alice->>Bob:Hello Bob, how are you?'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
expect(actors.Bob.description).toBe('Bob') expect(actors.Bob.description).toBe('Bob')
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(1) expect(messages.length).toBe(1)
expect(messages[0].type).toBe(sq.yy.LINETYPE.SOLID) expect(messages[0].type).toBe(parser.yy.LINETYPE.SOLID)
}) })
it('it should handle in arrow messages', function () { it('it should handle in arrow messages', function () {
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'Alice-->>Bob:Hello Bob, how are you?' 'Alice-->>Bob:Hello Bob, how are you?'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
expect(actors.Bob.description).toBe('Bob') expect(actors.Bob.description).toBe('Bob')
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(1) expect(messages.length).toBe(1)
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED) expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED)
}) })
it('it should handle actor activation', function () { it('it should handle actor activation', function () {
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
@ -164,19 +166,19 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->>Alice:Hello Alice, I\'m fine and you?\n' + 'Bob-->>Alice:Hello Alice, I\'m fine and you?\n' +
'deactivate Bob' 'deactivate Bob'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
expect(actors.Bob.description).toBe('Bob') expect(actors.Bob.description).toBe('Bob')
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(4) expect(messages.length).toBe(4)
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED) expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED)
expect(messages[1].type).toBe(sq.yy.LINETYPE.ACTIVE_START) expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
expect(messages[1].from.actor).toBe('Bob') expect(messages[1].from.actor).toBe('Bob')
expect(messages[2].type).toBe(sq.yy.LINETYPE.DOTTED) expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED)
expect(messages[3].type).toBe(sq.yy.LINETYPE.ACTIVE_END) expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_END)
expect(messages[3].from.actor).toBe('Bob') expect(messages[3].from.actor).toBe('Bob')
}) })
it('it should handle actor one line notation activation', function () { it('it should handle actor one line notation activation', function () {
@ -184,19 +186,19 @@ describe('when parsing a sequenceDiagram', function () {
'Alice-->>+Bob:Hello Bob, how are you?\n' + 'Alice-->>+Bob:Hello Bob, how are you?\n' +
'Bob-->>- Alice:Hello Alice, I\'m fine and you?' 'Bob-->>- Alice:Hello Alice, I\'m fine and you?'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
expect(actors.Bob.description).toBe('Bob') expect(actors.Bob.description).toBe('Bob')
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(4) expect(messages.length).toBe(4)
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED) expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED)
expect(messages[1].type).toBe(sq.yy.LINETYPE.ACTIVE_START) expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
expect(messages[1].from.actor).toBe('Bob') expect(messages[1].from.actor).toBe('Bob')
expect(messages[2].type).toBe(sq.yy.LINETYPE.DOTTED) expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED)
expect(messages[3].type).toBe(sq.yy.LINETYPE.ACTIVE_END) expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_END)
expect(messages[3].from.actor).toBe('Bob') expect(messages[3].from.actor).toBe('Bob')
}) })
it('it should handle stacked activations', function () { it('it should handle stacked activations', function () {
@ -206,23 +208,23 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->>- Alice:Hello Alice, please meet Carol?\n' + 'Bob-->>- Alice:Hello Alice, please meet Carol?\n' +
'Carol->>- Bob:Oh Bob, I\'m so happy to be here!' 'Carol->>- Bob:Oh Bob, I\'m so happy to be here!'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
expect(actors.Bob.description).toBe('Bob') expect(actors.Bob.description).toBe('Bob')
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(8) expect(messages.length).toBe(8)
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED) expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED)
expect(messages[1].type).toBe(sq.yy.LINETYPE.ACTIVE_START) expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
expect(messages[1].from.actor).toBe('Bob') expect(messages[1].from.actor).toBe('Bob')
expect(messages[2].type).toBe(sq.yy.LINETYPE.DOTTED) expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED)
expect(messages[3].type).toBe(sq.yy.LINETYPE.ACTIVE_START) expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
expect(messages[3].from.actor).toBe('Carol') expect(messages[3].from.actor).toBe('Carol')
expect(messages[5].type).toBe(sq.yy.LINETYPE.ACTIVE_END) expect(messages[5].type).toBe(parser.yy.LINETYPE.ACTIVE_END)
expect(messages[5].from.actor).toBe('Bob') expect(messages[5].from.actor).toBe('Bob')
expect(messages[7].type).toBe(sq.yy.LINETYPE.ACTIVE_END) expect(messages[7].type).toBe(parser.yy.LINETYPE.ACTIVE_END)
expect(messages[7].from.actor).toBe('Carol') expect(messages[7].from.actor).toBe('Carol')
}) })
it('it should handle comments in a sequenceDiagram', function () { it('it should handle comments in a sequenceDiagram', function () {
@ -232,12 +234,12 @@ describe('when parsing a sequenceDiagram', function () {
'Note right of Bob: Bob thinks\n' + 'Note right of Bob: Bob thinks\n' +
'Bob-->Alice: I am good thanks!' 'Bob-->Alice: I am good thanks!'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(3) expect(messages.length).toBe(3)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -250,12 +252,12 @@ describe('when parsing a sequenceDiagram', function () {
'Note right of Bob: Bob thinks\n' + 'Note right of Bob: Bob thinks\n' +
'Bob-->Alice: I am good thanks!\n' 'Bob-->Alice: I am good thanks!\n'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(3) expect(messages.length).toBe(3)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -267,12 +269,12 @@ describe('when parsing a sequenceDiagram', function () {
'Note right of Bob: Bob thinks;' + 'Note right of Bob: Bob thinks;' +
'Bob-->Alice: I am good thanks!;' 'Bob-->Alice: I am good thanks!;'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(3) expect(messages.length).toBe(3)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -285,12 +287,12 @@ describe('when parsing a sequenceDiagram', function () {
'Note right of Bob: Bob thinks\n' + 'Note right of Bob: Bob thinks\n' +
'Bob-->Alice: I am good thanks!' 'Bob-->Alice: I am good thanks!'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(3) expect(messages.length).toBe(3)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -303,12 +305,12 @@ describe('when parsing a sequenceDiagram', function () {
'Note right of Bob: Bob thinks\n' + 'Note right of Bob: Bob thinks\n' +
'Bob-->Alice: I am good thanks!' 'Bob-->Alice: I am good thanks!'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(3) expect(messages.length).toBe(3)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -327,12 +329,12 @@ describe('when parsing a sequenceDiagram', function () {
' John->Bob: How about you?\n' + ' John->Bob: How about you?\n' +
'Bob-->John: Jolly good!' 'Bob-->John: Jolly good!'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(8) expect(messages.length).toBe(8)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -343,9 +345,9 @@ describe('when parsing a sequenceDiagram', function () {
'Alice->Bob: Hello Bob, how are you?\n' + 'Alice->Bob: Hello Bob, how are you?\n' +
'Note over Bob: Bob thinks\n' 'Note over Bob: Bob thinks\n'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[1].from).toBe('Bob') expect(messages[1].from).toBe('Bob')
expect(messages[1].to).toBe('Bob') expect(messages[1].to).toBe('Bob')
}) })
@ -355,9 +357,9 @@ describe('when parsing a sequenceDiagram', function () {
'Note over Alice,Bob: confusion\n' + 'Note over Alice,Bob: confusion\n' +
'Note over Bob,Alice: resolution\n' 'Note over Bob,Alice: resolution\n'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[1].from).toBe('Alice') expect(messages[1].from).toBe('Alice')
expect(messages[1].to).toBe('Bob') expect(messages[1].to).toBe('Bob')
expect(messages[2].from).toBe('Bob') expect(messages[2].from).toBe('Bob')
@ -372,12 +374,12 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: I am good thanks!\n' + 'Bob-->Alice: I am good thanks!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(5) expect(messages.length).toBe(5)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -392,12 +394,12 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: I am good thanks!\n' + 'Bob-->Alice: I am good thanks!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(5) expect(messages.length).toBe(5)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -414,13 +416,13 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: Feel sick...\n' + 'Bob-->Alice: Feel sick...\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
actors.Bob.description = 'Bob' actors.Bob.description = 'Bob'
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(7) expect(messages.length).toBe(7)
expect(messages[0].from).toBe('Alice') expect(messages[0].from).toBe('Alice')
@ -439,13 +441,13 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->>Alice: It\'s good!\n' + 'Bob-->>Alice: It\'s good!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
expect(actors.Alice.description).toBe('Alice') expect(actors.Alice.description).toBe('Alice')
expect(actors.Bob.description).toBe('Bob') expect(actors.Bob.description).toBe('Bob')
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages.length).toBe(10) expect(messages.length).toBe(10)
expect(messages[0].message).toBe('Parallel one') expect(messages[0].message).toBe('Parallel one')
@ -456,9 +458,9 @@ describe('when parsing a sequenceDiagram', function () {
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'Alice->Bob: -:<>,;# comment' 'Alice->Bob: -:<>,;# comment'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[0].message).toBe('-:<>,') expect(messages[0].message).toBe('-:<>,')
}) })
it('it should handle special characters in notes', function () { it('it should handle special characters in notes', function () {
@ -466,9 +468,9 @@ describe('when parsing a sequenceDiagram', function () {
'Alice->Bob: Hello Bob, how are you?\n' + 'Alice->Bob: Hello Bob, how are you?\n' +
'Note right of Bob: -:<>,;# comment' 'Note right of Bob: -:<>,;# comment'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[1].message).toBe('-:<>,') expect(messages[1].message).toBe('-:<>,')
}) })
it('it should handle special characters in loop', function () { it('it should handle special characters in loop', function () {
@ -478,9 +480,9 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: I am good thanks!\n' + 'Bob-->Alice: I am good thanks!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[1].message).toBe('-:<>,') expect(messages[1].message).toBe('-:<>,')
}) })
it('it should handle special characters in opt', function () { it('it should handle special characters in opt', function () {
@ -490,9 +492,9 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: I am good thanks!\n' + 'Bob-->Alice: I am good thanks!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[1].message).toBe('-:<>,') expect(messages[1].message).toBe('-:<>,')
}) })
it('it should handle special characters in alt', function () { it('it should handle special characters in alt', function () {
@ -504,9 +506,9 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: I am good thanks!\n' + 'Bob-->Alice: I am good thanks!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[1].message).toBe('-:<>,') expect(messages[1].message).toBe('-:<>,')
expect(messages[3].message).toBe(',<>:-') expect(messages[3].message).toBe(',<>:-')
}) })
@ -519,9 +521,9 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: I am good thanks!\n' + 'Bob-->Alice: I am good thanks!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[1].message).toBe('-:<>,') expect(messages[1].message).toBe('-:<>,')
expect(messages[3].message).toBe(',<>:-') expect(messages[3].message).toBe(',<>:-')
}) })
@ -532,9 +534,9 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: I am good thanks!\n' + 'Bob-->Alice: I am good thanks!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[1].message).toBe('') expect(messages[1].message).toBe('')
expect(messages[2].message).toBe('I am good thanks!') expect(messages[2].message).toBe('I am good thanks!')
}) })
@ -545,9 +547,9 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: I am good thanks!\n' + 'Bob-->Alice: I am good thanks!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[1].message).toBe('') expect(messages[1].message).toBe('')
expect(messages[2].message).toBe('I am good thanks!') expect(messages[2].message).toBe('I am good thanks!')
}) })
@ -560,9 +562,9 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: I am good thanks!\n' + 'Bob-->Alice: I am good thanks!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[1].message).toBe('') expect(messages[1].message).toBe('')
expect(messages[2].message).toBe('I am good thanks!') expect(messages[2].message).toBe('I am good thanks!')
expect(messages[3].message).toBe('') expect(messages[3].message).toBe('')
@ -577,9 +579,9 @@ describe('when parsing a sequenceDiagram', function () {
'Bob-->Alice: I am good thanks!\n' + 'Bob-->Alice: I am good thanks!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
expect(messages[1].message).toBe('') expect(messages[1].message).toBe('')
expect(messages[2].message).toBe('I am good thanks!') expect(messages[2].message).toBe('I am good thanks!')
expect(messages[3].message).toBe('') expect(messages[3].message).toBe('')
@ -590,8 +592,8 @@ describe('when parsing a sequenceDiagram', function () {
describe('when checking the bounds in a sequenceDiagram', function () { describe('when checking the bounds in a sequenceDiagram', function () {
var conf var conf
beforeEach(function () { beforeEach(function () {
sq.yy = require('./sequenceDb') parser.yy = sequenceDb
sq.yy.clear() parser.yy.clear()
conf = { conf = {
diagramMarginX: 50, diagramMarginX: 50,
diagramMarginY: 10, diagramMarginY: 10,
@ -604,53 +606,53 @@ describe('when checking the bounds in a sequenceDiagram', function () {
boxTextMargin: 15, boxTextMargin: 15,
noteMargin: 25 noteMargin: 25
} }
sd.setConf(conf) renderer.setConf(conf)
}) })
it('it should handle a simple bound call', function () { it('it should handle a simple bound call', function () {
sd.bounds.init() renderer.bounds.init()
sd.bounds.insert(100, 100, 200, 200) renderer.bounds.insert(100, 100, 200, 200)
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(100) expect(bounds.startx).toBe(100)
expect(bounds.starty).toBe(100) expect(bounds.starty).toBe(100)
expect(bounds.stopx).toBe(200) expect(bounds.stopx).toBe(200)
expect(bounds.stopy).toBe(200) expect(bounds.stopy).toBe(200)
}) })
it('it should handle an expanding bound', function () { it('it should handle an expanding bound', function () {
sd.bounds.init() renderer.bounds.init()
sd.bounds.insert(100, 100, 200, 200) renderer.bounds.insert(100, 100, 200, 200)
sd.bounds.insert(25, 50, 300, 400) renderer.bounds.insert(25, 50, 300, 400)
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(25) expect(bounds.startx).toBe(25)
expect(bounds.starty).toBe(50) expect(bounds.starty).toBe(50)
expect(bounds.stopx).toBe(300) expect(bounds.stopx).toBe(300)
expect(bounds.stopy).toBe(400) expect(bounds.stopy).toBe(400)
}) })
it('it should handle inserts within the bound without changing the outer bounds', function () { it('it should handle inserts within the bound without changing the outer bounds', function () {
sd.bounds.init() renderer.bounds.init()
sd.bounds.insert(100, 100, 200, 200) renderer.bounds.insert(100, 100, 200, 200)
sd.bounds.insert(25, 50, 300, 400) renderer.bounds.insert(25, 50, 300, 400)
sd.bounds.insert(125, 150, 150, 200) renderer.bounds.insert(125, 150, 150, 200)
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(25) expect(bounds.startx).toBe(25)
expect(bounds.starty).toBe(50) expect(bounds.starty).toBe(50)
expect(bounds.stopx).toBe(300) expect(bounds.stopx).toBe(300)
expect(bounds.stopy).toBe(400) expect(bounds.stopy).toBe(400)
}) })
it('it should handle a loop without expanding the area', function () { it('it should handle a loop without expanding the area', function () {
sd.bounds.init() renderer.bounds.init()
sd.bounds.insert(25, 50, 300, 400) renderer.bounds.insert(25, 50, 300, 400)
sd.bounds.verticalPos = 150 renderer.bounds.verticalPos = 150
sd.bounds.newLoop() renderer.bounds.newLoop()
sd.bounds.insert(125, 150, 150, 200) renderer.bounds.insert(125, 150, 150, 200)
var loop = sd.bounds.endLoop() var loop = renderer.bounds.endLoop()
expect(loop.startx).toBe(125 - conf.boxMargin) expect(loop.startx).toBe(125 - conf.boxMargin)
expect(loop.starty).toBe(150 - conf.boxMargin) expect(loop.starty).toBe(150 - conf.boxMargin)
@ -658,7 +660,7 @@ describe('when checking the bounds in a sequenceDiagram', function () {
expect(loop.stopy).toBe(200 + conf.boxMargin) expect(loop.stopy).toBe(200 + conf.boxMargin)
// Check bounds of first loop // Check bounds of first loop
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(25) expect(bounds.startx).toBe(25)
expect(bounds.starty).toBe(50) expect(bounds.starty).toBe(50)
@ -666,16 +668,16 @@ describe('when checking the bounds in a sequenceDiagram', function () {
expect(bounds.stopy).toBe(400) expect(bounds.stopy).toBe(400)
}) })
it('it should handle multiple loops withtout expanding the bounds', function () { it('it should handle multiple loops withtout expanding the bounds', function () {
sd.bounds.init() renderer.bounds.init()
sd.bounds.insert(100, 100, 1000, 1000) renderer.bounds.insert(100, 100, 1000, 1000)
sd.bounds.verticalPos = 200 renderer.bounds.verticalPos = 200
sd.bounds.newLoop() renderer.bounds.newLoop()
sd.bounds.newLoop() renderer.bounds.newLoop()
sd.bounds.insert(200, 200, 300, 300) renderer.bounds.insert(200, 200, 300, 300)
// Check bounds of first loop // Check bounds of first loop
var loop = sd.bounds.endLoop() var loop = renderer.bounds.endLoop()
expect(loop.startx).toBe(200 - conf.boxMargin) expect(loop.startx).toBe(200 - conf.boxMargin)
expect(loop.starty).toBe(200 - conf.boxMargin) expect(loop.starty).toBe(200 - conf.boxMargin)
@ -683,7 +685,7 @@ describe('when checking the bounds in a sequenceDiagram', function () {
expect(loop.stopy).toBe(300 + conf.boxMargin) expect(loop.stopy).toBe(300 + conf.boxMargin)
// Check bounds of second loop // Check bounds of second loop
loop = sd.bounds.endLoop() loop = renderer.bounds.endLoop()
expect(loop.startx).toBe(200 - 2 * conf.boxMargin) expect(loop.startx).toBe(200 - 2 * conf.boxMargin)
expect(loop.starty).toBe(200 - 2 * conf.boxMargin) expect(loop.starty).toBe(200 - 2 * conf.boxMargin)
@ -691,7 +693,7 @@ describe('when checking the bounds in a sequenceDiagram', function () {
expect(loop.stopy).toBe(300 + 2 * conf.boxMargin) expect(loop.stopy).toBe(300 + 2 * conf.boxMargin)
// Check bounds of first loop // Check bounds of first loop
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(100) expect(bounds.startx).toBe(100)
expect(bounds.starty).toBe(100) expect(bounds.starty).toBe(100)
@ -699,14 +701,14 @@ describe('when checking the bounds in a sequenceDiagram', function () {
expect(bounds.stopy).toBe(1000) expect(bounds.stopy).toBe(1000)
}) })
it('it should handle a loop that expands the area', function () { it('it should handle a loop that expands the area', function () {
sd.bounds.init() renderer.bounds.init()
sd.bounds.insert(100, 100, 200, 200) renderer.bounds.insert(100, 100, 200, 200)
sd.bounds.verticalPos = 200 renderer.bounds.verticalPos = 200
sd.bounds.newLoop() renderer.bounds.newLoop()
sd.bounds.insert(50, 50, 300, 300) renderer.bounds.insert(50, 50, 300, 300)
var loop = sd.bounds.endLoop() var loop = renderer.bounds.endLoop()
expect(loop.startx).toBe(50 - conf.boxMargin) expect(loop.startx).toBe(50 - conf.boxMargin)
expect(loop.starty).toBe(50 - conf.boxMargin) expect(loop.starty).toBe(50 - conf.boxMargin)
@ -714,7 +716,7 @@ describe('when checking the bounds in a sequenceDiagram', function () {
expect(loop.stopy).toBe(300 + conf.boxMargin) expect(loop.stopy).toBe(300 + conf.boxMargin)
// Check bounds after the loop // Check bounds after the loop
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(loop.startx) expect(bounds.startx).toBe(loop.startx)
expect(bounds.starty).toBe(loop.starty) expect(bounds.starty).toBe(loop.starty)
@ -726,8 +728,8 @@ describe('when checking the bounds in a sequenceDiagram', function () {
describe('when rendering a sequenceDiagram', function () { describe('when rendering a sequenceDiagram', function () {
var conf var conf
beforeEach(function () { beforeEach(function () {
sq.yy = require('./sequenceDb') parser.yy = sequenceDb
sq.yy.clear() parser.yy.clear()
delete global.mermaid_config delete global.mermaid_config
@ -773,19 +775,19 @@ describe('when rendering a sequenceDiagram', function () {
boxTextMargin: 15, boxTextMargin: 15,
noteMargin: 25 noteMargin: 25
} }
sd.setConf(conf) renderer.setConf(conf)
}); });
['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) { ['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) {
it('it should handle one actor, when textPlacement is ' + textPlacement, function () { it('it should handle one actor, when textPlacement is ' + textPlacement, function () {
sd.setConf(addConf(conf, 'textPlacement', textPlacement)) renderer.setConf(addConf(conf, 'textPlacement', textPlacement))
sd.bounds.init() renderer.bounds.init()
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'participant Alice' 'participant Alice'
sq.parse(str) parser.parse(str)
sd.draw(str, 'tst') renderer.draw(str, 'tst')
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(0) expect(bounds.startx).toBe(0)
expect(bounds.starty).toBe(0) expect(bounds.starty).toBe(0)
expect(bounds.stopx).toBe(conf.width) expect(bounds.stopx).toBe(conf.width)
@ -793,15 +795,15 @@ describe('when rendering a sequenceDiagram', function () {
}) })
}) })
it('it should handle one actor and a centered note', function () { it('it should handle one actor and a centered note', function () {
sd.bounds.init() renderer.bounds.init()
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'participant Alice\n' + 'participant Alice\n' +
'Note over Alice: Alice thinks\n' 'Note over Alice: Alice thinks\n'
sq.parse(str) parser.parse(str)
sd.draw(str, 'tst') renderer.draw(str, 'tst')
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(0) expect(bounds.startx).toBe(0)
expect(bounds.starty).toBe(0) expect(bounds.starty).toBe(0)
expect(bounds.stopx).toBe(conf.width) expect(bounds.stopx).toBe(conf.width)
@ -809,15 +811,15 @@ describe('when rendering a sequenceDiagram', function () {
expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10) expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10)
}) })
it('it should handle one actor and a note to the left', function () { it('it should handle one actor and a note to the left', function () {
sd.bounds.init() renderer.bounds.init()
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'participant Alice\n' + 'participant Alice\n' +
'Note left of Alice: Alice thinks' 'Note left of Alice: Alice thinks'
sq.parse(str) parser.parse(str)
sd.draw(str, 'tst') renderer.draw(str, 'tst')
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(-(conf.width / 2) - (conf.actorMargin / 2)) expect(bounds.startx).toBe(-(conf.width / 2) - (conf.actorMargin / 2))
expect(bounds.starty).toBe(0) expect(bounds.starty).toBe(0)
expect(bounds.stopx).toBe(conf.width) expect(bounds.stopx).toBe(conf.width)
@ -825,15 +827,15 @@ describe('when rendering a sequenceDiagram', function () {
expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10) expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10)
}) })
it('it should handle one actor and a note to the right', function () { it('it should handle one actor and a note to the right', function () {
sd.bounds.init() renderer.bounds.init()
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'participant Alice\n' + 'participant Alice\n' +
'Note right of Alice: Alice thinks' 'Note right of Alice: Alice thinks'
sq.parse(str) parser.parse(str)
sd.draw(str, 'tst') renderer.draw(str, 'tst')
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(0) expect(bounds.startx).toBe(0)
expect(bounds.starty).toBe(0) expect(bounds.starty).toBe(0)
expect(bounds.stopx).toBe((conf.width / 2) + (conf.actorMargin / 2) + conf.width) expect(bounds.stopx).toBe((conf.width / 2) + (conf.actorMargin / 2) + conf.width)
@ -841,61 +843,61 @@ describe('when rendering a sequenceDiagram', function () {
expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10) expect(bounds.stopy).toBe(conf.height + conf.boxMargin + 2 * conf.noteMargin + 10)
}) })
it('it should handle two actors', function () { it('it should handle two actors', function () {
sd.bounds.init() renderer.bounds.init()
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?' 'Alice->Bob: Hello Bob, how are you?'
sq.parse(str) parser.parse(str)
sd.draw(str, 'tst') renderer.draw(str, 'tst')
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(0) expect(bounds.startx).toBe(0)
expect(bounds.starty).toBe(0) expect(bounds.starty).toBe(0)
expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin) expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin)
expect(bounds.stopy).toBe(0 + conf.messageMargin + conf.height) expect(bounds.stopy).toBe(0 + conf.messageMargin + conf.height)
}) })
it('it should handle two actors and two centered shared notes', function () { it('it should handle two actors and two centered shared notes', function () {
sd.bounds.init() renderer.bounds.init()
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' + 'Alice->Bob: Hello Bob, how are you?\n' +
'Note over Alice,Bob: Looks\n' + 'Note over Alice,Bob: Looks\n' +
'Note over Bob,Alice: Looks back\n' 'Note over Bob,Alice: Looks back\n'
sq.parse(str) parser.parse(str)
sd.draw(str, 'tst') renderer.draw(str, 'tst')
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(0) expect(bounds.startx).toBe(0)
expect(bounds.starty).toBe(0) expect(bounds.starty).toBe(0)
expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin) expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin)
expect(bounds.stopy).toBe(conf.height + conf.messageMargin + 2 * (conf.boxMargin + 2 * conf.noteMargin + 10)) expect(bounds.stopy).toBe(conf.height + conf.messageMargin + 2 * (conf.boxMargin + 2 * conf.noteMargin + 10))
}) })
it('it should draw two actors and two messages', function () { it('it should draw two actors and two messages', function () {
sd.bounds.init() renderer.bounds.init()
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' + 'Alice->Bob: Hello Bob, how are you?\n' +
'Bob->Alice: Fine!' 'Bob->Alice: Fine!'
sq.parse(str) parser.parse(str)
sd.draw(str, 'tst') renderer.draw(str, 'tst')
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(0) expect(bounds.startx).toBe(0)
expect(bounds.starty).toBe(0) expect(bounds.starty).toBe(0)
expect(bounds.stopx).toBe(0 + conf.width * 2 + conf.actorMargin) expect(bounds.stopx).toBe(0 + conf.width * 2 + conf.actorMargin)
expect(bounds.stopy).toBe(0 + 2 * conf.messageMargin + conf.height) expect(bounds.stopy).toBe(0 + 2 * conf.messageMargin + conf.height)
}) })
it('it should draw two actors notes to the right', function () { it('it should draw two actors notes to the right', function () {
sd.bounds.init() renderer.bounds.init()
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' + 'Alice->Bob: Hello Bob, how are you?\n' +
'Note right of Bob: Bob thinks\n' + 'Note right of Bob: Bob thinks\n' +
'Bob->Alice: Fine!' 'Bob->Alice: Fine!'
sq.parse(str) parser.parse(str)
sd.draw(str, 'tst') renderer.draw(str, 'tst')
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(0) expect(bounds.startx).toBe(0)
expect(bounds.starty).toBe(0) expect(bounds.starty).toBe(0)
@ -905,16 +907,16 @@ describe('when rendering a sequenceDiagram', function () {
expect(bounds.stopy).toBe(2 * conf.messageMargin + conf.height + conf.boxMargin + 10 + 2 * conf.noteMargin) expect(bounds.stopy).toBe(2 * conf.messageMargin + conf.height + conf.boxMargin + 10 + 2 * conf.noteMargin)
}) })
it('it should draw two actors notes to the left', function () { it('it should draw two actors notes to the left', function () {
sd.bounds.init() renderer.bounds.init()
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' + 'Alice->Bob: Hello Bob, how are you?\n' +
'Note left of Alice: Bob thinks\n' + 'Note left of Alice: Bob thinks\n' +
'Bob->Alice: Fine!' 'Bob->Alice: Fine!'
sq.parse(str) parser.parse(str)
sd.draw(str, 'tst') renderer.draw(str, 'tst')
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(-(conf.width / 2) - (conf.actorMargin / 2)) expect(bounds.startx).toBe(-(conf.width / 2) - (conf.actorMargin / 2))
expect(bounds.starty).toBe(0) expect(bounds.starty).toBe(0)
@ -922,16 +924,16 @@ describe('when rendering a sequenceDiagram', function () {
expect(bounds.stopy).toBe(2 * conf.messageMargin + conf.height + conf.boxMargin + 10 + 2 * conf.noteMargin) expect(bounds.stopy).toBe(2 * conf.messageMargin + conf.height + conf.boxMargin + 10 + 2 * conf.noteMargin)
}) })
it('it should draw two loops', function () { it('it should draw two loops', function () {
sd.bounds.init() renderer.bounds.init()
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'Alice->Bob: Hello Bob, how are you?\n' + 'Alice->Bob: Hello Bob, how are you?\n' +
'loop Cheers\n' + 'loop Cheers\n' +
'Bob->Alice: Fine!\n' + 'Bob->Alice: Fine!\n' +
'end' 'end'
sq.parse(str) parser.parse(str)
sd.draw(str, 'tst') renderer.draw(str, 'tst')
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(0) expect(bounds.startx).toBe(0)
expect(bounds.starty).toBe(0) expect(bounds.starty).toBe(0)
@ -943,8 +945,8 @@ describe('when rendering a sequenceDiagram', function () {
describe('when rendering a sequenceDiagram with actor mirror activated', function () { describe('when rendering a sequenceDiagram with actor mirror activated', function () {
var conf var conf
beforeEach(function () { beforeEach(function () {
sq.yy = require('./sequenceDb') parser.yy = sequenceDb
sq.yy.clear() parser.yy.clear()
NewD3 = function () { NewD3 = function () {
var o = { var o = {
@ -992,19 +994,19 @@ describe('when rendering a sequenceDiagram with actor mirror activated', functio
// Prolongs the edge of the diagram downwards // Prolongs the edge of the diagram downwards
bottomMarginAdj: 1 bottomMarginAdj: 1
} }
sd.setConf(conf) renderer.setConf(conf)
}); });
['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) { ['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) {
it('it should handle one actor, when textPlacement is' + textPlacement, function () { it('it should handle one actor, when textPlacement is' + textPlacement, function () {
sd.setConf(addConf(conf, 'textPlacement', textPlacement)) renderer.setConf(addConf(conf, 'textPlacement', textPlacement))
sd.bounds.init() renderer.bounds.init()
var str = 'sequenceDiagram\n' + var str = 'sequenceDiagram\n' +
'participant Alice' 'participant Alice'
sq.parse(str) parser.parse(str)
sd.draw(str, 'tst') renderer.draw(str, 'tst')
var bounds = sd.bounds.getBounds() var bounds = renderer.bounds.getBounds()
expect(bounds.startx).toBe(0) expect(bounds.startx).toBe(0)
expect(bounds.starty).toBe(0) expect(bounds.starty).toBe(0)
expect(bounds.stopx).toBe(conf.width) expect(bounds.stopx).toBe(conf.width)

View File

@ -1,9 +1,10 @@
import svgDraw from './svgDraw' import svgDraw from './svgDraw'
import { logger } from '../../logger' import { logger } from '../../logger'
import d3 from '../../d3' import d3 from '../../d3'
import { parser } from './parser/sequenceDiagram'
import sequenceDb from './sequenceDb'
var sq = require('./parser/sequenceDiagram').parser parser.yy = sequenceDb
sq.yy = require('./sequenceDb')
var conf = { var conf = {
@ -34,7 +35,7 @@ var conf = {
textPlacement: 'tspan' textPlacement: 'tspan'
} }
module.exports.bounds = { export const bounds = {
data: { data: {
startx: undefined, startx: undefined,
stopx: undefined, stopx: undefined,
@ -75,15 +76,15 @@ module.exports.bounds = {
_self.updateVal(item, 'starty', starty - n * conf.boxMargin, Math.min) _self.updateVal(item, 'starty', starty - n * conf.boxMargin, Math.min)
_self.updateVal(item, 'stopy', stopy + n * conf.boxMargin, Math.max) _self.updateVal(item, 'stopy', stopy + n * conf.boxMargin, Math.max)
_self.updateVal(module.exports.bounds.data, 'startx', startx - n * conf.boxMargin, Math.min) _self.updateVal(bounds.data, 'startx', startx - n * conf.boxMargin, Math.min)
_self.updateVal(module.exports.bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max) _self.updateVal(bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max)
if (!(type === 'activation')) { if (!(type === 'activation')) {
_self.updateVal(item, 'startx', startx - n * conf.boxMargin, Math.min) _self.updateVal(item, 'startx', startx - n * conf.boxMargin, Math.min)
_self.updateVal(item, 'stopx', stopx + n * conf.boxMargin, Math.max) _self.updateVal(item, 'stopx', stopx + n * conf.boxMargin, Math.max)
_self.updateVal(module.exports.bounds.data, 'starty', starty - n * conf.boxMargin, Math.min) _self.updateVal(bounds.data, 'starty', starty - n * conf.boxMargin, Math.min)
_self.updateVal(module.exports.bounds.data, 'stopy', stopy + n * conf.boxMargin, Math.max) _self.updateVal(bounds.data, 'stopy', stopy + n * conf.boxMargin, Math.max)
} }
} }
} }
@ -99,15 +100,15 @@ module.exports.bounds = {
_starty = Math.min(starty, stopy) _starty = Math.min(starty, stopy)
_stopy = Math.max(starty, stopy) _stopy = Math.max(starty, stopy)
this.updateVal(module.exports.bounds.data, 'startx', _startx, Math.min) this.updateVal(bounds.data, 'startx', _startx, Math.min)
this.updateVal(module.exports.bounds.data, 'starty', _starty, Math.min) this.updateVal(bounds.data, 'starty', _starty, Math.min)
this.updateVal(module.exports.bounds.data, 'stopx', _stopx, Math.max) this.updateVal(bounds.data, 'stopx', _stopx, Math.max)
this.updateVal(module.exports.bounds.data, 'stopy', _stopy, Math.max) this.updateVal(bounds.data, 'stopy', _stopy, Math.max)
this.updateBounds(_startx, _starty, _stopx, _stopy) this.updateBounds(_startx, _starty, _stopx, _stopy)
}, },
newActivation: function (message, diagram) { newActivation: function (message, diagram) {
var actorRect = sq.yy.getActors()[message.from.actor] var actorRect = parser.yy.getActors()[message.from.actor]
var stackedSize = actorActivations(message.from.actor).length var stackedSize = actorActivations(message.from.actor).length
var x = actorRect.x + conf.width / 2 + (stackedSize - 1) * conf.activationWidth / 2 var x = actorRect.x + conf.width / 2 + (stackedSize - 1) * conf.activationWidth / 2
this.activations.push({ this.activations.push({
@ -138,7 +139,7 @@ module.exports.bounds = {
var loop = this.sequenceItems.pop() var loop = this.sequenceItems.pop()
loop.sections = loop.sections || [] loop.sections = loop.sections || []
loop.sectionTitles = loop.sectionTitles || [] loop.sectionTitles = loop.sectionTitles || []
loop.sections.push(module.exports.bounds.getVerticalPos()) loop.sections.push(bounds.getVerticalPos())
loop.sectionTitles.push(message) loop.sectionTitles.push(message)
this.sequenceItems.push(loop) this.sequenceItems.push(loop)
}, },
@ -188,13 +189,13 @@ var drawNote = function (elem, startx, verticalPos, msg, forceWidth) {
textElem = svgDraw.drawText(g, textObj, 2 * rect.width - conf.noteMargin) textElem = svgDraw.drawText(g, textObj, 2 * rect.width - conf.noteMargin)
textHeight = textElem[0][0].getBBox().height textHeight = textElem[0][0].getBBox().height
rectElem.attr('width', 2 * rect.width) rectElem.attr('width', 2 * rect.width)
module.exports.bounds.insert(startx, verticalPos, startx + 2 * rect.width, verticalPos + 2 * conf.noteMargin + textHeight) bounds.insert(startx, verticalPos, startx + 2 * rect.width, verticalPos + 2 * conf.noteMargin + textHeight)
} else { } else {
module.exports.bounds.insert(startx, verticalPos, startx + rect.width, verticalPos + 2 * conf.noteMargin + textHeight) bounds.insert(startx, verticalPos, startx + rect.width, verticalPos + 2 * conf.noteMargin + textHeight)
} }
rectElem.attr('height', textHeight + 2 * conf.noteMargin) rectElem.attr('height', textHeight + 2 * conf.noteMargin)
module.exports.bounds.bumpVerticalPos(textHeight + 2 * conf.noteMargin) bounds.bumpVerticalPos(textHeight + 2 * conf.noteMargin)
} }
/** /**
@ -232,20 +233,20 @@ var drawMessage = function (elem, startx, stopx, verticalPos, msg) {
.attr('d', 'M ' + startx + ',' + verticalPos + ' C ' + (startx + 60) + ',' + (verticalPos - 10) + ' ' + (startx + 60) + ',' + .attr('d', 'M ' + startx + ',' + verticalPos + ' C ' + (startx + 60) + ',' + (verticalPos - 10) + ' ' + (startx + 60) + ',' +
(verticalPos + 30) + ' ' + startx + ',' + (verticalPos + 20)) (verticalPos + 30) + ' ' + startx + ',' + (verticalPos + 20))
module.exports.bounds.bumpVerticalPos(30) bounds.bumpVerticalPos(30)
var dx = Math.max(textWidth / 2, 100) var dx = Math.max(textWidth / 2, 100)
module.exports.bounds.insert(startx - dx, module.exports.bounds.getVerticalPos() - 10, stopx + dx, module.exports.bounds.getVerticalPos()) bounds.insert(startx - dx, bounds.getVerticalPos() - 10, stopx + dx, bounds.getVerticalPos())
} else { } else {
line = g.append('line') line = g.append('line')
line.attr('x1', startx) line.attr('x1', startx)
line.attr('y1', verticalPos) line.attr('y1', verticalPos)
line.attr('x2', stopx) line.attr('x2', stopx)
line.attr('y2', verticalPos) line.attr('y2', verticalPos)
module.exports.bounds.insert(startx, module.exports.bounds.getVerticalPos() - 10, stopx, module.exports.bounds.getVerticalPos()) bounds.insert(startx, bounds.getVerticalPos() - 10, stopx, bounds.getVerticalPos())
} }
// Make an SVG Container // Make an SVG Container
// Draw the line // Draw the line
if (msg.type === sq.yy.LINETYPE.DOTTED || msg.type === sq.yy.LINETYPE.DOTTED_CROSS || msg.type === sq.yy.LINETYPE.DOTTED_OPEN) { if (msg.type === parser.yy.LINETYPE.DOTTED || msg.type === parser.yy.LINETYPE.DOTTED_CROSS || msg.type === parser.yy.LINETYPE.DOTTED_OPEN) {
line.style('stroke-dasharray', ('3, 3')) line.style('stroke-dasharray', ('3, 3'))
line.attr('class', 'messageLine1') line.attr('class', 'messageLine1')
} else { } else {
@ -262,16 +263,16 @@ var drawMessage = function (elem, startx, stopx, verticalPos, msg) {
line.attr('stroke-width', 2) line.attr('stroke-width', 2)
line.attr('stroke', 'black') line.attr('stroke', 'black')
line.style('fill', 'none') // remove any fill colour line.style('fill', 'none') // remove any fill colour
if (msg.type === sq.yy.LINETYPE.SOLID || msg.type === sq.yy.LINETYPE.DOTTED) { if (msg.type === parser.yy.LINETYPE.SOLID || msg.type === parser.yy.LINETYPE.DOTTED) {
line.attr('marker-end', 'url(' + url + '#arrowhead)') line.attr('marker-end', 'url(' + url + '#arrowhead)')
} }
if (msg.type === sq.yy.LINETYPE.SOLID_CROSS || msg.type === sq.yy.LINETYPE.DOTTED_CROSS) { if (msg.type === parser.yy.LINETYPE.SOLID_CROSS || msg.type === parser.yy.LINETYPE.DOTTED_CROSS) {
line.attr('marker-end', 'url(' + url + '#crosshead)') line.attr('marker-end', 'url(' + url + '#crosshead)')
} }
} }
module.exports.drawActors = function (diagram, actors, actorKeys, verticalPos) { export const drawActors = function (diagram, actors, actorKeys, verticalPos) {
var i var i
// Draw the actors // Draw the actors
for (i = 0; i < actorKeys.length; i++) { for (i = 0; i < actorKeys.length; i++) {
@ -285,14 +286,14 @@ module.exports.drawActors = function (diagram, actors, actorKeys, verticalPos) {
// Draw the box with the attached line // Draw the box with the attached line
svgDraw.drawActor(diagram, actors[key].x, verticalPos, actors[key].description, conf) svgDraw.drawActor(diagram, actors[key].x, verticalPos, actors[key].description, conf)
module.exports.bounds.insert(actors[key].x, verticalPos, actors[key].x + conf.width, conf.height) bounds.insert(actors[key].x, verticalPos, actors[key].x + conf.width, conf.height)
} }
// Add a margin between the actor boxes and the first arrow // Add a margin between the actor boxes and the first arrow
module.exports.bounds.bumpVerticalPos(conf.height) bounds.bumpVerticalPos(conf.height)
} }
module.exports.setConf = function (cnf) { export const setConf = function (cnf) {
var keys = Object.keys(cnf) var keys = Object.keys(cnf)
keys.forEach(function (key) { keys.forEach(function (key) {
@ -301,14 +302,14 @@ module.exports.setConf = function (cnf) {
} }
var actorActivations = function (actor) { var actorActivations = function (actor) {
return module.exports.bounds.activations.filter(function (activation) { return bounds.activations.filter(function (activation) {
return activation.actor === actor return activation.actor === actor
}) })
} }
var actorFlowVerticaBounds = function (actor) { var actorFlowVerticaBounds = function (actor) {
// handle multiple stacked activations for same actor // handle multiple stacked activations for same actor
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
var activations = actorActivations(actor) var activations = actorActivations(actor)
var left = activations.reduce(function (acc, activation) { return Math.min(acc, activation.startx) }, actors[actor].x + conf.width / 2) var left = activations.reduce(function (acc, activation) { return Math.min(acc, activation.startx) }, actors[actor].x + conf.width / 2)
@ -321,11 +322,11 @@ var actorFlowVerticaBounds = function (actor) {
* @param text * @param text
* @param id * @param id
*/ */
module.exports.draw = function (text, id) { export const draw = function (text, id) {
sq.yy.clear() parser.yy.clear()
sq.parse(text + '\n') parser.parse(text + '\n')
module.exports.bounds.init() bounds.init()
var diagram = d3.select('#' + id) var diagram = d3.select('#' + id)
var startx var startx
@ -333,25 +334,25 @@ module.exports.draw = function (text, id) {
var forceWidth var forceWidth
// Fetch data from the parsing // Fetch data from the parsing
var actors = sq.yy.getActors() var actors = parser.yy.getActors()
var actorKeys = sq.yy.getActorKeys() var actorKeys = parser.yy.getActorKeys()
var messages = sq.yy.getMessages() var messages = parser.yy.getMessages()
var title = sq.yy.getTitle() var title = parser.yy.getTitle()
module.exports.drawActors(diagram, actors, actorKeys, 0) drawActors(diagram, actors, actorKeys, 0)
// The arrow head definition is attached to the svg once // The arrow head definition is attached to the svg once
svgDraw.insertArrowHead(diagram) svgDraw.insertArrowHead(diagram)
svgDraw.insertArrowCrossHead(diagram) svgDraw.insertArrowCrossHead(diagram)
function activeEnd (msg, verticalPos) { function activeEnd (msg, verticalPos) {
var activationData = module.exports.bounds.endActivation(msg) var activationData = bounds.endActivation(msg)
if (activationData.starty + 18 > verticalPos) { if (activationData.starty + 18 > verticalPos) {
activationData.starty = verticalPos - 6 activationData.starty = verticalPos - 6
verticalPos += 12 verticalPos += 12
} }
svgDraw.drawActivation(diagram, activationData, verticalPos, conf) svgDraw.drawActivation(diagram, activationData, verticalPos, conf)
module.exports.bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos) bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos)
} }
// var lastMsg // var lastMsg
@ -361,89 +362,89 @@ module.exports.draw = function (text, id) {
var loopData var loopData
switch (msg.type) { switch (msg.type) {
case sq.yy.LINETYPE.NOTE: case parser.yy.LINETYPE.NOTE:
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
startx = actors[msg.from].x startx = actors[msg.from].x
stopx = actors[msg.to].x stopx = actors[msg.to].x
if (msg.placement === sq.yy.PLACEMENT.RIGHTOF) { if (msg.placement === parser.yy.PLACEMENT.RIGHTOF) {
drawNote(diagram, startx + (conf.width + conf.actorMargin) / 2, module.exports.bounds.getVerticalPos(), msg) drawNote(diagram, startx + (conf.width + conf.actorMargin) / 2, bounds.getVerticalPos(), msg)
} else if (msg.placement === sq.yy.PLACEMENT.LEFTOF) { } else if (msg.placement === parser.yy.PLACEMENT.LEFTOF) {
drawNote(diagram, startx - (conf.width + conf.actorMargin) / 2, module.exports.bounds.getVerticalPos(), msg) drawNote(diagram, startx - (conf.width + conf.actorMargin) / 2, bounds.getVerticalPos(), msg)
} else if (msg.to === msg.from) { } else if (msg.to === msg.from) {
// Single-actor over // Single-actor over
drawNote(diagram, startx, module.exports.bounds.getVerticalPos(), msg) drawNote(diagram, startx, bounds.getVerticalPos(), msg)
} else { } else {
// Multi-actor over // Multi-actor over
forceWidth = Math.abs(startx - stopx) + conf.actorMargin forceWidth = Math.abs(startx - stopx) + conf.actorMargin
drawNote(diagram, (startx + stopx + conf.width - forceWidth) / 2, module.exports.bounds.getVerticalPos(), msg, drawNote(diagram, (startx + stopx + conf.width - forceWidth) / 2, bounds.getVerticalPos(), msg,
forceWidth) forceWidth)
} }
break break
case sq.yy.LINETYPE.ACTIVE_START: case parser.yy.LINETYPE.ACTIVE_START:
module.exports.bounds.newActivation(msg, diagram) bounds.newActivation(msg, diagram)
break break
case sq.yy.LINETYPE.ACTIVE_END: case parser.yy.LINETYPE.ACTIVE_END:
activeEnd(msg, module.exports.bounds.getVerticalPos()) activeEnd(msg, bounds.getVerticalPos())
break break
case sq.yy.LINETYPE.LOOP_START: case parser.yy.LINETYPE.LOOP_START:
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
module.exports.bounds.newLoop(msg.message) bounds.newLoop(msg.message)
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin) bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
break break
case sq.yy.LINETYPE.LOOP_END: case parser.yy.LINETYPE.LOOP_END:
loopData = module.exports.bounds.endLoop() loopData = bounds.endLoop()
svgDraw.drawLoop(diagram, loopData, 'loop', conf) svgDraw.drawLoop(diagram, loopData, 'loop', conf)
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
break break
case sq.yy.LINETYPE.OPT_START: case parser.yy.LINETYPE.OPT_START:
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
module.exports.bounds.newLoop(msg.message) bounds.newLoop(msg.message)
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin) bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
break break
case sq.yy.LINETYPE.OPT_END: case parser.yy.LINETYPE.OPT_END:
loopData = module.exports.bounds.endLoop() loopData = bounds.endLoop()
svgDraw.drawLoop(diagram, loopData, 'opt', conf) svgDraw.drawLoop(diagram, loopData, 'opt', conf)
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
break break
case sq.yy.LINETYPE.ALT_START: case parser.yy.LINETYPE.ALT_START:
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
module.exports.bounds.newLoop(msg.message) bounds.newLoop(msg.message)
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin) bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
break break
case sq.yy.LINETYPE.ALT_ELSE: case parser.yy.LINETYPE.ALT_ELSE:
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
loopData = module.exports.bounds.addSectionToLoop(msg.message) loopData = bounds.addSectionToLoop(msg.message)
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
break break
case sq.yy.LINETYPE.ALT_END: case parser.yy.LINETYPE.ALT_END:
loopData = module.exports.bounds.endLoop() loopData = bounds.endLoop()
svgDraw.drawLoop(diagram, loopData, 'alt', conf) svgDraw.drawLoop(diagram, loopData, 'alt', conf)
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
break break
case sq.yy.LINETYPE.PAR_START: case parser.yy.LINETYPE.PAR_START:
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
module.exports.bounds.newLoop(msg.message) bounds.newLoop(msg.message)
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin) bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
break break
case sq.yy.LINETYPE.PAR_AND: case parser.yy.LINETYPE.PAR_AND:
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
loopData = module.exports.bounds.addSectionToLoop(msg.message) loopData = bounds.addSectionToLoop(msg.message)
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
break break
case sq.yy.LINETYPE.PAR_END: case parser.yy.LINETYPE.PAR_END:
loopData = module.exports.bounds.endLoop() loopData = bounds.endLoop()
svgDraw.drawLoop(diagram, loopData, 'par', conf) svgDraw.drawLoop(diagram, loopData, 'par', conf)
module.exports.bounds.bumpVerticalPos(conf.boxMargin) bounds.bumpVerticalPos(conf.boxMargin)
break break
default: default:
try { try {
// lastMsg = msg // lastMsg = msg
module.exports.bounds.bumpVerticalPos(conf.messageMargin) bounds.bumpVerticalPos(conf.messageMargin)
var fromBounds = actorFlowVerticaBounds(msg.from) var fromBounds = actorFlowVerticaBounds(msg.from)
var toBounds = actorFlowVerticaBounds(msg.to) var toBounds = actorFlowVerticaBounds(msg.to)
var fromIdx = fromBounds[0] <= toBounds[0] ? 1 : 0 var fromIdx = fromBounds[0] <= toBounds[0] ? 1 : 0
@ -451,10 +452,10 @@ module.exports.draw = function (text, id) {
startx = fromBounds[fromIdx] startx = fromBounds[fromIdx]
stopx = toBounds[toIdx] stopx = toBounds[toIdx]
var verticalPos = module.exports.bounds.getVerticalPos() var verticalPos = bounds.getVerticalPos()
drawMessage(diagram, startx, stopx, verticalPos, msg) drawMessage(diagram, startx, stopx, verticalPos, msg)
var allBounds = fromBounds.concat(toBounds) var allBounds = fromBounds.concat(toBounds)
module.exports.bounds.insert(Math.min.apply(null, allBounds), verticalPos, Math.max.apply(null, allBounds), verticalPos) bounds.insert(Math.min.apply(null, allBounds), verticalPos, Math.max.apply(null, allBounds), verticalPos)
} catch (e) { } catch (e) {
console.error('error while drawing message', e) console.error('error while drawing message', e)
} }
@ -463,11 +464,11 @@ module.exports.draw = function (text, id) {
if (conf.mirrorActors) { if (conf.mirrorActors) {
// Draw actors below diagram // Draw actors below diagram
module.exports.bounds.bumpVerticalPos(conf.boxMargin * 2) bounds.bumpVerticalPos(conf.boxMargin * 2)
module.exports.drawActors(diagram, actors, actorKeys, module.exports.bounds.getVerticalPos()) drawActors(diagram, actors, actorKeys, bounds.getVerticalPos())
} }
var box = module.exports.bounds.getBounds() var box = bounds.getBounds()
// Adjust line height of actor lines now that the height of the diagram is known // Adjust line height of actor lines now that the height of the diagram is known
logger.debug('For line height fix Querying: #' + id + ' .actor-line') logger.debug('For line height fix Querying: #' + id + ' .actor-line')

View File

@ -1,4 +1,4 @@
module.exports.drawRect = function (elem, rectData) { export const drawRect = function (elem, rectData) {
var rectElem = elem.append('rect') var rectElem = elem.append('rect')
rectElem.attr('x', rectData.x) rectElem.attr('x', rectData.x)
rectElem.attr('y', rectData.y) rectElem.attr('y', rectData.y)
@ -16,7 +16,7 @@ module.exports.drawRect = function (elem, rectData) {
return rectElem return rectElem
} }
module.exports.drawText = function (elem, textData, width) { export const drawText = function (elem, textData, width) {
// Remove and ignore br:s // Remove and ignore br:s
var nText = textData.text.replace(/<br\/?>/ig, ' ') var nText = textData.text.replace(/<br\/?>/ig, ' ')
@ -45,7 +45,7 @@ module.exports.drawText = function (elem, textData, width) {
return textElem return textElem
} }
module.exports.drawLabel = function (elem, txtObject) { export const drawLabel = function (elem, txtObject) {
function genPoints (x, y, width, height, cut) { function genPoints (x, y, width, height, cut) {
return x + ',' + y + ' ' + return x + ',' + y + ' ' +
(x + width) + ',' + y + ' ' + (x + width) + ',' + y + ' ' +
@ -59,7 +59,7 @@ module.exports.drawLabel = function (elem, txtObject) {
txtObject.y = txtObject.y + txtObject.labelMargin txtObject.y = txtObject.y + txtObject.labelMargin
txtObject.x = txtObject.x + 0.5 * txtObject.labelMargin txtObject.x = txtObject.x + 0.5 * txtObject.labelMargin
module.exports.drawText(elem, txtObject) drawText(elem, txtObject)
} }
var actorCnt = -1 var actorCnt = -1
/** /**
@ -68,7 +68,7 @@ var actorCnt = -1
* @param pos The position if the actor in the liost of actors * @param pos The position if the actor in the liost of actors
* @param description The text in the box * @param description The text in the box
*/ */
module.exports.drawActor = function (elem, left, verticalPos, description, conf) { export const drawActor = function (elem, left, verticalPos, description, conf) {
var center = left + (conf.width / 2) var center = left + (conf.width / 2)
var g = elem.append('g') var g = elem.append('g')
if (verticalPos === 0) { if (verticalPos === 0) {
@ -84,7 +84,7 @@ module.exports.drawActor = function (elem, left, verticalPos, description, conf)
.attr('stroke', '#999') .attr('stroke', '#999')
} }
var rect = module.exports.getNoteRect() var rect = getNoteRect()
rect.x = left rect.x = left
rect.y = verticalPos rect.y = verticalPos
rect.fill = '#eaeaea' rect.fill = '#eaeaea'
@ -93,13 +93,13 @@ module.exports.drawActor = function (elem, left, verticalPos, description, conf)
rect.class = 'actor' rect.class = 'actor'
rect.rx = 3 rect.rx = 3
rect.ry = 3 rect.ry = 3
module.exports.drawRect(g, rect) drawRect(g, rect)
_drawTextCandidateFunc(conf)(description, g, _drawTextCandidateFunc(conf)(description, g,
rect.x, rect.y, rect.width, rect.height, { 'class': 'actor' }) rect.x, rect.y, rect.width, rect.height, { 'class': 'actor' })
} }
module.exports.anchorElement = function (elem) { export const anchorElement = function (elem) {
return elem.append('g') return elem.append('g')
} }
/** /**
@ -108,15 +108,15 @@ module.exports.anchorElement = function (elem) {
* @param bounds - activation box bounds * @param bounds - activation box bounds
* @param verticalPos - precise y cooridnate of bottom activation box edge * @param verticalPos - precise y cooridnate of bottom activation box edge
*/ */
module.exports.drawActivation = function (elem, bounds, verticalPos) { export const drawActivation = function (elem, bounds, verticalPos) {
var rect = module.exports.getNoteRect() var rect = getNoteRect()
var g = bounds.anchored var g = bounds.anchored
rect.x = bounds.startx rect.x = bounds.startx
rect.y = bounds.starty rect.y = bounds.starty
rect.fill = '#f4f4f4' rect.fill = '#f4f4f4'
rect.width = bounds.stopx - bounds.startx rect.width = bounds.stopx - bounds.startx
rect.height = verticalPos - bounds.starty rect.height = verticalPos - bounds.starty
module.exports.drawRect(g, rect) drawRect(g, rect)
} }
/** /**
@ -125,7 +125,7 @@ module.exports.drawActivation = function (elem, bounds, verticalPos) {
* @param pos The position if the actor in the list of actors * @param pos The position if the actor in the list of actors
* @param description The text in the box * @param description The text in the box
*/ */
module.exports.drawLoop = function (elem, bounds, labelText, conf) { export const drawLoop = function (elem, bounds, labelText, conf) {
var g = elem.append('g') var g = elem.append('g')
var drawLoopLine = function (startx, starty, stopx, stopy) { var drawLoopLine = function (startx, starty, stopx, stopy) {
return g.append('line') return g.append('line')
@ -145,30 +145,30 @@ module.exports.drawLoop = function (elem, bounds, labelText, conf) {
}) })
} }
var txt = module.exports.getTextObj() var txt = getTextObj()
txt.text = labelText txt.text = labelText
txt.x = bounds.startx txt.x = bounds.startx
txt.y = bounds.starty txt.y = bounds.starty
txt.labelMargin = 1.5 * 10 // This is the small box that says "loop" txt.labelMargin = 1.5 * 10 // This is the small box that says "loop"
txt.class = 'labelText' // Its size & position are fixed. txt.class = 'labelText' // Its size & position are fixed.
module.exports.drawLabel(g, txt) drawLabel(g, txt)
txt = module.exports.getTextObj() txt = getTextObj()
txt.text = '[ ' + bounds.title + ' ]' txt.text = '[ ' + bounds.title + ' ]'
txt.x = bounds.startx + (bounds.stopx - bounds.startx) / 2 txt.x = bounds.startx + (bounds.stopx - bounds.startx) / 2
txt.y = bounds.starty + 1.5 * conf.boxMargin txt.y = bounds.starty + 1.5 * conf.boxMargin
txt.anchor = 'middle' txt.anchor = 'middle'
txt.class = 'loopText' txt.class = 'loopText'
module.exports.drawText(g, txt) drawText(g, txt)
if (typeof bounds.sectionTitles !== 'undefined') { if (typeof bounds.sectionTitles !== 'undefined') {
bounds.sectionTitles.forEach(function (item, idx) { bounds.sectionTitles.forEach(function (item, idx) {
if (item !== '') { if (item !== '') {
txt.text = '[ ' + item + ' ]' txt.text = '[ ' + item + ' ]'
txt.y = bounds.sections[idx] + 1.5 * conf.boxMargin txt.y = bounds.sections[idx] + 1.5 * conf.boxMargin
module.exports.drawText(g, txt) drawText(g, txt)
} }
}) })
} }
@ -177,7 +177,7 @@ module.exports.drawLoop = function (elem, bounds, labelText, conf) {
/** /**
* Setup arrow head and define the marker. The result is appended to the svg. * Setup arrow head and define the marker. The result is appended to the svg.
*/ */
module.exports.insertArrowHead = function (elem) { export const insertArrowHead = function (elem) {
elem.append('defs').append('marker') elem.append('defs').append('marker')
.attr('id', 'arrowhead') .attr('id', 'arrowhead')
.attr('refX', 5) .attr('refX', 5)
@ -191,7 +191,7 @@ module.exports.insertArrowHead = function (elem) {
/** /**
* Setup arrow head and define the marker. The result is appended to the svg. * Setup arrow head and define the marker. The result is appended to the svg.
*/ */
module.exports.insertArrowCrossHead = function (elem) { export const insertArrowCrossHead = function (elem) {
var defs = elem.append('defs') var defs = elem.append('defs')
var marker = defs.append('marker') var marker = defs.append('marker')
.attr('id', 'crosshead') .attr('id', 'crosshead')
@ -219,7 +219,7 @@ module.exports.insertArrowCrossHead = function (elem) {
// this is actual shape for arrowhead // this is actual shape for arrowhead
} }
module.exports.getTextObj = function () { export const getTextObj = function () {
var txt = { var txt = {
x: 0, x: 0,
y: 0, y: 0,
@ -235,7 +235,7 @@ module.exports.getTextObj = function () {
return txt return txt
} }
module.exports.getNoteRect = function () { export const getNoteRect = function () {
var rect = { var rect = {
x: 0, x: 0,
y: 0, y: 0,

View File

@ -6,6 +6,7 @@ import he from 'he'
import mermaidAPI from './mermaidAPI' import mermaidAPI from './mermaidAPI'
import { logger } from './logger' import { logger } from './logger'
import pkg from '../package.json'
var nextId = 0 var nextId = 0
@ -110,7 +111,7 @@ var init = function () {
} }
const version = function () { const version = function () {
return 'v' + require('../package.json').version return 'v' + pkg.version
} }
const initialize = function (config) { const initialize = function (config) {

View File

@ -1,5 +1,8 @@
/* eslint-env jasmine */ /* eslint-env jasmine */
import mermaid from './mermaid' import mermaid from './mermaid'
import graphDb from './diagrams/flowchart/graphDb'
import flowParser from './diagrams/flowchart/parser/flow'
import flowRenderer from './diagrams/flowchart/flowRenderer'
describe('when using mermaid and ', function () { describe('when using mermaid and ', function () {
describe('when detecting chart type ', function () { describe('when detecting chart type ', function () {
@ -48,19 +51,15 @@ describe('when using mermaid and ', function () {
}) })
describe('when calling addEdges ', function () { describe('when calling addEdges ', function () {
var graph = require('./diagrams/flowchart/graphDb')
var flow = require('./diagrams/flowchart/parser/flow')
var flowRend = require('./diagrams/flowchart/flowRenderer')
beforeEach(function () { beforeEach(function () {
global.mermaid_config = { startOnLoad: false } global.mermaid_config = { startOnLoad: false }
flow.parser.yy = graph flowParser.parser.yy = graphDb
graph.clear() graphDb.clear()
}) })
it('it should handle edges with text', function () { it('it should handle edges with text', function () {
flow.parser.parse('graph TD;A-->|text ex|B;') flowParser.parser.parse('graph TD;A-->|text ex|B;')
flow.parser.yy.getVertices() flowParser.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flowParser.parser.yy.getEdges()
var mockG = { var mockG = {
setEdge: function (start, end, options) { setEdge: function (start, end, options) {
@ -71,13 +70,13 @@ describe('when using mermaid and ', function () {
} }
} }
flowRend.addEdges(edges, mockG) flowRenderer.addEdges(edges, mockG)
}) })
it('should handle edges without text', function () { it('should handle edges without text', function () {
flow.parser.parse('graph TD;A-->B;') flowParser.parser.parse('graph TD;A-->B;')
flow.parser.yy.getVertices() flowParser.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flowParser.parser.yy.getEdges()
var mockG = { var mockG = {
setEdge: function (start, end, options) { setEdge: function (start, end, options) {
@ -87,13 +86,13 @@ describe('when using mermaid and ', function () {
} }
} }
flowRend.addEdges(edges, mockG) flowRenderer.addEdges(edges, mockG)
}) })
it('should handle open-ended edges', function () { it('should handle open-ended edges', function () {
flow.parser.parse('graph TD;A---B;') flowParser.parser.parse('graph TD;A---B;')
flow.parser.yy.getVertices() flowParser.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flowParser.parser.yy.getEdges()
var mockG = { var mockG = {
setEdge: function (start, end, options) { setEdge: function (start, end, options) {
@ -103,13 +102,13 @@ describe('when using mermaid and ', function () {
} }
} }
flowRend.addEdges(edges, mockG) flowRenderer.addEdges(edges, mockG)
}) })
it('should handle edges with styles defined', function () { it('should handle edges with styles defined', function () {
flow.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;') flowParser.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;')
flow.parser.yy.getVertices() flowParser.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flowParser.parser.yy.getEdges()
var mockG = { var mockG = {
setEdge: function (start, end, options) { setEdge: function (start, end, options) {
@ -120,12 +119,12 @@ describe('when using mermaid and ', function () {
} }
} }
flowRend.addEdges(edges, mockG) flowRenderer.addEdges(edges, mockG)
}) })
it('should handle edges with interpolation defined', function () { it('should handle edges with interpolation defined', function () {
flow.parser.parse('graph TD;A---B; linkStyle 0 interpolate basis') flowParser.parser.parse('graph TD;A---B; linkStyle 0 interpolate basis')
flow.parser.yy.getVertices() flowParser.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flowParser.parser.yy.getEdges()
var mockG = { var mockG = {
setEdge: function (start, end, options) { setEdge: function (start, end, options) {
@ -136,12 +135,12 @@ describe('when using mermaid and ', function () {
} }
} }
flowRend.addEdges(edges, mockG) flowRenderer.addEdges(edges, mockG)
}) })
it('should handle edges with text and styles defined', function () { it('should handle edges with text and styles defined', function () {
flow.parser.parse('graph TD;A---|the text|B; linkStyle 0 stroke:val1,stroke-width:val2;') flowParser.parser.parse('graph TD;A---|the text|B; linkStyle 0 stroke:val1,stroke-width:val2;')
flow.parser.yy.getVertices() flowParser.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flowParser.parser.yy.getEdges()
var mockG = { var mockG = {
setEdge: function (start, end, options) { setEdge: function (start, end, options) {
@ -153,13 +152,13 @@ describe('when using mermaid and ', function () {
} }
} }
flowRend.addEdges(edges, mockG) flowRenderer.addEdges(edges, mockG)
}) })
it('should set fill to "none" by default when handling edges', function () { it('should set fill to "none" by default when handling edges', function () {
flow.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;') flowParser.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;')
flow.parser.yy.getVertices() flowParser.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flowParser.parser.yy.getEdges()
var mockG = { var mockG = {
setEdge: function (start, end, options) { setEdge: function (start, end, options) {
@ -170,13 +169,13 @@ describe('when using mermaid and ', function () {
} }
} }
flowRend.addEdges(edges, mockG) flowRenderer.addEdges(edges, mockG)
}) })
it('should not set fill to none if fill is set in linkStyle', function () { it('should not set fill to none if fill is set in linkStyle', function () {
flow.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2,fill:blue;') flowParser.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2,fill:blue;')
flow.parser.yy.getVertices() flowParser.parser.yy.getVertices()
var edges = flow.parser.yy.getEdges() var edges = flowParser.parser.yy.getEdges()
var mockG = { var mockG = {
setEdge: function (start, end, options) { setEdge: function (start, end, options) {
expect(start).toBe('A') expect(start).toBe('A')
@ -186,7 +185,7 @@ describe('when using mermaid and ', function () {
} }
} }
flowRend.addEdges(edges, mockG) flowRenderer.addEdges(edges, mockG)
}) })
}) })

View File

@ -33,6 +33,7 @@ import gitGraphParser from './diagrams/gitGraph/parser/gitGraph'
import gitGraphRenderer from './diagrams/gitGraph/gitGraphRenderer' import gitGraphRenderer from './diagrams/gitGraph/gitGraphRenderer'
import gitGraphAst from './diagrams/gitGraph/gitGraphAst' import gitGraphAst from './diagrams/gitGraph/gitGraphAst'
import d3 from './d3' import d3 from './d3'
import pkg from '../package.json'
/** /**
* ## Configuration * ## Configuration
@ -288,11 +289,11 @@ function parse (text) {
* Function returning version information * Function returning version information
* @returns {string} A string containing the version info * @returns {string} A string containing the version info
*/ */
module.exports.version = function () { export const version = function () {
return require('../package.json').version return pkg.version
} }
module.exports.encodeEntities = function (text) { export const encodeEntities = function (text) {
var txt = text var txt = text
txt = txt.replace(/style.*:\S*#.*;/g, function (s) { txt = txt.replace(/style.*:\S*#.*;/g, function (s) {
@ -318,7 +319,7 @@ module.exports.encodeEntities = function (text) {
return txt return txt
} }
module.exports.decodeEntities = function (text) { export const decodeEntities = function (text) {
var txt = text var txt = text
txt = txt.replace(/fl°°/g, function () { txt = txt.replace(/fl°°/g, function () {
@ -383,7 +384,7 @@ var render = function (id, txt, cb, container) {
} }
window.txt = txt window.txt = txt
txt = module.exports.encodeEntities(txt) txt = encodeEntities(txt)
var element = d3.select('#d' + id).node() var element = d3.select('#d' + id).node()
var graphType = utils.detectType(txt) var graphType = utils.detectType(txt)
@ -438,7 +439,7 @@ var render = function (id, txt, cb, container) {
break break
case 'info': case 'info':
config.info.arrowMarkerAbsolute = config.arrowMarkerAbsolute config.info.arrowMarkerAbsolute = config.arrowMarkerAbsolute
info.draw(txt, id, module.exports.version()) info.draw(txt, id, version())
if (config.cloneCssStyles) { if (config.cloneCssStyles) {
utils.cloneCssStyles(element.firstChild, []) utils.cloneCssStyles(element.firstChild, [])
} }
@ -457,7 +458,7 @@ var render = function (id, txt, cb, container) {
// Fix for when the base tag is used // Fix for when the base tag is used
var svgCode = d3.select('#d' + id).node().innerHTML.replace(/url\(#arrowhead/g, 'url(' + url + '#arrowhead', 'g') var svgCode = d3.select('#d' + id).node().innerHTML.replace(/url\(#arrowhead/g, 'url(' + url + '#arrowhead', 'g')
svgCode = module.exports.decodeEntities(svgCode) svgCode = decodeEntities(svgCode)
if (typeof cb !== 'undefined') { if (typeof cb !== 'undefined') {
cb(svgCode, graph.bindFunctions) cb(svgCode, graph.bindFunctions)

View File

@ -1,13 +1,12 @@
/* eslint-env jest */ /* eslint-env jest */
/* eslint-env jasmine */ /* eslint-env jasmine */
const fs = require('fs') import fs from 'fs'
const path = require('path') import path from 'path'
import async from 'async'
import clone from 'clone'
import rimraf from 'rimraf'
const async = require('async') import mermaidCli from '../lib'
const clone = require('clone')
const rimraf = require('rimraf')
const mermaid = require('../lib')
const fileTestMermaid = path.join('test', 'fixtures', 'test.mermaid') const fileTestMermaid = path.join('test', 'fixtures', 'test.mermaid')
const isWin = /^win/.test(process.platform) const isWin = /^win/.test(process.platform)
@ -53,7 +52,7 @@ test('output of single png', function (done) {
opt.outputDir += '_png' opt.outputDir += '_png'
opt.png = true opt.png = true
mermaid.process(opt.files, opt, function (code) { mermaidCli.process(opt.files, opt, function (code) {
expect(code).toBe(0) expect(code).toBe(0)
verifyFiles(expected, opt.outputDir, done) verifyFiles(expected, opt.outputDir, done)
@ -70,7 +69,7 @@ test('output of multiple png', function (done) {
opt.outputDir += '_png' opt.outputDir += '_png'
opt.png = true opt.png = true
mermaid.process(opt.files, opt, function (code) { mermaidCli.process(opt.files, opt, function (code) {
expect(code).toBe(0) expect(code).toBe(0)
verifyFiles(expected, opt.outputDir, done) verifyFiles(expected, opt.outputDir, done)
@ -86,7 +85,7 @@ test('output of single svg', function (done) {
opt.outputDir += '_svg' opt.outputDir += '_svg'
opt.svg = true opt.svg = true
mermaid.process(opt.files, opt, function (code) { mermaidCli.process(opt.files, opt, function (code) {
expect(code).toBe(0) expect(code).toBe(0)
verifyFiles(expected, opt.outputDir, done) verifyFiles(expected, opt.outputDir, done)
@ -103,7 +102,7 @@ test('output of multiple svg', function (done) {
opt.outputDir += '_svg' opt.outputDir += '_svg'
opt.svg = true opt.svg = true
mermaid.process(opt.files, opt, function (code) { mermaidCli.process(opt.files, opt, function (code) {
expect(code).toBe(0) expect(code).toBe(0)
verifyFiles(expected, opt.outputDir, done) verifyFiles(expected, opt.outputDir, done)
@ -122,14 +121,14 @@ test('output including CSS', function (done) {
opt2.png = true opt2.png = true
opt2.outputDir += '_css_png' opt2.outputDir += '_css_png'
mermaid.process(opt.files, opt, function (code) { mermaidCli.process(opt.files, opt, function (code) {
expect(code).toBe(0) expect(code).toBe(0)
const filename = path.join(opt.outputDir, path.basename(expected[0])) const filename = path.join(opt.outputDir, path.basename(expected[0]))
const one = fs.statSync(filename) const one = fs.statSync(filename)
opt2.css = path.join('test', 'fixtures', 'test.css') opt2.css = path.join('test', 'fixtures', 'test.css')
mermaid.process(opt2.files, opt2, function (code) { mermaidCli.process(opt2.files, opt2, function (code) {
expect(code).toBe(0) expect(code).toBe(0)
const two = fs.statSync(filename) const two = fs.statSync(filename)
expect(one.size).not.toBe(two.size) expect(one.size).not.toBe(two.size)

View File

@ -1,6 +1,6 @@
/* eslint-env jest */ /* eslint-env jest */
/* eslint-env jasmine */ /* eslint-env jasmine */
const cliPath = '../lib/cli' import cli from '../lib/cli'
beforeEach(() => { beforeEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 64000 jasmine.DEFAULT_TIMEOUT_INTERVAL = 64000
@ -9,7 +9,6 @@ beforeEach(() => {
test('parses multiple files', function (done) { test('parses multiple files', function (done) {
expect.assertions(3) expect.assertions(3)
const cli = require(cliPath)
const argv = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid'] const argv = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
const expected = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid'] const expected = ['example/file1.mermaid', 'file2.mermaid', 'file3.mermaid']
@ -25,7 +24,6 @@ test('parses multiple files', function (done) {
test('defaults to png', function (done) { test('defaults to png', function (done) {
expect.assertions(3) expect.assertions(3)
const cli = require(cliPath)
const argv = ['example/file1.mermaid'] const argv = ['example/file1.mermaid']
cli.parse(argv, function (err, msg, opt) { cli.parse(argv, function (err, msg, opt) {
@ -40,7 +38,6 @@ test('defaults to png', function (done) {
test('setting svg unsets png', function (done) { test('setting svg unsets png', function (done) {
expect.assertions(3) expect.assertions(3)
const cli = require(cliPath)
const argv = ['example/file1.mermaid', '-s'] const argv = ['example/file1.mermaid', '-s']
cli.parse(argv, function (err, msg, opt) { cli.parse(argv, function (err, msg, opt) {
@ -55,7 +52,6 @@ test('setting svg unsets png', function (done) {
test('setting png and svg is allowed', function (done) { test('setting png and svg is allowed', function (done) {
expect.assertions(3) expect.assertions(3)
const cli = require(cliPath)
const argv = ['example/file1.mermaid', '-s', '-p'] const argv = ['example/file1.mermaid', '-s', '-p']
cli.parse(argv, function (err, msg, opt) { cli.parse(argv, function (err, msg, opt) {
@ -70,7 +66,6 @@ test('setting png and svg is allowed', function (done) {
test('setting an output directory succeeds', function (done) { test('setting an output directory succeeds', function (done) {
expect.assertions(2) expect.assertions(2)
const cli = require(cliPath)
const argv = ['example/file1.mermaid', '-o', 'example/'] const argv = ['example/file1.mermaid', '-o', 'example/']
cli.parse(argv, function (err, msg, opt) { cli.parse(argv, function (err, msg, opt) {
@ -83,7 +78,6 @@ test('setting an output directory succeeds', function (done) {
test('not setting a css source file uses a default style', function (done) { test('not setting a css source file uses a default style', function (done) {
expect.assertions(2) expect.assertions(2)
const cli = require(cliPath)
const argv = ['example/file1.mermaid'] const argv = ['example/file1.mermaid']
cli.parse(argv, function (err, msg, opt) { cli.parse(argv, function (err, msg, opt) {
@ -96,7 +90,6 @@ test('not setting a css source file uses a default style', function (done) {
test('setting a css source file succeeds', function (done) { test('setting a css source file succeeds', function (done) {
expect.assertions(2) expect.assertions(2)
const cli = require(cliPath)
const argv = ['example/file1.mermaid', '-t', 'test/fixtures/test.css'] const argv = ['example/file1.mermaid', '-t', 'test/fixtures/test.css']
cli.parse(argv, function (err, msg, opt) { cli.parse(argv, function (err, msg, opt) {
@ -109,7 +102,6 @@ test('setting a css source file succeeds', function (done) {
test('setting an output directory incorrectly causes an error', function (done) { test('setting an output directory incorrectly causes an error', function (done) {
expect.assertions(1) expect.assertions(1)
const cli = require(cliPath)
const argv = ['-o'] const argv = ['-o']
cli.parse(argv, function (err) { cli.parse(argv, function (err) {
@ -122,7 +114,6 @@ test('setting an output directory incorrectly causes an error', function (done)
test('a callback function is called after parsing', function (done) { test('a callback function is called after parsing', function (done) {
expect.assertions(3) expect.assertions(3)
const cli = require(cliPath)
const argv = ['example/file1.mermaid'] const argv = ['example/file1.mermaid']
cli.parse(argv, function (err, msg, opts) { cli.parse(argv, function (err, msg, opts) {

View File

@ -1,14 +1,13 @@
/* eslint-env jest */ /* eslint-env jest */
/* eslint-env jasmine */ /* eslint-env jasmine */
const exec = require('child_process').exec import path from 'path'
const path = require('path') import rimraf from 'rimraf'
import { exec } from 'child_process'
const rimraf = require('rimraf')
const localSearchPath = './node_modules/.bin' + path.delimiter + process.env.PATH const localSearchPath = './node_modules/.bin' + path.delimiter + process.env.PATH
const testDir = 'test/fixtures/samples/'.replace('/', path.sep) const testDir = 'test/fixtures/samples/'.replace('/', path.sep)
const phantomjs = 'node_modules/.bin/phantomjs '.replace('/', path.sep) const phantomjs = 'node_modules/.bin/phantomjs '.replace('/', path.sep)
const loadHtmlSaveScreenshotPngScripts = testDir + path.sep + 'load_html_save_screenshot_png.phantomjs' const loadHtmlSaveScreenshotPngScripts = testDir + path.sep + 'load_html_save_screenshot_png.js'
rimraf.sync(testDir + '*.actual.*') rimraf.sync(testDir + '*.actual.*')

View File

@ -0,0 +1,16 @@
// usage: ../../../node_modules/.bin/phantomjs <html> <png>
import system from 'system'
import webpage from 'webpage'
const html = system.args[1]
const png = system.args[2]
console.log('png:', png)
const page = webpage.create()
page.open(html)
page.onLoadFinished = function () {
page.render(png)
global.phantom.exit()
}

View File

@ -1,15 +0,0 @@
// usage: ../../../node_modules/.bin/phantomjs <html> <png>
var system = require('system');
var html = system.args[1];
var png = system.args[2];
console.log('png:', png)
var page = require('webpage').create(),
loadInProgress = false,
fs = require('fs');
page.open(html);
page.onLoadFinished = function() {
loadInProgress = false;
page.render(png);
phantom.exit();
}

View File

@ -1,21 +0,0 @@
{
"name": "usageTests",
"version": "0.4.0",
"homepage": "https://github.com/knsv/mermaid",
"authors": [
"knsv <knut@sveido.com>"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"requirejs": "~2.1.16",
"mermaid": "~0.4.0",
"qunit": "~1.18.0"
}
}

View File

@ -1,47 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="bower_components/mermaid/dist/mermaid.min.js"></script>
<script>
var mermaid_config = {
startOnLoad:true
}
</script>
<script>
function apa(){
console.log('CLICKED');
}
</script>
</head>
<body>
TEST 0.2.16
<div class="mermaid">
graph TD;
sq[Square shape2] --> ci((Circle shape // Начало))
</div>
<h1>Shapes</h1>
<div class="mermaid">
info
</div>
<div class="mermaid">
graph LR
A[Square Rect] -- Link text --> B((Circle))
A --> C(Round Rect)
B --> D{Rhombus}
C --> D
</div>
<div class="mermaid">
graph TD;
sq[Square shape]-->ci((Circle shape));
od>Odd shape]---|Two line<br>edge comment|ro;
od2>Really long text in an Odd shape]-->od3>Really long text with linebreak<br>in an Odd shape];
di{Diamond is <br/> broken}-->ro(Rounded<br>square<br>shape);
di-->ro2(Rounded square shape);
e((Inner circle URL))-->f(,.?!+-*ز);
style e red;
</div>
</body>
</html>

View File

@ -1,11 +0,0 @@
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"gulp": "^3.8.10"
},
"author": "",
"license": "MIT"
}

View File

@ -1,30 +0,0 @@
/* eslint-env qunit */
require.config({
paths: {
mermaid: '../../dist/mermaid'
},
shim: {
mermaid: {
exports: 'mermaid'
}
}
})
require([], function () {
QUnit.module('requireTest.html')
QUnit.test('using mermaid in requirejs', function (assert) {
var done = assert.async()
require(['mermaid'], function (mermaid) {
assert.ok(mermaid, 'mermaid is not null')
console.log(mermaid)
mermaid.init()
assert.equal(window.d3.selectAll('path')[0].length, 8,
'drew 8 paths')
done()
})
})
QUnit.load()
QUnit.start()
})

View File

@ -1,27 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="bower_components/qunit/qunit/qunit.css" />
<link rel="stylesheet" href="../../dist/mermaid.forest.css"/>
<script src="bower_components/qunit/qunit/qunit.js"></script>
<script>
QUnit.config.autostart = false;
</script>
<script data-main="reqJsApp.js" src="bower_components/requirejs/require.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div class="mermaid">
graph LR
A-->B
B-->C
C-->A
D-->C
</div>
</body>
</html>