{"version":3,"names":[],"mappings":"","sources":["chartist-plugin-fill-donut.js"],"sourcesContent":["/**\r\n * Chartist.js plugin to pre fill donuts with animations\r\n * author: moxx\r\n * author-url: https://github.com/moxx/chartist-plugin-fill-donut\r\n *\r\n */\r\n(function (document, Chartist) {\r\n 'use strict';\r\n\r\n var defaultOptions = {\r\n fillClass: 'ct-fill-donut',\r\n label: {\r\n html: 'div',\r\n class: 'ct-fill-donut-label'\r\n },\r\n items: [{}]\r\n };\r\n\r\n Chartist.plugins = Chartist.plugins || {};\r\n Chartist.plugins.fillDonut = function (options) {\r\n options = Chartist.extend({}, defaultOptions, options);\r\n return function fillDonut(chart) {\r\n if (chart instanceof Chartist.Pie) {\r\n var $chart = chart.container;\r\n $chart.style.position = 'relative';\r\n var $svg;\r\n\r\n var drawDonut = function(data) {\r\n if (data.type === 'slice') {\r\n if (data.index === 0) {\r\n $svg = $chart.querySelector('svg');\r\n }\r\n\r\n var $clone = data.group._node.cloneNode(true);\r\n options.fillClass.split(\" \").forEach(function (className) {\r\n $clone.setAttribute('class', $clone.getAttribute('class') + ' ' + className);\r\n });\r\n\r\n [].forEach.call($clone.querySelectorAll('path'), function (el) {\r\n [].forEach.call(el.querySelectorAll('animate'), function (node) {\r\n node.parentNode.removeChild(node);\r\n });\r\n\r\n el.removeAttribute('stroke-dashoffset');\r\n });\r\n\r\n $svg.insertBefore($clone, $svg.childNodes[0]);\r\n\r\n }\r\n };\r\n\r\n chart.on('draw', function (data) {\r\n drawDonut(data);\r\n });\r\n\r\n chart.on('created', function (data) {\r\n var itemIndex = 0;\r\n\r\n if (chart.options.fillDonutOptions) {\r\n options = Chartist.extend({}, options, chart.options.fillDonutOptions);\r\n drawDonut(data);\r\n }\r\n\r\n [].forEach.call(options.items, function (thisItem) {\r\n var $wrapper = document.createElement(options.label.html);\r\n options.label.class.split(\" \").forEach(function (className) {\r\n if ($wrapper.classList) {\r\n $wrapper.classList.add(className);\r\n } else {\r\n $wrapper.className += ' ' + className;\r\n }\r\n });\r\n var item = Chartist.extend({}, {\r\n class: '',\r\n id: '',\r\n content: 'fillText',\r\n position: 'center', //bottom, top, left, right\r\n offsetY: 0, //top, bottom in px\r\n offsetX: 0 //left, right in px\r\n }, thisItem);\r\n\r\n\r\n if (item.id.length > 0) {\r\n $wrapper.setAttribute('id', item.id);\r\n }\r\n if (item.class.length > 0) {\r\n $wrapper.setAttribute('class', item.class);\r\n }\r\n\r\n [].forEach.call($chart.querySelectorAll('*[data-fill-index$=\"fdid-' + itemIndex + '\"]'), function (node) {\r\n node.parentNode.removeChild(node);\r\n });\r\n $wrapper.setAttribute('data-fill-index', 'fdid-' + itemIndex);\r\n itemIndex += 1;\r\n\r\n $wrapper.insertAdjacentHTML('beforeend', item.content);\r\n $wrapper.style.position = 'absolute';\r\n $chart.appendChild($wrapper);\r\n\r\n var cWidth = Math.ceil($chart.offsetWidth / 2);\r\n var cHeight = Math.ceil($chart.clientHeight / 2);\r\n var wWidth = Math.ceil($wrapper.offsetWidth / 2);\r\n var wHeight = Math.ceil($wrapper.clientHeight / 2);\r\n\r\n var style = {\r\n bottom: {\r\n bottom: 0 + item.offsetY + \"px\",\r\n left: (cWidth - wWidth) + item.offsetX + \"px\"\r\n },\r\n top: {\r\n top: 0 + item.offsetY + \"px\",\r\n left: (cWidth - wWidth) + item.offsetX + \"px\"\r\n },\r\n left: {\r\n top: (cHeight - wHeight) + item.offsetY + \"px\",\r\n left: 0 + item.offsetX + \"px\"\r\n },\r\n right: {\r\n top: (cHeight - wHeight) + item.offsetY + \"px\",\r\n right: 0 + item.offsetX + \"px\"\r\n },\r\n center: {\r\n top: (cHeight - wHeight) + item.offsetY + \"px\",\r\n left: (cWidth - wWidth) + item.offsetX + \"px\"\r\n }\r\n };\r\n\r\n Chartist.extend($wrapper.style, style[item.position]);\r\n });\r\n });\r\n }\r\n };\r\n };\r\n}(document, Chartist)); // jshint ignore:line\r\n"],"file":"chartist-plugin-fill-donut.js"}