From 174d457aa9ef04eb4a9cbf0c8073b2206511258c Mon Sep 17 00:00:00 2001 From: Thach Lockevn Date: Wed, 1 Nov 2017 16:13:38 +0700 Subject: [PATCH] add wrapHtml option set wrapHtml = false, the output of generate() will be the SVG markup only (without the wrapping div) Use wrapHtml = false, legend = false, we can have pure SVG output ignore .vs from Visual Studio IDE fix typo in README --- .gitignore | 1 + README.md | 4 ++++ lib/index.js | 7 ++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 66fc316..d6d147f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ !node_modules/canvas.js bundle.js +/.vs diff --git a/README.md b/README.md index 07289f3..633b61d 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,10 @@ __Arguments__ - `legend` - A boolean used to determine whether a legend should be generated. Defaults to `true`. + - `wrapHtml` - A boolean used to determine whether a `
` wrapping the SVG should be generated. Defaults to `true`. + + - A pure SVG will be generated if set both `legend` and `wrapHtml` to `false`. + - `data` - An object containing data used to generate the chart. The structure of this object depends on chart `type`. Please refer to the [Chartist Api Documentation](http://gionkunz.github.io/chartist-js/api-documentation.html) for complete details. diff --git a/lib/index.js b/lib/index.js index 51fe143..151ea3d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -25,11 +25,12 @@ const generate = R.curryN(3, co.wrap(function * (type, options, data) { // process options options = is.function(options) ? options(Chartist) : options; if (is.not.json(options)) throw new TypeError('options must be an object or a function that returns an object.'); - options = Ru.defaults({ legend: true }, options); + options = Ru.defaults({ legend: true, wrapHtml: true }, options); // create chart const chart = yield generateChart(Chartist, window, type, options, data); - const legend = options.legend ? generateLegend(data) : ''; - return `
${chart}${legend}
`; + const legend = options.legend ? generateLegend(data) : ''; + + return options.wrapHtml ? `
${chart}${legend}
` : `${chart}${legend}`; })); module.exports = generate;