Comparing version 7.0.11 to 7.0.12
#!/usr/bin/env node | ||
var chalk = require('chalk') | ||
var cli = require('../lib/cli.js') | ||
var lib = require('../lib') | ||
import chalk from 'chalk' | ||
import cli from '../lib/cli' | ||
import lib from '../lib' | ||
cli.parse(process.argv.slice(2), function (err, message, options) { | ||
@@ -8,0 +9,0 @@ if (err) { |
@@ -1,17 +0,16 @@ | ||
var fs = require('fs') | ||
var exec = require('child_process').exec | ||
var chalk = require('chalk') | ||
var which = require('which') | ||
var parseArgs = require('minimist') | ||
var semver = require('semver') | ||
var path = require('path') | ||
import fs from 'fs' | ||
import chalk from 'chalk' | ||
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 PHANTOM_VERSION = '^2.1.0' | ||
import pkg from '../package.json' | ||
var PHANTOM_VERSION = '^2.1.15' | ||
var info = chalk.blue.bold | ||
module.exports = (function () { | ||
return new Cli() | ||
}()) | ||
function Cli (options) { | ||
@@ -65,5 +64,3 @@ this.options = { | ||
var options = parseArgs(argv, this.options) | ||
if (options.version) { | ||
var pkg = require('../package.json') | ||
this.message = '' + pkg.version | ||
@@ -154,6 +151,4 @@ next(null, this.message) | ||
var err | ||
if (typeof phantomPath === 'undefined') { | ||
try { | ||
var phantom = require('phantomjs') | ||
phantomPath = phantom.path | ||
@@ -199,1 +194,7 @@ } catch (e) { | ||
} | ||
const cli = (function () { | ||
return new Cli() | ||
}()) | ||
export default cli |
@@ -1,10 +0,7 @@ | ||
var path = require('path') | ||
var spawn = require('child_process').spawn | ||
import path from 'path' | ||
import mkdirp from 'mkdirp' | ||
import { spawn } from 'child_process' | ||
var mkdirp = require('mkdirp') | ||
var phantomscript = path.join(__dirname, 'phantomscript.js') | ||
module.exports = { process: processMermaid } | ||
function processMermaid (files, _options, _next) { | ||
@@ -44,1 +41,3 @@ var options = _options || {} | ||
} | ||
export default { process: processMermaid } |
@@ -8,2 +8,5 @@ /** | ||
*/ | ||
import system from 'system' | ||
import fs from 'fs' | ||
import webpage from 'webpage' | ||
@@ -28,6 +31,2 @@ window.phantom.onError = function (msg, trace) { | ||
var system = require('system') | ||
var fs = require('fs') | ||
var webpage = require('webpage') | ||
var page = webpage.create() | ||
@@ -34,0 +33,0 @@ var files = system.args.slice(10, system.args.length) |
{ | ||
"name": "mermaid", | ||
"version": "7.0.11", | ||
"version": "7.0.12", | ||
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.", | ||
@@ -25,6 +25,6 @@ "main": "dist/mermaid.core.js", | ||
"karma": "node -r babel-register node_modules/.bin/karma start karma.conf.js --single-run", | ||
"tape": "node -r babel-register node_modules/.bin/tape test/cli_test-*.js", | ||
"test": "yarn lint && yarn tape && yarn karma", | ||
"jest": "jest --coverage --runInBand", | ||
"test": "yarn lint && yarn karma", | ||
"jison": "gulp jison", | ||
"prepublishOnly": "yarn build && yarn test" | ||
"prepublishOnly": "yarn build && yarn release && yarn test" | ||
}, | ||
@@ -73,2 +73,3 @@ "repository": { | ||
"jasmine-es6": "^0.4.1", | ||
"jest": "^21.0.2", | ||
"jison": "^0.4.18", | ||
@@ -85,3 +86,2 @@ "karma": "^1.7.1", | ||
"style-loader": "^0.18.2", | ||
"tape": "^4.8.0", | ||
"webpack": "^3.5.6", | ||
@@ -95,3 +95,6 @@ "webpack-node-externals": "^1.6.0" | ||
"src" | ||
] | ||
], | ||
"jest": { | ||
"testRegex": "test/cli_test-.+?\\.js" | ||
} | ||
} |
@@ -214,7 +214,3 @@ # mermaid | ||
Manual test in Node.js: | ||
node dist/demo/index.js | ||
## Release | ||
@@ -221,0 +217,0 @@ |
@@ -1,5 +0,3 @@ | ||
const d3 = require('d3') | ||
import d3 from 'd3' | ||
module.exports = d3; | ||
/* | ||
@@ -448,1 +446,3 @@ D3 Text Wrap | ||
})() | ||
export default d3 |
var Logger = require('../../logger') | ||
var log = Logger.Log | ||
import { logger } from '../../logger' | ||
var relations = [] | ||
@@ -17,3 +17,3 @@ | ||
*/ | ||
exports.addClass = function (id) { | ||
export const addClass = function (id) { | ||
if (typeof classes[id] === 'undefined') { | ||
@@ -28,3 +28,3 @@ classes[id] = { | ||
exports.clear = function () { | ||
export const clear = function () { | ||
relations = [] | ||
@@ -34,22 +34,21 @@ 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) { | ||
log.warn('Adding relation: ' + JSON.stringify(relation)) | ||
module.exports.addClass(relation.id1) | ||
module.exports.addClass(relation.id2) | ||
export const addRelation = function (relation) { | ||
logger.warn('Adding relation: ' + JSON.stringify(relation)) | ||
addClass(relation.id1) | ||
addClass(relation.id2) | ||
relations.push(relation) | ||
} | ||
exports.addMembers = function (className, MembersArr) { | ||
export const addMembers = function (className, MembersArr) { | ||
var theClass = classes[className] | ||
@@ -65,3 +64,3 @@ if (typeof MembersArr === 'string') { | ||
exports.cleanupLabel = function (label) { | ||
export const cleanupLabel = function (label) { | ||
if (label.substring(0, 1) === ':') { | ||
@@ -74,3 +73,3 @@ return label.substr(2).trim() | ||
exports.lineType = { | ||
export const lineType = { | ||
LINE: 0, | ||
@@ -80,3 +79,3 @@ DOTTED_LINE: 1 | ||
exports.relationType = { | ||
export const relationType = { | ||
AGGREGATION: 0, | ||
@@ -87,1 +86,14 @@ EXTENSION: 1, | ||
} | ||
export default { | ||
addClass, | ||
clear, | ||
getClass, | ||
getClasses, | ||
getRelations, | ||
addRelation, | ||
addMembers, | ||
cleanupLabel, | ||
lineType, | ||
relationType | ||
} |
/* eslint-env jasmine */ | ||
/** | ||
* Created by knut on 14-11-18. | ||
*/ | ||
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 | ||
}) | ||
@@ -22,3 +19,3 @@ | ||
cd.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -33,3 +30,3 @@ it('should handle relation definition of different types and directions', function () { | ||
cd.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -43,3 +40,3 @@ | ||
cd.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -53,3 +50,3 @@ it('should handle class definitions', function () { | ||
cd.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -64,3 +61,3 @@ | ||
cd.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -79,3 +76,3 @@ it('should handle parsing of method statements grouped by brackets', function () { | ||
cd.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -112,3 +109,3 @@ | ||
cd.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -118,8 +115,5 @@ }) | ||
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() | ||
}) | ||
@@ -130,11 +124,11 @@ it('should handle relation definitions EXTENSION', function () { | ||
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) | ||
}) | ||
@@ -145,11 +139,11 @@ it('should handle relation definitions AGGREGATION and dotted line', function () { | ||
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) | ||
}) | ||
@@ -160,11 +154,11 @@ it('should handle relation definitions COMPOSITION on both sides', function () { | ||
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) | ||
}) | ||
@@ -175,11 +169,11 @@ it('should handle relation definitions no types', function () { | ||
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) | ||
}) | ||
@@ -190,11 +184,11 @@ it('should handle relation definitions with type only on right side', function () { | ||
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) | ||
}) | ||
@@ -210,19 +204,19 @@ | ||
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,13 +0,11 @@ | ||
/** | ||
* Created by knut on 14-11-23. | ||
*/ | ||
var cd = require('./parser/classDiagram').parser | ||
var cDDb = require('./classDb') | ||
cd.yy = cDDb | ||
var d3 = require('../../d3') | ||
var Logger = require('../../logger') | ||
var log = Logger.Log | ||
var dagre = require('dagre-layout') | ||
import dagre from 'dagre-layout' | ||
import classDb from './classDb' | ||
import d3 from '../../d3' | ||
import { logger } from '../../logger' | ||
import { parser } from './parser/classDiagram' | ||
parser.yy = classDb | ||
var idCache | ||
@@ -130,9 +128,9 @@ idCache = {} | ||
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' | ||
@@ -212,3 +210,3 @@ } | ||
var drawClass = function (elem, classDef) { | ||
log.info('Rendering class ' + classDef) | ||
logger.info('Rendering class ' + classDef) | ||
@@ -298,3 +296,3 @@ var addTspan = function (textEl, txt, isFirst) { | ||
module.exports.setConf = function (cnf) { | ||
export const setConf = function (cnf) { | ||
var keys = Object.keys(cnf) | ||
@@ -311,7 +309,7 @@ | ||
*/ | ||
module.exports.draw = function (text, id) { | ||
cd.yy.clear() | ||
cd.parse(text) | ||
export const draw = function (text, id) { | ||
parser.yy.clear() | ||
parser.parse(text) | ||
log.info('Rendering diagram ' + text) | ||
logger.info('Rendering diagram ' + text) | ||
@@ -337,3 +335,3 @@ /// / Fetch the default direction, use TD if none was found | ||
var classes = cDDb.getClasses() | ||
var classes = classDb.getClasses() | ||
var keys = Object.keys(classes) | ||
@@ -348,8 +346,8 @@ var i | ||
g.setNode(node.id, node) | ||
log.info('Org height: ' + node.height) | ||
logger.info('Org height: ' + node.height) | ||
} | ||
var relations = cDDb.getRelations() | ||
var relations = classDb.getRelations() | ||
relations.forEach(function (relation) { | ||
log.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation)) | ||
logger.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation)) | ||
g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), { relation: relation }) | ||
@@ -360,3 +358,3 @@ }) | ||
if (typeof v !== 'undefined') { | ||
log.debug('Node ' + v + ': ' + JSON.stringify(g.node(v))) | ||
logger.debug('Node ' + v + ': ' + JSON.stringify(g.node(v))) | ||
d3.select('#' + v).attr('transform', 'translate(' + (g.node(v).x - (g.node(v).width / 2)) + ',' + (g.node(v).y - (g.node(v).height / 2)) + ' )') | ||
@@ -366,3 +364,3 @@ } | ||
g.edges().forEach(function (e) { | ||
log.debug('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(g.edge(e))) | ||
logger.debug('Edge ' + e.v + ' -> ' + e.w + ': ' + JSON.stringify(g.edge(e))) | ||
drawEdge(diagram, g.edge(e), g.edge(e).relation) | ||
@@ -375,1 +373,6 @@ }) | ||
} | ||
export default { | ||
setConf, | ||
draw | ||
} |
/* eslint-env jasmine */ | ||
/** | ||
* Created by knut on 14-11-18. | ||
*/ | ||
describe('class diagram, ', function () { | ||
@@ -7,0 +3,0 @@ describe('when rendering a classDiagram', function () { |
@@ -0,10 +1,8 @@ | ||
import { parser } from './parser/example' | ||
import exampleDb from './exampleDb' | ||
/* eslint-env jasmine */ | ||
/** | ||
* Created by knut on 14-11-18. | ||
*/ | ||
describe('when parsing an info graph it', function () { | ||
var ex | ||
beforeEach(function () { | ||
ex = require('./parser/example').parser | ||
ex.yy = require('./exampleDb') | ||
parser.yy = exampleDb | ||
}) | ||
@@ -15,3 +13,3 @@ | ||
ex.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -21,4 +19,4 @@ it('should handle an showMessage statement definition', function () { | ||
ex.parse(str) | ||
parser.parse(str) | ||
}) | ||
}) |
@@ -1,6 +0,2 @@ | ||
/** | ||
* Created by knut on 15-01-14. | ||
*/ | ||
var Logger = require('../../logger') | ||
var log = Logger.Log | ||
import { logger } from '../../logger' | ||
@@ -10,21 +6,24 @@ var message = '' | ||
exports.setMessage = function (txt) { | ||
log.debug('Setting message to: ' + 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 | ||
} | ||
exports.parseError = function (err, hash) { | ||
global.mermaidAPI.parseError(err, hash) | ||
export default { | ||
setMessage, | ||
getMessage, | ||
setInfo, | ||
getInfo | ||
} |
@@ -1,10 +0,6 @@ | ||
/** | ||
* Created by knut on 14-12-11. | ||
*/ | ||
var db = require('./exampleDb') | ||
var exampleParser = require('./parser/example.js') | ||
var d3 = require('../../d3') | ||
import db from './exampleDb' | ||
import exampleParser from './parser/example.js' | ||
import d3 from '../../d3' | ||
var Logger = require('../../logger') | ||
var log = Logger.Log | ||
import { logger } from '../../logger' | ||
@@ -16,7 +12,7 @@ /** | ||
*/ | ||
exports.draw = function (txt, id, ver) { | ||
export const draw = function (txt, id, ver) { | ||
var parser | ||
parser = exampleParser.parser | ||
parser.yy = db | ||
log.debug('Renering example diagram') | ||
logger.debug('Renering example diagram') | ||
// Parse the graph definition | ||
@@ -41,1 +37,5 @@ parser.parse(txt) | ||
} | ||
export default { | ||
draw | ||
} |
@@ -1,15 +0,11 @@ | ||
/** | ||
* Created by knut on 14-12-11. | ||
*/ | ||
var graph = require('./graphDb') | ||
var flow = require('./parser/flow') | ||
var dot = require('./parser/dot') | ||
var d3 = require('../../d3') | ||
var dagreD3 = require('dagre-d3-renderer') | ||
var Logger = require('../../logger') | ||
var log = Logger.Log | ||
import graphDb from './graphDb' | ||
import flow from './parser/flow' | ||
import dot from './parser/dot' | ||
import d3 from '../../d3' | ||
import dagreD3 from 'dagre-d3-renderer' | ||
import { logger } from '../../logger' | ||
var conf = { | ||
} | ||
module.exports.setConf = function (cnf) { | ||
export const setConf = function (cnf) { | ||
var keys = Object.keys(cnf) | ||
@@ -27,3 +23,3 @@ var i | ||
*/ | ||
module.exports.addVertices = function (vert, g) { | ||
export const addVertices = function (vert, g) { | ||
var keys = Object.keys(vert) | ||
@@ -143,3 +139,3 @@ | ||
*/ | ||
module.exports.addEdges = function (edges, g) { | ||
export const addEdges = function (edges, g) { | ||
var cnt = 0 | ||
@@ -224,5 +220,5 @@ | ||
*/ | ||
module.exports.getClasses = function (text, isDot) { | ||
export const getClasses = function (text, isDot) { | ||
var parser | ||
graph.clear() | ||
graphDb.clear() | ||
if (isDot) { | ||
@@ -233,3 +229,3 @@ parser = dot.parser | ||
} | ||
parser.yy = graph | ||
parser.yy = graphDb | ||
@@ -239,3 +235,3 @@ // Parse the graph definition | ||
var classes = graph.getClasses() | ||
var classes = graphDb.getClasses() | ||
@@ -258,6 +254,6 @@ // Add default class if undefined | ||
*/ | ||
module.exports.draw = function (text, id, isDot) { | ||
log.debug('Drawing flowchart') | ||
export const draw = function (text, id, isDot) { | ||
logger.debug('Drawing flowchart') | ||
var parser | ||
graph.clear() | ||
graphDb.clear() | ||
if (isDot) { | ||
@@ -268,3 +264,3 @@ parser = dot.parser | ||
} | ||
parser.yy = graph | ||
parser.yy = graphDb | ||
@@ -275,3 +271,3 @@ // Parse the graph definition | ||
} catch (err) { | ||
log.debug('Parsing failed') | ||
logger.debug('Parsing failed') | ||
} | ||
@@ -281,3 +277,3 @@ | ||
var dir | ||
dir = graph.getDirection() | ||
dir = graphDb.getDirection() | ||
if (typeof dir === 'undefined') { | ||
@@ -303,13 +299,13 @@ dir = 'TD' | ||
var subG | ||
var subGraphs = graph.getSubGraphs() | ||
var subGraphs = graphDb.getSubGraphs() | ||
var i = 0 | ||
for (i = subGraphs.length - 1; i >= 0; i--) { | ||
subG = subGraphs[i] | ||
graph.addVertex(subG.id, subG.title, 'group', undefined) | ||
graphDb.addVertex(subG.id, subG.title, 'group', undefined) | ||
} | ||
// Fetch the verices/nodes and edges/links from the parsed graph definition | ||
var vert = graph.getVertices() | ||
var vert = graphDb.getVertices() | ||
var edges = graph.getEdges() | ||
var edges = graphDb.getEdges() | ||
@@ -327,4 +323,4 @@ i = 0 | ||
} | ||
module.exports.addVertices(vert, g) | ||
module.exports.addEdges(edges, g) | ||
addVertices(vert, g) | ||
addEdges(edges, g) | ||
@@ -448,3 +444,3 @@ // Create the renderer | ||
.attr('title', function () { | ||
return graph.getTooltip(this.id) | ||
return graphDb.getTooltip(this.id) | ||
}) | ||
@@ -470,3 +466,3 @@ | ||
// Index nodes | ||
graph.indexNodes('subGraph' + i) | ||
graphDb.indexNodes('subGraph' + i) | ||
@@ -521,1 +517,9 @@ for (i = 0; i < subGraphs.length; i++) { | ||
} | ||
export default { | ||
setConf, | ||
addVertices, | ||
addEdges, | ||
getClasses, | ||
draw | ||
} |
@@ -1,9 +0,5 @@ | ||
/** | ||
* Created by knut on 14-11-03. | ||
*/ | ||
var Logger = require('../../logger') | ||
var log = Logger.Log | ||
var utils = require('../../utils') | ||
import { logger } from '../../logger' | ||
import utils from '../../utils' | ||
import d3 from '../../d3' | ||
var d3 = require('../../d3') | ||
var vertices = {} | ||
@@ -25,3 +21,3 @@ var edges = [] | ||
*/ | ||
exports.addVertex = function (id, text, type, style) { | ||
export const addVertex = function (id, text, type, style) { | ||
var txt | ||
@@ -71,4 +67,4 @@ | ||
*/ | ||
exports.addLink = function (start, end, type, linktext) { | ||
log.info('Got edge...', start, end) | ||
export const addLink = function (start, end, type, linktext) { | ||
logger.info('Got edge...', start, end) | ||
var edge = { start: start, end: end, type: undefined, text: '' } | ||
@@ -98,3 +94,3 @@ linktext = type.text | ||
*/ | ||
exports.updateLinkInterpolate = function (pos, interp) { | ||
export const updateLinkInterpolate = function (pos, interp) { | ||
if (pos === 'default') { | ||
@@ -112,3 +108,3 @@ edges.defaultInterpolate = interp | ||
*/ | ||
exports.updateLink = function (pos, style) { | ||
export const updateLink = function (pos, style) { | ||
if (pos === 'default') { | ||
@@ -124,3 +120,3 @@ edges.defaultStyle = style | ||
exports.addClass = function (id, style) { | ||
export const addClass = function (id, style) { | ||
if (typeof classes[id] === 'undefined') { | ||
@@ -143,3 +139,3 @@ classes[id] = { id: id, styles: [] } | ||
*/ | ||
exports.setDirection = function (dir) { | ||
export const setDirection = function (dir) { | ||
direction = dir | ||
@@ -152,3 +148,3 @@ } | ||
*/ | ||
exports.setClass = function (id, className) { | ||
export const setClass = function (id, className) { | ||
if (id.indexOf(',') > 0) { | ||
@@ -204,3 +200,3 @@ id.split(',').forEach(function (id2) { | ||
} | ||
exports.getTooltip = function (id) { | ||
export const getTooltip = function (id) { | ||
return tooltips[id] | ||
@@ -213,3 +209,3 @@ } | ||
*/ | ||
exports.setClickEvent = function (id, functionName, link, tooltip) { | ||
export const setClickEvent = function (id, functionName, link, tooltip) { | ||
if (id.indexOf(',') > 0) { | ||
@@ -228,3 +224,3 @@ id.split(',').forEach(function (id2) { | ||
exports.bindFunctions = function (element) { | ||
export const bindFunctions = function (element) { | ||
funs.forEach(function (fun) { | ||
@@ -234,3 +230,3 @@ fun(element) | ||
} | ||
exports.getDirection = function () { | ||
export const getDirection = function () { | ||
return direction | ||
@@ -242,3 +238,3 @@ } | ||
*/ | ||
exports.getVertices = function () { | ||
export const getVertices = function () { | ||
return vertices | ||
@@ -251,3 +247,3 @@ } | ||
*/ | ||
exports.getEdges = function () { | ||
export const getEdges = function () { | ||
return edges | ||
@@ -260,3 +256,3 @@ } | ||
*/ | ||
exports.getClasses = function () { | ||
export const getClasses = function () { | ||
return classes | ||
@@ -308,3 +304,3 @@ } | ||
*/ | ||
exports.clear = function () { | ||
export const clear = function () { | ||
vertices = {} | ||
@@ -323,3 +319,3 @@ classes = {} | ||
*/ | ||
exports.defaultStyle = function () { | ||
export const defaultStyle = function () { | ||
return 'fill:#ffa;stroke: #f66; stroke-width: 3px; stroke-dasharray: 5, 5;fill:#ffa;stroke: #666;' | ||
@@ -331,3 +327,3 @@ } | ||
*/ | ||
exports.addSubGraph = function (list, title) { | ||
export const addSubGraph = function (list, title) { | ||
function uniq (a) { | ||
@@ -367,3 +363,3 @@ var prims = { 'boolean': {}, 'number': {}, 'string': {} } | ||
var posCrossRef = [] | ||
var indexNodes = function (id, pos) { | ||
var indexNodes2 = function (id, pos) { | ||
var nodes = subGraphs[pos].nodes | ||
@@ -389,3 +385,3 @@ secCount = secCount + 1 | ||
if (childPos >= 0) { | ||
var res = indexNodes(id, childPos) | ||
var res = indexNodes2(id, childPos) | ||
if (res.result) { | ||
@@ -409,18 +405,37 @@ return { | ||
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 | ||
} | ||
exports.parseError = function (err, hash) { | ||
global.mermaidAPI.parseError(err, hash) | ||
export default { | ||
addVertex, | ||
addLink, | ||
updateLinkInterpolate, | ||
updateLink, | ||
addClass, | ||
setDirection, | ||
setClass, | ||
getTooltip, | ||
setClickEvent, | ||
bindFunctions, | ||
getDirection, | ||
getVertices, | ||
getEdges, | ||
getClasses, | ||
clear, | ||
defaultStyle, | ||
addSubGraph, | ||
getDepthFirstPos, | ||
indexNodes, | ||
getSubGraphs | ||
} |
@@ -1,15 +0,8 @@ | ||
/** | ||
* Created by knut on 14-11-03. | ||
*/ | ||
import graphDb from '../graphDb' | ||
import flow from './flow' | ||
var graph = require('../graphDb') | ||
var flow = require('./flow') | ||
describe('when parsing ', function () { | ||
beforeEach(function () { | ||
flow.parser.yy = require('../graphDb') | ||
flow.parser.yy = graphDb | ||
flow.parser.yy.clear() | ||
/* flow.parser.parse.parseError= function parseError(str, hash) { | ||
log.debugconsole.log(str); | ||
} */ | ||
}) | ||
@@ -479,3 +472,3 @@ | ||
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') | ||
@@ -486,7 +479,7 @@ | ||
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"') | ||
@@ -497,7 +490,7 @@ | ||
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"') | ||
@@ -508,6 +501,6 @@ | ||
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"') | ||
@@ -518,3 +511,3 @@ | ||
expect(graph.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', 'tooltip') | ||
expect(graphDb.setClickEvent).toHaveBeenCalledWith('A', undefined, 'click.html', 'tooltip') | ||
}) | ||
@@ -521,0 +514,0 @@ }) |
/* eslint-env jasmine */ | ||
/** | ||
* Created by knut on 14-11-18. | ||
*/ | ||
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 | ||
}) | ||
@@ -15,3 +13,3 @@ | ||
gantt.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -21,3 +19,3 @@ it('should handle an dateFormat definition', function () { | ||
gantt.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -27,3 +25,3 @@ it('should handle an dateFormat definition', function () { | ||
gantt.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -33,3 +31,3 @@ it('should handle an section definition', function () { | ||
gantt.parse(str) | ||
parser.parse(str) | ||
}) | ||
@@ -54,4 +52,4 @@ /** | ||
gantt.parse(str) | ||
parser.parse(str) | ||
}) | ||
}) |
@@ -1,7 +0,3 @@ | ||
/** | ||
* Created by knut on 15-01-14. | ||
*/ | ||
var moment = require('moment') | ||
var Logger = require('../../logger') | ||
var log = Logger.Log | ||
import moment from 'moment' | ||
import { logger } from '../../logger' | ||
@@ -14,3 +10,3 @@ var dateFormat = '' | ||
module.exports.clear = function () { | ||
export const clear = function () { | ||
sections = [] | ||
@@ -26,18 +22,18 @@ tasks = [] | ||
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 | ||
@@ -47,3 +43,3 @@ sections.push(txt) | ||
module.exports.getTasks = function () { | ||
export const getTasks = function () { | ||
var allItemsPricessed = compileTasks() | ||
@@ -70,3 +66,3 @@ var maxDepth = 10 | ||
if (afterStatement !== null) { | ||
var task = module.exports.findTaskById(afterStatement[1]) | ||
var task = findTaskById(afterStatement[1]) | ||
@@ -85,4 +81,4 @@ if (typeof task === 'undefined') { | ||
} else { | ||
log.debug('Invalid date:' + str) | ||
log.debug('With date format:' + dateFormat.trim()) | ||
logger.debug('Invalid date:' + str) | ||
logger.debug('With date format:' + dateFormat.trim()) | ||
} | ||
@@ -162,3 +158,3 @@ | ||
var task = {} | ||
var df = module.exports.getDateFormat() | ||
var df = getDateFormat() | ||
@@ -276,3 +272,3 @@ // Get tags like active, done cand crit | ||
var taskDb = {} | ||
module.exports.addTask = function (descr, data) { | ||
export const addTask = function (descr, data) { | ||
var rawTask = { | ||
@@ -301,3 +297,3 @@ section: currentSection, | ||
module.exports.findTaskById = function (id) { | ||
export const findTaskById = function (id) { | ||
var pos = taskDb[id] | ||
@@ -307,3 +303,3 @@ return rawTasks[pos] | ||
module.exports.addTaskOrg = function (descr, data) { | ||
export const addTaskOrg = function (descr, data) { | ||
var newTask = { | ||
@@ -327,3 +323,3 @@ section: currentSection, | ||
var compileTasks = function () { | ||
var df = module.exports.getDateFormat() | ||
var df = getDateFormat() | ||
@@ -335,3 +331,3 @@ var compileTask = function (pos) { | ||
case 'prevTaskEnd': | ||
var prevTask = module.exports.findTaskById(task.prevTaskId) | ||
var prevTask = findTaskById(task.prevTaskId) | ||
task.startTime = prevTask.endTime | ||
@@ -367,4 +363,13 @@ break | ||
module.exports.parseError = function (err, hash) { | ||
global.mermaidAPI.parseError(err, hash) | ||
export default { | ||
clear, | ||
setDateFormat, | ||
getDateFormat, | ||
setTitle, | ||
getTitle, | ||
addSection, | ||
getTasks, | ||
addTask, | ||
findTaskById, | ||
addTaskOrg | ||
} |
/* eslint-env jasmine */ | ||
/** | ||
* Created by knut on 14-11-18. | ||
*/ | ||
import moment from 'moment' | ||
import ganttDb from './ganttDb' | ||
describe('when using the ganttDb', function () { | ||
var gDb | ||
var moment = require('moment') | ||
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()) | ||
@@ -25,6 +21,6 @@ expect(tasks[0].endTime).toEqual(moment('2013-01-12', 'YYYY-MM-DD').toDate()) | ||
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()) | ||
@@ -36,6 +32,6 @@ expect(tasks[0].endTime).toEqual(moment('2013-01-03', 'YYYY-MM-DD').toDate()) | ||
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()) | ||
@@ -47,6 +43,6 @@ expect(tasks[0].endTime).toEqual(moment('2013-01-01 2:00', 'YYYY-MM-DD hh:mm').toDate()) | ||
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()) | ||
@@ -58,6 +54,6 @@ expect(tasks[0].endTime).toEqual(moment('2013-01-01 00:02', 'YYYY-MM-DD hh:mm').toDate()) | ||
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()) | ||
@@ -69,6 +65,6 @@ expect(tasks[0].endTime).toEqual(moment('2013-01-01 00:00:02', 'YYYY-MM-DD hh:mm:ss').toDate()) | ||
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()) | ||
@@ -81,8 +77,8 @@ expect(tasks[0].endTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) | ||
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() | ||
@@ -95,7 +91,7 @@ expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) | ||
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))) | ||
@@ -107,6 +103,6 @@ expect(tasks[1].id).toEqual('id2') | ||
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()) | ||
@@ -119,6 +115,6 @@ expect(tasks[0].endTime).toEqual(moment('2013-01-12', 'YYYY-MM-DD').toDate()) | ||
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()) | ||
@@ -131,8 +127,8 @@ expect(tasks[0].endTime).toEqual(moment('2013-01-05', 'YYYY-MM-DD').toDate()) | ||
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() | ||
@@ -144,8 +140,8 @@ expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) | ||
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() | ||
@@ -158,8 +154,8 @@ expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) | ||
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() | ||
@@ -172,10 +168,10 @@ expect(tasks[1].startTime).toEqual(moment('2013-01-15', 'YYYY-MM-DD').toDate()) | ||
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() | ||
@@ -182,0 +178,0 @@ expect(tasks[1].startTime).toEqual(moment('2013-01-17', 'YYYY-MM-DD').toDate()) |
@@ -1,6 +0,10 @@ | ||
var gantt = require('./parser/gantt').parser | ||
gantt.yy = require('./ganttDb') | ||
var d3 = require('../../d3') | ||
var moment = require('moment') | ||
import moment from 'moment' | ||
import { parser } from './parser/gantt' | ||
import ganttDb from './ganttDb' | ||
import d3 from '../../d3' | ||
parser.yy = ganttDb | ||
var daysInChart | ||
@@ -18,3 +22,3 @@ var conf = { | ||
} | ||
module.exports.setConf = function (cnf) { | ||
export const setConf = function (cnf) { | ||
var keys = Object.keys(cnf) | ||
@@ -27,5 +31,5 @@ | ||
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) | ||
@@ -43,3 +47,3 @@ var elem = document.getElementById(id) | ||
var taskArray = gantt.yy.getTasks() | ||
var taskArray = parser.yy.getTasks() | ||
@@ -89,3 +93,3 @@ // Set height based on number of tasks | ||
svg.append('text') | ||
.text(gantt.yy.getTitle()) | ||
.text(parser.yy.getTitle()) | ||
.attr('x', w / 2) | ||
@@ -404,1 +408,6 @@ .attr('y', conf.titleTopMargin) | ||
} | ||
export default { | ||
setConf, | ||
draw | ||
} |
import _ from 'lodash' | ||
const Logger = require('../../logger') | ||
const log = Logger.Log | ||
import { logger } from '../../logger' | ||
@@ -27,3 +26,3 @@ var commits = {} | ||
function isfastforwardable (currentCommit, otherCommit) { | ||
log.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id) | ||
logger.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id) | ||
while (currentCommit.seq <= otherCommit.seq && currentCommit !== otherCommit) { | ||
@@ -33,3 +32,3 @@ // only if other branch has more commits | ||
if (Array.isArray(otherCommit.parent)) { | ||
log.debug('In merge commit:', otherCommit.parent) | ||
logger.debug('In merge commit:', otherCommit.parent) | ||
return isfastforwardable(currentCommit, commits[otherCommit.parent[0]]) || | ||
@@ -41,3 +40,3 @@ isfastforwardable(currentCommit, commits[otherCommit.parent[1]]) | ||
} | ||
log.debug(currentCommit.id, otherCommit.id) | ||
logger.debug(currentCommit.id, otherCommit.id) | ||
return currentCommit.id === otherCommit.id | ||
@@ -53,8 +52,8 @@ } | ||
module.exports.setDirection = function (dir) { | ||
export const setDirection = function (dir) { | ||
direction = dir | ||
} | ||
var options = {} | ||
module.exports.setOptions = function (rawOptString) { | ||
log.debug('options str', rawOptString) | ||
export const setOptions = function (rawOptString) { | ||
logger.debug('options str', rawOptString) | ||
rawOptString = rawOptString && rawOptString.trim() | ||
@@ -65,11 +64,11 @@ rawOptString = rawOptString || '{}' | ||
} catch (e) { | ||
log.error('error while parsing gitGraph options', e.message) | ||
logger.error('error while parsing gitGraph options', e.message) | ||
} | ||
} | ||
module.exports.getOptions = function () { | ||
export const getOptions = function () { | ||
return options | ||
} | ||
module.exports.commit = function (msg) { | ||
export const commit = function (msg) { | ||
var commit = { | ||
@@ -84,15 +83,15 @@ id: getId(), | ||
branches[curBranch] = commit.id | ||
log.debug('in pushCommit ' + commit.id) | ||
logger.debug('in pushCommit ' + commit.id) | ||
} | ||
module.exports.branch = function (name) { | ||
export const branch = function (name) { | ||
branches[name] = head != null ? head.id : null | ||
log.debug('in createBranch') | ||
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)) { | ||
log.debug('Already merged') | ||
logger.debug('Already merged') | ||
return | ||
@@ -115,8 +114,8 @@ } | ||
} | ||
log.debug(branches) | ||
log.debug('in mergeBranch') | ||
logger.debug(branches) | ||
logger.debug('in mergeBranch') | ||
} | ||
module.exports.checkout = function (branch) { | ||
log.debug('in checkout') | ||
export const checkout = function (branch) { | ||
logger.debug('in checkout') | ||
curBranch = branch | ||
@@ -127,8 +126,8 @@ var id = branches[curBranch] | ||
module.exports.reset = function (commitRef) { | ||
log.debug('in reset', commitRef) | ||
export const reset = function (commitRef) { | ||
logger.debug('in reset', commitRef) | ||
var ref = commitRef.split(':')[0] | ||
var parentCount = parseInt(commitRef.split(':')[1]) | ||
var commit = ref === 'HEAD' ? head : commits[branches[ref]] | ||
log.debug(commit, parentCount) | ||
logger.debug(commit, parentCount) | ||
while (parentCount > 0) { | ||
@@ -139,3 +138,3 @@ commit = commits[commit.parent] | ||
var err = 'Critical error - unique parent commit not found during reset' | ||
log.error(err) | ||
logger.error(err) | ||
throw err | ||
@@ -171,3 +170,3 @@ } | ||
}) | ||
log.debug(label.join(' ')) | ||
logger.debug(label.join(' ')) | ||
if (Array.isArray(commit.parent)) { | ||
@@ -187,9 +186,9 @@ var newCommit = commits[commit.parent[0]] | ||
module.exports.prettyPrint = function () { | ||
log.debug(commits) | ||
var node = module.exports.getCommitsArray()[0] | ||
export const prettyPrint = function () { | ||
logger.debug(commits) | ||
var node = getCommitsArray()[0] | ||
prettyPrintCommitHistory([node]) | ||
} | ||
module.exports.clear = function () { | ||
export const clear = function () { | ||
commits = {} | ||
@@ -202,3 +201,3 @@ head = null | ||
module.exports.getBranchesAsObjArray = function () { | ||
export const getBranchesAsObjArray = function () { | ||
const branchArr = _.map(branches, function (value, key) { | ||
@@ -210,13 +209,33 @@ return { 'name': key, 'commit': commits[value] } | ||
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) { log.debug(o.id) }) | ||
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 } | ||
export default { | ||
setDirection, | ||
setOptions, | ||
getOptions, | ||
commit, | ||
branch, | ||
merge, | ||
checkout, | ||
reset, | ||
prettyPrint, | ||
clear, | ||
getBranchesAsObjArray, | ||
getBranches, | ||
getCommits, | ||
getCommitsArray, | ||
getCurrentBranch, | ||
getDirection, | ||
getHead | ||
} |
/* eslint-env jasmine */ | ||
var parser = require('./parser/gitGraph').parser | ||
var ast = require('./gitGraphAst.js') | ||
import gitGraphAst from './gitGraphAst' | ||
import { parser } from './parser/gitGraph' | ||
describe('when parsing a gitGraph', function () { | ||
beforeEach(function () { | ||
parser.yy = ast | ||
parser.yy = gitGraphAst | ||
parser.yy.clear() | ||
@@ -8,0 +9,0 @@ }) |
import _ from 'lodash' | ||
const db = require('./gitGraphAst') | ||
const gitGraphParser = require('./parser/gitGraph') | ||
const d3 = require('../../d3') | ||
const Logger = require('../../logger') | ||
const log = Logger.Log | ||
import db from './gitGraphAst' | ||
import gitGraphParser from './parser/gitGraph' | ||
import d3 from '../../d3' | ||
import { logger } from '../../logger' | ||
@@ -30,3 +29,3 @@ var allCommitsDict = {} | ||
var apiConfig = {} | ||
exports.setConf = function (c) { | ||
export const setConf = function (c) { | ||
apiConfig = c | ||
@@ -90,3 +89,3 @@ } | ||
function svgDrawLineForCommits (svg, fromId, toId, direction, color) { | ||
log.debug('svgDrawLineForCommits: ', fromId, toId) | ||
logger.debug('svgDrawLineForCommits: ', fromId, toId) | ||
var fromBbox = getElementCoords(svg.select('#node-' + fromId + ' circle')) | ||
@@ -167,3 +166,3 @@ var toBbox = getElementCoords(svg.select('#node-' + toId + ' circle')) | ||
commit = allCommitsDict[commitid] | ||
log.debug('in renderCommitHistory', commit.id, commit.seq) | ||
logger.debug('in renderCommitHistory', commit.id, commit.seq) | ||
if (svg.select('#node-' + commitid).size() > 0) { | ||
@@ -196,3 +195,3 @@ return | ||
if (branch) { | ||
log.debug('found branch ', branch.name) | ||
logger.debug('found branch ', branch.name) | ||
svg.select('#node-' + commit.id + ' p') | ||
@@ -218,3 +217,3 @@ .append('xhtml:span') | ||
if (_.isArray(commitid)) { | ||
log.debug('found merge commmit', commitid) | ||
logger.debug('found merge commmit', commitid) | ||
renderCommitHistory(svg, commitid[0], branches, direction) | ||
@@ -244,3 +243,3 @@ branchNum++ | ||
exports.draw = function (txt, id, ver) { | ||
export const draw = function (txt, id, ver) { | ||
try { | ||
@@ -251,3 +250,3 @@ var parser | ||
log.debug('in gitgraph renderer', txt, id, ver) | ||
logger.debug('in gitgraph renderer', txt, id, ver) | ||
// Parse the graph definition | ||
@@ -257,3 +256,3 @@ parser.parse(txt + '\n') | ||
config = _.extend(config, apiConfig, db.getOptions()) | ||
log.debug('effective options', config) | ||
logger.debug('effective options', config) | ||
var direction = db.getDirection() | ||
@@ -280,5 +279,10 @@ allCommitsDict = db.getCommits() | ||
} catch (e) { | ||
log.error('Error while rendering gitgraph') | ||
log.error(e.message) | ||
logger.error('Error while rendering gitgraph') | ||
logger.error(e.message) | ||
} | ||
} | ||
export default { | ||
setConf, | ||
draw | ||
} |
@@ -1,4 +0,3 @@ | ||
/** | ||
* Created by knut on 14-11-19. | ||
*/ | ||
import { logger } from '../../logger' | ||
var actors = {} | ||
@@ -8,6 +7,4 @@ var messages = [] | ||
var title = '' | ||
var Logger = require('../../logger') | ||
var log = Logger.Log | ||
module.exports.addActor = function (id, name, description) { | ||
export const addActor = function (id, name, description) { | ||
// Don't allow description nulling | ||
@@ -23,29 +20,29 @@ var old = actors[id] | ||
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) { | ||
log.debug('Adding message from=' + idFrom + ' to=' + idTo + ' message=' + message + ' type=' + 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 = {} | ||
@@ -55,3 +52,3 @@ messages = [] | ||
module.exports.LINETYPE = { | ||
export const LINETYPE = { | ||
SOLID: 0, | ||
@@ -78,3 +75,3 @@ DOTTED: 1, | ||
module.exports.ARROWTYPE = { | ||
export const ARROWTYPE = { | ||
FILLED: 0, | ||
@@ -84,3 +81,3 @@ OPEN: 1 | ||
module.exports.PLACEMENT = { | ||
export const PLACEMENT = { | ||
LEFTOF: 0, | ||
@@ -91,3 +88,3 @@ RIGHTOF: 1, | ||
module.exports.addNote = function (actor, placement, message) { | ||
export const addNote = function (actor, placement, message) { | ||
var note = { actor: actor, placement: placement, message: message } | ||
@@ -99,17 +96,13 @@ | ||
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.parseError = function (err, hash) { | ||
global.mermaidAPI.parseError(err, hash) | ||
} | ||
module.exports.apply = function (param) { | ||
export const apply = function (param) { | ||
if (param instanceof Array) { | ||
param.forEach(function (item) { | ||
module.exports.apply(item) | ||
apply(item) | ||
}) | ||
@@ -119,48 +112,48 @@ } else { | ||
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 | ||
@@ -170,1 +163,19 @@ } | ||
} | ||
export default { | ||
addActor, | ||
addMessage, | ||
addSignal, | ||
getMessages, | ||
getActors, | ||
getActor, | ||
getActorKeys, | ||
getTitle, | ||
clear, | ||
LINETYPE, | ||
ARROWTYPE, | ||
PLACEMENT, | ||
addNote, | ||
setTitle, | ||
apply | ||
} |
/* eslint-env jasmine */ | ||
/** | ||
* Created by knut on 14-11-18. | ||
*/ | ||
import { parser } from './parser/sequenceDiagram' | ||
import sequenceDb from './sequenceDb' | ||
import MyModuleInjector from 'inject-loader!./sequenceRenderer' // eslint-disable-line import/no-webpack-loader-syntax | ||
var sq = require('./parser/sequenceDiagram').parser | ||
var NewD3 | ||
@@ -17,4 +16,4 @@ | ||
} | ||
const MyModuleInjector = require('inject-loader!./sequenceRenderer') // eslint-disable-line import/no-webpack-loader-syntax | ||
var sd = MyModuleInjector({ | ||
var renderer = MyModuleInjector({ | ||
'../../d3': d3 | ||
@@ -33,4 +32,4 @@ }) | ||
beforeEach(function () { | ||
sq.yy = require('./sequenceDb') | ||
sq.yy.clear() | ||
parser.yy = sequenceDb | ||
parser.yy.clear() | ||
}) | ||
@@ -43,8 +42,8 @@ it('it should handle a sequenceDiagram defintion', function () { | ||
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() | ||
@@ -62,9 +61,9 @@ expect(messages.length).toBe(3) | ||
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() | ||
@@ -81,8 +80,8 @@ expect(messages.length).toBe(3) | ||
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() | ||
@@ -100,5 +99,5 @@ expect(messages.length).toBe(2) | ||
sq.parse(str) | ||
parser.parse(str) | ||
var actors = sq.yy.getActors() | ||
var actors = parser.yy.getActors() | ||
expect(Object.keys(actors)).toEqual(['A', 'B']) | ||
@@ -108,3 +107,3 @@ expect(actors.A.description).toBe('Alice') | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages.length).toBe(2) | ||
@@ -118,11 +117,11 @@ expect(messages[0].from).toBe('A') | ||
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) | ||
}) | ||
@@ -133,11 +132,11 @@ it('it should handle in async dotted messages', function () { | ||
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) | ||
}) | ||
@@ -148,11 +147,11 @@ it('it should handle in arrow messages', function () { | ||
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) | ||
}) | ||
@@ -163,11 +162,11 @@ it('it should handle in arrow messages', function () { | ||
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) | ||
}) | ||
@@ -181,15 +180,15 @@ it('it should handle actor activation', function () { | ||
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') | ||
@@ -202,15 +201,15 @@ }) | ||
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') | ||
@@ -225,19 +224,19 @@ }) | ||
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') | ||
@@ -252,8 +251,8 @@ }) | ||
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() | ||
@@ -271,8 +270,8 @@ expect(messages.length).toBe(3) | ||
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() | ||
@@ -289,8 +288,8 @@ expect(messages.length).toBe(3) | ||
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() | ||
@@ -308,8 +307,8 @@ expect(messages.length).toBe(3) | ||
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() | ||
@@ -327,8 +326,8 @@ expect(messages.length).toBe(3) | ||
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() | ||
@@ -352,8 +351,8 @@ expect(messages.length).toBe(3) | ||
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() | ||
@@ -369,5 +368,5 @@ expect(messages.length).toBe(8) | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[1].from).toBe('Bob') | ||
@@ -382,5 +381,5 @@ expect(messages[1].to).toBe('Bob') | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[1].from).toBe('Alice') | ||
@@ -400,8 +399,8 @@ expect(messages[1].to).toBe('Bob') | ||
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() | ||
@@ -421,8 +420,8 @@ expect(messages.length).toBe(5) | ||
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() | ||
@@ -444,4 +443,4 @@ expect(messages.length).toBe(5) | ||
sq.parse(str) | ||
var actors = sq.yy.getActors() | ||
parser.parse(str) | ||
var actors = parser.yy.getActors() | ||
@@ -451,3 +450,3 @@ expect(actors.Alice.description).toBe('Alice') | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
@@ -471,4 +470,4 @@ expect(messages.length).toBe(7) | ||
sq.parse(str) | ||
var actors = sq.yy.getActors() | ||
parser.parse(str) | ||
var actors = parser.yy.getActors() | ||
@@ -478,3 +477,3 @@ expect(actors.Alice.description).toBe('Alice') | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
@@ -490,5 +489,5 @@ expect(messages.length).toBe(10) | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[0].message).toBe('-:<>,') | ||
@@ -501,5 +500,5 @@ }) | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[1].message).toBe('-:<>,') | ||
@@ -514,5 +513,5 @@ }) | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[1].message).toBe('-:<>,') | ||
@@ -527,5 +526,5 @@ }) | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[1].message).toBe('-:<>,') | ||
@@ -542,5 +541,5 @@ }) | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[1].message).toBe('-:<>,') | ||
@@ -558,5 +557,5 @@ expect(messages[3].message).toBe(',<>:-') | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[1].message).toBe('-:<>,') | ||
@@ -572,5 +571,5 @@ expect(messages[3].message).toBe(',<>:-') | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[1].message).toBe('') | ||
@@ -586,5 +585,5 @@ expect(messages[2].message).toBe('I am good thanks!') | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[1].message).toBe('') | ||
@@ -602,5 +601,5 @@ expect(messages[2].message).toBe('I am good thanks!') | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[1].message).toBe('') | ||
@@ -620,5 +619,5 @@ expect(messages[2].message).toBe('I am good thanks!') | ||
sq.parse(str) | ||
parser.parse(str) | ||
var messages = sq.yy.getMessages() | ||
var messages = parser.yy.getMessages() | ||
expect(messages[1].message).toBe('') | ||
@@ -634,4 +633,4 @@ expect(messages[2].message).toBe('I am good thanks!') | ||
beforeEach(function () { | ||
sq.yy = require('./sequenceDb') | ||
sq.yy.clear() | ||
parser.yy = sequenceDb | ||
parser.yy.clear() | ||
conf = { | ||
@@ -649,10 +648,10 @@ diagramMarginX: 50, | ||
} | ||
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) | ||
@@ -664,8 +663,8 @@ expect(bounds.starty).toBe(100) | ||
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) | ||
@@ -677,9 +676,9 @@ expect(bounds.starty).toBe(50) | ||
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) | ||
@@ -691,10 +690,10 @@ expect(bounds.starty).toBe(50) | ||
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() | ||
@@ -707,3 +706,3 @@ expect(loop.startx).toBe(125 - conf.boxMargin) | ||
// Check bounds of first loop | ||
var bounds = sd.bounds.getBounds() | ||
var bounds = renderer.bounds.getBounds() | ||
@@ -716,12 +715,12 @@ expect(bounds.startx).toBe(25) | ||
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() | ||
@@ -734,3 +733,3 @@ expect(loop.startx).toBe(200 - conf.boxMargin) | ||
// Check bounds of second loop | ||
loop = sd.bounds.endLoop() | ||
loop = renderer.bounds.endLoop() | ||
@@ -743,3 +742,3 @@ expect(loop.startx).toBe(200 - 2 * conf.boxMargin) | ||
// Check bounds of first loop | ||
var bounds = sd.bounds.getBounds() | ||
var bounds = renderer.bounds.getBounds() | ||
@@ -752,10 +751,10 @@ expect(bounds.startx).toBe(100) | ||
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() | ||
@@ -768,3 +767,3 @@ expect(loop.startx).toBe(50 - conf.boxMargin) | ||
// Check bounds after the loop | ||
var bounds = sd.bounds.getBounds() | ||
var bounds = renderer.bounds.getBounds() | ||
@@ -781,4 +780,4 @@ expect(bounds.startx).toBe(loop.startx) | ||
beforeEach(function () { | ||
sq.yy = require('./sequenceDb') | ||
sq.yy.clear() | ||
parser.yy = sequenceDb | ||
parser.yy.clear() | ||
@@ -829,15 +828,15 @@ delete global.mermaid_config | ||
} | ||
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) | ||
@@ -850,3 +849,3 @@ expect(bounds.starty).toBe(0) | ||
it('it should handle one actor and a centered note', function () { | ||
sd.bounds.init() | ||
renderer.bounds.init() | ||
var str = 'sequenceDiagram\n' + | ||
@@ -856,6 +855,6 @@ 'participant Alice\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) | ||
@@ -868,3 +867,3 @@ expect(bounds.starty).toBe(0) | ||
it('it should handle one actor and a note to the left', function () { | ||
sd.bounds.init() | ||
renderer.bounds.init() | ||
var str = 'sequenceDiagram\n' + | ||
@@ -874,6 +873,6 @@ 'participant Alice\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(-(conf.width / 2) - (conf.actorMargin / 2)) | ||
@@ -886,3 +885,3 @@ expect(bounds.starty).toBe(0) | ||
it('it should handle one actor and a note to the right', function () { | ||
sd.bounds.init() | ||
renderer.bounds.init() | ||
var str = 'sequenceDiagram\n' + | ||
@@ -892,6 +891,6 @@ 'participant Alice\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) | ||
@@ -904,10 +903,10 @@ expect(bounds.starty).toBe(0) | ||
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) | ||
@@ -919,3 +918,3 @@ expect(bounds.starty).toBe(0) | ||
it('it should handle two actors and two centered shared notes', function () { | ||
sd.bounds.init() | ||
renderer.bounds.init() | ||
var str = 'sequenceDiagram\n' + | ||
@@ -926,6 +925,6 @@ 'Alice->Bob: Hello Bob, how are you?\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) | ||
@@ -937,3 +936,3 @@ expect(bounds.starty).toBe(0) | ||
it('it should draw two actors and two messages', function () { | ||
sd.bounds.init() | ||
renderer.bounds.init() | ||
var str = 'sequenceDiagram\n' + | ||
@@ -943,6 +942,6 @@ 'Alice->Bob: Hello Bob, how are you?\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) | ||
@@ -954,3 +953,3 @@ expect(bounds.starty).toBe(0) | ||
it('it should draw two actors notes to the right', function () { | ||
sd.bounds.init() | ||
renderer.bounds.init() | ||
var str = 'sequenceDiagram\n' + | ||
@@ -961,6 +960,6 @@ 'Alice->Bob: Hello Bob, how are you?\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) | ||
@@ -975,3 +974,3 @@ expect(bounds.starty).toBe(0) | ||
it('it should draw two actors notes to the left', function () { | ||
sd.bounds.init() | ||
renderer.bounds.init() | ||
var str = 'sequenceDiagram\n' + | ||
@@ -982,6 +981,6 @@ 'Alice->Bob: Hello Bob, how are you?\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(-(conf.width / 2) - (conf.actorMargin / 2)) | ||
@@ -994,3 +993,3 @@ expect(bounds.starty).toBe(0) | ||
it('it should draw two loops', function () { | ||
sd.bounds.init() | ||
renderer.bounds.init() | ||
var str = 'sequenceDiagram\n' + | ||
@@ -1001,6 +1000,6 @@ 'Alice->Bob: Hello Bob, how are you?\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) | ||
@@ -1017,4 +1016,4 @@ expect(bounds.starty).toBe(0) | ||
beforeEach(function () { | ||
sq.yy = require('./sequenceDb') | ||
sq.yy.clear() | ||
parser.yy = sequenceDb | ||
parser.yy.clear() | ||
@@ -1067,15 +1066,15 @@ NewD3 = function () { | ||
} | ||
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) | ||
@@ -1082,0 +1081,0 @@ expect(bounds.starty).toBe(0) |
@@ -1,11 +0,8 @@ | ||
/** | ||
* Created by knut on 14-11-23. | ||
*/ | ||
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') | ||
var svgDraw = require('./svgDraw') | ||
var d3 = require('../../d3') | ||
var Logger = require('../../logger') | ||
var log = Logger.Log | ||
parser.yy = sequenceDb | ||
@@ -41,3 +38,3 @@ var conf = { | ||
module.exports.bounds = { | ||
export const bounds = { | ||
data: { | ||
@@ -83,4 +80,4 @@ startx: undefined, | ||
_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) | ||
@@ -91,4 +88,4 @@ if (!(type === 'activation')) { | ||
_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) | ||
} | ||
@@ -109,6 +106,6 @@ } | ||
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) | ||
@@ -118,3 +115,3 @@ 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 | ||
@@ -150,3 +147,3 @@ var x = actorRect.x + conf.width / 2 + (stackedSize - 1) * conf.activationWidth / 2 | ||
loop.sectionTitles = loop.sectionTitles || [] | ||
loop.sections.push(module.exports.bounds.getVerticalPos()) | ||
loop.sections.push(bounds.getVerticalPos()) | ||
loop.sectionTitles.push(message) | ||
@@ -201,9 +198,9 @@ this.sequenceItems.push(loop) | ||
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) | ||
} | ||
@@ -246,5 +243,5 @@ | ||
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 { | ||
@@ -256,7 +253,7 @@ line = g.append('line') | ||
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')) | ||
@@ -278,7 +275,7 @@ line.attr('class', 'messageLine1') | ||
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)') | ||
@@ -288,3 +285,3 @@ } | ||
module.exports.drawActors = function (diagram, actors, actorKeys, verticalPos) { | ||
export const drawActors = function (diagram, actors, actorKeys, verticalPos) { | ||
var i | ||
@@ -303,10 +300,10 @@ // Draw the actors | ||
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) | ||
@@ -320,3 +317,3 @@ | ||
var actorActivations = function (actor) { | ||
return module.exports.bounds.activations.filter(function (activation) { | ||
return bounds.activations.filter(function (activation) { | ||
return activation.actor === actor | ||
@@ -328,3 +325,3 @@ }) | ||
// handle multiple stacked activations for same actor | ||
var actors = sq.yy.getActors() | ||
var actors = parser.yy.getActors() | ||
var activations = actorActivations(actor) | ||
@@ -342,7 +339,7 @@ | ||
*/ | ||
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) | ||
@@ -355,7 +352,7 @@ | ||
// 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) | ||
@@ -367,3 +364,3 @@ // The arrow head definition is attached to the svg once | ||
function activeEnd (msg, verticalPos) { | ||
var activationData = module.exports.bounds.endActivation(msg) | ||
var activationData = bounds.endActivation(msg) | ||
if (activationData.starty + 18 > verticalPos) { | ||
@@ -375,3 +372,3 @@ activationData.starty = verticalPos - 6 | ||
module.exports.bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos) | ||
bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos) | ||
} | ||
@@ -386,4 +383,4 @@ | ||
switch (msg.type) { | ||
case sq.yy.LINETYPE.NOTE: | ||
module.exports.bounds.bumpVerticalPos(conf.boxMargin) | ||
case parser.yy.LINETYPE.NOTE: | ||
bounds.bumpVerticalPos(conf.boxMargin) | ||
@@ -393,74 +390,74 @@ startx = actors[msg.from].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 | ||
@@ -470,3 +467,3 @@ default: | ||
// lastMsg = msg | ||
module.exports.bounds.bumpVerticalPos(conf.messageMargin) | ||
bounds.bumpVerticalPos(conf.messageMargin) | ||
var fromBounds = actorFlowVerticaBounds(msg.from) | ||
@@ -479,6 +476,6 @@ var toBounds = actorFlowVerticaBounds(msg.to) | ||
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) { | ||
@@ -492,10 +489,10 @@ console.error('error while drawing message', e) | ||
// 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 | ||
log.debug('For line height fix Querying: #' + id + ' .actor-line') | ||
logger.debug('For line height fix Querying: #' + id + ' .actor-line') | ||
var actorLines = d3.selectAll('#' + id + ' .actor-line') | ||
@@ -530,1 +527,8 @@ actorLines.attr('y2', box.stopy) | ||
} | ||
export default { | ||
bounds, | ||
drawActors, | ||
setConf, | ||
draw | ||
} |
@@ -1,5 +0,2 @@ | ||
/** | ||
* Created by knut on 14-12-20. | ||
*/ | ||
module.exports.drawRect = function (elem, rectData) { | ||
export const drawRect = function (elem, rectData) { | ||
var rectElem = elem.append('rect') | ||
@@ -22,3 +19,3 @@ rectElem.attr('x', rectData.x) | ||
module.exports.drawText = function (elem, textData, width) { | ||
export const drawText = function (elem, textData, width) { | ||
// Remove and ignore br:s | ||
@@ -52,3 +49,3 @@ var nText = textData.text.replace(/<br\/?>/ig, ' ') | ||
module.exports.drawLabel = function (elem, txtObject) { | ||
export const drawLabel = function (elem, txtObject) { | ||
function genPoints (x, y, width, height, cut) { | ||
@@ -67,3 +64,3 @@ return x + ',' + y + ' ' + | ||
txtObject.x = txtObject.x + 0.5 * txtObject.labelMargin | ||
module.exports.drawText(elem, txtObject) | ||
drawText(elem, txtObject) | ||
} | ||
@@ -77,3 +74,3 @@ var actorCnt = -1 | ||
*/ | ||
module.exports.drawActor = function (elem, left, verticalPos, description, conf) { | ||
export const drawActor = function (elem, left, verticalPos, description, conf) { | ||
var center = left + (conf.width / 2) | ||
@@ -94,3 +91,3 @@ var g = elem.append('g') | ||
var rect = module.exports.getNoteRect() | ||
var rect = getNoteRect() | ||
rect.x = left | ||
@@ -104,3 +101,3 @@ rect.y = verticalPos | ||
rect.ry = 3 | ||
module.exports.drawRect(g, rect) | ||
drawRect(g, rect) | ||
@@ -111,3 +108,3 @@ _drawTextCandidateFunc(conf)(description, g, | ||
module.exports.anchorElement = function (elem) { | ||
export const anchorElement = function (elem) { | ||
return elem.append('g') | ||
@@ -121,4 +118,4 @@ } | ||
*/ | ||
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 | ||
@@ -130,3 +127,3 @@ rect.x = bounds.startx | ||
rect.height = verticalPos - bounds.starty | ||
module.exports.drawRect(g, rect) | ||
drawRect(g, rect) | ||
} | ||
@@ -140,3 +137,3 @@ | ||
*/ | ||
module.exports.drawLoop = function (elem, bounds, labelText, conf) { | ||
export const drawLoop = function (elem, bounds, labelText, conf) { | ||
var g = elem.append('g') | ||
@@ -161,3 +158,3 @@ var drawLoopLine = function (startx, starty, stopx, stopy) { | ||
var txt = module.exports.getTextObj() | ||
var txt = getTextObj() | ||
txt.text = labelText | ||
@@ -169,5 +166,5 @@ txt.x = bounds.startx | ||
module.exports.drawLabel(g, txt) | ||
drawLabel(g, txt) | ||
txt = module.exports.getTextObj() | ||
txt = getTextObj() | ||
txt.text = '[ ' + bounds.title + ' ]' | ||
@@ -179,3 +176,3 @@ txt.x = bounds.startx + (bounds.stopx - bounds.startx) / 2 | ||
module.exports.drawText(g, txt) | ||
drawText(g, txt) | ||
@@ -187,3 +184,3 @@ if (typeof bounds.sectionTitles !== 'undefined') { | ||
txt.y = bounds.sections[idx] + 1.5 * conf.boxMargin | ||
module.exports.drawText(g, txt) | ||
drawText(g, txt) | ||
} | ||
@@ -197,3 +194,3 @@ }) | ||
*/ | ||
module.exports.insertArrowHead = function (elem) { | ||
export const insertArrowHead = function (elem) { | ||
elem.append('defs').append('marker') | ||
@@ -212,3 +209,3 @@ .attr('id', 'arrowhead') | ||
*/ | ||
module.exports.insertArrowCrossHead = function (elem) { | ||
export const insertArrowCrossHead = function (elem) { | ||
var defs = elem.append('defs') | ||
@@ -241,3 +238,3 @@ var marker = defs.append('marker') | ||
module.exports.getTextObj = function () { | ||
export const getTextObj = function () { | ||
var txt = { | ||
@@ -258,3 +255,3 @@ x: 0, | ||
module.exports.getNoteRect = function () { | ||
export const getNoteRect = function () { | ||
var rect = { | ||
@@ -338,1 +335,15 @@ x: 0, | ||
})() | ||
export default { | ||
drawRect, | ||
drawText, | ||
drawLabel, | ||
drawActor, | ||
anchorElement, | ||
drawActivation, | ||
drawLoop, | ||
insertArrowHead, | ||
insertArrowCrossHead, | ||
getTextObj, | ||
getNoteRect | ||
} |
import moment from 'moment' | ||
const format = (level) => { | ||
const time = moment().format('HH:mm:ss (SSS)') | ||
return `%c ${time} :%c${level}: ` | ||
export const LEVELS = { | ||
debug: 1, | ||
info: 2, | ||
warn: 3, | ||
error: 4, | ||
fatal: 5 | ||
} | ||
export const Log = { | ||
export const logger = { | ||
debug: () => {}, | ||
@@ -16,26 +19,28 @@ info: () => {}, | ||
/** | ||
* logLevel , decides the amount of logging to be used. | ||
* * debug: 1 | ||
* * info: 2 | ||
* * warn: 3 | ||
* * error: 4 | ||
* * fatal: 5 | ||
*/ | ||
export const setLogLevel = function (level) { | ||
if (level < 6) { | ||
Log.fatal = console.log.bind(console, format('FATAL'), 'color:grey;', 'color: red;') | ||
logger.debug = () => {} | ||
logger.info = () => {} | ||
logger.warn = () => {} | ||
logger.error = () => {} | ||
logger.fatal = () => {} | ||
if (level <= LEVELS.fatal) { | ||
logger.fatal = console.log.bind(console, '\x1b[35m', format('FATAL')) | ||
} | ||
if (level < 5) { | ||
Log.error = console.log.bind(console, format('ERROR'), 'color:grey;', 'color: red;') | ||
if (level <= LEVELS.error) { | ||
logger.error = console.log.bind(console, '\x1b[31m', format('ERROR')) | ||
} | ||
if (level < 4) { | ||
Log.warn = console.log.bind(console, format('WARN'), 'color:grey;', 'color: orange;') | ||
if (level <= LEVELS.warn) { | ||
logger.warn = console.log.bind(console, `\x1b[33m`, format('WARN')) | ||
} | ||
if (level < 3) { | ||
Log.info = console.log.bind(console, format('INFO'), 'color:grey;', 'color: info;') | ||
if (level <= LEVELS.info) { | ||
logger.info = console.log.bind(console, '\x1b[34m', format('INFO')) | ||
} | ||
if (level < 2) { | ||
Log.debug = console.log.bind(console, format('DEBUG'), 'color:grey;', 'color: green;') | ||
if (level <= LEVELS.debug) { | ||
logger.debug = console.log.bind(console, '\x1b[32m', format('DEBUG')) | ||
} | ||
} | ||
const format = (level) => { | ||
const time = moment().format('HH:mm:ss.SSS') | ||
return `${time} : ${level} : ` | ||
} |
@@ -5,7 +5,8 @@ /** | ||
*/ | ||
var he = require('he') | ||
import he from 'he' | ||
var Logger = require('./logger') | ||
var log = Logger.Log | ||
var mermaidAPI = require('./mermaidAPI') | ||
import mermaidAPI from './mermaidAPI' | ||
import { logger } from './logger' | ||
import pkg from '../package.json' | ||
var nextId = 0 | ||
@@ -36,3 +37,3 @@ | ||
var conf = mermaidAPI.getConfig() | ||
log.debug('Starting rendering diagrams') | ||
logger.debug('Starting rendering diagrams') | ||
var nodes | ||
@@ -42,3 +43,3 @@ if (arguments.length >= 2) { | ||
if (typeof arguments[0] !== 'undefined') { | ||
global.mermaid.sequenceConfig = arguments[0] | ||
mermaid.sequenceConfig = arguments[0] | ||
} | ||
@@ -55,3 +56,3 @@ | ||
callback = arguments[arguments.length - 1] | ||
log.debug('Callback function found') | ||
logger.debug('Callback function found') | ||
} else { | ||
@@ -61,5 +62,5 @@ if (typeof conf.mermaid !== 'undefined') { | ||
callback = conf.mermaid.callback | ||
log.debug('Callback function found') | ||
logger.debug('Callback function found') | ||
} else { | ||
log.debug('No Callback function found') | ||
logger.debug('No Callback function found') | ||
} | ||
@@ -76,10 +77,10 @@ } | ||
} | ||
log.debug('Start On Load before: ' + global.mermaid.startOnLoad) | ||
if (typeof global.mermaid.startOnLoad !== 'undefined') { | ||
log.debug('Start On Load inner: ' + global.mermaid.startOnLoad) | ||
mermaidAPI.initialize({ startOnLoad: global.mermaid.startOnLoad }) | ||
logger.debug('Start On Load before: ' + mermaid.startOnLoad) | ||
if (typeof mermaid.startOnLoad !== 'undefined') { | ||
logger.debug('Start On Load inner: ' + mermaid.startOnLoad) | ||
mermaidAPI.initialize({ startOnLoad: mermaid.startOnLoad }) | ||
} | ||
if (typeof global.mermaid.ganttConfig !== 'undefined') { | ||
mermaidAPI.initialize({ gantt: global.mermaid.ganttConfig }) | ||
if (typeof mermaid.ganttConfig !== 'undefined') { | ||
mermaidAPI.initialize({ gantt: mermaid.ganttConfig }) | ||
} | ||
@@ -119,13 +120,13 @@ | ||
const version = function () { | ||
return 'v' + require('../package.json').version | ||
return 'v' + pkg.version | ||
} | ||
const initialize = function (config) { | ||
log.debug('Initializing mermaid') | ||
logger.debug('Initializing mermaid') | ||
if (typeof config.mermaid !== 'undefined') { | ||
if (typeof config.mermaid.startOnLoad !== 'undefined') { | ||
global.mermaid.startOnLoad = config.mermaid.startOnLoad | ||
mermaid.startOnLoad = config.mermaid.startOnLoad | ||
} | ||
if (typeof config.mermaid.htmlLabels !== 'undefined') { | ||
global.mermaid.htmlLabels = config.mermaid.htmlLabels | ||
mermaid.htmlLabels = config.mermaid.htmlLabels | ||
} | ||
@@ -146,7 +147,7 @@ } | ||
if (global.mermaid_config.htmlLabels === false) { | ||
global.mermaid.htmlLabels = false | ||
mermaid.htmlLabels = false | ||
} | ||
} | ||
if (global.mermaid.startOnLoad) { | ||
if (mermaid.startOnLoad) { | ||
// For backwards compatability reasons also check mermaid_config variable | ||
@@ -156,3 +157,3 @@ if (typeof global.mermaid_config !== 'undefined') { | ||
if (global.mermaid_config.startOnLoad === true) { | ||
global.mermaid.init() | ||
mermaid.init() | ||
} | ||
@@ -163,11 +164,11 @@ } else { | ||
if (config.startOnLoad) { | ||
global.mermaid.init() | ||
mermaid.init() | ||
} | ||
} | ||
} else { | ||
if (typeof global.mermaid.startOnLoad === 'undefined') { | ||
log.debug('In start, no config') | ||
if (typeof mermaid.startOnLoad === 'undefined') { | ||
logger.debug('In start, no config') | ||
config = mermaidAPI.getConfig() | ||
if (config.startOnLoad) { | ||
global.mermaid.init() | ||
mermaid.init() | ||
} | ||
@@ -188,17 +189,13 @@ } | ||
const mermaid = { | ||
mermaidAPI, | ||
startOnLoad: true, | ||
htmlLabels: true, | ||
mermaidAPI, | ||
parse: mermaidAPI.parse, | ||
render: mermaidAPI.render, | ||
init, | ||
initialize, | ||
version, | ||
parse: mermaidAPI.parse, | ||
parseError: function (err) { | ||
log.debug('Mermaid Syntax error:') | ||
log.debug(err) | ||
}, | ||
render: mermaidAPI.render, | ||
contentLoaded | ||
@@ -205,0 +202,0 @@ } |
/* eslint-env jasmine */ | ||
/** | ||
* Created by knut on 14-11-26. | ||
*/ | ||
/** | ||
* Created by knut on 14-11-23. | ||
*/ | ||
import mermaid from './mermaid' | ||
import graphDb from './diagrams/flowchart/graphDb' | ||
import flowParser from './diagrams/flowchart/parser/flow' | ||
import flowRenderer from './diagrams/flowchart/flowRenderer' | ||
global.mermaid = mermaid | ||
describe('when using mermaid and ', function () { | ||
describe('when detecting chart type ', function () { | ||
it('should not start rendering with mermaid_config.startOnLoad set to false', function () { | ||
global.mermaid_config = {startOnLoad: false} | ||
global.mermaid_config = { startOnLoad: false } | ||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>' | ||
spyOn(global.mermaid, 'init') | ||
spyOn(mermaid, 'init') | ||
mermaid.contentLoaded() | ||
expect(global.mermaid.init).not.toHaveBeenCalled() | ||
expect(mermaid.init).not.toHaveBeenCalled() | ||
}) | ||
it('should not start rendering with mermaid.startOnLoad set to false', function () { | ||
global.mermaid.startOnLoad = false | ||
global.mermaid_config = {startOnLoad: true} | ||
mermaid.startOnLoad = false | ||
global.mermaid_config = { startOnLoad: true } | ||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>' | ||
spyOn(global.mermaid, 'init') | ||
spyOn(mermaid, 'init') | ||
mermaid.contentLoaded() | ||
expect(global.mermaid.init).not.toHaveBeenCalled() | ||
expect(mermaid.init).not.toHaveBeenCalled() | ||
}) | ||
it('should start rendering with both startOnLoad set', function () { | ||
global.mermaid.startOnLoad = true | ||
global.mermaid_config = {startOnLoad: true} | ||
mermaid.startOnLoad = true | ||
global.mermaid_config = { startOnLoad: true } | ||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>' | ||
spyOn(global.mermaid, 'init') | ||
spyOn(mermaid, 'init') | ||
mermaid.contentLoaded() | ||
expect(global.mermaid.init).toHaveBeenCalled() | ||
expect(mermaid.init).toHaveBeenCalled() | ||
}) | ||
it('should start rendering with mermaid.startOnLoad set and no mermaid_config defined', function () { | ||
global.mermaid.startOnLoad = true | ||
mermaid.startOnLoad = true | ||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>' | ||
spyOn(global.mermaid, 'init') | ||
spyOn(mermaid, 'init') | ||
mermaid.contentLoaded() | ||
expect(global.mermaid.init).toHaveBeenCalled() | ||
expect(mermaid.init).toHaveBeenCalled() | ||
}) | ||
@@ -52,5 +47,5 @@ | ||
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>' | ||
spyOn(global.mermaid, 'init') | ||
spyOn(mermaid, 'init') | ||
mermaid.contentLoaded() | ||
expect(global.mermaid.init).toHaveBeenCalled() | ||
expect(mermaid.init).toHaveBeenCalled() | ||
}) | ||
@@ -60,15 +55,11 @@ }) | ||
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() | ||
global.mermaid_config = { startOnLoad: false } | ||
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() | ||
@@ -84,9 +75,9 @@ var mockG = { | ||
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() | ||
@@ -101,9 +92,9 @@ var mockG = { | ||
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() | ||
@@ -118,9 +109,9 @@ var mockG = { | ||
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() | ||
@@ -136,8 +127,8 @@ var mockG = { | ||
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() | ||
@@ -153,8 +144,8 @@ var mockG = { | ||
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() | ||
@@ -171,9 +162,9 @@ var mockG = { | ||
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() | ||
@@ -189,9 +180,9 @@ var mockG = { | ||
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 = { | ||
@@ -206,3 +197,3 @@ setEdge: function (start, end, options) { | ||
flowRend.addEdges(edges, mockG) | ||
flowRenderer.addEdges(edges, mockG) | ||
}) | ||
@@ -212,82 +203,57 @@ }) | ||
describe('checking validity of input ', function () { | ||
it('it should return false for an invalid definiton', function () { | ||
spyOn(global.mermaid, 'parseError') | ||
var res = mermaid.parse('this is not a mermaid diagram definition') | ||
expect(res).toBe(false) | ||
expect(global.mermaid.parseError).toHaveBeenCalled() | ||
it('it should throw for an invalid definiton', function () { | ||
expect(() => mermaid.parse('this is not a mermaid diagram definition')).toThrow() | ||
}) | ||
it('it should return true for a valid flow definition', function () { | ||
spyOn(global.mermaid, 'parseError') | ||
var res = mermaid.parse('graph TD;A--x|text including URL space|B;') | ||
expect(res).toBe(true) | ||
expect(global.mermaid.parseError).not.toHaveBeenCalled() | ||
it('it should not throw for a valid flow definition', function () { | ||
expect(() => mermaid.parse('graph TD;A--x|text including URL space|B;')).not.toThrow() | ||
}) | ||
it('it should return false for an invalid flow definition', function () { | ||
spyOn(global.mermaid, 'parseError') | ||
var res = mermaid.parse('graph TQ;A--x|text including URL space|B;') | ||
expect(res).toBe(false) | ||
expect(global.mermaid.parseError).toHaveBeenCalled() | ||
it('it should throw for an invalid flow definition', function () { | ||
expect(() => mermaid.parse('graph TQ;A--x|text including URL space|B;')).toThrow() | ||
}) | ||
it('it should return true for a valid sequenceDiagram definition', function () { | ||
spyOn(global.mermaid, 'parseError') | ||
var str = 'sequenceDiagram\n' + | ||
'Alice->Bob: Hello Bob, how are you?\n\n' + | ||
'%% Comment\n' + | ||
'Note right of Bob: Bob thinks\n' + | ||
'alt isWell\n\n' + | ||
'Bob-->Alice: I am good thanks!\n' + | ||
'else isSick\n' + | ||
'Bob-->Alice: Feel sick...\n' + | ||
'end' | ||
var res = mermaid.parse(str) | ||
expect(res).toBe(true) | ||
expect(global.mermaid.parseError).not.toHaveBeenCalled() | ||
it('it should not throw for a valid sequenceDiagram definition', function () { | ||
var text = 'sequenceDiagram\n' + | ||
'Alice->Bob: Hello Bob, how are you?\n\n' + | ||
'%% Comment\n' + | ||
'Note right of Bob: Bob thinks\n' + | ||
'alt isWell\n\n' + | ||
'Bob-->Alice: I am good thanks!\n' + | ||
'else isSick\n' + | ||
'Bob-->Alice: Feel sick...\n' + | ||
'end' | ||
expect(() => mermaid.parse(text)).not.toThrow() | ||
}) | ||
it('it should return false for an invalid sequenceDiagram definition', function () { | ||
spyOn(global.mermaid, 'parseError') | ||
var str = 'sequenceDiagram\n' + | ||
'Alice:->Bob: Hello Bob, how are you?\n\n' + | ||
'%% Comment\n' + | ||
'Note right of Bob: Bob thinks\n' + | ||
'alt isWell\n\n' + | ||
'Bob-->Alice: I am good thanks!\n' + | ||
'else isSick\n' + | ||
'Bob-->Alice: Feel sick...\n' + | ||
'end' | ||
var res = mermaid.parse(str) | ||
expect(res).toBe(false) | ||
expect(global.mermaid.parseError).toHaveBeenCalled() | ||
it('it should throw for an invalid sequenceDiagram definition', function () { | ||
var text = 'sequenceDiagram\n' + | ||
'Alice:->Bob: Hello Bob, how are you?\n\n' + | ||
'%% Comment\n' + | ||
'Note right of Bob: Bob thinks\n' + | ||
'alt isWell\n\n' + | ||
'Bob-->Alice: I am good thanks!\n' + | ||
'else isSick\n' + | ||
'Bob-->Alice: Feel sick...\n' + | ||
'end' | ||
expect(() => mermaid.parse(text)).toThrow() | ||
}) | ||
it('it should return true for a valid dot definition', function () { | ||
spyOn(global.mermaid, 'parseError') | ||
var res = mermaid.parse('digraph\n' + | ||
'{\n' + | ||
' a -> b -> c -- d -> e;\n' + | ||
' a -- e;\n' + | ||
'}') | ||
expect(res).toBe(true) | ||
expect(global.mermaid.parseError).not.toHaveBeenCalled() | ||
it('it should not throw for a valid dot definition', function () { | ||
const text = 'digraph\n' + | ||
'{\n' + | ||
' a -> b -> c -- d -> e;\n' + | ||
' a -- e;\n' + | ||
'}' | ||
expect(() => mermaid.parse(text)).not.toThrow() | ||
}) | ||
it('it should return false for an invalid dot definition', function () { | ||
spyOn(global.mermaid, 'parseError') | ||
var res = mermaid.parse('digraph\n' + | ||
'{\n' + | ||
'a -:> b -> c -- d -> e;\n' + | ||
'a -- e;\n' + | ||
'}') | ||
expect(res).toBe(false) | ||
expect(global.mermaid.parseError).toHaveBeenCalled() | ||
it('it should throw for an invalid dot definition', function () { | ||
const text = 'digraph\n' + | ||
'{\n' + | ||
'a -:> b -> c -- d -> e;\n' + | ||
'a -- e;\n' + | ||
'}' | ||
expect(() => mermaid.parse(text)).toThrow() | ||
}) | ||
}) | ||
}) |
@@ -13,28 +13,27 @@ /** | ||
* somewhere in the page or something completely different. | ||
*/ | ||
var Logger = require('./logger') | ||
var log = Logger.Log | ||
*/ | ||
import { logger, setLogLevel } from './logger' | ||
import graph from './diagrams/flowchart/graphDb' | ||
import utils from './utils' | ||
import flowRenderer from './diagrams/flowchart/flowRenderer' | ||
import seq from './diagrams/sequenceDiagram/sequenceRenderer' | ||
import info from './diagrams/example/exampleRenderer' | ||
import infoParser from './diagrams/example/parser/example' | ||
import flowParser from './diagrams/flowchart/parser/flow' | ||
import dotParser from './diagrams/flowchart/parser/dot' | ||
import sequenceParser from './diagrams/sequenceDiagram/parser/sequenceDiagram' | ||
import sequenceDb from './diagrams/sequenceDiagram/sequenceDb' | ||
import infoDb from './diagrams/example/exampleDb' | ||
import gantt from './diagrams/gantt/ganttRenderer' | ||
import ganttParser from './diagrams/gantt/parser/gantt' | ||
import ganttDb from './diagrams/gantt/ganttDb' | ||
import classParser from './diagrams/classDiagram/parser/classDiagram' | ||
import classRenderer from './diagrams/classDiagram/classRenderer' | ||
import classDb from './diagrams/classDiagram/classDb' | ||
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' | ||
var graph = require('./diagrams/flowchart/graphDb') | ||
var utils = require('./utils') | ||
var flowRenderer = require('./diagrams/flowchart/flowRenderer') | ||
var seq = require('./diagrams/sequenceDiagram/sequenceRenderer') | ||
var info = require('./diagrams/example/exampleRenderer') | ||
var infoParser = require('./diagrams/example/parser/example') | ||
var flowParser = require('./diagrams/flowchart/parser/flow') | ||
var dotParser = require('./diagrams/flowchart/parser/dot') | ||
var sequenceParser = require('./diagrams/sequenceDiagram/parser/sequenceDiagram') | ||
var sequenceDb = require('./diagrams/sequenceDiagram/sequenceDb') | ||
var infoDb = require('./diagrams/example/exampleDb') | ||
var gantt = require('./diagrams/gantt/ganttRenderer') | ||
var ganttParser = require('./diagrams/gantt/parser/gantt') | ||
var ganttDb = require('./diagrams/gantt/ganttDb') | ||
var classParser = require('./diagrams/classDiagram/parser/classDiagram') | ||
var classRenderer = require('./diagrams/classDiagram/classRenderer') | ||
var classDb = require('./diagrams/classDiagram/classDb') | ||
var gitGraphParser = require('./diagrams/gitGraph/parser/gitGraph') | ||
var gitGraphRenderer = require('./diagrams/gitGraph/gitGraphRenderer') | ||
var gitGraphAst = require('./diagrams/gitGraph/gitGraphAst') | ||
var d3 = require('./d3') | ||
/** | ||
@@ -244,11 +243,5 @@ * ## Configuration | ||
Logger.setLogLevel(config.logLevel) | ||
setLogLevel(config.logLevel) | ||
/** | ||
* ## parse | ||
* Function that parses a mermaid diagram definition. If parsing fails the parseError callback is called and an error is | ||
* thrown and | ||
* @param text | ||
*/ | ||
var parse = function (text) { | ||
function parse (text) { | ||
var graphType = utils.detectType(text) | ||
@@ -288,10 +281,9 @@ var parser | ||
try { | ||
parser.parse(text) | ||
return true | ||
} catch (err) { | ||
return false | ||
parser.parser.yy.parseError = (str, hash) => { | ||
const error = { str, hash } | ||
throw error | ||
} | ||
parser.parse(text) | ||
} | ||
module.exports.parse = parse | ||
@@ -303,7 +295,7 @@ /** | ||
*/ | ||
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 | ||
@@ -334,3 +326,3 @@ | ||
module.exports.decodeEntities = function (text) { | ||
export const decodeEntities = function (text) { | ||
var txt = text | ||
@@ -400,3 +392,3 @@ | ||
window.txt = txt | ||
txt = module.exports.encodeEntities(txt) | ||
txt = encodeEntities(txt) | ||
@@ -456,3 +448,3 @@ var element = d3.select('#d' + id).node() | ||
config.info.arrowMarkerAbsolute = config.arrowMarkerAbsolute | ||
info.draw(txt, id, module.exports.version()) | ||
info.draw(txt, id, version()) | ||
if (config.cloneCssStyles) { | ||
@@ -476,3 +468,3 @@ utils.cloneCssStyles(element.firstChild, []) | ||
svgCode = module.exports.decodeEntities(svgCode) | ||
svgCode = decodeEntities(svgCode) | ||
@@ -482,3 +474,3 @@ if (typeof cb !== 'undefined') { | ||
} else { | ||
log.warn('CB = undefined!') | ||
logger.warn('CB = undefined!') | ||
} | ||
@@ -494,3 +486,3 @@ | ||
module.exports.render = function (id, text, cb, containerElement) { | ||
function render2 (id, text, cb, containerElement) { | ||
try { | ||
@@ -509,3 +501,3 @@ if (arguments.length === 1) { | ||
} catch (e) { | ||
log.warn(e) | ||
logger.warn(e) | ||
} | ||
@@ -524,7 +516,7 @@ } | ||
for (j = 0; j < lvl2Keys.length; j++) { | ||
log.debug('Setting conf ', lvl1Keys[i], '-', lvl2Keys[j]) | ||
logger.debug('Setting conf ', lvl1Keys[i], '-', lvl2Keys[j]) | ||
if (typeof config[lvl1Keys[i]] === 'undefined') { | ||
config[lvl1Keys[i]] = {} | ||
} | ||
log.debug('Setting config: ' + lvl1Keys[i] + ' ' + lvl2Keys[j] + ' to ' + cnf[lvl1Keys[i]][lvl2Keys[j]]) | ||
logger.debug('Setting config: ' + lvl1Keys[i] + ' ' + lvl2Keys[j] + ' to ' + cnf[lvl1Keys[i]][lvl2Keys[j]]) | ||
config[lvl1Keys[i]][lvl2Keys[j]] = cnf[lvl1Keys[i]][lvl2Keys[j]] | ||
@@ -538,4 +530,4 @@ } | ||
module.exports.initialize = function (options) { | ||
log.debug('Initializing mermaidAPI') | ||
function initialize (options) { | ||
logger.debug('Initializing mermaidAPI') | ||
// Update default config with options supplied at initialization | ||
@@ -545,23 +537,17 @@ if (typeof options === 'object') { | ||
} | ||
Logger.setLogLevel(config.logLevel) | ||
setLogLevel(config.logLevel) | ||
} | ||
module.exports.getConfig = function () { | ||
function getConfig () { | ||
return config | ||
} | ||
module.exports.parseError = function (err, hash) { | ||
if (typeof mermaid !== 'undefined') { | ||
global.mermaid.parseError(err, hash) | ||
} else { | ||
log.debug('Mermaid Syntax error:') | ||
log.debug(err) | ||
} | ||
} | ||
global.mermaidAPI = { | ||
render: module.exports.render, | ||
parse: module.exports.parse, | ||
initialize: module.exports.initialize, | ||
const mermaidAPI = { | ||
render: render2, | ||
parse, | ||
initialize, | ||
detectType: utils.detectType, | ||
parseError: module.exports.parseError, | ||
getConfig: module.exports.getConfig | ||
getConfig | ||
} | ||
export default mermaidAPI |
/* eslint-env jasmine */ | ||
/** | ||
* Created by knut on 14-11-26. | ||
*/ | ||
/** | ||
* Created by knut on 14-11-23. | ||
*/ | ||
var api = require('./mermaidAPI.js') | ||
import mermaidAPI from './mermaidAPI' | ||
@@ -18,7 +12,7 @@ describe('when using mermaidAPI and ', function () { | ||
it('should copy a literal into the configuration', function () { | ||
var orgConfig = api.getConfig() | ||
var orgConfig = mermaidAPI.getConfig() | ||
expect(orgConfig.testLiteral).toBe(undefined) | ||
api.initialize({ 'testLiteral': true }) | ||
var config = api.getConfig() | ||
mermaidAPI.initialize({ 'testLiteral': true }) | ||
var config = mermaidAPI.getConfig() | ||
@@ -28,3 +22,3 @@ expect(config.testLiteral).toBe(true) | ||
it('should copy a an object into the configuration', function () { | ||
var orgConfig = api.getConfig() | ||
var orgConfig = mermaidAPI.getConfig() | ||
expect(orgConfig.testObject).toBe(undefined) | ||
@@ -37,5 +31,5 @@ | ||
api.initialize({ 'testObject': object }) | ||
api.initialize({ 'testObject': { 'test3': true } }) | ||
var config = api.getConfig() | ||
mermaidAPI.initialize({ 'testObject': object }) | ||
mermaidAPI.initialize({ 'testObject': { 'test3': true } }) | ||
var config = mermaidAPI.getConfig() | ||
@@ -49,18 +43,9 @@ expect(config.testObject.test1).toBe(1) | ||
describe('checking validity of input ', function () { | ||
it('it should return false for an invalid definiton', function () { | ||
global.mermaidAPI.parseError = function () { } | ||
spyOn(global.mermaidAPI, 'parseError') | ||
var res = api.parse('this is not a mermaid diagram definition') | ||
expect(res).toBe(false) | ||
expect(global.mermaidAPI.parseError).toHaveBeenCalled() | ||
it('it should throw for an invalid definiton', function () { | ||
expect(() => mermaidAPI.parse('this is not a mermaid diagram definition')).toThrow() | ||
}) | ||
it('it should return true for a valid definiton', function () { | ||
spyOn(global.mermaidAPI, 'parseError') | ||
var res = api.parse('graph TD;A--x|text including URL space|B;') | ||
expect(res).toBe(true) | ||
expect(global.mermaidAPI.parseError).not.toHaveBeenCalled() | ||
it('it should not throw for a valid definiton', function () { | ||
expect(() => mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).not.toThrow() | ||
}) | ||
}) | ||
}) |
@@ -1,2 +0,2 @@ | ||
import { Log } from './logger' | ||
import { logger } from './logger' | ||
@@ -39,3 +39,3 @@ /** | ||
if (text.match(/^\s*classDiagram/)) { | ||
Log.debug('Detected classDiagram syntax') | ||
logger.debug('Detected classDiagram syntax') | ||
return 'classDiagram' | ||
@@ -45,3 +45,3 @@ } | ||
if (text.match(/^\s*gitGraph/)) { | ||
Log.debug('Detected gitGraph syntax') | ||
logger.debug('Detected gitGraph syntax') | ||
return 'gitGraph' | ||
@@ -80,3 +80,3 @@ } | ||
if (typeof (rule) !== 'undefined') { | ||
Log.warn('Invalid CSS selector "' + rule.selectorText + '"', err) | ||
logger.warn('Invalid CSS selector "' + rule.selectorText + '"', err) | ||
} | ||
@@ -145,1 +145,7 @@ } | ||
} | ||
export default { | ||
detectType, | ||
cloneCssStyles, | ||
isSubstringInArray | ||
} |
/* eslint-env jasmine */ | ||
/** | ||
* Created by knut on 14-11-23. | ||
*/ | ||
var utils = require('./utils') | ||
import utils from './utils' | ||
@@ -7,0 +4,0 @@ describe('when detecting chart type ', function () { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4135138
90
88103
2
235
14
9