mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-30 12:49:41 +02:00
Fix for issue #204, added width option to the CLI. Default value for width is 1200.
Added logger using es6 syntax
This commit is contained in:
10
lib/cli.js
10
lib/cli.js
@@ -27,6 +27,7 @@ function cli(options) {
|
||||
, sequenceConfig: 'c'
|
||||
, ganttConfig: 'g'
|
||||
, css: 't'
|
||||
, width: 'w'
|
||||
}
|
||||
, 'boolean': ['help', 'png', 'svg']
|
||||
, 'string': ['outputDir']
|
||||
@@ -50,6 +51,7 @@ function cli(options) {
|
||||
, " -g --ganttConfig Specify the path to the file with the configuration to be applied in the gantt diagram"
|
||||
, " -h --help Show this message"
|
||||
, " -v --verbose Show logging"
|
||||
, " -w --width width of the generated png (number)"
|
||||
, " --version Print version and quit"
|
||||
]
|
||||
|
||||
@@ -97,11 +99,8 @@ cli.prototype.parse = function(argv, next) {
|
||||
options.sequenceConfig = checkConfig(options.sequenceConfig)
|
||||
}
|
||||
|
||||
|
||||
if (options.ganttConfig) {
|
||||
console.log('Got conf1'+options.ganttConfig);
|
||||
options.ganttConfig = checkConfig(options.ganttConfig)
|
||||
console.log('Got conf'+options.ganttConfig);
|
||||
}
|
||||
|
||||
if (options.css) {
|
||||
@@ -114,6 +113,11 @@ cli.prototype.parse = function(argv, next) {
|
||||
options.css = fs.readFileSync(path.join(__dirname, '..', 'dist', 'mermaid.css'))
|
||||
}
|
||||
|
||||
// set svg/png flags appropriately
|
||||
if(!options.width){
|
||||
options.width = 1200;
|
||||
}
|
||||
|
||||
this.checkPhantom = createCheckPhantom(options.phantomPath)
|
||||
|
||||
this.checkPhantom(function(err, path) {
|
||||
|
@@ -22,6 +22,7 @@ function processMermaid(files, _options, _next) {
|
||||
, options.sequenceConfig
|
||||
, options.ganttConfig
|
||||
, options.verbose
|
||||
, options.width
|
||||
]
|
||||
|
||||
files.forEach(function(file) {
|
||||
|
@@ -30,8 +30,14 @@ var system = require('system')
|
||||
|
||||
|
||||
var page = webpage.create()
|
||||
, files = phantom.args.slice(7, phantom.args.length)
|
||||
, options = {
|
||||
, files = phantom.args.slice(8, phantom.args.length)
|
||||
, width = phantom.args[7]
|
||||
|
||||
if(typeof width === 'undefined'){
|
||||
width = 1200;
|
||||
}
|
||||
|
||||
var options = {
|
||||
outputDir: phantom.args[0]
|
||||
, png: phantom.args[1] === 'true' ? true : false
|
||||
, svg: phantom.args[2] === 'true' ? true : false
|
||||
@@ -39,6 +45,7 @@ var page = webpage.create()
|
||||
, sequenceConfig: phantom.args[4]
|
||||
, ganttConfig: phantom.args[5]
|
||||
, verbose: phantom.args[6] === 'true' ? true : false
|
||||
, width: width
|
||||
}
|
||||
, log = logger(options.verbose)
|
||||
|
||||
@@ -80,7 +87,8 @@ files.forEach(function(file) {
|
||||
svgContent = page.evaluate(executeInPage, {
|
||||
contents : contents,
|
||||
ganttConfig : options.ganttConfig,
|
||||
sequenceConfig : options.sequenceConfig
|
||||
sequenceConfig : options.sequenceConfig,
|
||||
confWidth : options.width
|
||||
})
|
||||
oDOM = oParser.parseFromString(svgContent, "text/xml")
|
||||
|
||||
@@ -213,6 +221,7 @@ function executeInPage(data) {
|
||||
, boundingBox
|
||||
, width
|
||||
, height
|
||||
, confWidth = data.confWidth
|
||||
|
||||
toRemove = document.getElementsByClassName('mermaid')
|
||||
if (toRemove && toRemove.length) {
|
||||
@@ -257,7 +266,8 @@ function executeInPage(data) {
|
||||
document.body.appendChild(sc)
|
||||
}
|
||||
|
||||
|
||||
//console.log(document.head.innerHTML);
|
||||
//console.log(document.body.innerHTML);
|
||||
mermaid.init();
|
||||
|
||||
svg = document.querySelector('svg')
|
||||
@@ -266,25 +276,27 @@ function executeInPage(data) {
|
||||
width = boundingBox.width * 1.5; // adding the scale factor for consistency with output in chrome browser
|
||||
height = boundingBox.height * 1.5; // adding the scale factor for consistency with output in chrome browser
|
||||
|
||||
var scalefactor = confWidth/(width-8);
|
||||
|
||||
// resizing the body to fit the svg
|
||||
document.body.setAttribute(
|
||||
'style'
|
||||
, 'width: ' + width + '; height: ' + height + ';'
|
||||
, 'width: ' + (confWidth-8) + '; height: ' + (height*scalefactor) + ';'
|
||||
)
|
||||
// resizing the svg via css for consistent display
|
||||
svg.setAttribute(
|
||||
'style'
|
||||
, 'width: ' + width + '; height: ' + height + ';'
|
||||
, 'width: ' + (confWidth-8) + '; height: ' + (height*scalefactor) + ';'
|
||||
)
|
||||
|
||||
// set witdth and height attributes used to set the viewport when rending png image
|
||||
svg.setAttribute(
|
||||
'width'
|
||||
, width
|
||||
, confWidth
|
||||
)
|
||||
svg.setAttribute(
|
||||
'height'
|
||||
, height
|
||||
, height*scalefactor
|
||||
)
|
||||
|
||||
svgValue = xmlSerializer.serializeToString(svg)
|
||||
|
Reference in New Issue
Block a user