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