const defaults = {
title: '',
titleClass: 'ct-title',
textAnchor: 'middle',
padding: {
x: 0,
y: 10
}
}
function vctTitle (options) {
options = Object.assign({}, defaults, options)
return function ctTitle (chart, Chartist) {
chart.on('created', function (data) {
const xPos = (data.chartRect.x2 - data.chartRect.x1) / 2 + data.chartRect.x1 - options.padding.x
const yPos = data.chartRect.y2 - options.padding.y
const title = new Chartist.Svg('text')
title.addClass(options.titleClass)
title.text(options.title)
title.attr({
x: xPos,
y: yPos,
'text-anchor': options.textAnchor
})
data.svg.append(title, true)
})
}
}
export default vctTitle
|