Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) */);
})
```

Expand All @@ -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) */);
})
```

Expand All @@ -198,6 +200,6 @@ co(function * () {
{name: 'Series 1', value: 15 },
{name: 'Series 2', value: 25 }
]
});
}/* ,true/false (divWrap) */);
})
```
9 changes: 5 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<div class="ct-chart">${chart}${legend}</div>`;
return options.divWrap ? `<div class="ct-chart">${chart}${legend}</div>` : `${chart}${legend}`;
}));

module.exports = generate;