mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Replace exports. with module.exports
This commit is contained in:
parent
626fdfe345
commit
5da8c26cb6
@ -42,8 +42,8 @@ module.exports.getRelations = function () {
|
||||
|
||||
exports.addRelation = function (relation) {
|
||||
log.warn('Adding relation: ' + JSON.stringify(relation))
|
||||
exports.addClass(relation.id1)
|
||||
exports.addClass(relation.id2)
|
||||
module.exports.addClass(relation.id1)
|
||||
module.exports.addClass(relation.id2)
|
||||
|
||||
relations.push(relation)
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ module.exports.setConf = function (cnf) {
|
||||
* @param vert Object containing the vertices.
|
||||
* @param g The graph that is to be drawn.
|
||||
*/
|
||||
exports.addVertices = function (vert, g) {
|
||||
module.exports.addVertices = function (vert, g) {
|
||||
var keys = Object.keys(vert)
|
||||
|
||||
var styleFromStyleArr = function (styleStr, arr) {
|
||||
@ -139,7 +139,7 @@ exports.addVertices = function (vert, g) {
|
||||
* @param {Object} edges The edges to add to the graph
|
||||
* @param {Object} g The graph object
|
||||
*/
|
||||
exports.addEdges = function (edges, g) {
|
||||
module.exports.addEdges = function (edges, g) {
|
||||
var cnt = 0
|
||||
|
||||
var defaultStyle
|
||||
@ -219,7 +219,7 @@ exports.addEdges = function (edges, g) {
|
||||
* Returns the all the styles from classDef statements in the graph definition.
|
||||
* @returns {object} classDef styles
|
||||
*/
|
||||
exports.getClasses = function (text, isDot) {
|
||||
module.exports.getClasses = function (text, isDot) {
|
||||
var parser
|
||||
graph.clear()
|
||||
if (isDot) {
|
||||
@ -250,7 +250,7 @@ exports.getClasses = function (text, isDot) {
|
||||
* @param text
|
||||
* @param id
|
||||
*/
|
||||
exports.draw = function (text, id, isDot) {
|
||||
module.exports.draw = function (text, id, isDot) {
|
||||
log.debug('Drawing flowchart')
|
||||
var parser
|
||||
graph.clear()
|
||||
@ -314,8 +314,8 @@ exports.draw = function (text, id, isDot) {
|
||||
g.setParent(subG.nodes[j], subG.id)
|
||||
}
|
||||
}
|
||||
exports.addVertices(vert, g)
|
||||
exports.addEdges(edges, g)
|
||||
module.exports.addVertices(vert, g)
|
||||
module.exports.addEdges(edges, g)
|
||||
|
||||
// Create the renderer
|
||||
var Render = dagreD3.render
|
||||
|
@ -11,7 +11,7 @@ var sections = []
|
||||
var tasks = []
|
||||
var currentSection = ''
|
||||
|
||||
exports.clear = function () {
|
||||
module.exports.clear = function () {
|
||||
sections = []
|
||||
tasks = []
|
||||
currentSection = ''
|
||||
@ -22,27 +22,27 @@ exports.clear = function () {
|
||||
rawTasks = []
|
||||
}
|
||||
|
||||
exports.setDateFormat = function (txt) {
|
||||
module.exports.setDateFormat = function (txt) {
|
||||
dateFormat = txt
|
||||
}
|
||||
|
||||
exports.getDateFormat = function () {
|
||||
module.exports.getDateFormat = function () {
|
||||
return dateFormat
|
||||
}
|
||||
exports.setTitle = function (txt) {
|
||||
module.exports.setTitle = function (txt) {
|
||||
title = txt
|
||||
}
|
||||
|
||||
exports.getTitle = function () {
|
||||
module.exports.getTitle = function () {
|
||||
return title
|
||||
}
|
||||
|
||||
exports.addSection = function (txt) {
|
||||
module.exports.addSection = function (txt) {
|
||||
currentSection = txt
|
||||
sections.push(txt)
|
||||
}
|
||||
|
||||
exports.getTasks = function () {
|
||||
module.exports.getTasks = function () {
|
||||
var allItemsPricessed = compileTasks()
|
||||
var maxDepth = 10
|
||||
var iterationCount = 0
|
||||
@ -64,7 +64,7 @@ var getStartDate = function (prevTime, dateFormat, str) {
|
||||
var afterStatement = re.exec(str.trim())
|
||||
|
||||
if (afterStatement !== null) {
|
||||
var task = exports.findTaskById(afterStatement[1])
|
||||
var task = module.exports.findTaskById(afterStatement[1])
|
||||
|
||||
if (typeof task === 'undefined') {
|
||||
var dt = new Date()
|
||||
@ -154,7 +154,7 @@ var compileData = function (prevTask, dataStr) {
|
||||
var data = ds.split(',')
|
||||
|
||||
var task = {}
|
||||
var df = exports.getDateFormat()
|
||||
var df = module.exports.getDateFormat()
|
||||
|
||||
// Get tags like active, done cand crit
|
||||
var matchFound = true
|
||||
@ -267,7 +267,7 @@ var lastTask
|
||||
var lastTaskID
|
||||
var rawTasks = []
|
||||
var taskDb = {}
|
||||
exports.addTask = function (descr, data) {
|
||||
module.exports.addTask = function (descr, data) {
|
||||
var rawTask = {
|
||||
section: currentSection,
|
||||
type: currentSection,
|
||||
@ -291,12 +291,12 @@ exports.addTask = function (descr, data) {
|
||||
taskDb[rawTask.id] = pos - 1
|
||||
}
|
||||
|
||||
exports.findTaskById = function (id) {
|
||||
module.exports.findTaskById = function (id) {
|
||||
var pos = taskDb[id]
|
||||
return rawTasks[pos]
|
||||
}
|
||||
|
||||
exports.addTaskOrg = function (descr, data) {
|
||||
module.exports.addTaskOrg = function (descr, data) {
|
||||
var newTask = {
|
||||
section: currentSection,
|
||||
type: currentSection,
|
||||
@ -315,14 +315,14 @@ exports.addTaskOrg = function (descr, data) {
|
||||
}
|
||||
|
||||
var compileTasks = function () {
|
||||
var df = exports.getDateFormat()
|
||||
var df = module.exports.getDateFormat()
|
||||
|
||||
var compileTask = function (pos) {
|
||||
var task = rawTasks[pos]
|
||||
var startTime = ''
|
||||
switch (rawTasks[pos].raw.startTime.type) {
|
||||
case 'prevTaskEnd':
|
||||
var prevTask = exports.findTaskById(task.prevTaskId)
|
||||
var prevTask = module.exports.findTaskById(task.prevTaskId)
|
||||
task.startTime = prevTask.endTime
|
||||
break
|
||||
case 'getStartDate':
|
||||
@ -353,6 +353,6 @@ var compileTasks = function () {
|
||||
return allProcessed
|
||||
}
|
||||
|
||||
exports.parseError = function (err, hash) {
|
||||
module.exports.parseError = function (err, hash) {
|
||||
global.mermaidAPI.parseError(err, hash)
|
||||
}
|
||||
|
@ -47,11 +47,11 @@ function isReachableFrom (currentCommit, otherCommit) {
|
||||
return false
|
||||
}
|
||||
|
||||
exports.setDirection = function (dir) {
|
||||
module.exports.setDirection = function (dir) {
|
||||
direction = dir
|
||||
}
|
||||
var options = {}
|
||||
exports.setOptions = function (rawOptString) {
|
||||
module.exports.setOptions = function (rawOptString) {
|
||||
log.debug('options str', rawOptString)
|
||||
rawOptString = rawOptString && rawOptString.trim()
|
||||
rawOptString = rawOptString || '{}'
|
||||
@ -62,11 +62,11 @@ exports.setOptions = function (rawOptString) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.getOptions = function () {
|
||||
module.exports.getOptions = function () {
|
||||
return options
|
||||
}
|
||||
|
||||
exports.commit = function (msg) {
|
||||
module.exports.commit = function (msg) {
|
||||
var commit = {
|
||||
id: getId(),
|
||||
message: msg,
|
||||
@ -79,12 +79,12 @@ exports.commit = function (msg) {
|
||||
log.debug('in pushCommit ' + commit.id)
|
||||
}
|
||||
|
||||
exports.branch = function (name) {
|
||||
module.exports.branch = function (name) {
|
||||
branches[name] = head != null ? head.id : null
|
||||
log.debug('in createBranch')
|
||||
}
|
||||
|
||||
exports.merge = function (otherBranch) {
|
||||
module.exports.merge = function (otherBranch) {
|
||||
var currentCommit = commits[branches[curBranch]]
|
||||
var otherCommit = commits[branches[otherBranch]]
|
||||
if (isReachableFrom(currentCommit, otherCommit)) {
|
||||
@ -110,14 +110,14 @@ exports.merge = function (otherBranch) {
|
||||
log.debug('in mergeBranch')
|
||||
}
|
||||
|
||||
exports.checkout = function (branch) {
|
||||
module.exports.checkout = function (branch) {
|
||||
log.debug('in checkout')
|
||||
curBranch = branch
|
||||
var id = branches[curBranch]
|
||||
head = commits[id]
|
||||
}
|
||||
|
||||
exports.reset = function (commitRef) {
|
||||
module.exports.reset = function (commitRef) {
|
||||
log.debug('in reset', commitRef)
|
||||
var ref = commitRef.split(':')[0]
|
||||
var parentCount = parseInt(commitRef.split(':')[1])
|
||||
@ -174,13 +174,13 @@ function prettyPrintCommitHistory (commitArr) {
|
||||
prettyPrintCommitHistory(commitArr)
|
||||
}
|
||||
|
||||
exports.prettyPrint = function () {
|
||||
module.exports.prettyPrint = function () {
|
||||
log.debug(commits)
|
||||
var node = exports.getCommitsArray()[0]
|
||||
var node = module.exports.getCommitsArray()[0]
|
||||
prettyPrintCommitHistory([node])
|
||||
}
|
||||
|
||||
exports.clear = function () {
|
||||
module.exports.clear = function () {
|
||||
commits = {}
|
||||
head = null
|
||||
branches = { 'master': head }
|
||||
@ -188,22 +188,22 @@ exports.clear = function () {
|
||||
seq = 0
|
||||
}
|
||||
|
||||
exports.getBranchesAsObjArray = function () {
|
||||
module.exports.getBranchesAsObjArray = function () {
|
||||
const branchArr = _.map(branches, function (value, key) {
|
||||
return { 'name': key, 'commit': commits[value] }
|
||||
})
|
||||
return branchArr
|
||||
}
|
||||
|
||||
exports.getBranches = function () { return branches }
|
||||
exports.getCommits = function () { return commits }
|
||||
exports.getCommitsArray = function () {
|
||||
module.exports.getBranches = function () { return branches }
|
||||
module.exports.getCommits = function () { return commits }
|
||||
module.exports.getCommitsArray = function () {
|
||||
var commitArr = Object.keys(commits).map(function (key) {
|
||||
return commits[key]
|
||||
})
|
||||
commitArr.forEach(function (o) { log.debug(o.id) })
|
||||
return _.orderBy(commitArr, ['seq'], ['desc'])
|
||||
}
|
||||
exports.getCurrentBranch = function () { return curBranch }
|
||||
exports.getDirection = function () { return direction }
|
||||
exports.getHead = function () { return head }
|
||||
module.exports.getCurrentBranch = function () { return curBranch }
|
||||
module.exports.getDirection = function () { return direction }
|
||||
module.exports.getHead = function () { return head }
|
||||
|
@ -8,7 +8,7 @@ var title = ''
|
||||
var Logger = require('../../logger')
|
||||
var log = Logger.Log
|
||||
|
||||
exports.addActor = function (id, name, description) {
|
||||
module.exports.addActor = function (id, name, description) {
|
||||
// Don't allow description nulling
|
||||
var old = actors[id]
|
||||
if (old && name === old.name && description == null) return
|
||||
@ -19,38 +19,38 @@ exports.addActor = function (id, name, description) {
|
||||
actors[id] = { name: name, description: description }
|
||||
}
|
||||
|
||||
exports.addMessage = function (idFrom, idTo, message, answer) {
|
||||
module.exports.addMessage = function (idFrom, idTo, message, answer) {
|
||||
messages.push({ from: idFrom, to: idTo, message: message, answer: answer })
|
||||
}
|
||||
|
||||
exports.addSignal = function (idFrom, idTo, message, messageType) {
|
||||
module.exports.addSignal = function (idFrom, idTo, message, messageType) {
|
||||
log.debug('Adding message from=' + idFrom + ' to=' + idTo + ' message=' + message + ' type=' + messageType)
|
||||
messages.push({ from: idFrom, to: idTo, message: message, type: messageType })
|
||||
}
|
||||
|
||||
exports.getMessages = function () {
|
||||
module.exports.getMessages = function () {
|
||||
return messages
|
||||
}
|
||||
|
||||
exports.getActors = function () {
|
||||
module.exports.getActors = function () {
|
||||
return actors
|
||||
}
|
||||
exports.getActor = function (id) {
|
||||
module.exports.getActor = function (id) {
|
||||
return actors[id]
|
||||
}
|
||||
exports.getActorKeys = function () {
|
||||
module.exports.getActorKeys = function () {
|
||||
return Object.keys(actors)
|
||||
}
|
||||
exports.getTitle = function () {
|
||||
module.exports.getTitle = function () {
|
||||
return title
|
||||
}
|
||||
|
||||
exports.clear = function () {
|
||||
module.exports.clear = function () {
|
||||
actors = {}
|
||||
messages = []
|
||||
}
|
||||
|
||||
exports.LINETYPE = {
|
||||
module.exports.LINETYPE = {
|
||||
SOLID: 0,
|
||||
DOTTED: 1,
|
||||
NOTE: 2,
|
||||
@ -72,89 +72,89 @@ exports.LINETYPE = {
|
||||
PAR_END: 21
|
||||
}
|
||||
|
||||
exports.ARROWTYPE = {
|
||||
module.exports.ARROWTYPE = {
|
||||
FILLED: 0,
|
||||
OPEN: 1
|
||||
}
|
||||
|
||||
exports.PLACEMENT = {
|
||||
module.exports.PLACEMENT = {
|
||||
LEFTOF: 0,
|
||||
RIGHTOF: 1,
|
||||
OVER: 2
|
||||
}
|
||||
|
||||
exports.addNote = function (actor, placement, message) {
|
||||
module.exports.addNote = function (actor, placement, message) {
|
||||
var note = { actor: actor, placement: placement, message: message }
|
||||
|
||||
// Coerce actor into a [to, from, ...] array
|
||||
var actors = [].concat(actor, actor)
|
||||
|
||||
notes.push(note)
|
||||
messages.push({ from: actors[0], to: actors[1], message: message, type: exports.LINETYPE.NOTE, placement: placement })
|
||||
messages.push({ from: actors[0], to: actors[1], message: message, type: module.exports.LINETYPE.NOTE, placement: placement })
|
||||
}
|
||||
|
||||
exports.setTitle = function (titleText) {
|
||||
module.exports.setTitle = function (titleText) {
|
||||
title = titleText
|
||||
}
|
||||
|
||||
exports.parseError = function (err, hash) {
|
||||
module.exports.parseError = function (err, hash) {
|
||||
global.mermaidAPI.parseError(err, hash)
|
||||
}
|
||||
|
||||
exports.apply = function (param) {
|
||||
module.exports.apply = function (param) {
|
||||
if (param instanceof Array) {
|
||||
param.forEach(function (item) {
|
||||
exports.apply(item)
|
||||
module.exports.apply(item)
|
||||
})
|
||||
} else {
|
||||
switch (param.type) {
|
||||
case 'addActor':
|
||||
exports.addActor(param.actor, param.actor, param.description)
|
||||
module.exports.addActor(param.actor, param.actor, param.description)
|
||||
break
|
||||
case 'activeStart':
|
||||
exports.addSignal(param.actor, undefined, undefined, param.signalType)
|
||||
module.exports.addSignal(param.actor, undefined, undefined, param.signalType)
|
||||
break
|
||||
case 'activeEnd':
|
||||
exports.addSignal(param.actor, undefined, undefined, param.signalType)
|
||||
module.exports.addSignal(param.actor, undefined, undefined, param.signalType)
|
||||
break
|
||||
case 'addNote':
|
||||
exports.addNote(param.actor, param.placement, param.text)
|
||||
module.exports.addNote(param.actor, param.placement, param.text)
|
||||
break
|
||||
case 'addMessage':
|
||||
exports.addSignal(param.from, param.to, param.msg, param.signalType)
|
||||
module.exports.addSignal(param.from, param.to, param.msg, param.signalType)
|
||||
break
|
||||
case 'loopStart':
|
||||
exports.addSignal(undefined, undefined, param.loopText, param.signalType)
|
||||
module.exports.addSignal(undefined, undefined, param.loopText, param.signalType)
|
||||
break
|
||||
case 'loopEnd':
|
||||
exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
module.exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
break
|
||||
case 'optStart':
|
||||
exports.addSignal(undefined, undefined, param.optText, param.signalType)
|
||||
module.exports.addSignal(undefined, undefined, param.optText, param.signalType)
|
||||
break
|
||||
case 'optEnd':
|
||||
exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
module.exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
break
|
||||
case 'altStart':
|
||||
exports.addSignal(undefined, undefined, param.altText, param.signalType)
|
||||
module.exports.addSignal(undefined, undefined, param.altText, param.signalType)
|
||||
break
|
||||
case 'else':
|
||||
exports.addSignal(undefined, undefined, param.altText, param.signalType)
|
||||
module.exports.addSignal(undefined, undefined, param.altText, param.signalType)
|
||||
break
|
||||
case 'altEnd':
|
||||
exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
module.exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
break
|
||||
case 'setTitle':
|
||||
exports.setTitle(param.text)
|
||||
module.exports.setTitle(param.text)
|
||||
break
|
||||
case 'parStart':
|
||||
exports.addSignal(undefined, undefined, param.parText, param.signalType)
|
||||
module.exports.addSignal(undefined, undefined, param.parText, param.signalType)
|
||||
break
|
||||
case 'and':
|
||||
exports.addSignal(undefined, undefined, param.parText, param.signalType)
|
||||
module.exports.addSignal(undefined, undefined, param.parText, param.signalType)
|
||||
break
|
||||
case 'parEnd':
|
||||
exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
module.exports.addSignal(undefined, undefined, undefined, param.signalType)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ var conf = {
|
||||
textPlacement: 'tspan'
|
||||
}
|
||||
|
||||
exports.bounds = {
|
||||
module.exports.bounds = {
|
||||
data: {
|
||||
startx: undefined,
|
||||
stopx: undefined,
|
||||
@ -79,15 +79,15 @@ exports.bounds = {
|
||||
_self.updateVal(item, 'starty', starty - n * conf.boxMargin, Math.min)
|
||||
_self.updateVal(item, 'stopy', stopy + n * conf.boxMargin, Math.max)
|
||||
|
||||
_self.updateVal(exports.bounds.data, 'startx', startx - n * conf.boxMargin, Math.min)
|
||||
_self.updateVal(exports.bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max)
|
||||
_self.updateVal(module.exports.bounds.data, 'startx', startx - n * conf.boxMargin, Math.min)
|
||||
_self.updateVal(module.exports.bounds.data, 'stopx', stopx + n * conf.boxMargin, Math.max)
|
||||
|
||||
if (!(type === 'activation')) {
|
||||
_self.updateVal(item, 'startx', startx - n * conf.boxMargin, Math.min)
|
||||
_self.updateVal(item, 'stopx', stopx + n * conf.boxMargin, Math.max)
|
||||
|
||||
_self.updateVal(exports.bounds.data, 'starty', starty - n * conf.boxMargin, Math.min)
|
||||
_self.updateVal(exports.bounds.data, 'stopy', stopy + n * conf.boxMargin, Math.max)
|
||||
_self.updateVal(module.exports.bounds.data, 'starty', starty - n * conf.boxMargin, Math.min)
|
||||
_self.updateVal(module.exports.bounds.data, 'stopy', stopy + n * conf.boxMargin, Math.max)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,10 +103,10 @@ exports.bounds = {
|
||||
_starty = Math.min(starty, stopy)
|
||||
_stopy = Math.max(starty, stopy)
|
||||
|
||||
this.updateVal(exports.bounds.data, 'startx', _startx, Math.min)
|
||||
this.updateVal(exports.bounds.data, 'starty', _starty, Math.min)
|
||||
this.updateVal(exports.bounds.data, 'stopx', _stopx, Math.max)
|
||||
this.updateVal(exports.bounds.data, 'stopy', _stopy, Math.max)
|
||||
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.updateBounds(_startx, _starty, _stopx, _stopy)
|
||||
},
|
||||
@ -142,7 +142,7 @@ exports.bounds = {
|
||||
var loop = this.sequenceItems.pop()
|
||||
loop.sections = loop.sections || []
|
||||
loop.sectionTitles = loop.sectionTitles || []
|
||||
loop.sections.push(exports.bounds.getVerticalPos())
|
||||
loop.sections.push(module.exports.bounds.getVerticalPos())
|
||||
loop.sectionTitles.push(message)
|
||||
this.sequenceItems.push(loop)
|
||||
},
|
||||
@ -192,13 +192,13 @@ var drawNote = function (elem, startx, verticalPos, msg, forceWidth) {
|
||||
textElem = svgDraw.drawText(g, textObj, 2 * rect.width - conf.noteMargin)
|
||||
textHeight = textElem[0][0].getBBox().height
|
||||
rectElem.attr('width', 2 * rect.width)
|
||||
exports.bounds.insert(startx, verticalPos, startx + 2 * rect.width, verticalPos + 2 * conf.noteMargin + textHeight)
|
||||
module.exports.bounds.insert(startx, verticalPos, startx + 2 * rect.width, verticalPos + 2 * conf.noteMargin + textHeight)
|
||||
} else {
|
||||
exports.bounds.insert(startx, verticalPos, startx + rect.width, verticalPos + 2 * conf.noteMargin + textHeight)
|
||||
module.exports.bounds.insert(startx, verticalPos, startx + rect.width, verticalPos + 2 * conf.noteMargin + textHeight)
|
||||
}
|
||||
|
||||
rectElem.attr('height', textHeight + 2 * conf.noteMargin)
|
||||
exports.bounds.bumpVerticalPos(textHeight + 2 * conf.noteMargin)
|
||||
module.exports.bounds.bumpVerticalPos(textHeight + 2 * conf.noteMargin)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -236,16 +236,16 @@ var drawMessage = function (elem, startx, stopx, verticalPos, msg) {
|
||||
.attr('d', 'M ' + startx + ',' + verticalPos + ' C ' + (startx + 60) + ',' + (verticalPos - 10) + ' ' + (startx + 60) + ',' +
|
||||
(verticalPos + 30) + ' ' + startx + ',' + (verticalPos + 20))
|
||||
|
||||
exports.bounds.bumpVerticalPos(30)
|
||||
module.exports.bounds.bumpVerticalPos(30)
|
||||
var dx = Math.max(textWidth / 2, 100)
|
||||
exports.bounds.insert(startx - dx, exports.bounds.getVerticalPos() - 10, stopx + dx, exports.bounds.getVerticalPos())
|
||||
module.exports.bounds.insert(startx - dx, module.exports.bounds.getVerticalPos() - 10, stopx + dx, module.exports.bounds.getVerticalPos())
|
||||
} else {
|
||||
line = g.append('line')
|
||||
line.attr('x1', startx)
|
||||
line.attr('y1', verticalPos)
|
||||
line.attr('x2', stopx)
|
||||
line.attr('y2', verticalPos)
|
||||
exports.bounds.insert(startx, exports.bounds.getVerticalPos() - 10, stopx, exports.bounds.getVerticalPos())
|
||||
module.exports.bounds.insert(startx, module.exports.bounds.getVerticalPos() - 10, stopx, module.exports.bounds.getVerticalPos())
|
||||
}
|
||||
// Make an SVG Container
|
||||
// Draw the line
|
||||
@ -289,11 +289,11 @@ module.exports.drawActors = function (diagram, actors, actorKeys, verticalPos) {
|
||||
|
||||
// Draw the box with the attached line
|
||||
svgDraw.drawActor(diagram, actors[key].x, verticalPos, actors[key].description, conf)
|
||||
exports.bounds.insert(actors[key].x, verticalPos, actors[key].x + conf.width, conf.height)
|
||||
module.exports.bounds.insert(actors[key].x, verticalPos, actors[key].x + conf.width, conf.height)
|
||||
}
|
||||
|
||||
// Add a margin between the actor boxes and the first arrow
|
||||
exports.bounds.bumpVerticalPos(conf.height)
|
||||
module.exports.bounds.bumpVerticalPos(conf.height)
|
||||
}
|
||||
|
||||
module.exports.setConf = function (cnf) {
|
||||
@ -329,7 +329,7 @@ module.exports.draw = function (text, id) {
|
||||
sq.yy.clear()
|
||||
sq.parse(text + '\n')
|
||||
|
||||
exports.bounds.init()
|
||||
module.exports.bounds.init()
|
||||
var diagram = d3.select('#' + id)
|
||||
|
||||
var startx
|
||||
@ -348,14 +348,14 @@ module.exports.draw = function (text, id) {
|
||||
svgDraw.insertArrowCrossHead(diagram)
|
||||
|
||||
function activeEnd (msg, verticalPos) {
|
||||
var activationData = exports.bounds.endActivation(msg)
|
||||
var activationData = module.exports.bounds.endActivation(msg)
|
||||
if (activationData.starty + 18 > verticalPos) {
|
||||
activationData.starty = verticalPos - 6
|
||||
verticalPos += 12
|
||||
}
|
||||
svgDraw.drawActivation(diagram, activationData, verticalPos, conf)
|
||||
|
||||
exports.bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos)
|
||||
module.exports.bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos)
|
||||
}
|
||||
|
||||
// var lastMsg
|
||||
@ -366,88 +366,88 @@ module.exports.draw = function (text, id) {
|
||||
|
||||
switch (msg.type) {
|
||||
case sq.yy.LINETYPE.NOTE:
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
|
||||
startx = actors[msg.from].x
|
||||
stopx = actors[msg.to].x
|
||||
|
||||
if (msg.placement === sq.yy.PLACEMENT.RIGHTOF) {
|
||||
drawNote(diagram, startx + (conf.width + conf.actorMargin) / 2, exports.bounds.getVerticalPos(), msg)
|
||||
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, exports.bounds.getVerticalPos(), msg)
|
||||
drawNote(diagram, startx - (conf.width + conf.actorMargin) / 2, module.exports.bounds.getVerticalPos(), msg)
|
||||
} else if (msg.to === msg.from) {
|
||||
// Single-actor over
|
||||
drawNote(diagram, startx, exports.bounds.getVerticalPos(), msg)
|
||||
drawNote(diagram, startx, module.exports.bounds.getVerticalPos(), msg)
|
||||
} else {
|
||||
// Multi-actor over
|
||||
forceWidth = Math.abs(startx - stopx) + conf.actorMargin
|
||||
drawNote(diagram, (startx + stopx + conf.width - forceWidth) / 2, exports.bounds.getVerticalPos(), msg,
|
||||
drawNote(diagram, (startx + stopx + conf.width - forceWidth) / 2, module.exports.bounds.getVerticalPos(), msg,
|
||||
forceWidth)
|
||||
}
|
||||
break
|
||||
case sq.yy.LINETYPE.ACTIVE_START:
|
||||
exports.bounds.newActivation(msg, diagram)
|
||||
module.exports.bounds.newActivation(msg, diagram)
|
||||
break
|
||||
case sq.yy.LINETYPE.ACTIVE_END:
|
||||
activeEnd(msg, exports.bounds.getVerticalPos())
|
||||
activeEnd(msg, module.exports.bounds.getVerticalPos())
|
||||
break
|
||||
case sq.yy.LINETYPE.LOOP_START:
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
exports.bounds.newLoop(msg.message)
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.newLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.LOOP_END:
|
||||
loopData = exports.bounds.endLoop()
|
||||
loopData = module.exports.bounds.endLoop()
|
||||
|
||||
svgDraw.drawLoop(diagram, loopData, 'loop', conf)
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.OPT_START:
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
exports.bounds.newLoop(msg.message)
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.newLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.OPT_END:
|
||||
loopData = exports.bounds.endLoop()
|
||||
loopData = module.exports.bounds.endLoop()
|
||||
|
||||
svgDraw.drawLoop(diagram, loopData, 'opt', conf)
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.ALT_START:
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
exports.bounds.newLoop(msg.message)
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.newLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.ALT_ELSE:
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
loopData = exports.bounds.addSectionToLoop(msg.message)
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
loopData = module.exports.bounds.addSectionToLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.ALT_END:
|
||||
loopData = exports.bounds.endLoop()
|
||||
loopData = module.exports.bounds.endLoop()
|
||||
|
||||
svgDraw.drawLoop(diagram, loopData, 'alt', conf)
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.PAR_START:
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
exports.bounds.newLoop(msg.message)
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.newLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin + conf.boxTextMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.PAR_AND:
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
loopData = exports.bounds.addSectionToLoop(msg.message)
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
loopData = module.exports.bounds.addSectionToLoop(msg.message)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
case sq.yy.LINETYPE.PAR_END:
|
||||
loopData = exports.bounds.endLoop()
|
||||
loopData = module.exports.bounds.endLoop()
|
||||
svgDraw.drawLoop(diagram, loopData, 'par', conf)
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin)
|
||||
break
|
||||
default:
|
||||
try {
|
||||
// lastMsg = msg
|
||||
exports.bounds.bumpVerticalPos(conf.messageMargin)
|
||||
module.exports.bounds.bumpVerticalPos(conf.messageMargin)
|
||||
var fromBounds = actorFlowVerticaBounds(msg.from)
|
||||
var toBounds = actorFlowVerticaBounds(msg.to)
|
||||
var fromIdx = fromBounds[0] <= toBounds[0] ? 1 : 0
|
||||
@ -455,10 +455,10 @@ module.exports.draw = function (text, id) {
|
||||
startx = fromBounds[fromIdx]
|
||||
stopx = toBounds[toIdx]
|
||||
|
||||
var verticalPos = exports.bounds.getVerticalPos()
|
||||
var verticalPos = module.exports.bounds.getVerticalPos()
|
||||
drawMessage(diagram, startx, stopx, verticalPos, msg)
|
||||
var allBounds = fromBounds.concat(toBounds)
|
||||
exports.bounds.insert(Math.min.apply(null, allBounds), verticalPos, Math.max.apply(null, allBounds), verticalPos)
|
||||
module.exports.bounds.insert(Math.min.apply(null, allBounds), verticalPos, Math.max.apply(null, allBounds), verticalPos)
|
||||
} catch (e) {
|
||||
console.error('error while drawing message', e)
|
||||
}
|
||||
@ -467,11 +467,11 @@ module.exports.draw = function (text, id) {
|
||||
|
||||
if (conf.mirrorActors) {
|
||||
// Draw actors below diagram
|
||||
exports.bounds.bumpVerticalPos(conf.boxMargin * 2)
|
||||
module.exports.drawActors(diagram, actors, actorKeys, exports.bounds.getVerticalPos())
|
||||
module.exports.bounds.bumpVerticalPos(conf.boxMargin * 2)
|
||||
module.exports.drawActors(diagram, actors, actorKeys, module.exports.bounds.getVerticalPos())
|
||||
}
|
||||
|
||||
var box = exports.bounds.getBounds()
|
||||
var box = module.exports.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')
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Created by knut on 14-12-20.
|
||||
*/
|
||||
exports.drawRect = function (elem, rectData) {
|
||||
module.exports.drawRect = function (elem, rectData) {
|
||||
var rectElem = elem.append('rect')
|
||||
rectElem.attr('x', rectData.x)
|
||||
rectElem.attr('y', rectData.y)
|
||||
@ -19,7 +19,7 @@ exports.drawRect = function (elem, rectData) {
|
||||
return rectElem
|
||||
}
|
||||
|
||||
exports.drawText = function (elem, textData, width) {
|
||||
module.exports.drawText = function (elem, textData, width) {
|
||||
// Remove and ignore br:s
|
||||
var nText = textData.text.replace(/<br\/?>/ig, ' ')
|
||||
|
||||
@ -48,7 +48,7 @@ exports.drawText = function (elem, textData, width) {
|
||||
return textElem
|
||||
}
|
||||
|
||||
exports.drawLabel = function (elem, txtObject) {
|
||||
module.exports.drawLabel = function (elem, txtObject) {
|
||||
function genPoints (x, y, width, height, cut) {
|
||||
return x + ',' + y + ' ' +
|
||||
(x + width) + ',' + y + ' ' +
|
||||
@ -62,7 +62,7 @@ exports.drawLabel = function (elem, txtObject) {
|
||||
|
||||
txtObject.y = txtObject.y + txtObject.labelMargin
|
||||
txtObject.x = txtObject.x + 0.5 * txtObject.labelMargin
|
||||
exports.drawText(elem, txtObject)
|
||||
module.exports.drawText(elem, txtObject)
|
||||
}
|
||||
var actorCnt = -1
|
||||
/**
|
||||
@ -71,7 +71,7 @@ var actorCnt = -1
|
||||
* @param pos The position if the actor in the liost of actors
|
||||
* @param description The text in the box
|
||||
*/
|
||||
exports.drawActor = function (elem, left, verticalPos, description, conf) {
|
||||
module.exports.drawActor = function (elem, left, verticalPos, description, conf) {
|
||||
var center = left + (conf.width / 2)
|
||||
var g = elem.append('g')
|
||||
if (verticalPos === 0) {
|
||||
@ -87,7 +87,7 @@ exports.drawActor = function (elem, left, verticalPos, description, conf) {
|
||||
.attr('stroke', '#999')
|
||||
}
|
||||
|
||||
var rect = exports.getNoteRect()
|
||||
var rect = module.exports.getNoteRect()
|
||||
rect.x = left
|
||||
rect.y = verticalPos
|
||||
rect.fill = '#eaeaea'
|
||||
@ -96,13 +96,13 @@ exports.drawActor = function (elem, left, verticalPos, description, conf) {
|
||||
rect.class = 'actor'
|
||||
rect.rx = 3
|
||||
rect.ry = 3
|
||||
exports.drawRect(g, rect)
|
||||
module.exports.drawRect(g, rect)
|
||||
|
||||
_drawTextCandidateFunc(conf)(description, g,
|
||||
rect.x, rect.y, rect.width, rect.height, { 'class': 'actor' })
|
||||
}
|
||||
|
||||
exports.anchorElement = function (elem) {
|
||||
module.exports.anchorElement = function (elem) {
|
||||
return elem.append('g')
|
||||
}
|
||||
/**
|
||||
@ -111,15 +111,15 @@ exports.anchorElement = function (elem) {
|
||||
* @param bounds - activation box bounds
|
||||
* @param verticalPos - precise y cooridnate of bottom activation box edge
|
||||
*/
|
||||
exports.drawActivation = function (elem, bounds, verticalPos) {
|
||||
var rect = exports.getNoteRect()
|
||||
module.exports.drawActivation = function (elem, bounds, verticalPos) {
|
||||
var rect = module.exports.getNoteRect()
|
||||
var g = bounds.anchored
|
||||
rect.x = bounds.startx
|
||||
rect.y = bounds.starty
|
||||
rect.fill = '#f4f4f4'
|
||||
rect.width = bounds.stopx - bounds.startx
|
||||
rect.height = verticalPos - bounds.starty
|
||||
exports.drawRect(g, rect)
|
||||
module.exports.drawRect(g, rect)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,7 +128,7 @@ exports.drawActivation = function (elem, bounds, verticalPos) {
|
||||
* @param pos The position if the actor in the list of actors
|
||||
* @param description The text in the box
|
||||
*/
|
||||
exports.drawLoop = function (elem, bounds, labelText, conf) {
|
||||
module.exports.drawLoop = function (elem, bounds, labelText, conf) {
|
||||
var g = elem.append('g')
|
||||
var drawLoopLine = function (startx, starty, stopx, stopy) {
|
||||
return g.append('line')
|
||||
@ -148,30 +148,30 @@ exports.drawLoop = function (elem, bounds, labelText, conf) {
|
||||
})
|
||||
}
|
||||
|
||||
var txt = exports.getTextObj()
|
||||
var txt = module.exports.getTextObj()
|
||||
txt.text = labelText
|
||||
txt.x = bounds.startx
|
||||
txt.y = bounds.starty
|
||||
txt.labelMargin = 1.5 * 10 // This is the small box that says "loop"
|
||||
txt.class = 'labelText' // Its size & position are fixed.
|
||||
|
||||
exports.drawLabel(g, txt)
|
||||
module.exports.drawLabel(g, txt)
|
||||
|
||||
txt = exports.getTextObj()
|
||||
txt = module.exports.getTextObj()
|
||||
txt.text = '[ ' + bounds.title + ' ]'
|
||||
txt.x = bounds.startx + (bounds.stopx - bounds.startx) / 2
|
||||
txt.y = bounds.starty + 1.5 * conf.boxMargin
|
||||
txt.anchor = 'middle'
|
||||
txt.class = 'loopText'
|
||||
|
||||
exports.drawText(g, txt)
|
||||
module.exports.drawText(g, txt)
|
||||
|
||||
if (typeof bounds.sectionTitles !== 'undefined') {
|
||||
bounds.sectionTitles.forEach(function (item, idx) {
|
||||
if (item !== '') {
|
||||
txt.text = '[ ' + item + ' ]'
|
||||
txt.y = bounds.sections[idx] + 1.5 * conf.boxMargin
|
||||
exports.drawText(g, txt)
|
||||
module.exports.drawText(g, txt)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -180,7 +180,7 @@ exports.drawLoop = function (elem, bounds, labelText, conf) {
|
||||
/**
|
||||
* Setup arrow head and define the marker. The result is appended to the svg.
|
||||
*/
|
||||
exports.insertArrowHead = function (elem) {
|
||||
module.exports.insertArrowHead = function (elem) {
|
||||
elem.append('defs').append('marker')
|
||||
.attr('id', 'arrowhead')
|
||||
.attr('refX', 5)
|
||||
@ -194,7 +194,7 @@ exports.insertArrowHead = function (elem) {
|
||||
/**
|
||||
* Setup arrow head and define the marker. The result is appended to the svg.
|
||||
*/
|
||||
exports.insertArrowCrossHead = function (elem) {
|
||||
module.exports.insertArrowCrossHead = function (elem) {
|
||||
var defs = elem.append('defs')
|
||||
var marker = defs.append('marker')
|
||||
.attr('id', 'crosshead')
|
||||
@ -222,7 +222,7 @@ exports.insertArrowCrossHead = function (elem) {
|
||||
// this is actual shape for arrowhead
|
||||
}
|
||||
|
||||
exports.getTextObj = function () {
|
||||
module.exports.getTextObj = function () {
|
||||
var txt = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
@ -238,7 +238,7 @@ exports.getTextObj = function () {
|
||||
return txt
|
||||
}
|
||||
|
||||
exports.getNoteRect = function () {
|
||||
module.exports.getNoteRect = function () {
|
||||
var rect = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
|
@ -290,18 +290,18 @@ var parse = function (text) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
exports.parse = parse
|
||||
module.exports.parse = parse
|
||||
|
||||
/**
|
||||
* ## version
|
||||
* Function returning version information
|
||||
* @returns {string} A string containing the version info
|
||||
*/
|
||||
exports.version = function () {
|
||||
module.exports.version = function () {
|
||||
return require('../package.json').version
|
||||
}
|
||||
|
||||
exports.encodeEntities = function (text) {
|
||||
module.exports.encodeEntities = function (text) {
|
||||
var txt = text
|
||||
|
||||
txt = txt.replace(/style.*:\S*#.*;/g, function (s) {
|
||||
@ -327,7 +327,7 @@ exports.encodeEntities = function (text) {
|
||||
return txt
|
||||
}
|
||||
|
||||
exports.decodeEntities = function (text) {
|
||||
module.exports.decodeEntities = function (text) {
|
||||
var txt = text
|
||||
|
||||
txt = txt.replace(/fl°°/g, function () {
|
||||
@ -392,7 +392,7 @@ var render = function (id, txt, cb, container) {
|
||||
}
|
||||
|
||||
window.txt = txt
|
||||
txt = exports.encodeEntities(txt)
|
||||
txt = module.exports.encodeEntities(txt)
|
||||
|
||||
var element = d3.select('#d' + id).node()
|
||||
var graphType = utils.detectType(txt)
|
||||
@ -447,7 +447,7 @@ var render = function (id, txt, cb, container) {
|
||||
break
|
||||
case 'info':
|
||||
config.info.arrowMarkerAbsolute = config.arrowMarkerAbsolute
|
||||
info.draw(txt, id, exports.version())
|
||||
info.draw(txt, id, module.exports.version())
|
||||
if (config.cloneCssStyles) {
|
||||
utils.cloneCssStyles(element.firstChild, [])
|
||||
}
|
||||
@ -466,7 +466,7 @@ var render = function (id, txt, cb, container) {
|
||||
// Fix for when the base tag is used
|
||||
var svgCode = d3.select('#d' + id).node().innerHTML.replace(/url\(#arrowhead/g, 'url(' + url + '#arrowhead', 'g')
|
||||
|
||||
svgCode = exports.decodeEntities(svgCode)
|
||||
svgCode = module.exports.decodeEntities(svgCode)
|
||||
|
||||
if (typeof cb !== 'undefined') {
|
||||
cb(svgCode, graph.bindFunctions)
|
||||
@ -482,7 +482,7 @@ var render = function (id, txt, cb, container) {
|
||||
return svgCode
|
||||
}
|
||||
|
||||
exports.render = function (id, text, cb, containerElement) {
|
||||
module.exports.render = function (id, text, cb, containerElement) {
|
||||
try {
|
||||
if (arguments.length === 1) {
|
||||
text = id
|
||||
@ -523,7 +523,7 @@ var setConf = function (cnf) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.initialize = function (options) {
|
||||
module.exports.initialize = function (options) {
|
||||
log.debug('Initializing mermaidAPI')
|
||||
// Update default config with options supplied at initialization
|
||||
if (typeof options === 'object') {
|
||||
@ -531,11 +531,11 @@ exports.initialize = function (options) {
|
||||
}
|
||||
Logger.setLogLevel(config.logLevel)
|
||||
}
|
||||
exports.getConfig = function () {
|
||||
module.exports.getConfig = function () {
|
||||
return config
|
||||
}
|
||||
|
||||
exports.parseError = function (err, hash) {
|
||||
module.exports.parseError = function (err, hash) {
|
||||
if (typeof mermaid !== 'undefined') {
|
||||
global.mermaid.parseError(err, hash)
|
||||
} else {
|
||||
@ -544,10 +544,10 @@ exports.parseError = function (err, hash) {
|
||||
}
|
||||
}
|
||||
global.mermaidAPI = {
|
||||
render: exports.render,
|
||||
parse: exports.parse,
|
||||
initialize: exports.initialize,
|
||||
render: module.exports.render,
|
||||
parse: module.exports.parse,
|
||||
initialize: module.exports.initialize,
|
||||
detectType: utils.detectType,
|
||||
parseError: exports.parseError,
|
||||
getConfig: exports.getConfig
|
||||
parseError: module.exports.parseError,
|
||||
getConfig: module.exports.getConfig
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user