all files / src/ index.js

100% Statements 12/12
100% Branches 0/0
100% Functions 3/3
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                                          
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