{"version":3,"sources":["chartist-plugin-accessibility.js"],"names":["root","factory","define","amd","Chartist","returnExportsGlobal","exports","module","require","this","window","document","Element","name","attrs","parent","elem","e","children","push","_attrs","_parent","text","after","_textAfter","_textBefore","toString","Object","keys","filter","attrName","bind","map","join","concat","child","defaultOptions","caption","seriesHeader","valueTransform","noop","summary","undefined","class","elementId","Date","visuallyHiddenStyles","plugins","ctAccessibility","options","extend","chart","on","data","containerElement","svg","_node","parentNode","previousElement","querySelector","removeChild","attr","aria-hidden","element","style","id","tBody","firstRow","Pie","dataArray","getDataArray","optionsProvider","getCurrentOptions","reverseData","labels","forEach","scope","role","row","dataValue","normalizedData","series","index","seriesName","appendChild","DOMParser","parseFromString","getElementById"],"mappings":";;;;;;CAAC,SAAUA,EAAMC,GACO,kBAAXC,SAAyBA,OAAOC,IAEzCD,QAAQ,YAAa,SAAUE,GAC7B,MAAQJ,GAAKK,oBAAsBJ,EAAQG,KAEjB,gBAAZE,SAIhBC,OAAOD,QAAUL,EAAQO,QAAQ,aAEjCR,EAAK,oCAAsCC,EAAQG,WAErDK,KAAM,SAAUL,GAiKhB,MA1JC,UAAUM,EAAQC,EAAUP,GAC3B,YAGA,SAASQ,GAAQC,EAAMC,EAAOC,GAC5B,OACEC,KAAM,SAAUH,EAAMC,GACpB,GAAIG,GAAIL,EAAQC,EAAMC,EAAOL,KAE7B,OADAA,MAAKS,SAASC,KAAKF,GACZA,GAETC,YACAL,KAAMA,EACNO,OAAQN,MACRO,QAASN,EACTA,OAAQ,WACN,MAAON,MAAKY,SAEdP,MAAO,SAAUA,GAEf,MADAL,MAAKW,OAASN,EACPL,MAETa,KAAM,SAAUA,EAAMC,GAMpB,MALIA,GACFd,KAAKe,WAAaF,EAElBb,KAAKgB,YAAcH,EAEdb,MAETiB,SAAU,WACR,GAAIZ,GAAQa,OAAOC,KAAKnB,KAAKW,QAAQS,OAAO,SAAUC,GACpD,MAAOrB,MAAKW,OAAOU,IAAuC,IAA1BrB,KAAKW,OAAOU,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KqB,OAAOC,QAAQ,SAAUrD,GAClC6C,EACGnD,KAAK,MACJ4D,MAAO,MACPC,KAAM,iBAEPvD,KAAKA,IAGV,IAAIwD,GAAMZ,EAAMlD,KAAK,KAGrBqD,GAAUM,QAAQ,SAAUI,GAC1BD,EAAI9D,KAAK,MAAMM,KAAK2B,EAAQV,eAAewC,UAGxC,CAEL,GAAIC,GAAiB5E,EAASkE,aAAanB,EAAME,KAAMF,EAAMoB,gBAAgBC,oBAAoBC,cAGhGxB,EAAQX,cAAcJ,OAAOiB,EAAME,KAAKqB,QAAQC,QAAQ,SAAUrD,GACjE6C,EACGnD,KAAK,MACJ4D,MAAO,MACPC,KAAM,iBAEPvD,KAAKA,KAIV6B,EAAME,KAAK4B,OAAON,QAAQ,SAAUM,EAAQC,GAC1C,GAAIC,GAAaF,EAAOpE,OAASqE,EAAQ,EAAG,YAAYjD,KAAK,IAEzD6C,EAAMZ,EAAMlD,KAAK,KAErB8D,GAAI9D,KAAK,MACP4D,MAAO,MACPC,KAAM,cACLvD,KAAK6D,GAERH,EAAeE,GAAOP,QAAQ,SAAUI,GACtCD,EAAI9D,KAAK,MAAMM,KAAK2B,EAAQV,eAAewC,QAMjDzB,EAAiB8B,aAAY,GAAIC,YAAYC,gBAAgBvB,EAAQrC,WAAY,aAAa6D,eAAe3C,SAKnHlC,OAAQC,SAAUP,GAEbA,EAAS2C,QAAQC","file":"chartist-plugin-accessibility.min.js","sourcesContent":["(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define([\"chartist\"], function (Chartist) {\n return (root.returnExportsGlobal = factory(Chartist));\n });\n } else if (typeof exports === 'object') {\n // Node. Does not work with strict CommonJS, but\n // only CommonJS-like enviroments that support module.exports,\n // like Node.\n module.exports = factory(require(\"chartist\"));\n } else {\n root['Chartist.plugins.ctAccessibility'] = factory(Chartist);\n }\n}(this, function (Chartist) {\n\n /**\n * Chartist.js plugin that generates visually hidden tables for better accessibility. It's also possible to initialize a Chart with data from an existing table.\n *\n */\n /* global Chartist */\n (function (window, document, Chartist) {\n 'use strict';\n\n // A simple recursive DOM string builder\n function Element(name, attrs, parent) {\n return {\n elem: function (name, attrs) {\n var e = Element(name, attrs, this);\n this.children.push(e);\n return e;\n },\n children: [],\n name: name,\n _attrs: attrs || {},\n _parent: parent,\n parent: function () {\n return this._parent;\n },\n attrs: function (attrs) {\n this._attrs = attrs;\n return this;\n },\n text: function (text, after) {\n if (after) {\n this._textAfter = text;\n } else {\n this._textBefore = text;\n }\n return this;\n },\n toString: function () {\n var attrs = Object.keys(this._attrs).filter(function (attrName) {\n return this._attrs[attrName] || this._attrs[attrName] === 0;\n }.bind(this)).map(function (attrName) {\n return [attrName, '=\"', this._attrs[attrName], '\"'].join('');\n }.bind(this)).join(' ');\n\n return ['<', this.name, attrs ? ' ' + attrs : '', '>', this._textBefore].concat(this.children.map(function (child) {\n return child.toString();\n })).concat([this._textAfter, '']).join('');\n }\n };\n }\n\n var defaultOptions = {\n caption: 'A graphical chart',\n seriesHeader: 'Series name',\n valueTransform: Chartist.noop,\n summary: undefined,\n class: undefined,\n elementId: function () {\n return 'ct-accessibility-table-' + (+new Date());\n },\n visuallyHiddenStyles: 'position:absolute;left:-10000px;top:auto;width:1px;height:1px;overflow:hidden;'\n };\n\n Chartist.plugins = Chartist.plugins || {};\n\n Chartist.plugins.ctAccessibility = function (options) {\n\n options = Chartist.extend({}, defaultOptions, options);\n\n return function ctAccessibility(chart) {\n var elementId = typeof options.elementId === 'function' ? options.elementId() : options.elementId;\n\n chart.on('created', function (data) {\n var containerElement = data.svg._node.parentNode;\n\n var previousElement = containerElement.querySelector('#' + elementId);\n if(previousElement) {\n containerElement.removeChild(previousElement);\n }\n\n // As we are now compensating the SVG graphic with the chart with an accessibility table, we hide it for ARIA\n data.svg.attr({\n 'aria-hidden': 'true'\n });\n\n // Create wrapper element\n var element = Element('div', {\n style: options.visuallyHiddenStyles,\n id: elementId\n });\n\n // Create table body with caption\n var tBody = element.elem('table', {\n summary: options.summary,\n class: options.class\n }).elem('caption')\n .text(options.caption)\n .elem('tbody');\n\n var firstRow = tBody.elem('tr');\n\n if (chart instanceof Chartist.Pie) {\n // For pie charts we have only column headers and one series\n var dataArray = Chartist.getDataArray(chart.data, chart.optionsProvider.getCurrentOptions().reverseData);\n\n // First render the column headers with our pie chart labels\n chart.data.labels.forEach(function (text) {\n firstRow\n .elem('th', {\n scope: 'col',\n role: 'columnheader'\n })\n .text(text);\n });\n\n var row = tBody.elem('tr');\n\n // Add all data fields of our pie chart to the row\n dataArray.forEach(function (dataValue) {\n row.elem('td').text(options.valueTransform(dataValue));\n });\n\n } else {\n // For line and bar charts we have multiple series and therefore also row headers\n var normalizedData = Chartist.getDataArray(chart.data, chart.optionsProvider.getCurrentOptions().reverseData);\n\n // Add column headers inclusing the series column header for the row headers\n [options.seriesHeader].concat(chart.data.labels).forEach(function (text) {\n firstRow\n .elem('th', {\n scope: 'col',\n role: 'columnheader'\n })\n .text(text);\n });\n\n // Add all data rows including their row headers\n chart.data.series.forEach(function (series, index) {\n var seriesName = series.name || [index + 1, '. Series'].join('');\n\n var row = tBody.elem('tr');\n\n row.elem('th', {\n scope: 'row',\n role: 'rowheader'\n }).text(seriesName);\n\n normalizedData[index].forEach(function (dataValue) {\n row.elem('td').text(options.valueTransform(dataValue));\n });\n });\n }\n\n // Update invisible table in DOM and update table element with newly created table\n containerElement.appendChild(new DOMParser().parseFromString(element.toString(), 'text/html').getElementById(elementId));\n });\n };\n };\n\n }(window, document, Chartist));\n\n return Chartist.plugins.ctAccessibility;\n\n}));\n"]}