mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Replace require with import
This commit is contained in:
parent
c9442653e9
commit
a7d79baf00
@ -5,7 +5,7 @@ import { jsConfig } from './webpack.config.base'
|
||||
|
||||
const webpackConfig = jsConfig()
|
||||
|
||||
module.exports = function (config) {
|
||||
export default function (config) {
|
||||
config.set({
|
||||
|
||||
// base path that will be used to resolve all patterns (eg. files, exclude)
|
||||
|
20
lib/cli.js
20
lib/cli.js
@ -4,17 +4,15 @@ import which from 'which'
|
||||
import parseArgs from 'minimist'
|
||||
import semver from 'semver'
|
||||
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
|
||||
|
||||
module.exports = (function () {
|
||||
return new Cli()
|
||||
}())
|
||||
|
||||
function Cli (options) {
|
||||
this.options = {
|
||||
alias: {
|
||||
@ -63,9 +61,7 @@ function Cli (options) {
|
||||
Cli.prototype.parse = function (argv, next) {
|
||||
this.errors = [] // clear errors
|
||||
var options = parseArgs(argv, this.options)
|
||||
|
||||
if (options.version) {
|
||||
var pkg = require('../package.json')
|
||||
this.message = '' + pkg.version
|
||||
next(null, this.message)
|
||||
} else if (options.help) {
|
||||
@ -151,10 +147,8 @@ function createCheckPhantom (_phantomPath) {
|
||||
return function checkPhantom (_next) {
|
||||
var next = _next || function () { }
|
||||
var err
|
||||
|
||||
if (typeof phantomPath === 'undefined') {
|
||||
try {
|
||||
var phantom = require('phantomjs')
|
||||
phantomPath = phantom.path
|
||||
} catch (e) {
|
||||
try {
|
||||
@ -195,3 +189,9 @@ function createCheckPhantom (_phantomPath) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const cli = (function () {
|
||||
return new Cli()
|
||||
}())
|
||||
|
||||
export default cli
|
||||
|
@ -1,12 +1,9 @@
|
||||
import path from 'path'
|
||||
import mkdirp from 'mkdirp'
|
||||
|
||||
var spawn = require('child_process').spawn
|
||||
import { spawn } from 'child_process'
|
||||
|
||||
var phantomscript = path.join(__dirname, 'phantomscript.js')
|
||||
|
||||
module.exports = { process: processMermaid }
|
||||
|
||||
function processMermaid (files, _options, _next) {
|
||||
var options = _options || {}
|
||||
var outputDir = options.outputDir || process.cwd()
|
||||
@ -41,3 +38,5 @@ function processMermaid (files, _options, _next) {
|
||||
phantom.stdout.pipe(process.stdout)
|
||||
})
|
||||
}
|
||||
|
||||
export default { process: processMermaid }
|
||||
|
@ -14,7 +14,7 @@ classes = {
|
||||
* @param type
|
||||
* @param style
|
||||
*/
|
||||
exports.addClass = function (id) {
|
||||
export const addClass = function (id) {
|
||||
if (typeof classes[id] === 'undefined') {
|
||||
classes[id] = {
|
||||
id: id,
|
||||
@ -24,31 +24,30 @@ exports.addClass = function (id) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.clear = function () {
|
||||
export const clear = function () {
|
||||
relations = []
|
||||
classes = {}
|
||||
}
|
||||
|
||||
module.exports.getClass = function (id) {
|
||||
export const getClass = function (id) {
|
||||
return classes[id]
|
||||
}
|
||||
module.exports.getClasses = function () {
|
||||
export const getClasses = function () {
|
||||
return classes
|
||||
}
|
||||
|
||||
module.exports.getRelations = function () {
|
||||
export const getRelations = function () {
|
||||
return relations
|
||||
}
|
||||
|
||||
exports.addRelation = function (relation) {
|
||||
export const addRelation = function (relation) {
|
||||
logger.warn('Adding relation: ' + JSON.stringify(relation))
|
||||
module.exports.addClass(relation.id1)
|
||||
module.exports.addClass(relation.id2)
|
||||
|
||||
addClass(relation.id1)
|
||||
addClass(relation.id2)
|
||||
relations.push(relation)
|
||||
}
|
||||
|
||||
exports.addMembers = function (className, MembersArr) {
|
||||
export const addMembers = function (className, MembersArr) {
|
||||
var theClass = classes[className]
|
||||
if (typeof MembersArr === 'string') {
|
||||
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) === ':') {
|
||||
return label.substr(2).trim()
|
||||
} else {
|
||||
@ -67,12 +66,12 @@ exports.cleanupLabel = function (label) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.lineType = {
|
||||
export const lineType = {
|
||||
LINE: 0,
|
||||
DOTTED_LINE: 1
|
||||
}
|
||||
|
||||
exports.relationType = {
|
||||
export const relationType = {
|
||||
AGGREGATION: 0,
|
||||
EXTENSION: 1,
|
||||
COMPOSITION: 2,
|
||||
|
@ -1,11 +1,11 @@
|
||||
/* eslint-env jasmine */
|
||||
import { parser } from './parser/classDiagram'
|
||||
import classDb from './classDb'
|
||||
|
||||
describe('class diagram, ', function () {
|
||||
describe('when parsing an info graph it', function () {
|
||||
var cd, cDDb
|
||||
beforeEach(function () {
|
||||
cd = require('./parser/classDiagram').parser
|
||||
cDDb = require('./classDb')
|
||||
cd.yy = cDDb
|
||||
parser.yy = classDb
|
||||
})
|
||||
|
||||
it('should handle relation definitions', function () {
|
||||
@ -16,7 +16,7 @@ describe('class diagram, ', function () {
|
||||
'Class07 .. Class08\n' +
|
||||
'Class09 -- Class1'
|
||||
|
||||
cd.parse(str)
|
||||
parser.parse(str)
|
||||
})
|
||||
it('should handle relation definition of different types and directions', function () {
|
||||
var str = 'classDiagram\n' +
|
||||
@ -26,7 +26,7 @@ describe('class diagram, ', function () {
|
||||
'Class17 ..|> Class18\n' +
|
||||
'Class19 <--* Class20'
|
||||
|
||||
cd.parse(str)
|
||||
parser.parse(str)
|
||||
})
|
||||
|
||||
it('should handle cardinality and labels', function () {
|
||||
@ -35,7 +35,7 @@ describe('class diagram, ', function () {
|
||||
'Class03 o-- Class04 : aggregation\n' +
|
||||
'Class05 --> "1" Class06'
|
||||
|
||||
cd.parse(str)
|
||||
parser.parse(str)
|
||||
})
|
||||
it('should handle class definitions', function () {
|
||||
var str = 'classDiagram\n' +
|
||||
@ -44,7 +44,7 @@ describe('class diagram, ', function () {
|
||||
'Car *-- Wheel : have 4 >\n' +
|
||||
'Car -- Person : < owns'
|
||||
|
||||
cd.parse(str)
|
||||
parser.parse(str)
|
||||
})
|
||||
|
||||
it('should handle method statements', function () {
|
||||
@ -54,7 +54,7 @@ describe('class diagram, ', function () {
|
||||
'ArrayList : Object[] elementData\n' +
|
||||
'ArrayList : size()'
|
||||
|
||||
cd.parse(str)
|
||||
parser.parse(str)
|
||||
})
|
||||
it('should handle parsing of method statements grouped by brackets', function () {
|
||||
var str = 'classDiagram\n' +
|
||||
@ -68,7 +68,7 @@ describe('class diagram, ', function () {
|
||||
' departureTime : Date\n' +
|
||||
'}'
|
||||
|
||||
cd.parse(str)
|
||||
parser.parse(str)
|
||||
})
|
||||
|
||||
it('should handle parsing of separators', function () {
|
||||
@ -100,87 +100,84 @@ describe('class diagram, ', function () {
|
||||
'String password\n' +
|
||||
'}'
|
||||
|
||||
cd.parse(str)
|
||||
parser.parse(str)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when fetching data from an classDiagram graph it', function () {
|
||||
var cd, cDDb
|
||||
beforeEach(function () {
|
||||
cd = require('./parser/classDiagram').parser
|
||||
cDDb = require('./classDb')
|
||||
cd.yy = cDDb
|
||||
cd.yy.clear()
|
||||
parser.yy = classDb
|
||||
parser.yy.clear()
|
||||
})
|
||||
it('should handle relation definitions EXTENSION', function () {
|
||||
var str = 'classDiagram\n' +
|
||||
'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(cd.yy.getClass('Class02').id).toBe('Class02')
|
||||
expect(relations[0].relation.type1).toBe(cDDb.relationType.EXTENSION)
|
||||
expect(parser.yy.getClass('Class01').id).toBe('Class01')
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02')
|
||||
expect(relations[0].relation.type1).toBe(classDb.relationType.EXTENSION)
|
||||
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 () {
|
||||
var str = 'classDiagram\n' +
|
||||
'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(cd.yy.getClass('Class02').id).toBe('Class02')
|
||||
expect(relations[0].relation.type1).toBe(cDDb.relationType.AGGREGATION)
|
||||
expect(parser.yy.getClass('Class01').id).toBe('Class01')
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02')
|
||||
expect(relations[0].relation.type1).toBe(classDb.relationType.AGGREGATION)
|
||||
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 () {
|
||||
var str = 'classDiagram\n' +
|
||||
'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(cd.yy.getClass('Class02').id).toBe('Class02')
|
||||
expect(relations[0].relation.type1).toBe(cDDb.relationType.COMPOSITION)
|
||||
expect(relations[0].relation.type2).toBe(cDDb.relationType.COMPOSITION)
|
||||
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE)
|
||||
expect(parser.yy.getClass('Class01').id).toBe('Class01')
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02')
|
||||
expect(relations[0].relation.type1).toBe(classDb.relationType.COMPOSITION)
|
||||
expect(relations[0].relation.type2).toBe(classDb.relationType.COMPOSITION)
|
||||
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE)
|
||||
})
|
||||
it('should handle relation definitions no types', function () {
|
||||
var str = 'classDiagram\n' +
|
||||
'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(cd.yy.getClass('Class02').id).toBe('Class02')
|
||||
expect(parser.yy.getClass('Class01').id).toBe('Class01')
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02')
|
||||
expect(relations[0].relation.type1).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 () {
|
||||
var str = 'classDiagram\n' +
|
||||
'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(cd.yy.getClass('Class02').id).toBe('Class02')
|
||||
expect(parser.yy.getClass('Class01').id).toBe('Class01')
|
||||
expect(parser.yy.getClass('Class02').id).toBe('Class02')
|
||||
expect(relations[0].relation.type1).toBe('none')
|
||||
expect(relations[0].relation.type2).toBe(cDDb.relationType.EXTENSION)
|
||||
expect(relations[0].relation.lineType).toBe(cDDb.lineType.LINE)
|
||||
expect(relations[0].relation.type2).toBe(classDb.relationType.EXTENSION)
|
||||
expect(relations[0].relation.lineType).toBe(classDb.lineType.LINE)
|
||||
})
|
||||
|
||||
it('should handle multiple classes and relation definitions', function () {
|
||||
@ -191,21 +188,21 @@ describe('class diagram, ', function () {
|
||||
'Class07 .. Class08\n' +
|
||||
'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(cd.yy.getClass('Class10').id).toBe('Class10')
|
||||
expect(parser.yy.getClass('Class01').id).toBe('Class01')
|
||||
expect(parser.yy.getClass('Class10').id).toBe('Class10')
|
||||
|
||||
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.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.type2).toBe('none')
|
||||
expect(relations[3].relation.lineType).toBe(cDDb.lineType.DOTTED_LINE)
|
||||
expect(relations[3].relation.lineType).toBe(classDb.lineType.DOTTED_LINE)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,12 +1,12 @@
|
||||
|
||||
import dagre from 'dagre-layout'
|
||||
|
||||
import cDDb from './classDb'
|
||||
import classDb from './classDb'
|
||||
import d3 from '../../d3'
|
||||
import { logger } from '../../logger'
|
||||
var cd = require('./parser/classDiagram').parser
|
||||
import { parser } from './parser/classDiagram'
|
||||
|
||||
cd.yy = cDDb
|
||||
parser.yy = classDb
|
||||
|
||||
var idCache
|
||||
idCache = {}
|
||||
@ -125,13 +125,13 @@ var edgeCount = 0
|
||||
var drawEdge = function (elem, path, relation) {
|
||||
var getRelationType = function (type) {
|
||||
switch (type) {
|
||||
case cDDb.relationType.AGGREGATION:
|
||||
case classDb.relationType.AGGREGATION:
|
||||
return 'aggregation'
|
||||
case cDDb.relationType.EXTENSION:
|
||||
case classDb.relationType.EXTENSION:
|
||||
return 'extension'
|
||||
case cDDb.relationType.COMPOSITION:
|
||||
case classDb.relationType.COMPOSITION:
|
||||
return 'composition'
|
||||
case cDDb.relationType.DEPENDENCY:
|
||||
case classDb.relationType.DEPENDENCY:
|
||||
return 'dependency'
|
||||
}
|
||||
}
|
||||
@ -291,7 +291,7 @@ var drawClass = function (elem, classDef) {
|
||||
return classInfo
|
||||
}
|
||||
|
||||
module.exports.setConf = function (cnf) {
|
||||
export const setConf = function (cnf) {
|
||||
var keys = Object.keys(cnf)
|
||||
|
||||
keys.forEach(function (key) {
|
||||
@ -303,9 +303,9 @@ module.exports.setConf = function (cnf) {
|
||||
* @param text
|
||||
* @param id
|
||||
*/
|
||||
module.exports.draw = function (text, id) {
|
||||
cd.yy.clear()
|
||||
cd.parse(text)
|
||||
export const draw = function (text, id) {
|
||||
parser.yy.clear()
|
||||
parser.parse(text)
|
||||
|
||||
logger.info('Rendering diagram ' + text)
|
||||
|
||||
@ -328,7 +328,7 @@ module.exports.draw = function (text, id) {
|
||||
return {}
|
||||
})
|
||||
|
||||
var classes = cDDb.getClasses()
|
||||
var classes = classDb.getClasses()
|
||||
var keys = Object.keys(classes)
|
||||
var i
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
@ -341,7 +341,7 @@ module.exports.draw = function (text, id) {
|
||||
logger.info('Org height: ' + node.height)
|
||||
}
|
||||
|
||||
var relations = cDDb.getRelations()
|
||||
var relations = classDb.getRelations()
|
||||
relations.forEach(function (relation) {
|
||||
logger.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation))
|
||||
g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), { relation: relation })
|
||||
|
@ -1,19 +1,20 @@
|
||||
import { parser } from './parser/example'
|
||||
import exampleDb from './exampleDb'
|
||||
|
||||
/* eslint-env jasmine */
|
||||
describe('when parsing an info graph it', function () {
|
||||
var ex
|
||||
beforeEach(function () {
|
||||
ex = require('./parser/example').parser
|
||||
ex.yy = require('./exampleDb')
|
||||
parser.yy = exampleDb
|
||||
})
|
||||
|
||||
it('should handle an info definition', function () {
|
||||
var str = 'info\nsay: hello'
|
||||
|
||||
ex.parse(str)
|
||||
parser.parse(str)
|
||||
})
|
||||
it('should handle an showMessage statement definition', function () {
|
||||
var str = 'info\nshowInfo'
|
||||
|
||||
ex.parse(str)
|
||||
parser.parse(str)
|
||||
})
|
||||
})
|
||||
|
@ -3,19 +3,19 @@ import { logger } from '../../logger'
|
||||
var message = ''
|
||||
var info = false
|
||||
|
||||
exports.setMessage = function (txt) {
|
||||
export const setMessage = function (txt) {
|
||||
logger.debug('Setting message to: ' + txt)
|
||||
message = txt
|
||||
}
|
||||
|
||||
exports.getMessage = function () {
|
||||
export const getMessage = function () {
|
||||
return message
|
||||
}
|
||||
|
||||
exports.setInfo = function (inf) {
|
||||
export const setInfo = function (inf) {
|
||||
info = inf
|
||||
}
|
||||
|
||||
exports.getInfo = function () {
|
||||
export const getInfo = function () {
|
||||
return info
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import { logger } from '../../logger'
|
||||
* @param text
|
||||
* @param id
|
||||
*/
|
||||
exports.draw = function (txt, id, ver) {
|
||||
export const draw = function (txt, id, ver) {
|
||||
var parser
|
||||
parser = exampleParser.parser
|
||||
parser.yy = db
|
||||
|
@ -7,7 +7,7 @@ import { logger } from '../../logger'
|
||||
|
||||
var conf = {
|
||||
}
|
||||
module.exports.setConf = function (cnf) {
|
||||
export const setConf = function (cnf) {
|
||||
var keys = Object.keys(cnf)
|
||||
var i
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
@ -20,7 +20,7 @@ module.exports.setConf = function (cnf) {
|
||||
* @param vert Object containing the vertices.
|
||||
* @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 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} g The graph object
|
||||
*/
|
||||
module.exports.addEdges = function (edges, g) {
|
||||
export const addEdges = function (edges, g) {
|
||||
var cnt = 0
|
||||
|
||||
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 {object} classDef styles
|
||||
*/
|
||||
module.exports.getClasses = function (text, isDot) {
|
||||
export const getClasses = function (text, isDot) {
|
||||
var parser
|
||||
graph.clear()
|
||||
if (isDot) {
|
||||
@ -246,7 +246,7 @@ module.exports.getClasses = function (text, isDot) {
|
||||
* @param text
|
||||
* @param id
|
||||
*/
|
||||
module.exports.draw = function (text, id, isDot) {
|
||||
export const draw = function (text, id, isDot) {
|
||||
logger.debug('Drawing flowchart')
|
||||
var parser
|
||||
graph.clear()
|
||||
@ -310,8 +310,8 @@ module.exports.draw = function (text, id, isDot) {
|
||||
g.setParent(subG.nodes[j], subG.id)
|
||||
}
|
||||
}
|
||||
module.exports.addVertices(vert, g)
|
||||
module.exports.addEdges(edges, g)
|
||||
addVertices(vert, g)
|
||||
addEdges(edges, g)
|
||||
|
||||
// Create the renderer
|
||||
var Render = dagreD3.render
|
||||
|
@ -18,7 +18,7 @@ var funs = []
|
||||
* @param type
|
||||
* @param style
|
||||
*/
|
||||
exports.addVertex = function (id, text, type, style) {
|
||||
export const addVertex = function (id, text, type, style) {
|
||||
var txt
|
||||
|
||||
if (typeof id === 'undefined') {
|
||||
@ -63,7 +63,7 @@ exports.addVertex = function (id, text, type, style) {
|
||||
* @param type
|
||||
* @param linktext
|
||||
*/
|
||||
exports.addLink = function (start, end, type, linktext) {
|
||||
export const addLink = function (start, end, type, linktext) {
|
||||
logger.info('Got edge...', start, end)
|
||||
var edge = { start: start, end: end, type: undefined, text: '' }
|
||||
linktext = type.text
|
||||
@ -89,7 +89,7 @@ exports.addLink = function (start, end, type, linktext) {
|
||||
* @param pos
|
||||
* @param interpolate
|
||||
*/
|
||||
exports.updateLinkInterpolate = function (pos, interp) {
|
||||
export const updateLinkInterpolate = function (pos, interp) {
|
||||
if (pos === 'default') {
|
||||
edges.defaultInterpolate = interp
|
||||
} else {
|
||||
@ -102,7 +102,7 @@ exports.updateLinkInterpolate = function (pos, interp) {
|
||||
* @param pos
|
||||
* @param style
|
||||
*/
|
||||
exports.updateLink = function (pos, style) {
|
||||
export const updateLink = function (pos, style) {
|
||||
if (pos === 'default') {
|
||||
edges.defaultStyle = style
|
||||
} 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') {
|
||||
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.
|
||||
* @param dir
|
||||
*/
|
||||
exports.setDirection = function (dir) {
|
||||
export const setDirection = function (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.
|
||||
* @param dir
|
||||
*/
|
||||
exports.setClass = function (id, className) {
|
||||
export const setClass = function (id, className) {
|
||||
if (id.indexOf(',') > 0) {
|
||||
id.split(',').forEach(function (id2) {
|
||||
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]
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ exports.getTooltip = function (id) {
|
||||
* Called by parser when a graph definition is found, stores the direction of the chart.
|
||||
* @param dir
|
||||
*/
|
||||
exports.setClickEvent = function (id, functionName, link, tooltip) {
|
||||
export const setClickEvent = function (id, functionName, link, tooltip) {
|
||||
if (id.indexOf(',') > 0) {
|
||||
id.split(',').forEach(function (id2) {
|
||||
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) {
|
||||
fun(element)
|
||||
})
|
||||
}
|
||||
exports.getDirection = function () {
|
||||
export const getDirection = function () {
|
||||
return direction
|
||||
}
|
||||
/**
|
||||
* Retrieval function for fetching the found nodes after parsing has completed.
|
||||
* @returns {{}|*|vertices}
|
||||
*/
|
||||
exports.getVertices = function () {
|
||||
export const getVertices = function () {
|
||||
return vertices
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ exports.getVertices = function () {
|
||||
* Retrieval function for fetching the found links after parsing has completed.
|
||||
* @returns {{}|*|edges}
|
||||
*/
|
||||
exports.getEdges = function () {
|
||||
export const getEdges = function () {
|
||||
return edges
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ exports.getEdges = function () {
|
||||
* Retrieval function for fetching the found class definitions after parsing has completed.
|
||||
* @returns {{}|*|classes}
|
||||
*/
|
||||
exports.getClasses = function () {
|
||||
export const getClasses = function () {
|
||||
return classes
|
||||
}
|
||||
|
||||
@ -287,7 +287,7 @@ funs.push(setupToolTips)
|
||||
/**
|
||||
* Clears the internal graph db so that a new graph can be parsed.
|
||||
*/
|
||||
exports.clear = function () {
|
||||
export const clear = function () {
|
||||
vertices = {}
|
||||
classes = {}
|
||||
edges = []
|
||||
@ -301,14 +301,14 @@ exports.clear = function () {
|
||||
*
|
||||
* @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;'
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
var prims = { 'boolean': {}, 'number': {}, 'string': {} }
|
||||
var objs = []
|
||||
@ -343,7 +343,7 @@ var getPosForId = function (id) {
|
||||
}
|
||||
var secCount = -1
|
||||
var posCrossRef = []
|
||||
var indexNodes = function (id, pos) {
|
||||
var indexNodes2 = function (id, pos) {
|
||||
var nodes = subGraphs[pos].nodes
|
||||
secCount = secCount + 1
|
||||
if (secCount > 2000) {
|
||||
@ -364,7 +364,7 @@ var indexNodes = function (id, pos) {
|
||||
var childPos = getPosForId(nodes[count])
|
||||
// Ignore regular nodes (pos will be -1)
|
||||
if (childPos >= 0) {
|
||||
var res = indexNodes(id, childPos)
|
||||
var res = indexNodes2(id, childPos)
|
||||
if (res.result) {
|
||||
return {
|
||||
result: true,
|
||||
@ -383,16 +383,16 @@ var indexNodes = function (id, pos) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.getDepthFirstPos = function (pos) {
|
||||
export const getDepthFirstPos = function (pos) {
|
||||
return posCrossRef[pos]
|
||||
}
|
||||
exports.indexNodes = function () {
|
||||
export const indexNodes = function () {
|
||||
secCount = -1
|
||||
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
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import graph from '../graphDb'
|
||||
import graphDb from '../graphDb'
|
||||
import flow from './flow'
|
||||
|
||||
describe('when parsing ', function () {
|
||||
beforeEach(function () {
|
||||
flow.parser.yy = require('../graphDb')
|
||||
flow.parser.yy = graphDb
|
||||
flow.parser.yy.clear()
|
||||
})
|
||||
|
||||
@ -469,42 +469,42 @@ describe('when parsing ', function () {
|
||||
|
||||
describe('it should handle interaction, ', 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 vert = flow.parser.yy.getVertices()
|
||||
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 () {
|
||||
spyOn(graph, 'setClickEvent')
|
||||
spyOn(graphDb, 'setClickEvent')
|
||||
var res = flow.parser.parse('graph TD\nA-->B\nclick A callback "tooltip"')
|
||||
|
||||
var vert = flow.parser.yy.getVertices()
|
||||
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 () {
|
||||
spyOn(graph, 'setClickEvent')
|
||||
spyOn(graphDb, 'setClickEvent')
|
||||
var res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html"')
|
||||
|
||||
var vert = flow.parser.yy.getVertices()
|
||||
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 () {
|
||||
spyOn(graph, 'setClickEvent')
|
||||
spyOn(graphDb, 'setClickEvent')
|
||||
var res = flow.parser.parse('graph TD\nA-->B\nclick A "click.html" "tooltip"')
|
||||
|
||||
var vert = flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
|
||||
expect(graph.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', 'tooltip')
|
||||
expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', 'tooltip')
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -1,30 +1,31 @@
|
||||
/* eslint-env jasmine */
|
||||
import { parser } from './parser/gantt'
|
||||
import ganttDb from './ganttDb'
|
||||
|
||||
describe('when parsing a gantt diagram it', function () {
|
||||
var gantt
|
||||
beforeEach(function () {
|
||||
gantt = require('./parser/gantt').parser
|
||||
gantt.yy = require('./ganttDb')
|
||||
parser.yy = ganttDb
|
||||
})
|
||||
|
||||
it('should handle an dateFormat definition', function () {
|
||||
var str = 'gantt\ndateFormat yyyy-mm-dd'
|
||||
|
||||
gantt.parse(str)
|
||||
parser.parse(str)
|
||||
})
|
||||
it('should handle an dateFormat definition', function () {
|
||||
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 () {
|
||||
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 () {
|
||||
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
|
||||
@ -44,6 +45,6 @@ describe('when parsing a gantt diagram it', function () {
|
||||
'section Documentation\n' +
|
||||
'Design jison grammar:des1, 2014-01-01, 2014-01-04'
|
||||
|
||||
gantt.parse(str)
|
||||
parser.parse(str)
|
||||
})
|
||||
})
|
||||
|
@ -7,7 +7,7 @@ var sections = []
|
||||
var tasks = []
|
||||
var currentSection = ''
|
||||
|
||||
module.exports.clear = function () {
|
||||
export const clear = function () {
|
||||
sections = []
|
||||
tasks = []
|
||||
currentSection = ''
|
||||
@ -18,27 +18,27 @@ module.exports.clear = function () {
|
||||
rawTasks = []
|
||||
}
|
||||
|
||||
module.exports.setDateFormat = function (txt) {
|
||||
export const setDateFormat = function (txt) {
|
||||
dateFormat = txt
|
||||
}
|
||||
|
||||
module.exports.getDateFormat = function () {
|
||||
export const getDateFormat = function () {
|
||||
return dateFormat
|
||||
}
|
||||
module.exports.setTitle = function (txt) {
|
||||
export const setTitle = function (txt) {
|
||||
title = txt
|
||||
}
|
||||
|
||||
module.exports.getTitle = function () {
|
||||
export const getTitle = function () {
|
||||
return title
|
||||
}
|
||||
|
||||
module.exports.addSection = function (txt) {
|
||||
export const addSection = function (txt) {
|
||||
currentSection = txt
|
||||
sections.push(txt)
|
||||
}
|
||||
|
||||
module.exports.getTasks = function () {
|
||||
export const getTasks = function () {
|
||||
var allItemsPricessed = compileTasks()
|
||||
var maxDepth = 10
|
||||
var iterationCount = 0
|
||||
@ -60,7 +60,7 @@ var getStartDate = function (prevTime, dateFormat, str) {
|
||||
var afterStatement = re.exec(str.trim())
|
||||
|
||||
if (afterStatement !== null) {
|
||||
var task = module.exports.findTaskById(afterStatement[1])
|
||||
var task = findTaskById(afterStatement[1])
|
||||
|
||||
if (typeof task === 'undefined') {
|
||||
var dt = new Date()
|
||||
@ -150,7 +150,7 @@ var compileData = function (prevTask, dataStr) {
|
||||
var data = ds.split(',')
|
||||
|
||||
var task = {}
|
||||
var df = module.exports.getDateFormat()
|
||||
var df = getDateFormat()
|
||||
|
||||
// Get tags like active, done cand crit
|
||||
var matchFound = true
|
||||
@ -263,7 +263,7 @@ var lastTask
|
||||
var lastTaskID
|
||||
var rawTasks = []
|
||||
var taskDb = {}
|
||||
module.exports.addTask = function (descr, data) {
|
||||
export const addTask = function (descr, data) {
|
||||
var rawTask = {
|
||||
section: currentSection,
|
||||
type: currentSection,
|
||||
@ -287,12 +287,12 @@ module.exports.addTask = function (descr, data) {
|
||||
taskDb[rawTask.id] = pos - 1
|
||||
}
|
||||
|
||||
module.exports.findTaskById = function (id) {
|
||||
export const findTaskById = function (id) {
|
||||
var pos = taskDb[id]
|
||||
return rawTasks[pos]
|
||||
}
|
||||
|
||||
module.exports.addTaskOrg = function (descr, data) {
|
||||
export const addTaskOrg = function (descr, data) {
|
||||
var newTask = {
|
||||
section: currentSection,
|
||||
type: currentSection,
|
||||
@ -311,14 +311,14 @@ module.exports.addTaskOrg = function (descr, data) {
|
||||
}
|
||||
|
||||
var compileTasks = function () {
|
||||
var df = module.exports.getDateFormat()
|
||||
var df = getDateFormat()
|
||||
|
||||
var compileTask = function (pos) {
|
||||
var task = rawTasks[pos]
|
||||
var startTime = ''
|
||||
switch (rawTasks[pos].raw.startTime.type) {
|
||||
case 'prevTaskEnd':
|
||||
var prevTask = module.exports.findTaskById(task.prevTaskId)
|
||||
var prevTask = findTaskById(task.prevTaskId)
|
||||
task.startTime = prevTask.endTime
|
||||
break
|
||||
case 'getStartDate':
|
||||
|
@ -1,68 +1,67 @@
|
||||
/* eslint-env jasmine */
|
||||
describe('when using the ganttDb', function () {
|
||||
var gDb
|
||||
var moment = require('moment')
|
||||
import moment from 'moment'
|
||||
import ganttDb from './ganttDb'
|
||||
|
||||
describe('when using the ganttDb', function () {
|
||||
beforeEach(function () {
|
||||
gDb = require('./ganttDb')
|
||||
gDb.clear()
|
||||
ganttDb.clear()
|
||||
})
|
||||
|
||||
it('should handle an fixed dates', function () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2013-01-12')
|
||||
var tasks = gDb.getTasks()
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2013-01-12')
|
||||
var tasks = ganttDb.getTasks()
|
||||
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].id).toEqual('id1')
|
||||
expect(tasks[0].task).toEqual('test1')
|
||||
})
|
||||
it('should handle duration (days) instead of fixed date to determine end date', function () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2d')
|
||||
var tasks = gDb.getTasks()
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2d')
|
||||
var tasks = ganttDb.getTasks()
|
||||
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].id).toEqual('id1')
|
||||
expect(tasks[0].task).toEqual('test1')
|
||||
})
|
||||
it('should handle duration (hours) instead of fixed date to determine end date', function () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2h')
|
||||
var tasks = gDb.getTasks()
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2h')
|
||||
var tasks = ganttDb.getTasks()
|
||||
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].id).toEqual('id1')
|
||||
expect(tasks[0].task).toEqual('test1')
|
||||
})
|
||||
it('should handle duration (minutes) instead of fixed date to determine end date', function () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2m')
|
||||
var tasks = gDb.getTasks()
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2m')
|
||||
var tasks = ganttDb.getTasks()
|
||||
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].id).toEqual('id1')
|
||||
expect(tasks[0].task).toEqual('test1')
|
||||
})
|
||||
it('should handle duration (seconds) instead of fixed date to determine end date', function () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2s')
|
||||
var tasks = gDb.getTasks()
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2s')
|
||||
var tasks = ganttDb.getTasks()
|
||||
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].id).toEqual('id1')
|
||||
expect(tasks[0].task).toEqual('test1')
|
||||
})
|
||||
it('should handle duration (weeks) instead of fixed date to determine end date', function () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
var tasks = gDb.getTasks()
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
var tasks = ganttDb.getTasks()
|
||||
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].id).toEqual('id1')
|
||||
@ -70,12 +69,12 @@ describe('when using the ganttDb', function () {
|
||||
})
|
||||
|
||||
it('should handle relative start date based on id', function () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
gDb.addTask('test2', 'id2,after id1,1d')
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
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].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 () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
gDb.addTask('test2', 'id2,after id3,1d')
|
||||
var tasks = gDb.getTasks()
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
ganttDb.addTask('test2', 'id2,after id3,1d')
|
||||
var tasks = ganttDb.getTasks()
|
||||
expect(tasks[1].startTime).toEqual(new Date((new Date()).setHours(0, 0, 0, 0)))
|
||||
expect(tasks[1].id).toEqual('id2')
|
||||
expect(tasks[1].task).toEqual('test2')
|
||||
})
|
||||
|
||||
it('should handle fixed dates without id', function () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', '2013-01-01,2013-01-12')
|
||||
var tasks = gDb.getTasks()
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', '2013-01-01,2013-01-12')
|
||||
var tasks = ganttDb.getTasks()
|
||||
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].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 () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', '2013-01-01,4d')
|
||||
var tasks = gDb.getTasks()
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', '2013-01-01,4d')
|
||||
var tasks = ganttDb.getTasks()
|
||||
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].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 () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
gDb.addTask('test2', 'after id1,1d')
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
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].id).toEqual('task1')
|
||||
expect(tasks[1].task).toEqual('test2')
|
||||
})
|
||||
it('should handle a new task with only an end date as definition', function () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
gDb.addTask('test2', '2013-01-26')
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
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].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')
|
||||
})
|
||||
it('should handle a new task with only an end date as definition', function () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
gDb.addTask('test2', '2d')
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
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].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')
|
||||
})
|
||||
it('should handle relative start date based on id regardless of sections', function () {
|
||||
gDb.setDateFormat('YYYY-MM-DD')
|
||||
gDb.addSection('testa1')
|
||||
gDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
gDb.addTask('test2', 'id2,after id3,1d')
|
||||
gDb.addSection('testa2')
|
||||
gDb.addTask('test3', 'id3,after id1,2d')
|
||||
ganttDb.setDateFormat('YYYY-MM-DD')
|
||||
ganttDb.addSection('testa1')
|
||||
ganttDb.addTask('test1', 'id1,2013-01-01,2w')
|
||||
ganttDb.addTask('test2', 'id2,after id3,1d')
|
||||
ganttDb.addSection('testa2')
|
||||
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].endTime).toEqual(moment('2013-01-18', 'YYYY-MM-DD').toDate())
|
||||
|
@ -1,9 +1,11 @@
|
||||
|
||||
import moment from 'moment'
|
||||
|
||||
import { parser } from './parser/gantt'
|
||||
import ganttDb from './ganttDb'
|
||||
import d3 from '../../d3'
|
||||
var gantt = require('./parser/gantt').parser
|
||||
gantt.yy = require('./ganttDb')
|
||||
|
||||
parser.yy = ganttDb
|
||||
|
||||
var daysInChart
|
||||
var conf = {
|
||||
@ -17,7 +19,7 @@ var conf = {
|
||||
fontSize: 11,
|
||||
fontFamily: '"Open-Sans", "sans-serif"'
|
||||
}
|
||||
module.exports.setConf = function (cnf) {
|
||||
export const setConf = function (cnf) {
|
||||
var keys = Object.keys(cnf)
|
||||
|
||||
keys.forEach(function (key) {
|
||||
@ -25,9 +27,9 @@ module.exports.setConf = function (cnf) {
|
||||
})
|
||||
}
|
||||
var w
|
||||
module.exports.draw = function (text, id) {
|
||||
gantt.yy.clear()
|
||||
gantt.parse(text)
|
||||
export const draw = function (text, id) {
|
||||
parser.yy.clear()
|
||||
parser.parse(text)
|
||||
|
||||
var elem = document.getElementById(id)
|
||||
w = elem.parentElement.offsetWidth
|
||||
@ -40,7 +42,7 @@ module.exports.draw = function (text, id) {
|
||||
w = conf.useWidth
|
||||
}
|
||||
|
||||
var taskArray = gantt.yy.getTasks()
|
||||
var taskArray = parser.yy.getTasks()
|
||||
|
||||
// Set height based on number of tasks
|
||||
var h = taskArray.length * (conf.barHeight + conf.barGap) + 2 * conf.topPadding
|
||||
@ -85,7 +87,7 @@ module.exports.draw = function (text, id) {
|
||||
}
|
||||
|
||||
svg.append('text')
|
||||
.text(gantt.yy.getTitle())
|
||||
.text(parser.yy.getTitle())
|
||||
.attr('x', w / 2)
|
||||
.attr('y', conf.titleTopMargin)
|
||||
.attr('class', 'titleText')
|
||||
|
@ -46,11 +46,11 @@ function isReachableFrom (currentCommit, otherCommit) {
|
||||
return false
|
||||
}
|
||||
|
||||
module.exports.setDirection = function (dir) {
|
||||
export const setDirection = function (dir) {
|
||||
direction = dir
|
||||
}
|
||||
var options = {}
|
||||
module.exports.setOptions = function (rawOptString) {
|
||||
export const setOptions = function (rawOptString) {
|
||||
logger.debug('options str', rawOptString)
|
||||
rawOptString = rawOptString && rawOptString.trim()
|
||||
rawOptString = rawOptString || '{}'
|
||||
@ -61,11 +61,11 @@ module.exports.setOptions = function (rawOptString) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.getOptions = function () {
|
||||
export const getOptions = function () {
|
||||
return options
|
||||
}
|
||||
|
||||
module.exports.commit = function (msg) {
|
||||
export const commit = function (msg) {
|
||||
var commit = {
|
||||
id: getId(),
|
||||
message: msg,
|
||||
@ -78,12 +78,12 @@ module.exports.commit = function (msg) {
|
||||
logger.debug('in pushCommit ' + commit.id)
|
||||
}
|
||||
|
||||
module.exports.branch = function (name) {
|
||||
export const branch = function (name) {
|
||||
branches[name] = head != null ? head.id : null
|
||||
logger.debug('in createBranch')
|
||||
}
|
||||
|
||||
module.exports.merge = function (otherBranch) {
|
||||
export const merge = function (otherBranch) {
|
||||
var currentCommit = commits[branches[curBranch]]
|
||||
var otherCommit = commits[branches[otherBranch]]
|
||||
if (isReachableFrom(currentCommit, otherCommit)) {
|
||||
@ -109,14 +109,14 @@ module.exports.merge = function (otherBranch) {
|
||||
logger.debug('in mergeBranch')
|
||||
}
|
||||
|
||||
module.exports.checkout = function (branch) {
|
||||
export const checkout = function (branch) {
|
||||
logger.debug('in checkout')
|
||||
curBranch = branch
|
||||
var id = branches[curBranch]
|
||||
head = commits[id]
|
||||
}
|
||||
|
||||
module.exports.reset = function (commitRef) {
|
||||
export const reset = function (commitRef) {
|
||||
logger.debug('in reset', commitRef)
|
||||
var ref = commitRef.split(':')[0]
|
||||
var parentCount = parseInt(commitRef.split(':')[1])
|
||||
@ -173,13 +173,13 @@ function prettyPrintCommitHistory (commitArr) {
|
||||
prettyPrintCommitHistory(commitArr)
|
||||
}
|
||||
|
||||
module.exports.prettyPrint = function () {
|
||||
export const prettyPrint = function () {
|
||||
logger.debug(commits)
|
||||
var node = module.exports.getCommitsArray()[0]
|
||||
var node = getCommitsArray()[0]
|
||||
prettyPrintCommitHistory([node])
|
||||
}
|
||||
|
||||
module.exports.clear = function () {
|
||||
export const clear = function () {
|
||||
commits = {}
|
||||
head = null
|
||||
branches = { 'master': head }
|
||||
@ -187,22 +187,22 @@ module.exports.clear = function () {
|
||||
seq = 0
|
||||
}
|
||||
|
||||
module.exports.getBranchesAsObjArray = function () {
|
||||
export const getBranchesAsObjArray = function () {
|
||||
const branchArr = _.map(branches, function (value, key) {
|
||||
return { 'name': key, 'commit': commits[value] }
|
||||
})
|
||||
return branchArr
|
||||
}
|
||||
|
||||
module.exports.getBranches = function () { return branches }
|
||||
module.exports.getCommits = function () { return commits }
|
||||
module.exports.getCommitsArray = function () {
|
||||
export const getBranches = function () { return branches }
|
||||
export const getCommits = function () { return commits }
|
||||
export const getCommitsArray = function () {
|
||||
var commitArr = Object.keys(commits).map(function (key) {
|
||||
return commits[key]
|
||||
})
|
||||
commitArr.forEach(function (o) { logger.debug(o.id) })
|
||||
return _.orderBy(commitArr, ['seq'], ['desc'])
|
||||
}
|
||||
module.exports.getCurrentBranch = function () { return curBranch }
|
||||
module.exports.getDirection = function () { return direction }
|
||||
module.exports.getHead = function () { return head }
|
||||
export const getCurrentBranch = function () { return curBranch }
|
||||
export const getDirection = function () { return direction }
|
||||
export const getHead = function () { return head }
|
||||
|
@ -1,7 +1,6 @@
|
||||
/* eslint-env jasmine */
|
||||
import ast from './gitGraphAst'
|
||||
|
||||
var parser = require('./parser/gitGraph').parser
|
||||
import { parser } from './parser/gitGraph'
|
||||
|
||||
describe('when parsing a gitGraph', function () {
|
||||
beforeEach(function () {
|
||||
|
@ -26,7 +26,7 @@ var config = {
|
||||
}
|
||||
}
|
||||
var apiConfig = {}
|
||||
exports.setConf = function (c) {
|
||||
export const setConf = function (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 {
|
||||
var parser
|
||||
parser = gitGraphParser.parser
|
||||
|
@ -5,7 +5,7 @@ var messages = []
|
||||
var notes = []
|
||||
var title = ''
|
||||
|
||||
module.exports.addActor = function (id, name, description) {
|
||||
export const addActor = function (id, name, description) {
|
||||
// Don't allow description nulling
|
||||
var old = actors[id]
|
||||
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 }
|
||||
}
|
||||
|
||||
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 })
|
||||
}
|
||||
|
||||
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)
|
||||
messages.push({ from: idFrom, to: idTo, message: message, type: messageType })
|
||||
}
|
||||
|
||||
module.exports.getMessages = function () {
|
||||
export const getMessages = function () {
|
||||
return messages
|
||||
}
|
||||
|
||||
module.exports.getActors = function () {
|
||||
export const getActors = function () {
|
||||
return actors
|
||||
}
|
||||
module.exports.getActor = function (id) {
|
||||
export const getActor = function (id) {
|
||||
return actors[id]
|
||||
}
|
||||
module.exports.getActorKeys = function () {
|
||||
export const getActorKeys = function () {
|
||||
return Object.keys(actors)
|
||||
}
|
||||
module.exports.getTitle = function () {
|
||||
export const getTitle = function () {
|
||||
return title
|
||||
}
|
||||
|
||||
module.exports.clear = function () {
|
||||
export const clear = function () {
|
||||
actors = {}
|
||||
messages = []
|
||||
}
|
||||
|
||||
module.exports.LINETYPE = {
|
||||
export const LINETYPE = {
|
||||
SOLID: 0,
|
||||
DOTTED: 1,
|
||||
NOTE: 2,
|
||||
@ -69,85 +69,85 @@ module.exports.LINETYPE = {
|
||||
PAR_END: 21
|
||||
}
|
||||
|
||||
module.exports.ARROWTYPE = {
|
||||
export const ARROWTYPE = {
|
||||
FILLED: 0,
|
||||
OPEN: 1
|
||||
}
|
||||
|
||||
module.exports.PLACEMENT = {
|
||||
export const PLACEMENT = {
|
||||
LEFTOF: 0,
|
||||
RIGHTOF: 1,
|
||||
OVER: 2
|
||||
}
|
||||
|
||||
module.exports.addNote = function (actor, placement, message) {
|
||||
export const addNote = function (actor, placement, message) {
|
||||
var note = { actor: actor, placement: placement, message: message }
|
||||
|
||||
// Coerce actor into a [to, from, ...] array
|
||||
var actors = [].concat(actor, actor)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
module.exports.apply = function (param) {
|
||||
export const apply = function (param) {
|
||||
if (param instanceof Array) {
|
||||
param.forEach(function (item) {
|
||||
module.exports.apply(item)
|
||||
apply(item)
|
||||
})
|
||||
} else {
|
||||
switch (param.type) {
|
||||
case 'addActor':
|
||||
module.exports.addActor(param.actor, param.actor, param.description)
|
||||
addActor(param.actor, param.actor, param.description)
|
||||
break
|
||||
case 'activeStart':
|
||||
module.exports.addSignal(param.actor, undefined, undefined, param.signalType)
|
||||
addSignal(param.actor, undefined, undefined, param.signalType)
|
||||
break
|
||||
case 'activeEnd':
|
||||
module.exports.addSignal(param.actor, undefined, undefined, param.signalType)
|
||||
addSignal(param.actor, undefined, undefined, param.signalType)
|
||||
break
|
||||
case 'addNote':
|
||||
module.exports.addNote(param.actor, param.placement, param.text)
|
||||
addNote(param.actor, param.placement, param.text)
|
||||
break
|
||||
case 'addMessage':
|
||||
module.exports.addSignal(param.from, param.to, param.msg, param.signalType)
|
||||
addSignal(param.from, param.to, param.msg, param.signalType)
|
||||
break
|
||||
case 'loopStart':
|
||||
module.exports.addSignal(undefined, undefined, param.loopText, param.signalType)
|
||||
addSignal(undefined, undefined, param.loopText, param.signalType)
|
||||
break
|
||||
case 'loopEnd':
|
||||
module.exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
addSignal(undefined, undefined, undefined, param.signalType)
|
||||
break
|
||||
case 'optStart':
|
||||
module.exports.addSignal(undefined, undefined, param.optText, param.signalType)
|
||||
addSignal(undefined, undefined, param.optText, param.signalType)
|
||||
break
|
||||
case 'optEnd':
|
||||
module.exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
addSignal(undefined, undefined, undefined, param.signalType)
|
||||
break
|
||||
case 'altStart':
|
||||
module.exports.addSignal(undefined, undefined, param.altText, param.signalType)
|
||||
addSignal(undefined, undefined, param.altText, param.signalType)
|
||||
break
|
||||
case 'else':
|
||||
module.exports.addSignal(undefined, undefined, param.altText, param.signalType)
|
||||
addSignal(undefined, undefined, param.altText, param.signalType)
|
||||
break
|
||||
case 'altEnd':
|
||||
module.exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
addSignal(undefined, undefined, undefined, param.signalType)
|
||||
break
|
||||
case 'setTitle':
|
||||
module.exports.setTitle(param.text)
|
||||
setTitle(param.text)
|
||||
break
|
||||
case 'parStart':
|
||||
module.exports.addSignal(undefined, undefined, param.parText, param.signalType)
|
||||
addSignal(undefined, undefined, param.parText, param.signalType)
|
||||
break
|
||||
case 'and':
|
||||
module.exports.addSignal(undefined, undefined, param.parText, param.signalType)
|
||||
addSignal(undefined, undefined, param.parText, param.signalType)
|
||||
break
|
||||
case 'parEnd':
|
||||
module.exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
addSignal(undefined, undefined, undefined, param.signalType)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
/* 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
|
||||
|
||||
@ -11,8 +13,8 @@ var d3 = {
|
||||
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
|
||||
})
|
||||
|
||||
@ -26,8 +28,8 @@ function addConf (conf, key, value) {
|
||||
var str
|
||||
describe('when parsing a sequenceDiagram', function () {
|
||||
beforeEach(function () {
|
||||
sq.yy = require('./sequenceDb')
|
||||
sq.yy.clear()
|
||||
parser.yy = sequenceDb
|
||||
parser.yy.clear()
|
||||
})
|
||||
it('it should handle a sequenceDiagram defintion', function () {
|
||||
str = 'sequenceDiagram\n' +
|
||||
@ -35,12 +37,12 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Note right of Bob: Bob thinks\n' +
|
||||
'Bob-->Alice: I am good thanks!'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(3)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -53,13 +55,13 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Note right of Bob: Bob thinks\n' +
|
||||
'Bob-->Alice: I am good thanks!'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var title = sq.yy.getTitle()
|
||||
var messages = parser.yy.getMessages()
|
||||
var title = parser.yy.getTitle()
|
||||
|
||||
expect(messages.length).toBe(3)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -71,12 +73,12 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Alice->Bob:Hello Bob, how are - you?\n' +
|
||||
'Bob-->Alice: I am good thanks!'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(2)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -89,14 +91,14 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'A->B:Hello Bob, how are you?\n' +
|
||||
'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(actors.A.description).toBe('Alice')
|
||||
expect(actors.B.description).toBe('Bob')
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
expect(messages.length).toBe(2)
|
||||
expect(messages[0].from).toBe('A')
|
||||
expect(messages[1].from).toBe('B')
|
||||
@ -105,57 +107,57 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'Alice-xBob:Hello Bob, how are you?'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
expect(actors.Bob.description).toBe('Bob')
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
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 () {
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'Alice--xBob:Hello Bob, how are you?'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
expect(actors.Bob.description).toBe('Bob')
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
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 () {
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'Alice->>Bob:Hello Bob, how are you?'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
expect(actors.Bob.description).toBe('Bob')
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
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 () {
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'Alice-->>Bob:Hello Bob, how are you?'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
expect(actors.Bob.description).toBe('Bob')
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
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 () {
|
||||
var str = 'sequenceDiagram\n' +
|
||||
@ -164,19 +166,19 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Bob-->>Alice:Hello Alice, I\'m fine and you?\n' +
|
||||
'deactivate Bob'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
expect(actors.Bob.description).toBe('Bob')
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(4)
|
||||
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED)
|
||||
expect(messages[1].type).toBe(sq.yy.LINETYPE.ACTIVE_START)
|
||||
expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED)
|
||||
expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
|
||||
expect(messages[1].from.actor).toBe('Bob')
|
||||
expect(messages[2].type).toBe(sq.yy.LINETYPE.DOTTED)
|
||||
expect(messages[3].type).toBe(sq.yy.LINETYPE.ACTIVE_END)
|
||||
expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED)
|
||||
expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_END)
|
||||
expect(messages[3].from.actor).toBe('Bob')
|
||||
})
|
||||
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' +
|
||||
'Bob-->>- Alice:Hello Alice, I\'m fine and you?'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
expect(actors.Bob.description).toBe('Bob')
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(4)
|
||||
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED)
|
||||
expect(messages[1].type).toBe(sq.yy.LINETYPE.ACTIVE_START)
|
||||
expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED)
|
||||
expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
|
||||
expect(messages[1].from.actor).toBe('Bob')
|
||||
expect(messages[2].type).toBe(sq.yy.LINETYPE.DOTTED)
|
||||
expect(messages[3].type).toBe(sq.yy.LINETYPE.ACTIVE_END)
|
||||
expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED)
|
||||
expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_END)
|
||||
expect(messages[3].from.actor).toBe('Bob')
|
||||
})
|
||||
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' +
|
||||
'Carol->>- Bob:Oh Bob, I\'m so happy to be here!'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
expect(actors.Bob.description).toBe('Bob')
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(8)
|
||||
expect(messages[0].type).toBe(sq.yy.LINETYPE.DOTTED)
|
||||
expect(messages[1].type).toBe(sq.yy.LINETYPE.ACTIVE_START)
|
||||
expect(messages[0].type).toBe(parser.yy.LINETYPE.DOTTED)
|
||||
expect(messages[1].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
|
||||
expect(messages[1].from.actor).toBe('Bob')
|
||||
expect(messages[2].type).toBe(sq.yy.LINETYPE.DOTTED)
|
||||
expect(messages[3].type).toBe(sq.yy.LINETYPE.ACTIVE_START)
|
||||
expect(messages[2].type).toBe(parser.yy.LINETYPE.DOTTED)
|
||||
expect(messages[3].type).toBe(parser.yy.LINETYPE.ACTIVE_START)
|
||||
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[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')
|
||||
})
|
||||
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' +
|
||||
'Bob-->Alice: I am good thanks!'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(3)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -250,12 +252,12 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Note right of Bob: Bob thinks\n' +
|
||||
'Bob-->Alice: I am good thanks!\n'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(3)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -267,12 +269,12 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Note right of Bob: Bob thinks;' +
|
||||
'Bob-->Alice: I am good thanks!;'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(3)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -285,12 +287,12 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Note right of Bob: Bob thinks\n' +
|
||||
'Bob-->Alice: I am good thanks!'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(3)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -303,12 +305,12 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Note right of Bob: Bob thinks\n' +
|
||||
'Bob-->Alice: I am good thanks!'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(3)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -327,12 +329,12 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
' John->Bob: How about you?\n' +
|
||||
'Bob-->John: Jolly good!'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(8)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -343,9 +345,9 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Alice->Bob: Hello Bob, how are you?\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].to).toBe('Bob')
|
||||
})
|
||||
@ -355,9 +357,9 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Note over Alice,Bob: confusion\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].to).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' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(5)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -392,12 +394,12 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Bob-->Alice: I am good thanks!\n' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(5)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -414,13 +416,13 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Bob-->Alice: Feel sick...\n' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
actors.Bob.description = 'Bob'
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(7)
|
||||
expect(messages[0].from).toBe('Alice')
|
||||
@ -439,13 +441,13 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Bob-->>Alice: It\'s good!\n' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
var actors = sq.yy.getActors()
|
||||
parser.parse(str)
|
||||
var actors = parser.yy.getActors()
|
||||
|
||||
expect(actors.Alice.description).toBe('Alice')
|
||||
expect(actors.Bob.description).toBe('Bob')
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
|
||||
expect(messages.length).toBe(10)
|
||||
expect(messages[0].message).toBe('Parallel one')
|
||||
@ -456,9 +458,9 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'Alice->Bob: -:<>,;# comment'
|
||||
|
||||
sq.parse(str)
|
||||
parser.parse(str)
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
expect(messages[0].message).toBe('-:<>,')
|
||||
})
|
||||
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' +
|
||||
'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('-:<>,')
|
||||
})
|
||||
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' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
parser.parse(str)
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
expect(messages[1].message).toBe('-:<>,')
|
||||
})
|
||||
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' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
parser.parse(str)
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
expect(messages[1].message).toBe('-:<>,')
|
||||
})
|
||||
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' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
parser.parse(str)
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
expect(messages[1].message).toBe('-:<>,')
|
||||
expect(messages[3].message).toBe(',<>:-')
|
||||
})
|
||||
@ -519,9 +521,9 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Bob-->Alice: I am good thanks!\n' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
parser.parse(str)
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
expect(messages[1].message).toBe('-:<>,')
|
||||
expect(messages[3].message).toBe(',<>:-')
|
||||
})
|
||||
@ -532,9 +534,9 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Bob-->Alice: I am good thanks!\n' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
parser.parse(str)
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
expect(messages[1].message).toBe('')
|
||||
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' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
parser.parse(str)
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
expect(messages[1].message).toBe('')
|
||||
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' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
parser.parse(str)
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
expect(messages[1].message).toBe('')
|
||||
expect(messages[2].message).toBe('I am good thanks!')
|
||||
expect(messages[3].message).toBe('')
|
||||
@ -577,9 +579,9 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
'Bob-->Alice: I am good thanks!\n' +
|
||||
'end'
|
||||
|
||||
sq.parse(str)
|
||||
parser.parse(str)
|
||||
|
||||
var messages = sq.yy.getMessages()
|
||||
var messages = parser.yy.getMessages()
|
||||
expect(messages[1].message).toBe('')
|
||||
expect(messages[2].message).toBe('I am good thanks!')
|
||||
expect(messages[3].message).toBe('')
|
||||
@ -590,8 +592,8 @@ describe('when parsing a sequenceDiagram', function () {
|
||||
describe('when checking the bounds in a sequenceDiagram', function () {
|
||||
var conf
|
||||
beforeEach(function () {
|
||||
sq.yy = require('./sequenceDb')
|
||||
sq.yy.clear()
|
||||
parser.yy = sequenceDb
|
||||
parser.yy.clear()
|
||||
conf = {
|
||||
diagramMarginX: 50,
|
||||
diagramMarginY: 10,
|
||||
@ -604,53 +606,53 @@ describe('when checking the bounds in a sequenceDiagram', function () {
|
||||
boxTextMargin: 15,
|
||||
noteMargin: 25
|
||||
}
|
||||
sd.setConf(conf)
|
||||
renderer.setConf(conf)
|
||||
})
|
||||
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.starty).toBe(100)
|
||||
expect(bounds.stopx).toBe(200)
|
||||
expect(bounds.stopy).toBe(200)
|
||||
})
|
||||
it('it should handle an expanding bound', function () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
|
||||
sd.bounds.insert(100, 100, 200, 200)
|
||||
sd.bounds.insert(25, 50, 300, 400)
|
||||
renderer.bounds.insert(100, 100, 200, 200)
|
||||
renderer.bounds.insert(25, 50, 300, 400)
|
||||
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
expect(bounds.startx).toBe(25)
|
||||
expect(bounds.starty).toBe(50)
|
||||
expect(bounds.stopx).toBe(300)
|
||||
expect(bounds.stopy).toBe(400)
|
||||
})
|
||||
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)
|
||||
sd.bounds.insert(25, 50, 300, 400)
|
||||
sd.bounds.insert(125, 150, 150, 200)
|
||||
renderer.bounds.insert(100, 100, 200, 200)
|
||||
renderer.bounds.insert(25, 50, 300, 400)
|
||||
renderer.bounds.insert(125, 150, 150, 200)
|
||||
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
expect(bounds.startx).toBe(25)
|
||||
expect(bounds.starty).toBe(50)
|
||||
expect(bounds.stopx).toBe(300)
|
||||
expect(bounds.stopy).toBe(400)
|
||||
})
|
||||
it('it should handle a loop without expanding the area', function () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
|
||||
sd.bounds.insert(25, 50, 300, 400)
|
||||
sd.bounds.verticalPos = 150
|
||||
sd.bounds.newLoop()
|
||||
sd.bounds.insert(125, 150, 150, 200)
|
||||
renderer.bounds.insert(25, 50, 300, 400)
|
||||
renderer.bounds.verticalPos = 150
|
||||
renderer.bounds.newLoop()
|
||||
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.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)
|
||||
|
||||
// Check bounds of first loop
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
|
||||
expect(bounds.startx).toBe(25)
|
||||
expect(bounds.starty).toBe(50)
|
||||
@ -666,16 +668,16 @@ describe('when checking the bounds in a sequenceDiagram', function () {
|
||||
expect(bounds.stopy).toBe(400)
|
||||
})
|
||||
it('it should handle multiple loops withtout expanding the bounds', function () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
|
||||
sd.bounds.insert(100, 100, 1000, 1000)
|
||||
sd.bounds.verticalPos = 200
|
||||
sd.bounds.newLoop()
|
||||
sd.bounds.newLoop()
|
||||
sd.bounds.insert(200, 200, 300, 300)
|
||||
renderer.bounds.insert(100, 100, 1000, 1000)
|
||||
renderer.bounds.verticalPos = 200
|
||||
renderer.bounds.newLoop()
|
||||
renderer.bounds.newLoop()
|
||||
renderer.bounds.insert(200, 200, 300, 300)
|
||||
|
||||
// Check bounds of first loop
|
||||
var loop = sd.bounds.endLoop()
|
||||
var loop = renderer.bounds.endLoop()
|
||||
|
||||
expect(loop.startx).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)
|
||||
|
||||
// Check bounds of second loop
|
||||
loop = sd.bounds.endLoop()
|
||||
loop = renderer.bounds.endLoop()
|
||||
|
||||
expect(loop.startx).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)
|
||||
|
||||
// Check bounds of first loop
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
|
||||
expect(bounds.startx).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)
|
||||
})
|
||||
it('it should handle a loop that expands the area', function () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
|
||||
sd.bounds.insert(100, 100, 200, 200)
|
||||
sd.bounds.verticalPos = 200
|
||||
sd.bounds.newLoop()
|
||||
sd.bounds.insert(50, 50, 300, 300)
|
||||
renderer.bounds.insert(100, 100, 200, 200)
|
||||
renderer.bounds.verticalPos = 200
|
||||
renderer.bounds.newLoop()
|
||||
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.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)
|
||||
|
||||
// Check bounds after the loop
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
|
||||
expect(bounds.startx).toBe(loop.startx)
|
||||
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 () {
|
||||
var conf
|
||||
beforeEach(function () {
|
||||
sq.yy = require('./sequenceDb')
|
||||
sq.yy.clear()
|
||||
parser.yy = sequenceDb
|
||||
parser.yy.clear()
|
||||
|
||||
delete global.mermaid_config
|
||||
|
||||
@ -773,19 +775,19 @@ describe('when rendering a sequenceDiagram', function () {
|
||||
boxTextMargin: 15,
|
||||
noteMargin: 25
|
||||
}
|
||||
sd.setConf(conf)
|
||||
renderer.setConf(conf)
|
||||
});
|
||||
['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) {
|
||||
it('it should handle one actor, when textPlacement is ' + textPlacement, function () {
|
||||
sd.setConf(addConf(conf, 'textPlacement', textPlacement))
|
||||
sd.bounds.init()
|
||||
renderer.setConf(addConf(conf, 'textPlacement', textPlacement))
|
||||
renderer.bounds.init()
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'participant Alice'
|
||||
|
||||
sq.parse(str)
|
||||
sd.draw(str, 'tst')
|
||||
parser.parse(str)
|
||||
renderer.draw(str, 'tst')
|
||||
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
expect(bounds.startx).toBe(0)
|
||||
expect(bounds.starty).toBe(0)
|
||||
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 () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'participant Alice\n' +
|
||||
'Note over Alice: Alice thinks\n'
|
||||
|
||||
sq.parse(str)
|
||||
sd.draw(str, 'tst')
|
||||
parser.parse(str)
|
||||
renderer.draw(str, 'tst')
|
||||
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
expect(bounds.startx).toBe(0)
|
||||
expect(bounds.starty).toBe(0)
|
||||
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)
|
||||
})
|
||||
it('it should handle one actor and a note to the left', function () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'participant Alice\n' +
|
||||
'Note left of Alice: Alice thinks'
|
||||
|
||||
sq.parse(str)
|
||||
sd.draw(str, 'tst')
|
||||
parser.parse(str)
|
||||
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.starty).toBe(0)
|
||||
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)
|
||||
})
|
||||
it('it should handle one actor and a note to the right', function () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'participant Alice\n' +
|
||||
'Note right of Alice: Alice thinks'
|
||||
|
||||
sq.parse(str)
|
||||
sd.draw(str, 'tst')
|
||||
parser.parse(str)
|
||||
renderer.draw(str, 'tst')
|
||||
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
expect(bounds.startx).toBe(0)
|
||||
expect(bounds.starty).toBe(0)
|
||||
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)
|
||||
})
|
||||
it('it should handle two actors', function () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'Alice->Bob: Hello Bob, how are you?'
|
||||
|
||||
sq.parse(str)
|
||||
sd.draw(str, 'tst')
|
||||
parser.parse(str)
|
||||
renderer.draw(str, 'tst')
|
||||
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
expect(bounds.startx).toBe(0)
|
||||
expect(bounds.starty).toBe(0)
|
||||
expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin)
|
||||
expect(bounds.stopy).toBe(0 + conf.messageMargin + conf.height)
|
||||
})
|
||||
it('it should handle two actors and two centered shared notes', function () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'Alice->Bob: Hello Bob, how are you?\n' +
|
||||
'Note over Alice,Bob: Looks\n' +
|
||||
'Note over Bob,Alice: Looks back\n'
|
||||
|
||||
sq.parse(str)
|
||||
sd.draw(str, 'tst')
|
||||
parser.parse(str)
|
||||
renderer.draw(str, 'tst')
|
||||
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
expect(bounds.startx).toBe(0)
|
||||
expect(bounds.starty).toBe(0)
|
||||
expect(bounds.stopx).toBe(conf.width * 2 + conf.actorMargin)
|
||||
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 () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'Alice->Bob: Hello Bob, how are you?\n' +
|
||||
'Bob->Alice: Fine!'
|
||||
|
||||
sq.parse(str)
|
||||
sd.draw(str, 'tst')
|
||||
parser.parse(str)
|
||||
renderer.draw(str, 'tst')
|
||||
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
expect(bounds.startx).toBe(0)
|
||||
expect(bounds.starty).toBe(0)
|
||||
expect(bounds.stopx).toBe(0 + conf.width * 2 + conf.actorMargin)
|
||||
expect(bounds.stopy).toBe(0 + 2 * conf.messageMargin + conf.height)
|
||||
})
|
||||
it('it should draw two actors notes to the right', function () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'Alice->Bob: Hello Bob, how are you?\n' +
|
||||
'Note right of Bob: Bob thinks\n' +
|
||||
'Bob->Alice: Fine!'
|
||||
|
||||
sq.parse(str)
|
||||
sd.draw(str, 'tst')
|
||||
parser.parse(str)
|
||||
renderer.draw(str, 'tst')
|
||||
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
expect(bounds.startx).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)
|
||||
})
|
||||
it('it should draw two actors notes to the left', function () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'Alice->Bob: Hello Bob, how are you?\n' +
|
||||
'Note left of Alice: Bob thinks\n' +
|
||||
'Bob->Alice: Fine!'
|
||||
|
||||
sq.parse(str)
|
||||
sd.draw(str, 'tst')
|
||||
parser.parse(str)
|
||||
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.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)
|
||||
})
|
||||
it('it should draw two loops', function () {
|
||||
sd.bounds.init()
|
||||
renderer.bounds.init()
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'Alice->Bob: Hello Bob, how are you?\n' +
|
||||
'loop Cheers\n' +
|
||||
'Bob->Alice: Fine!\n' +
|
||||
'end'
|
||||
sq.parse(str)
|
||||
sd.draw(str, 'tst')
|
||||
parser.parse(str)
|
||||
renderer.draw(str, 'tst')
|
||||
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
expect(bounds.startx).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 () {
|
||||
var conf
|
||||
beforeEach(function () {
|
||||
sq.yy = require('./sequenceDb')
|
||||
sq.yy.clear()
|
||||
parser.yy = sequenceDb
|
||||
parser.yy.clear()
|
||||
|
||||
NewD3 = function () {
|
||||
var o = {
|
||||
@ -992,19 +994,19 @@ describe('when rendering a sequenceDiagram with actor mirror activated', functio
|
||||
// Prolongs the edge of the diagram downwards
|
||||
bottomMarginAdj: 1
|
||||
}
|
||||
sd.setConf(conf)
|
||||
renderer.setConf(conf)
|
||||
});
|
||||
['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) {
|
||||
it('it should handle one actor, when textPlacement is' + textPlacement, function () {
|
||||
sd.setConf(addConf(conf, 'textPlacement', textPlacement))
|
||||
sd.bounds.init()
|
||||
renderer.setConf(addConf(conf, 'textPlacement', textPlacement))
|
||||
renderer.bounds.init()
|
||||
var str = 'sequenceDiagram\n' +
|
||||
'participant Alice'
|
||||
|
||||
sq.parse(str)
|
||||
sd.draw(str, 'tst')
|
||||
parser.parse(str)
|
||||
renderer.draw(str, 'tst')
|
||||
|
||||
var bounds = sd.bounds.getBounds()
|
||||
var bounds = renderer.bounds.getBounds()
|
||||
expect(bounds.startx).toBe(0)
|
||||
expect(bounds.starty).toBe(0)
|
||||
expect(bounds.stopx).toBe(conf.width)
|
||||
|
@ -1,9 +1,10 @@
|
||||
import svgDraw from './svgDraw'
|
||||
import { logger } from '../../logger'
|
||||
import d3 from '../../d3'
|
||||
import { parser } from './parser/sequenceDiagram'
|
||||
import sequenceDb from './sequenceDb'
|
||||
|
||||
var sq = require('./parser/sequenceDiagram').parser
|
||||
sq.yy = require('./sequenceDb')
|
||||
parser.yy = sequenceDb
|
||||
|
||||
var conf = {
|
||||
|
||||
@ -34,7 +35,7 @@ var conf = {
|
||||
textPlacement: 'tspan'
|
||||
}
|
||||
|
||||
module.exports.bounds = {
|
||||
export const bounds = {
|
||||
data: {
|
||||
startx: undefined,
|
||||
stopx: undefined,
|
||||
@ -75,15 +76,15 @@ module.exports.bounds = {
|
||||
_self.updateVal(item, 'starty', starty - n * conf.boxMargin, Math.min)
|
||||
_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(module.exports.bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max)
|
||||
_self.updateVal(bounds.data, 'startx', startx - n * conf.boxMargin, Math.min)
|
||||
_self.updateVal(bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max)
|
||||
|
||||
if (!(type === 'activation')) {
|
||||
_self.updateVal(item, 'startx', startx - n * conf.boxMargin, Math.min)
|
||||
_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(module.exports.bounds.data, 'stopy', stopy + n * conf.boxMargin, Math.max)
|
||||
_self.updateVal(bounds.data, 'starty', starty - n * conf.boxMargin, Math.min)
|
||||
_self.updateVal(bounds.data, 'stopy', stopy + n * conf.boxMargin, Math.max)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,15 +100,15 @@ module.exports.bounds = {
|
||||
_starty = Math.min(starty, stopy)
|
||||
_stopy = Math.max(starty, stopy)
|
||||
|
||||
this.updateVal(module.exports.bounds.data, 'startx', _startx, Math.min)
|
||||
this.updateVal(module.exports.bounds.data, 'starty', _starty, Math.min)
|
||||
this.updateVal(module.exports.bounds.data, 'stopx', _stopx, Math.max)
|
||||
this.updateVal(module.exports.bounds.data, 'stopy', _stopy, Math.max)
|
||||
this.updateVal(bounds.data, 'startx', _startx, Math.min)
|
||||
this.updateVal(bounds.data, 'starty', _starty, Math.min)
|
||||
this.updateVal(bounds.data, 'stopx', _stopx, Math.max)
|
||||
this.updateVal(bounds.data, 'stopy', _stopy, Math.max)
|
||||
|
||||
this.updateBounds(_startx, _starty, _stopx, _stopy)
|
||||
},
|
||||
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 x = actorRect.x + conf.width / 2 + (stackedSize - 1) * conf.activationWidth / 2
|
||||
this.activations.push({
|
||||
@ -138,7 +139,7 @@ module.exports.bounds = {
|
||||
var loop = this.sequenceItems.pop()
|
||||
loop.sections = loop.sections || []
|
||||
loop.sectionTitles = loop.sectionTitles || []
|
||||
loop.sections.push(module.exports.bounds.getVerticalPos())
|
||||
loop.sections.push(bounds.getVerticalPos())
|
||||
loop.sectionTitles.push(message)
|
||||
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)
|
||||
textHeight = textElem[0][0].getBBox().height
|
||||
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 {
|
||||
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)
|
||||
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) + ',' +
|
||||
(verticalPos + 30) + ' ' + startx + ',' + (verticalPos + 20))
|
||||
|
||||
module.exports.bounds.bumpVerticalPos(30)
|
||||
bounds.bumpVerticalPos(30)
|
||||
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 {
|
||||
line = g.append('line')
|
||||
line.attr('x1', startx)
|
||||
line.attr('y1', verticalPos)
|
||||
line.attr('x2', stopx)
|
||||
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
|
||||
// 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.attr('class', 'messageLine1')
|
||||
} else {
|
||||
@ -262,16 +263,16 @@ var drawMessage = function (elem, startx, stopx, verticalPos, msg) {
|
||||
line.attr('stroke-width', 2)
|
||||
line.attr('stroke', 'black')
|
||||
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)')
|
||||
}
|
||||
|
||||
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)')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.drawActors = function (diagram, actors, actorKeys, verticalPos) {
|
||||
export const drawActors = function (diagram, actors, actorKeys, verticalPos) {
|
||||
var i
|
||||
// Draw the actors
|
||||
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
|
||||
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
|
||||
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)
|
||||
|
||||
keys.forEach(function (key) {
|
||||
@ -301,14 +302,14 @@ module.exports.setConf = function (cnf) {
|
||||
}
|
||||
|
||||
var actorActivations = function (actor) {
|
||||
return module.exports.bounds.activations.filter(function (activation) {
|
||||
return bounds.activations.filter(function (activation) {
|
||||
return activation.actor === actor
|
||||
})
|
||||
}
|
||||
|
||||
var actorFlowVerticaBounds = function (actor) {
|
||||
// handle multiple stacked activations for same actor
|
||||
var actors = sq.yy.getActors()
|
||||
var actors = parser.yy.getActors()
|
||||
var activations = actorActivations(actor)
|
||||
|
||||
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 id
|
||||
*/
|
||||
module.exports.draw = function (text, id) {
|
||||
sq.yy.clear()
|
||||
sq.parse(text + '\n')
|
||||
export const draw = function (text, id) {
|
||||
parser.yy.clear()
|
||||
parser.parse(text + '\n')
|
||||
|
||||
module.exports.bounds.init()
|
||||
bounds.init()
|
||||
var diagram = d3.select('#' + id)
|
||||
|
||||
var startx
|
||||
@ -333,25 +334,25 @@ module.exports.draw = function (text, id) {
|
||||
var forceWidth
|
||||
|
||||
// Fetch data from the parsing
|
||||
var actors = sq.yy.getActors()
|
||||
var actorKeys = sq.yy.getActorKeys()
|
||||
var messages = sq.yy.getMessages()
|
||||
var title = sq.yy.getTitle()
|
||||
module.exports.drawActors(diagram, actors, actorKeys, 0)
|
||||
var actors = parser.yy.getActors()
|
||||
var actorKeys = parser.yy.getActorKeys()
|
||||
var messages = parser.yy.getMessages()
|
||||
var title = parser.yy.getTitle()
|
||||
drawActors(diagram, actors, actorKeys, 0)
|
||||
|
||||
// The arrow head definition is attached to the svg once
|
||||
svgDraw.insertArrowHead(diagram)
|
||||
svgDraw.insertArrowCrossHead(diagram)
|
||||
|
||||
function activeEnd (msg, verticalPos) {
|
||||
var activationData = module.exports.bounds.endActivation(msg)
|
||||
var activationData = bounds.endActivation(msg)
|
||||
if (activationData.starty + 18 > verticalPos) {
|
||||
activationData.starty = verticalPos - 6
|
||||
verticalPos += 12
|
||||
}
|
||||
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
|
||||
@ -361,89 +362,89 @@ module.exports.draw = function (text, id) {
|
||||
var loopData
|
||||
|
||||
switch (msg.type) {
|
||||
case sq.yy.LINETYPE.NOTE:
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
case parser.yy.LINETYPE.NOTE:
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
|
||||
startx = actors[msg.from].x
|
||||
stopx = actors[msg.to].x
|
||||
|
||||
if (msg.placement === sq.yy.PLACEMENT.RIGHTOF) {
|
||||
drawNote(diagram, startx + (conf.width + conf.actorMargin) / 2, module.exports.bounds.getVerticalPos(), msg)
|
||||
} else if (msg.placement === sq.yy.PLACEMENT.LEFTOF) {
|
||||
drawNote(diagram, startx - (conf.width + conf.actorMargin) / 2, module.exports.bounds.getVerticalPos(), msg)
|
||||
if (msg.placement === parser.yy.PLACEMENT.RIGHTOF) {
|
||||
drawNote(diagram, startx + (conf.width + conf.actorMargin) / 2, bounds.getVerticalPos(), msg)
|
||||
} else if (msg.placement === parser.yy.PLACEMENT.LEFTOF) {
|
||||
drawNote(diagram, startx - (conf.width + conf.actorMargin) / 2, bounds.getVerticalPos(), msg)
|
||||
} else if (msg.to === msg.from) {
|
||||
// Single-actor over
|
||||
drawNote(diagram, startx, module.exports.bounds.getVerticalPos(), msg)
|
||||
drawNote(diagram, startx, bounds.getVerticalPos(), msg)
|
||||
} else {
|
||||
// Multi-actor over
|
||||
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)
|
||||
}
|
||||
break
|
||||
case sq.yy.LINETYPE.ACTIVE_START:
|
||||
module.exports.bounds.newActivation(msg, diagram)
|
||||
case parser.yy.LINETYPE.ACTIVE_START:
|
||||
bounds.newActivation(msg, diagram)
|
||||
break
|
||||
case sq.yy.LINETYPE.ACTIVE_END:
|
||||
activeEnd(msg, module.exports.bounds.getVerticalPos())
|
||||
case parser.yy.LINETYPE.ACTIVE_END:
|
||||
activeEnd(msg, bounds.getVerticalPos())
|
||||
break
|
||||
case sq.yy.LINETYPE.LOOP_START:
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.newLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
case parser.yy.LINETYPE.LOOP_START:
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
bounds.newLoop(msg.message)
|
||||
bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.LOOP_END:
|
||||
loopData = module.exports.bounds.endLoop()
|
||||
case parser.yy.LINETYPE.LOOP_END:
|
||||
loopData = bounds.endLoop()
|
||||
|
||||
svgDraw.drawLoop(diagram, loopData, 'loop', conf)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.OPT_START:
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.newLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
case parser.yy.LINETYPE.OPT_START:
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
bounds.newLoop(msg.message)
|
||||
bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.OPT_END:
|
||||
loopData = module.exports.bounds.endLoop()
|
||||
case parser.yy.LINETYPE.OPT_END:
|
||||
loopData = bounds.endLoop()
|
||||
|
||||
svgDraw.drawLoop(diagram, loopData, 'opt', conf)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.ALT_START:
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.newLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
case parser.yy.LINETYPE.ALT_START:
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
bounds.newLoop(msg.message)
|
||||
bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.ALT_ELSE:
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
loopData = module.exports.bounds.addSectionToLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
case parser.yy.LINETYPE.ALT_ELSE:
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
loopData = bounds.addSectionToLoop(msg.message)
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.ALT_END:
|
||||
loopData = module.exports.bounds.endLoop()
|
||||
case parser.yy.LINETYPE.ALT_END:
|
||||
loopData = bounds.endLoop()
|
||||
|
||||
svgDraw.drawLoop(diagram, loopData, 'alt', conf)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.PAR_START:
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.newLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
case parser.yy.LINETYPE.PAR_START:
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
bounds.newLoop(msg.message)
|
||||
bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.PAR_AND:
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
loopData = module.exports.bounds.addSectionToLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
case parser.yy.LINETYPE.PAR_AND:
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
loopData = bounds.addSectionToLoop(msg.message)
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.PAR_END:
|
||||
loopData = module.exports.bounds.endLoop()
|
||||
case parser.yy.LINETYPE.PAR_END:
|
||||
loopData = bounds.endLoop()
|
||||
svgDraw.drawLoop(diagram, loopData, 'par', conf)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
default:
|
||||
try {
|
||||
// lastMsg = msg
|
||||
module.exports.bounds.bumpVerticalPos(conf.messageMargin)
|
||||
bounds.bumpVerticalPos(conf.messageMargin)
|
||||
var fromBounds = actorFlowVerticaBounds(msg.from)
|
||||
var toBounds = actorFlowVerticaBounds(msg.to)
|
||||
var fromIdx = fromBounds[0] <= toBounds[0] ? 1 : 0
|
||||
@ -451,10 +452,10 @@ module.exports.draw = function (text, id) {
|
||||
startx = fromBounds[fromIdx]
|
||||
stopx = toBounds[toIdx]
|
||||
|
||||
var verticalPos = module.exports.bounds.getVerticalPos()
|
||||
var verticalPos = bounds.getVerticalPos()
|
||||
drawMessage(diagram, startx, stopx, verticalPos, msg)
|
||||
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) {
|
||||
console.error('error while drawing message', e)
|
||||
}
|
||||
@ -463,11 +464,11 @@ module.exports.draw = function (text, id) {
|
||||
|
||||
if (conf.mirrorActors) {
|
||||
// Draw actors below diagram
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin * 2)
|
||||
module.exports.drawActors(diagram, actors, actorKeys, module.exports.bounds.getVerticalPos())
|
||||
bounds.bumpVerticalPos(conf.boxMargin * 2)
|
||||
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
|
||||
logger.debug('For line height fix Querying: #' + id + ' .actor-line')
|
||||
|
@ -1,4 +1,4 @@
|
||||
module.exports.drawRect = function (elem, rectData) {
|
||||
export const drawRect = function (elem, rectData) {
|
||||
var rectElem = elem.append('rect')
|
||||
rectElem.attr('x', rectData.x)
|
||||
rectElem.attr('y', rectData.y)
|
||||
@ -16,7 +16,7 @@ module.exports.drawRect = function (elem, rectData) {
|
||||
return rectElem
|
||||
}
|
||||
|
||||
module.exports.drawText = function (elem, textData, width) {
|
||||
export const drawText = function (elem, textData, width) {
|
||||
// Remove and ignore br:s
|
||||
var nText = textData.text.replace(/<br\/?>/ig, ' ')
|
||||
|
||||
@ -45,7 +45,7 @@ module.exports.drawText = function (elem, textData, width) {
|
||||
return textElem
|
||||
}
|
||||
|
||||
module.exports.drawLabel = function (elem, txtObject) {
|
||||
export const drawLabel = function (elem, txtObject) {
|
||||
function genPoints (x, y, width, height, cut) {
|
||||
return x + ',' + y + ' ' +
|
||||
(x + width) + ',' + y + ' ' +
|
||||
@ -59,7 +59,7 @@ module.exports.drawLabel = function (elem, txtObject) {
|
||||
|
||||
txtObject.y = txtObject.y + txtObject.labelMargin
|
||||
txtObject.x = txtObject.x + 0.5 * txtObject.labelMargin
|
||||
module.exports.drawText(elem, txtObject)
|
||||
drawText(elem, txtObject)
|
||||
}
|
||||
var actorCnt = -1
|
||||
/**
|
||||
@ -68,7 +68,7 @@ var actorCnt = -1
|
||||
* @param pos The position if the actor in the liost of actors
|
||||
* @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 g = elem.append('g')
|
||||
if (verticalPos === 0) {
|
||||
@ -84,7 +84,7 @@ module.exports.drawActor = function (elem, left, verticalPos, description, conf)
|
||||
.attr('stroke', '#999')
|
||||
}
|
||||
|
||||
var rect = module.exports.getNoteRect()
|
||||
var rect = getNoteRect()
|
||||
rect.x = left
|
||||
rect.y = verticalPos
|
||||
rect.fill = '#eaeaea'
|
||||
@ -93,13 +93,13 @@ module.exports.drawActor = function (elem, left, verticalPos, description, conf)
|
||||
rect.class = 'actor'
|
||||
rect.rx = 3
|
||||
rect.ry = 3
|
||||
module.exports.drawRect(g, rect)
|
||||
drawRect(g, rect)
|
||||
|
||||
_drawTextCandidateFunc(conf)(description, g,
|
||||
rect.x, rect.y, rect.width, rect.height, { 'class': 'actor' })
|
||||
}
|
||||
|
||||
module.exports.anchorElement = function (elem) {
|
||||
export const anchorElement = function (elem) {
|
||||
return elem.append('g')
|
||||
}
|
||||
/**
|
||||
@ -108,15 +108,15 @@ module.exports.anchorElement = function (elem) {
|
||||
* @param bounds - activation box bounds
|
||||
* @param verticalPos - precise y cooridnate of bottom activation box edge
|
||||
*/
|
||||
module.exports.drawActivation = function (elem, bounds, verticalPos) {
|
||||
var rect = module.exports.getNoteRect()
|
||||
export const drawActivation = function (elem, bounds, verticalPos) {
|
||||
var rect = getNoteRect()
|
||||
var g = bounds.anchored
|
||||
rect.x = bounds.startx
|
||||
rect.y = bounds.starty
|
||||
rect.fill = '#f4f4f4'
|
||||
rect.width = bounds.stopx - bounds.startx
|
||||
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 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 drawLoopLine = function (startx, starty, stopx, stopy) {
|
||||
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.x = bounds.startx
|
||||
txt.y = bounds.starty
|
||||
txt.labelMargin = 1.5 * 10 // This is the small box that says "loop"
|
||||
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.x = bounds.startx + (bounds.stopx - bounds.startx) / 2
|
||||
txt.y = bounds.starty + 1.5 * conf.boxMargin
|
||||
txt.anchor = 'middle'
|
||||
txt.class = 'loopText'
|
||||
|
||||
module.exports.drawText(g, txt)
|
||||
drawText(g, txt)
|
||||
|
||||
if (typeof bounds.sectionTitles !== 'undefined') {
|
||||
bounds.sectionTitles.forEach(function (item, idx) {
|
||||
if (item !== '') {
|
||||
txt.text = '[ ' + item + ' ]'
|
||||
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.
|
||||
*/
|
||||
module.exports.insertArrowHead = function (elem) {
|
||||
export const insertArrowHead = function (elem) {
|
||||
elem.append('defs').append('marker')
|
||||
.attr('id', 'arrowhead')
|
||||
.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.
|
||||
*/
|
||||
module.exports.insertArrowCrossHead = function (elem) {
|
||||
export const insertArrowCrossHead = function (elem) {
|
||||
var defs = elem.append('defs')
|
||||
var marker = defs.append('marker')
|
||||
.attr('id', 'crosshead')
|
||||
@ -219,7 +219,7 @@ module.exports.insertArrowCrossHead = function (elem) {
|
||||
// this is actual shape for arrowhead
|
||||
}
|
||||
|
||||
module.exports.getTextObj = function () {
|
||||
export const getTextObj = function () {
|
||||
var txt = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
@ -235,7 +235,7 @@ module.exports.getTextObj = function () {
|
||||
return txt
|
||||
}
|
||||
|
||||
module.exports.getNoteRect = function () {
|
||||
export const getNoteRect = function () {
|
||||
var rect = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
|
@ -6,6 +6,7 @@ import he from 'he'
|
||||
|
||||
import mermaidAPI from './mermaidAPI'
|
||||
import { logger } from './logger'
|
||||
import pkg from '../package.json'
|
||||
|
||||
var nextId = 0
|
||||
|
||||
@ -110,7 +111,7 @@ var init = function () {
|
||||
}
|
||||
|
||||
const version = function () {
|
||||
return 'v' + require('../package.json').version
|
||||
return 'v' + pkg.version
|
||||
}
|
||||
|
||||
const initialize = function (config) {
|
||||
|
@ -1,5 +1,8 @@
|
||||
/* eslint-env jasmine */
|
||||
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 detecting chart type ', function () {
|
||||
@ -48,19 +51,15 @@ describe('when using mermaid and ', 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 () {
|
||||
global.mermaid_config = { startOnLoad: false }
|
||||
flow.parser.yy = graph
|
||||
graph.clear()
|
||||
flowParser.parser.yy = graphDb
|
||||
graphDb.clear()
|
||||
})
|
||||
it('it should handle edges with text', function () {
|
||||
flow.parser.parse('graph TD;A-->|text ex|B;')
|
||||
flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
flowParser.parser.parse('graph TD;A-->|text ex|B;')
|
||||
flowParser.parser.yy.getVertices()
|
||||
var edges = flowParser.parser.yy.getEdges()
|
||||
|
||||
var mockG = {
|
||||
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 () {
|
||||
flow.parser.parse('graph TD;A-->B;')
|
||||
flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
flowParser.parser.parse('graph TD;A-->B;')
|
||||
flowParser.parser.yy.getVertices()
|
||||
var edges = flowParser.parser.yy.getEdges()
|
||||
|
||||
var mockG = {
|
||||
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 () {
|
||||
flow.parser.parse('graph TD;A---B;')
|
||||
flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
flowParser.parser.parse('graph TD;A---B;')
|
||||
flowParser.parser.yy.getVertices()
|
||||
var edges = flowParser.parser.yy.getEdges()
|
||||
|
||||
var mockG = {
|
||||
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 () {
|
||||
flow.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;')
|
||||
flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
flowParser.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;')
|
||||
flowParser.parser.yy.getVertices()
|
||||
var edges = flowParser.parser.yy.getEdges()
|
||||
|
||||
var mockG = {
|
||||
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 () {
|
||||
flow.parser.parse('graph TD;A---B; linkStyle 0 interpolate basis')
|
||||
flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
flowParser.parser.parse('graph TD;A---B; linkStyle 0 interpolate basis')
|
||||
flowParser.parser.yy.getVertices()
|
||||
var edges = flowParser.parser.yy.getEdges()
|
||||
|
||||
var mockG = {
|
||||
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 () {
|
||||
flow.parser.parse('graph TD;A---|the text|B; linkStyle 0 stroke:val1,stroke-width:val2;')
|
||||
flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
flowParser.parser.parse('graph TD;A---|the text|B; linkStyle 0 stroke:val1,stroke-width:val2;')
|
||||
flowParser.parser.yy.getVertices()
|
||||
var edges = flowParser.parser.yy.getEdges()
|
||||
|
||||
var mockG = {
|
||||
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 () {
|
||||
flow.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;')
|
||||
flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
flowParser.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;')
|
||||
flowParser.parser.yy.getVertices()
|
||||
var edges = flowParser.parser.yy.getEdges()
|
||||
|
||||
var mockG = {
|
||||
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 () {
|
||||
flow.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2,fill:blue;')
|
||||
flow.parser.yy.getVertices()
|
||||
var edges = flow.parser.yy.getEdges()
|
||||
flowParser.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2,fill:blue;')
|
||||
flowParser.parser.yy.getVertices()
|
||||
var edges = flowParser.parser.yy.getEdges()
|
||||
var mockG = {
|
||||
setEdge: function (start, end, options) {
|
||||
expect(start).toBe('A')
|
||||
@ -186,7 +185,7 @@ describe('when using mermaid and ', function () {
|
||||
}
|
||||
}
|
||||
|
||||
flowRend.addEdges(edges, mockG)
|
||||
flowRenderer.addEdges(edges, mockG)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -33,6 +33,7 @@ import gitGraphParser from './diagrams/gitGraph/parser/gitGraph'
|
||||
import gitGraphRenderer from './diagrams/gitGraph/gitGraphRenderer'
|
||||
import gitGraphAst from './diagrams/gitGraph/gitGraphAst'
|
||||
import d3 from './d3'
|
||||
import pkg from '../package.json'
|
||||
|
||||
/**
|
||||
* ## Configuration
|
||||
@ -288,11 +289,11 @@ function parse (text) {
|
||||
* Function returning version information
|
||||
* @returns {string} A string containing the version info
|
||||
*/
|
||||
module.exports.version = function () {
|
||||
return require('../package.json').version
|
||||
export const version = function () {
|
||||
return pkg.version
|
||||
}
|
||||
|
||||
module.exports.encodeEntities = function (text) {
|
||||
export const encodeEntities = function (text) {
|
||||
var txt = text
|
||||
|
||||
txt = txt.replace(/style.*:\S*#.*;/g, function (s) {
|
||||
@ -318,7 +319,7 @@ module.exports.encodeEntities = function (text) {
|
||||
return txt
|
||||
}
|
||||
|
||||
module.exports.decodeEntities = function (text) {
|
||||
export const decodeEntities = function (text) {
|
||||
var txt = text
|
||||
|
||||
txt = txt.replace(/fl°°/g, function () {
|
||||
@ -383,7 +384,7 @@ var render = function (id, txt, cb, container) {
|
||||
}
|
||||
|
||||
window.txt = txt
|
||||
txt = module.exports.encodeEntities(txt)
|
||||
txt = encodeEntities(txt)
|
||||
|
||||
var element = d3.select('#d' + id).node()
|
||||
var graphType = utils.detectType(txt)
|
||||
@ -438,7 +439,7 @@ var render = function (id, txt, cb, container) {
|
||||
break
|
||||
case 'info':
|
||||
config.info.arrowMarkerAbsolute = config.arrowMarkerAbsolute
|
||||
info.draw(txt, id, module.exports.version())
|
||||
info.draw(txt, id, version())
|
||||
if (config.cloneCssStyles) {
|
||||
utils.cloneCssStyles(element.firstChild, [])
|
||||
}
|
||||
@ -457,7 +458,7 @@ var render = function (id, txt, cb, container) {
|
||||
// Fix for when the base tag is used
|
||||
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') {
|
||||
cb(svgCode, graph.bindFunctions)
|
||||
|
@ -1,13 +1,12 @@
|
||||
/* eslint-env jest */
|
||||
/* eslint-env jasmine */
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import async from 'async'
|
||||
import clone from 'clone'
|
||||
import rimraf from 'rimraf'
|
||||
|
||||
const async = require('async')
|
||||
const clone = require('clone')
|
||||
const rimraf = require('rimraf')
|
||||
|
||||
const mermaid = require('../lib')
|
||||
import mermaidCli from '../lib'
|
||||
|
||||
const fileTestMermaid = path.join('test', 'fixtures', 'test.mermaid')
|
||||
const isWin = /^win/.test(process.platform)
|
||||
@ -53,7 +52,7 @@ test('output of single png', function (done) {
|
||||
opt.outputDir += '_png'
|
||||
opt.png = true
|
||||
|
||||
mermaid.process(opt.files, opt, function (code) {
|
||||
mermaidCli.process(opt.files, opt, function (code) {
|
||||
expect(code).toBe(0)
|
||||
|
||||
verifyFiles(expected, opt.outputDir, done)
|
||||
@ -70,7 +69,7 @@ test('output of multiple png', function (done) {
|
||||
opt.outputDir += '_png'
|
||||
opt.png = true
|
||||
|
||||
mermaid.process(opt.files, opt, function (code) {
|
||||
mermaidCli.process(opt.files, opt, function (code) {
|
||||
expect(code).toBe(0)
|
||||
|
||||
verifyFiles(expected, opt.outputDir, done)
|
||||
@ -86,7 +85,7 @@ test('output of single svg', function (done) {
|
||||
opt.outputDir += '_svg'
|
||||
opt.svg = true
|
||||
|
||||
mermaid.process(opt.files, opt, function (code) {
|
||||
mermaidCli.process(opt.files, opt, function (code) {
|
||||
expect(code).toBe(0)
|
||||
|
||||
verifyFiles(expected, opt.outputDir, done)
|
||||
@ -103,7 +102,7 @@ test('output of multiple svg', function (done) {
|
||||
opt.outputDir += '_svg'
|
||||
opt.svg = true
|
||||
|
||||
mermaid.process(opt.files, opt, function (code) {
|
||||
mermaidCli.process(opt.files, opt, function (code) {
|
||||
expect(code).toBe(0)
|
||||
|
||||
verifyFiles(expected, opt.outputDir, done)
|
||||
@ -122,14 +121,14 @@ test('output including CSS', function (done) {
|
||||
opt2.png = true
|
||||
opt2.outputDir += '_css_png'
|
||||
|
||||
mermaid.process(opt.files, opt, function (code) {
|
||||
mermaidCli.process(opt.files, opt, function (code) {
|
||||
expect(code).toBe(0)
|
||||
const filename = path.join(opt.outputDir, path.basename(expected[0]))
|
||||
const one = fs.statSync(filename)
|
||||
|
||||
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)
|
||||
const two = fs.statSync(filename)
|
||||
expect(one.size).not.toBe(two.size)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* eslint-env jest */
|
||||
/* eslint-env jasmine */
|
||||
const cliPath = '../lib/cli'
|
||||
import cli from '../lib/cli'
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 64000
|
||||
@ -9,7 +9,6 @@ beforeEach(() => {
|
||||
test('parses multiple files', function (done) {
|
||||
expect.assertions(3)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['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) {
|
||||
expect.assertions(3)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid']
|
||||
|
||||
cli.parse(argv, function (err, msg, opt) {
|
||||
@ -40,7 +38,6 @@ test('defaults to png', function (done) {
|
||||
test('setting svg unsets png', function (done) {
|
||||
expect.assertions(3)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid', '-s']
|
||||
|
||||
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) {
|
||||
expect.assertions(3)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid', '-s', '-p']
|
||||
|
||||
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) {
|
||||
expect.assertions(2)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid', '-o', 'example/']
|
||||
|
||||
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) {
|
||||
expect.assertions(2)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid']
|
||||
|
||||
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) {
|
||||
expect.assertions(2)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid', '-t', 'test/fixtures/test.css']
|
||||
|
||||
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) {
|
||||
expect.assertions(1)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['-o']
|
||||
|
||||
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) {
|
||||
expect.assertions(3)
|
||||
|
||||
const cli = require(cliPath)
|
||||
const argv = ['example/file1.mermaid']
|
||||
|
||||
cli.parse(argv, function (err, msg, opts) {
|
||||
|
@ -1,14 +1,13 @@
|
||||
/* eslint-env jest */
|
||||
/* eslint-env jasmine */
|
||||
const exec = require('child_process').exec
|
||||
const path = require('path')
|
||||
|
||||
const rimraf = require('rimraf')
|
||||
import path from 'path'
|
||||
import rimraf from 'rimraf'
|
||||
import { exec } from 'child_process'
|
||||
|
||||
const localSearchPath = './node_modules/.bin' + path.delimiter + process.env.PATH
|
||||
const testDir = 'test/fixtures/samples/'.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.*')
|
||||
|
||||
|
16
test/fixtures/samples/load_html_save_screenshot_png.js
vendored
Normal file
16
test/fixtures/samples/load_html_save_screenshot_png.js
vendored
Normal 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()
|
||||
}
|
@ -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();
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
@ -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>
|
@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "test",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"gulp": "^3.8.10"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT"
|
||||
}
|
@ -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()
|
||||
})
|
@ -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>
|
Loading…
x
Reference in New Issue
Block a user