mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Fix code style issues
This commit is contained in:
parent
a2ce9e6a54
commit
ab398c64a8
38
lib/cli.js
38
lib/cli.js
@ -1,21 +1,21 @@
|
||||
var fs = require('fs'),
|
||||
exec = require('child_process').exec,
|
||||
chalk = require('chalk'),
|
||||
which = require('which'),
|
||||
parseArgs = require('minimist'),
|
||||
semver = require('semver'),
|
||||
path = require('path')
|
||||
var fs = require('fs')
|
||||
var exec = require('child_process').exec
|
||||
var chalk = require('chalk')
|
||||
var which = require('which')
|
||||
var parseArgs = require('minimist')
|
||||
var semver = require('semver')
|
||||
var path = require('path')
|
||||
|
||||
var PHANTOM_VERSION = '^2.1.0'
|
||||
|
||||
var info = chalk.blue.bold,
|
||||
note = chalk.green.bold
|
||||
var info = chalk.blue.bold
|
||||
// var note = chalk.green.bold
|
||||
|
||||
module.exports = (function () {
|
||||
return new cli()
|
||||
return new Cli()
|
||||
}())
|
||||
|
||||
function cli (options) {
|
||||
function Cli (options) {
|
||||
this.options = {
|
||||
alias: {
|
||||
help: 'h',
|
||||
@ -37,7 +37,7 @@ function cli (options) {
|
||||
this.errors = []
|
||||
this.message = null
|
||||
|
||||
this.helpMessage = [,
|
||||
this.helpMessage = [
|
||||
info('Usage: mermaid [options] <file>...'),
|
||||
'',
|
||||
'file The mermaid description file to be rendered',
|
||||
@ -60,10 +60,10 @@ function cli (options) {
|
||||
return this
|
||||
}
|
||||
|
||||
cli.prototype.parse = function (argv, next) {
|
||||
Cli.prototype.parse = function (argv, next) {
|
||||
this.errors = [] // clear errors
|
||||
var options = parseArgs(argv, this.options),
|
||||
phantom
|
||||
var options = parseArgs(argv, this.options)
|
||||
// var phantom
|
||||
|
||||
if (options.version) {
|
||||
var pkg = require('../package.json')
|
||||
@ -147,12 +147,12 @@ cli.prototype.parse = function (argv, next) {
|
||||
}
|
||||
|
||||
function createCheckPhantom (_phantomPath) {
|
||||
var phantomPath = _phantomPath,
|
||||
phantomVersion
|
||||
var phantomPath = _phantomPath
|
||||
// var phantomVersion
|
||||
|
||||
return function checkPhantom (_next) {
|
||||
var next = _next || function () {},
|
||||
err
|
||||
var next = _next || function () { }
|
||||
var err
|
||||
|
||||
if (typeof phantomPath === 'undefined') {
|
||||
try {
|
||||
|
20
lib/index.js
20
lib/index.js
@ -1,7 +1,7 @@
|
||||
var os = require('os'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
spawn = require('child_process').spawn
|
||||
// var os = require('os')
|
||||
// var fs = require('fs')
|
||||
var path = require('path')
|
||||
var spawn = require('child_process').spawn
|
||||
|
||||
var mkdirp = require('mkdirp')
|
||||
|
||||
@ -10,11 +10,11 @@ var phantomscript = path.join(__dirname, 'phantomscript.js')
|
||||
module.exports = { process: processMermaid }
|
||||
|
||||
function processMermaid (files, _options, _next) {
|
||||
var options = _options || {},
|
||||
outputDir = options.outputDir || process.cwd(),
|
||||
outputSuffix = options.outputSuffix || '',
|
||||
next = _next || function () {},
|
||||
phantomArgs = [
|
||||
var options = _options || {}
|
||||
var outputDir = options.outputDir || process.cwd()
|
||||
var outputSuffix = options.outputSuffix || ''
|
||||
var next = _next || function () { }
|
||||
var phantomArgs = [
|
||||
phantomscript,
|
||||
outputDir,
|
||||
options.png,
|
||||
@ -35,7 +35,7 @@ function processMermaid (files, _options, _next) {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
phantom = spawn(options.phantomPath, phantomArgs)
|
||||
var phantom = spawn(options.phantomPath, phantomArgs)
|
||||
|
||||
phantom.on('exit', next)
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* https://github.com/filamentgroup/grunticon
|
||||
*/
|
||||
|
||||
phantom.onError = function (msg, trace) {
|
||||
window.phantom.onError = function (msg, trace) {
|
||||
var msgStack = ['PHANTOM ERROR: ' + msg]
|
||||
if (trace && trace.length) {
|
||||
msgStack.push('TRACE:')
|
||||
@ -21,16 +21,16 @@ phantom.onError = function (msg, trace) {
|
||||
})
|
||||
}
|
||||
system.stderr.write(msgStack.join('\n'))
|
||||
phantom.exit(1)
|
||||
window.phantom.exit(1)
|
||||
}
|
||||
|
||||
var system = require('system'),
|
||||
fs = require('fs'),
|
||||
webpage = require('webpage')
|
||||
var system = require('system')
|
||||
var fs = require('fs')
|
||||
var webpage = require('webpage')
|
||||
|
||||
var page = webpage.create(),
|
||||
files = system.args.slice(10, system.args.length),
|
||||
width = system.args[8]
|
||||
var page = webpage.create()
|
||||
var files = system.args.slice(10, system.args.length)
|
||||
var width = system.args[8]
|
||||
|
||||
if (typeof width === 'undefined' || width === 'undefined') {
|
||||
width = 1200
|
||||
@ -45,8 +45,8 @@ var options = {
|
||||
verbose: system.args[7] === 'true',
|
||||
width: width,
|
||||
outputSuffix: system.args[9]
|
||||
},
|
||||
log = logger(options.verbose)
|
||||
}
|
||||
var log = logger(options.verbose)
|
||||
options.sequenceConfig.useMaxWidth = false
|
||||
|
||||
page.content = [
|
||||
@ -69,12 +69,12 @@ page.onConsoleMessage = function (msg, lineNum, sourceId) {
|
||||
console.log('Num files to execute : ' + files.length)
|
||||
|
||||
files.forEach(function (file) {
|
||||
var contents = fs.read(file),
|
||||
filename = file.split(fs.separator).slice(-1),
|
||||
oParser = new DOMParser(),
|
||||
oDOM,
|
||||
svgContent,
|
||||
allElements
|
||||
var contents = fs.read(file)
|
||||
var filename = file.split(fs.separator).slice(-1)
|
||||
var oParser = new window.DOMParser()
|
||||
var oDOM
|
||||
var svgContent
|
||||
var allElements
|
||||
|
||||
console.log('ready to execute png: ' + filename + '.png ')
|
||||
|
||||
@ -112,7 +112,7 @@ files.forEach(function (file) {
|
||||
}
|
||||
|
||||
if (options.svg) {
|
||||
var serialize = new XMLSerializer()
|
||||
var serialize = new window.XMLSerializer()
|
||||
fs.write(outputPath + '.svg'
|
||||
, serialize.serializeToString(oDOM) + '\n'
|
||||
, 'w'
|
||||
@ -121,15 +121,15 @@ files.forEach(function (file) {
|
||||
}
|
||||
})
|
||||
|
||||
phantom.exit()
|
||||
window.phantom.exit()
|
||||
|
||||
function logger (_verbose) {
|
||||
var verbose = _verbose
|
||||
|
||||
return function (_message, _level) {
|
||||
var level = level,
|
||||
message = _message,
|
||||
log
|
||||
var level = _level
|
||||
var message = _message
|
||||
var log
|
||||
|
||||
log = level === 'error' ? system.stderr : system.stdout
|
||||
|
||||
@ -149,7 +149,7 @@ function traverse (obj) {
|
||||
if (node && node.hasChildNodes()) {
|
||||
var child = node.firstChild
|
||||
while (child) {
|
||||
if (child.nodeType === 1 && child.nodeName != 'SCRIPT') {
|
||||
if (child.nodeType === 1 && child.nodeName !== 'SCRIPT') {
|
||||
tree.push(child)
|
||||
visit(child)
|
||||
}
|
||||
@ -166,10 +166,10 @@ function resolveSVGElement (element) {
|
||||
xmlns: 'http://www.w3.org/2000/xmlns/',
|
||||
xlink: 'http://www.w3.org/1999/xlink',
|
||||
svg: 'http://www.w3.org/2000/svg'
|
||||
},
|
||||
doctype = '<!DOCTYPE svg:svg PUBLIC' +
|
||||
' "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"' +
|
||||
' "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
|
||||
}
|
||||
// var doctype = '<!DOCTYPE svg:svg PUBLIC' +
|
||||
// ' "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"' +
|
||||
// ' "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
|
||||
|
||||
element.setAttribute('version', '1.1')
|
||||
// removing attributes so they aren't doubled up
|
||||
@ -187,48 +187,48 @@ function resolveSVGElement (element) {
|
||||
function setSVGStyle (svg, css) {
|
||||
if (!css || !svg) { return }
|
||||
var styles = svg.getElementsByTagName('style')
|
||||
if (!styles || styles.length == 0) { return }
|
||||
if (!styles || styles.length === 0) { return }
|
||||
styles[0].textContent = css
|
||||
}
|
||||
|
||||
function resolveForeignObjects (element) {
|
||||
return
|
||||
var children,
|
||||
textElement,
|
||||
textSpan
|
||||
// return
|
||||
// var children
|
||||
// var textElement
|
||||
// var textSpan
|
||||
|
||||
if (element.tagName === 'foreignObject') {
|
||||
textElement = document.createElement('text')
|
||||
textSpan = document.createElement('tspan')
|
||||
textSpan.setAttribute(
|
||||
'style'
|
||||
, 'font-size: 11.5pt; font-family: "sans-serif";'
|
||||
)
|
||||
textSpan.setAttribute('x', 0)
|
||||
textSpan.setAttribute('y', 14.5)
|
||||
textSpan.textContent = element.textContent
|
||||
// if (element.tagName === 'foreignObject') {
|
||||
// textElement = document.createElement('text')
|
||||
// textSpan = document.createElement('tspan')
|
||||
// textSpan.setAttribute(
|
||||
// 'style'
|
||||
// , 'font-size: 11.5pt; font-family: "sans-serif";'
|
||||
// )
|
||||
// textSpan.setAttribute('x', 0)
|
||||
// textSpan.setAttribute('y', 14.5)
|
||||
// textSpan.textContent = element.textContent
|
||||
|
||||
textElement.appendChild(textSpan)
|
||||
element.parentElement.appendChild(textElement)
|
||||
element.parentElement.removeChild(element)
|
||||
}
|
||||
// textElement.appendChild(textSpan)
|
||||
// element.parentElement.appendChild(textElement)
|
||||
// element.parentElement.removeChild(element)
|
||||
// }
|
||||
}
|
||||
|
||||
// The sandboxed function that's executed in-page by phantom
|
||||
function executeInPage (data) {
|
||||
var xmlSerializer = new XMLSerializer(),
|
||||
contents = data.contents,
|
||||
sequenceConfig = JSON.stringify(data.sequenceConfig),
|
||||
ganttConfig = JSON.stringify(data.ganttConfig).replace(/"(function.*})"/, '$1'),
|
||||
toRemove,
|
||||
el,
|
||||
elContent,
|
||||
svg,
|
||||
svgValue,
|
||||
boundingBox,
|
||||
width,
|
||||
height,
|
||||
confWidth = data.confWidth
|
||||
var xmlSerializer = new window.XMLSerializer()
|
||||
var contents = data.contents
|
||||
var sequenceConfig = JSON.stringify(data.sequenceConfig)
|
||||
var ganttConfig = JSON.stringify(data.ganttConfig).replace(/"(function.*})"/, '$1')
|
||||
// var toRemove
|
||||
// var el
|
||||
// var elContent
|
||||
var svg
|
||||
var svgValue
|
||||
var boundingBox
|
||||
var width
|
||||
var height
|
||||
var confWidth = data.confWidth
|
||||
|
||||
var toRemove = document.getElementsByClassName('mermaid')
|
||||
if (toRemove && toRemove.length) {
|
||||
@ -244,17 +244,17 @@ function executeInPage (data) {
|
||||
|
||||
var config = {
|
||||
sequenceDiagram: JSON.parse(sequenceConfig),
|
||||
flowchart: {useMaxWidth: false},
|
||||
flowchart: { useMaxWidth: false },
|
||||
logLevel: 1
|
||||
}
|
||||
|
||||
mermaid.initialize(config)
|
||||
window.mermaid.initialize(config)
|
||||
|
||||
var sc = document.createElement('script')
|
||||
sc.appendChild(document.createTextNode('mermaid.ganttConfig = ' + ganttConfig + ';'))
|
||||
document.body.appendChild(sc)
|
||||
|
||||
mermaid.init()
|
||||
window.mermaid.init()
|
||||
|
||||
svg = document.querySelector('svg')
|
||||
|
||||
|
@ -4,12 +4,12 @@ var log = Logger.Log
|
||||
var relations = []
|
||||
|
||||
var classes
|
||||
var idCache
|
||||
// var idCache
|
||||
classes = {
|
||||
}
|
||||
|
||||
// Functions to be run after graph rendering
|
||||
var funs = []
|
||||
// var funs = []
|
||||
/**
|
||||
* Function called by parser when a node definition has been found.
|
||||
* @param id
|
||||
|
@ -367,9 +367,9 @@ module.exports.draw = function (text, id) {
|
||||
}
|
||||
|
||||
var relations = cDDb.getRelations()
|
||||
var i = 0
|
||||
// var i = 0
|
||||
relations.forEach(function (relation) {
|
||||
i = i + 1
|
||||
// i = i + 1
|
||||
log.info('tjoho' + getGraphId(relation.id1) + getGraphId(relation.id2) + JSON.stringify(relation))
|
||||
g.setEdge(getGraphId(relation.id1), getGraphId(relation.id2), {relation: relation})
|
||||
})
|
||||
|
@ -17,12 +17,12 @@
|
||||
// var classRenderer = proxyquire('./classRenderer', { '../../d3': d3 });
|
||||
// var testDom = require('testdom')('<html><body><div id="tst"></div></body></html>');
|
||||
|
||||
var classRenderer = require('./classRenderer')
|
||||
var parser = require('./parser/classDiagram').parser
|
||||
// var classRenderer = require('./classRenderer')
|
||||
// var parser = require('./parser/classDiagram').parser
|
||||
|
||||
describe('class diagram, ', function () {
|
||||
describe('when rendering a classDiagram', function () {
|
||||
var conf
|
||||
// var conf
|
||||
beforeEach(function () {
|
||||
/// /parser.yy = require('./classDb');
|
||||
/// /parser.yy.clear();
|
||||
@ -101,8 +101,8 @@ describe('class diagram, ', function () {
|
||||
})
|
||||
})
|
||||
it('it should handle one actor', function () {
|
||||
var str = 'classDiagram\n' +
|
||||
'Class01 --|> Class02'
|
||||
// var str = 'classDiagram\n' +
|
||||
// 'Class01 --|> Class02'
|
||||
|
||||
// classRenderer.draw(str,'tst');
|
||||
|
||||
|
@ -74,11 +74,11 @@ exports.addVertices = function (vert, g) {
|
||||
var labelTypeStr = ''
|
||||
if (conf.htmlLabels) {
|
||||
labelTypeStr = 'html'
|
||||
verticeText = verticeText.replace(/fa:fa[\w\-]+/g, function (s) {
|
||||
verticeText = verticeText.replace(/fa:fa[\w-]+/g, function (s) {
|
||||
return '<i class="fa ' + s.substring(3) + '"></i>'
|
||||
})
|
||||
} else {
|
||||
var svg_label = document.createElementNS('http://www.w3.org/2000/svg', 'text')
|
||||
var svgLabel = document.createElementNS('http://www.w3.org/2000/svg', 'text')
|
||||
|
||||
var rows = verticeText.split(/<br>/)
|
||||
|
||||
@ -89,11 +89,11 @@ exports.addVertices = function (vert, g) {
|
||||
tspan.setAttribute('dy', '1em')
|
||||
tspan.setAttribute('x', '1')
|
||||
tspan.textContent = rows[j]
|
||||
svg_label.appendChild(tspan)
|
||||
svgLabel.appendChild(tspan)
|
||||
}
|
||||
|
||||
labelTypeStr = 'svg'
|
||||
verticeText = svg_label
|
||||
verticeText = svgLabel
|
||||
|
||||
// verticeText = verticeText.replace(/<br\/>/g, '\n');
|
||||
// labelTypeStr = 'text';
|
||||
@ -135,7 +135,7 @@ exports.addVertices = function (vert, g) {
|
||||
_shape = 'rect'
|
||||
}
|
||||
// Add the node
|
||||
g.setNode(vertice.id, {labelType: labelTypeStr, shape: _shape, label: verticeText, rx: radious, ry: radious, 'class': classStr, style: style, id: vertice.id})
|
||||
g.setNode(vertice.id, { labelType: labelTypeStr, shape: _shape, label: verticeText, rx: radious, ry: radious, 'class': classStr, style: style, id: vertice.id })
|
||||
})
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ exports.getClasses = function (text, isDot) {
|
||||
|
||||
// Add default class if undefined
|
||||
if (typeof (classes.default) === 'undefined') {
|
||||
classes.default = {id: 'default'}
|
||||
classes.default = { id: 'default' }
|
||||
// classes.default.styles = ['fill:#ffa','stroke:#666','stroke-width:3px'];
|
||||
classes.default.styles = []
|
||||
classes.default.clusterStyles = ['rx:4px', 'fill: rgb(255, 255, 222)', 'rx: 4px', 'stroke: rgb(170, 170, 51)', 'stroke-width: 1px']
|
||||
@ -326,18 +326,19 @@ exports.draw = function (text, id, isDot) {
|
||||
exports.addEdges(edges, g)
|
||||
|
||||
// Create the renderer
|
||||
var render = new dagreD3.render()
|
||||
var Render = dagreD3.render
|
||||
var render = new Render()
|
||||
|
||||
// Add custom shape for rhombus type of boc (decision)
|
||||
render.shapes().question = function (parent, bbox, node) {
|
||||
var w = bbox.width,
|
||||
h = bbox.height,
|
||||
s = (w + h) * 0.8,
|
||||
points = [
|
||||
{x: s / 2, y: 0},
|
||||
{x: s, y: -s / 2},
|
||||
{x: s / 2, y: -s},
|
||||
{x: 0, y: -s / 2}
|
||||
var w = bbox.width
|
||||
var h = bbox.height
|
||||
var s = (w + h) * 0.8
|
||||
var points = [
|
||||
{ x: s / 2, y: 0 },
|
||||
{ x: s, y: -s / 2 },
|
||||
{ x: s / 2, y: -s },
|
||||
{ x: 0, y: -s / 2 }
|
||||
]
|
||||
var shapeSvg = parent.insert('polygon', ':first-child')
|
||||
.attr('points', points.map(function (d) {
|
||||
@ -354,14 +355,14 @@ exports.draw = function (text, id, isDot) {
|
||||
|
||||
// Add custom shape for box with inverted arrow on left side
|
||||
render.shapes().rect_left_inv_arrow = function (parent, bbox, node) {
|
||||
var w = bbox.width,
|
||||
h = bbox.height,
|
||||
points = [
|
||||
{x: -h / 2, y: 0},
|
||||
{x: w, y: 0},
|
||||
{x: w, y: -h},
|
||||
{x: -h / 2, y: -h},
|
||||
{x: 0, y: -h / 2}
|
||||
var w = bbox.width
|
||||
var h = bbox.height
|
||||
var points = [
|
||||
{ x: -h / 2, y: 0 },
|
||||
{ x: w, y: 0 },
|
||||
{ x: w, y: -h },
|
||||
{ x: -h / 2, y: -h },
|
||||
{ x: 0, y: -h / 2 }
|
||||
]
|
||||
var shapeSvg = parent.insert('polygon', ':first-child')
|
||||
.attr('points', points.map(function (d) {
|
||||
@ -376,14 +377,14 @@ exports.draw = function (text, id, isDot) {
|
||||
|
||||
// Add custom shape for box with inverted arrow on right side
|
||||
render.shapes().rect_right_inv_arrow = function (parent, bbox, node) {
|
||||
var w = bbox.width,
|
||||
h = bbox.height,
|
||||
points = [
|
||||
{x: 0, y: 0},
|
||||
{x: w + h / 2, y: 0},
|
||||
{x: w, y: -h / 2},
|
||||
{x: w + h / 2, y: -h},
|
||||
{x: 0, y: -h}
|
||||
var w = bbox.width
|
||||
var h = bbox.height
|
||||
var points = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: w + h / 2, y: 0 },
|
||||
{ x: w, y: -h / 2 },
|
||||
{ x: w + h / 2, y: -h },
|
||||
{ x: 0, y: -h }
|
||||
]
|
||||
var shapeSvg = parent.insert('polygon', ':first-child')
|
||||
.attr('points', points.map(function (d) {
|
||||
@ -425,7 +426,7 @@ exports.draw = function (text, id, isDot) {
|
||||
.attr('markerHeight', 6)
|
||||
.attr('orient', 'auto')
|
||||
|
||||
var path = marker.append('path')
|
||||
marker.append('path')
|
||||
.attr('d', 'M 0 0 L 10 5 L 0 10 z')
|
||||
.attr('class', 'arrowheadPath')
|
||||
.style('stroke-width', 1)
|
||||
@ -446,7 +447,7 @@ exports.draw = function (text, id, isDot) {
|
||||
return graph.getTooltip(this.id)
|
||||
})
|
||||
|
||||
/*
|
||||
/*
|
||||
var xPos = document.querySelectorAll('.clusters rect')[0].x.baseVal.value;
|
||||
var width = document.querySelectorAll('.clusters rect')[0].width.baseVal.value;
|
||||
var cluster = d3.selectAll('.cluster');
|
||||
@ -457,7 +458,7 @@ exports.draw = function (text, id, isDot) {
|
||||
te.attr('id', 'apa12');
|
||||
te.style('text-anchor', 'middle');
|
||||
te.text('Title for cluster');
|
||||
*/
|
||||
*/
|
||||
if (conf.useMaxWidth) {
|
||||
// Center the graph
|
||||
svg.attr('height', '100%')
|
||||
@ -512,8 +513,8 @@ exports.draw = function (text, id, isDot) {
|
||||
// Add label rects for non html labels
|
||||
if (!conf.htmlLabels) {
|
||||
var labels = document.querySelectorAll('#' + id + ' .edgeLabel .label')
|
||||
var i
|
||||
for (i = 0; i < labels.length; i++) {
|
||||
var k
|
||||
for (k = 0; k < labels.length; k++) {
|
||||
var label = labels[i]
|
||||
|
||||
// Get dimensions of label
|
||||
|
Loading…
x
Reference in New Issue
Block a user