diff --git a/README.md b/README.md index 07289f3..00f62f3 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,8 @@ __Arguments__ - `meta` - Meta data is serialized and written to a ct:meta attribute on the series group. +- `divWrap` - A boolean, if set to `true` returns svg wrapped inside a div. If set to `false`, returns pure svg without any wrapping div. By default it is set to `true`. + Examples: ```js @@ -162,7 +164,7 @@ co(function * () { {name: 'Series 1', value: [1, 2, 3, 4, 5]}, {name: 'Series 2', value: [3, 4, 5, 6, 7]} ] - }); + }/* ,true/false (divWrap) */); }) ``` @@ -183,7 +185,7 @@ co(function * () { {name: 'Series 1', value: [1, 2, 3, 4, 5]}, {name: 'Series 2', value: [3, 4, 5, 6, 7]} ] - }); + }/* ,true/false (divWrap) */); }) ``` @@ -198,6 +200,6 @@ co(function * () { {name: 'Series 1', value: 15 }, {name: 'Series 2', value: 25 } ] - }); + }/* ,true/false (divWrap) */); }) ``` diff --git a/lib/index.js b/lib/index.js index 51fe143..202a3d7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -15,21 +15,22 @@ const Ru = require('@panosoft/ramda-utils'); * Chartist options + axis*.title * @param {Object} data * Chartist data object - * + * @param {Boolean} divWrap + * true, false * @return {Promise{String}} svg */ -const generate = R.curryN(3, co.wrap(function * (type, options, data) { +const generate = R.curryN(3, co.wrap(function * (type, options, data, divWrap = true) { const environment = yield chartist.initialize(); const window = environment.window; const Chartist = environment.Chartist; // 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, divWrap }, options); // create chart const chart = yield generateChart(Chartist, window, type, options, data); const legend = options.legend ? generateLegend(data) : ''; - return `
${chart}${legend}
`; + return options.divWrap ? `
${chart}${legend}
` : `${chart}${legend}`; })); module.exports = generate;