/*! Chartkick.js v5.0.1 | MIT License */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Chartkick=e()}(this,(function(){"use strict";function t(t){return"[object Array]"===Object.prototype.toString.call(t)}function e(t){return t instanceof Function}function r(t){return"[object Object]"===Object.prototype.toString.call(t)&&!e(t)&&t instanceof Object}function n(e,o){for(var a in o)"__proto__"!==a&&(r(o[a])||t(o[a])?(r(o[a])&&!r(e[a])&&(e[a]={}),t(o[a])&&!t(e[a])&&(e[a]=[]),n(e[a],o[a])):void 0!==o[a]&&(e[a]=o[a]))}function o(t,e){var r={};return n(r,t),n(r,e),r}var a=/^(\d\d\d\d)(?:-)?(\d\d)(?:-)?(\d\d)$/i;function i(t){return""+t}function s(t){return parseFloat(t)}function l(t){if(t instanceof Date)return t;if("number"==typeof t)return new Date(1e3*t);var e=i(t),r=e.match(a);if(r){var n=parseInt(r[1],10),o=parseInt(r[2],10)-1,s=parseInt(r[3],10);return new Date(n,o,s)}var l=e.replace(/ /,"T").replace(" ","").replace("UTC","Z");return new Date(Date.parse(l)||e)}function c(e){if(t(e))return e;var r=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.push([n,e[n]]);return r}function p(t,e,r,n,a,i,s,l){return function(c,p,u){var d=c.data,h=o({},t);return h=o(h,u||{}),(c.singleSeriesFormat||"legend"in p)&&e(h,p.legend,c.singleSeriesFormat),p.title&&r(h,p.title),"min"in p?n(h,p.min):function(t){for(var e=0;e=6}function v(t){return"number"==typeof t}var g=["bytes","KB","MB","GB","TB","PB","EB"];function b(t,e,r,n){t=t||"",r.prefix&&(e<0&&(e*=-1,t+="-"),t+=r.prefix);var o=r.suffix||"",a=r.precision,s=r.round;if(r.byteScale){var l=e>=0;l||(e*=-1);var c,p=n?r.byteScale:e;p>=0x1000000000000000?(e/=0x1000000000000000,c=6):p>=0x4000000000000?(e/=0x4000000000000,c=5):p>=1099511627776?(e/=1099511627776,c=4):p>=1073741824?(e/=1073741824,c=3):p>=1048576?(e/=1048576,c=2):p>=1024?(e/=1024,c=1):c=0,void 0===a&&void 0===s&&(e>=1023.5&&c=1e3?4:3),o=" "+g[c],l||(e*=-1)}if(void 0!==a&&void 0!==s)throw Error("Use either round or precision, not both");if(!n&&(void 0!==a&&(e=e.toPrecision(a),r.zeros||(e=parseFloat(e))),void 0!==s))if(s<0){var u=Math.pow(10,-1*s);e=parseInt((1*e/u).toFixed(0))*u}else e=e.toFixed(s),r.zeros||(e=parseFloat(e));if(r.thousands||r.decimal){var d=(e=i(e)).split(".");e=d[0],r.thousands&&(e=e.replace(/\B(?=(\d{3})+(?!\d))/g,r.thousands)),d.length>1&&(e+=(r.decimal||".")+d[1])}return t+e+o}function x(t,e,r){return r in e?e[r]:r in t.options?t.options[r]:null}var w={maintainAspectRatio:!1,animation:!1,plugins:{legend:{},tooltip:{displayColors:!1,callbacks:{}},title:{font:{size:20},color:"#333"}},interaction:{}},C={scales:{y:{ticks:{maxTicksLimit:4},title:{font:{size:16},color:"#333"},grid:{}},x:{grid:{drawOnChartArea:!1},title:{font:{size:16},color:"#333"},time:{},ticks:{}}}},_=["#3366CC","#DC3912","#FF9900","#109618","#990099","#3B3EAC","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#329262","#5574A6","#651067"];function k(t,e,r){void 0!==e?(t.plugins.legend.display=!!e,e&&!0!==e&&(t.plugins.legend.position=e)):r&&(t.plugins.legend.display=!1)}function S(t,e){t.plugins.title.display=!0,t.plugins.title.text=e}function A(t,e){null!==e&&(t.scales.x.min=s(e))}function T(t,e){t.scales.x.max=s(e)}function D(t,e){t.scales.x.stacked=!!e,t.scales.y.stacked=!!e}function O(t,e){t.scales.x.title.display=!0,t.scales.x.title.text=e}function L(t,e){t.scales.y.title.display=!0,t.scales.y.title.text=e}function z(t,e){var r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return r?"rgba("+parseInt(r[1],16)+", "+parseInt(r[2],16)+", "+parseInt(r[3],16)+", "+e+")":t}function E(t){return null!=t}function F(t){for(var e=1,r=function(t){for(var e=0,r=0;re&&(e=a)}return e}(t);r>=1024;)e*=1024,r/=1024;return e}function j(t,e,r){var n={thousands:t.options.thousands,decimal:t.options.decimal},a=o({prefix:t.options.prefix,suffix:t.options.suffix,precision:t.options.precision,round:t.options.round,zeros:t.options.zeros},n);if(t.options.bytes){var s=t.data;"pie"===r&&(s=[{data:s}]),a.byteScale=F(s)}if("pie"!==r){var l=e.scales.y;"bar"===r&&(l=e.scales.x),a.byteScale&&(l.ticks.stepSize||(l.ticks.stepSize=a.byteScale/2),l.ticks.maxTicksLimit||(l.ticks.maxTicksLimit=4)),l.ticks.callback||(l.ticks.callback=function(t){return b("",t,a,!0)}),"scatter"!==r&&"bubble"!==r||e.scales.x.ticks.callback||(e.scales.x.ticks.callback=function(t){return b("",t,n,!0)})}if(!e.plugins.tooltip.callbacks.label)if("scatter"===r)e.plugins.tooltip.callbacks.label=function(t){var e=t.dataset.label||"";e&&(e+=": ");var r=t.parsed;return e+"("+b("",r.x,n)+", "+b("",r.y,a)+")"};else if("bubble"===r)e.plugins.tooltip.callbacks.label=function(t){var e=t.dataset.label||"";e&&(e+=": ");var r=t.raw;return e+"("+b("",r.x,n)+", "+b("",r.y,a)+", "+b("",r.v,n)+")"};else if("pie"===r)e.plugins.tooltip.callbacks.label=function(t){return b("",t.parsed,a)};else{var c="bar"===r?"x":"y";e.plugins.tooltip.callbacks.label=function(t){if(null!==t.parsed[c]){var e=t.dataset.label||"";return e&&(e+=": "),b(e,t.parsed[c],a)}}}"line"!==r&&"area"!==r||"number"!==t.xtype||(e.scales.x.ticks.callback||(e.scales.x.ticks.callback=function(t){return i(t)}),e.plugins.tooltip.callbacks.title||(e.plugins.tooltip.callbacks.title=function(t){return i(t[0].parsed.x)}))}var B=p(o(w,C),k,S,(function(t,e){null!==e&&(t.scales.y.min=s(e))}),(function(t,e){t.scales.y.max=s(e)}),D,O,L);function N(t,e){return"bubble"===e?function(t){for(var e=t.data,r=[],n=function(t){for(var e=0,r=0;re&&(e=a)}return e}(e),o=0;o0){for(var S=(E(w)?l(w):i[0]).getTime(),A=(E(C)?l(C):i[0]).getTime(),T=1;TA&&(A=D)}var O,L=(A-S)/864e5;if(!r.scales.x.time.unit)if("year"===k||L>3650?(r.scales.x.time.unit="year",O=365):"month"===k||L>300?(r.scales.x.time.unit="month",O=30):"week"===k||"day"===k||L>10?(r.scales.x.time.unit="day",O=1):"hour"===k||L>.5?(r.scales.x.time.displayFormats={hour:"MMM d, h a"},r.scales.x.time.unit="hour",O=1/24):"minute"===k&&(r.scales.x.time.displayFormats={minute:"h:mm a"},r.scales.x.time.unit="minute",O=1/24/60),O&&L>0){var F=e.element.offsetWidth;if(F>0){var j=Math.ceil(L/O/(F/100));"week"===k&&1===O&&(j=7*Math.ceil(j/7)),r.scales.x.ticks.stepSize=j}}r.scales.x.time.tooltipFormat||("year"===k?r.scales.x.time.tooltipFormat="yyyy":"month"===k?r.scales.x.time.tooltipFormat="MMM yyyy":"week"===k||"day"===k?r.scales.x.time.tooltipFormat="PP":"hour"===k?r.scales.x.time.tooltipFormat="MMM d, h a":"minute"===k&&(r.scales.x.time.tooltipFormat="h:mm a"))}}return{labels:i,datasets:p}}var M=function(t){this.name="chartjs",this.library=t};M.prototype.renderLineChart=function(t,e){e||(e="line");var r=B(t,o({},t.options));j(t,r,e);var n=I(t,r,e);"number"===t.xtype?(r.scales.x.type=r.scales.x.type||"linear",r.scales.x.position=r.scales.x.position||"bottom"):r.scales.x.type="string"===t.xtype?"category":"time",this.drawChart(t,"line",n,r)},M.prototype.renderPieChart=function(t){var e=o({},w);t.options.donut&&(e.cutout="50%"),"legend"in t.options&&k(e,t.options.legend),t.options.title&&S(e,t.options.title),j(t,e=o(e,t.options.library||{}),"pie");for(var r=[],n=[],a=0;a25?n=25:n<10&&(n=10),r.scales.x.ticks.callback||(r.scales.x.ticks.callback=function(t){return(t=i(this.getLabelForValue(t))).length>n?t.substring(0,n-2)+"...":t})}(t,a,r),"mode"in r.interaction||(r.interaction.mode="index"),this.drawChart(t,"bar",a,r)},M.prototype.renderAreaChart=function(t){this.renderLineChart(t,"area")},M.prototype.renderBarChart=function(t){this.renderColumnChart(t,"bar")},M.prototype.renderScatterChart=function(t,e){e=e||"scatter";var r=B(t,t.options);j(t,r,e),"showLine"in r||(r.showLine=!1);var n=I(t,r,e);r.scales.x.type=r.scales.x.type||"linear",r.scales.x.position=r.scales.x.position||"bottom","mode"in r.interaction||(r.interaction.mode="nearest"),this.drawChart(t,e,n,r)},M.prototype.renderBubbleChart=function(t){this.renderScatterChart(t,"bubble")},M.prototype.destroy=function(t){t.chart&&t.chart.destroy()},M.prototype.drawChart=function(t,e,r,n){if(this.destroy(t),!t.destroyed){var o={type:e,data:r,options:n};t.options.code&&window.console.log("new Chart(ctx, "+JSON.stringify(o)+");"),t.element.innerHTML="";var a=t.element.getElementsByTagName("CANVAS")[0];t.chart=new this.library(a,o)}};var R={chart:{},xAxis:{title:{text:null},labels:{style:{fontSize:"12px"}}},yAxis:{title:{text:null},labels:{style:{fontSize:"12px"}}},title:{text:null},credits:{enabled:!1},legend:{borderWidth:0},tooltip:{style:{fontSize:"12px"}},plotOptions:{areaspline:{},area:{},series:{marker:{}}},time:{useUTC:!1}};function H(t,e,r){void 0!==e?(t.legend.enabled=!!e,e&&!0!==e&&("top"===e||"bottom"===e?t.legend.verticalAlign=e:(t.legend.layout="vertical",t.legend.verticalAlign="middle",t.legend.align=e))):r&&(t.legend.enabled=!1)}function P(t,e){t.title.text=e}var W=p(R,H,P,(function(t,e){t.yAxis.min=e}),(function(t,e){t.yAxis.max=e}),(function(t,e){var r=e?!0===e?"normal":e:null;t.plotOptions.series.stacking=r,t.plotOptions.area.stacking=r,t.plotOptions.areaspline.stacking=r}),(function(t,e){t.xAxis.title.text=e}),(function(t,e){t.yAxis.title.text=e}));function V(e,r,n){var o={prefix:e.options.prefix,suffix:e.options.suffix,thousands:e.options.thousands,decimal:e.options.decimal,precision:e.options.precision,round:e.options.round,zeros:e.options.zeros};"pie"===n||t(r.yAxis)||r.yAxis.labels.formatter||(r.yAxis.labels.formatter=function(){return b("",this.value,o)}),r.tooltip.pointFormatter||r.tooltip.pointFormat||(r.tooltip.pointFormatter=function(){return' '+b(this.series.name+": ",this.y,o)+"
"})}var G=function(t){this.name="highcharts",this.library=t};G.prototype.renderLineChart=function(t,e){var r={};"areaspline"===(e=e||"spline")&&(r={plotOptions:{areaspline:{stacking:"normal"},area:{stacking:"normal"},series:{marker:{enabled:!1}}}}),!1===t.options.curve&&("areaspline"===e?e="area":"spline"===e&&(e="line"));var n=W(t,t.options,r);"number"===t.xtype?n.xAxis.type=n.xAxis.type||"linear":n.xAxis.type="string"===t.xtype?"category":"datetime",n.chart.type||(n.chart.type=e),V(t,n,e);for(var o=t.data,a=0;a0?new Error("No charting library found for "+t):new Error("No charting libraries found - be sure to include one before your charts")}var it={charts:{},configure:function(t){for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(it.config[e]=t[e])},setDefaultOptions:function(t){it.options=t},eachChart:function(t){for(var e in it.charts)Object.prototype.hasOwnProperty.call(it.charts,e)&&t(it.charts[e])},destroyAll:function(){for(var t in it.charts)Object.prototype.hasOwnProperty.call(it.charts,t)&&(it.charts[t].destroy(),delete it.charts[t])},config:{},options:{},adapters:nt,addAdapter:ot,use:function(t){return ot(t),it}};function st(t,e){if("bubble"===e)return function(t){for(var e=[],r=0;r0)return!1;return!0}var dt=[],ht=0;function ft(){if(ht<4){var t=dt.shift();t&&(ht++,e=t[0],r=t[1],n=t[2],(o=new XMLHttpRequest).open("GET",e,!0),o.setRequestHeader("Content-Type","application/json"),o.onload=function(){ht--,ft(),200===o.status?r(JSON.parse(o.responseText)):n(o.statusText)},o.send(),ft())}var e,r,n,o}function yt(t,e){t.textContent=e}function mt(t,e,r){r||(e="Error Loading Chart: "+e),yt(t,e),t.style.color="#ff0000"}function vt(t){try{t.__render()}catch(e){throw mt(t.element,e.message),e}}function gt(t,e,r){if(r&&t.options.loading&&("string"==typeof e||"function"==typeof e)&&yt(t.element,t.options.loading),"string"==typeof e)n=e,o=function(e){t.rawData=e,vt(t)},a=function(e){mt(t.element,e)},dt.push([n,o,a]),ft();else if("function"==typeof e)try{e((function(e){t.rawData=e,vt(t)}),(function(e){mt(t.element,e,!0)}))}catch(e){mt(t.element,e,!0)}else t.rawData=e,vt(t);var n,o,a}function bt(t,e){if(ut(e.data,t)){var r=e.options.empty||e.options.messages&&e.options.messages.empty||"No data";yt(e.element,r)}else at(t,e),e.options.download&&!e.__downloadAttached&&"chartjs"===e.adapter&&function(t){var e=t.options.download;!0===e?e={}:"string"==typeof e&&(e={filename:e});var r=document.createElement("a");r.download=e.filename||"chart.png",r.style.position="absolute",r.style.top="20px",r.style.right="20px",r.style.zIndex=1e3,r.style.lineHeight="20px",r.target="_blank";var n=document.createElement("img");n.src="data:image/svg+xml;utf8,"+encodeURIComponent('\x3c!--! Font Awesome Free 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --\x3e'),n.alt="Download",n.style.width="20px",n.style.height="20px",n.style.border="none",r.appendChild(n);var o=t.element;o.style.position="relative",t.__downloadAttached=!0,t.__enterEvent=o.addEventListener("mouseover",(function(n){var a=n.relatedTarget;a&&(a===this||this.contains(a))||!t.options.download||(r.href=t.toImage(e),o.appendChild(r))})),t.__leaveEvent=o.addEventListener("mouseout",(function(t){var e=t.relatedTarget;e&&(e===this||this.contains(e))||r.parentNode&&r.parentNode.removeChild(r)}))}(e)}var xt=function(t,e,r){this.element=function(t){if("string"==typeof t){var e=t;if(!(t=document.getElementById(t)))throw new Error("No element with id "+e)}return t}(t),this.options=o(it.options,r||{}),this.dataSource=e,this.element.id&&(it.charts[this.element.id]=this),gt(this,e,!0),this.options.refresh&&this.startRefresh()};xt.prototype.getElement=function(){return this.element},xt.prototype.getDataSource=function(){return this.dataSource},xt.prototype.getData=function(){return this.data},xt.prototype.getOptions=function(){return this.options},xt.prototype.getChartObject=function(){return this.chart},xt.prototype.getAdapter=function(){return this.adapter},xt.prototype.updateData=function(t,e){this.dataSource=t,e&&this.__updateOptions(e),gt(this,t,!0)},xt.prototype.setOptions=function(t){this.__updateOptions(t),this.redraw()},xt.prototype.redraw=function(){gt(this,this.rawData)},xt.prototype.refreshData=function(){if("string"==typeof this.dataSource){var t=-1===this.dataSource.indexOf("?")?"?":"&";gt(this,this.dataSource+t+"_="+(new Date).getTime())}else"function"==typeof this.dataSource&>(this,this.dataSource)},xt.prototype.startRefresh=function(){var t=this,e=this.options.refresh;if(e&&"string"!=typeof this.dataSource&&"function"!=typeof this.dataSource)throw new Error("Data source must be a URL or callback for refresh");if(!this.intervalId){if(!e)throw new Error("No refresh interval");this.intervalId=setInterval((function(){t.refreshData()}),1e3*e)}},xt.prototype.stopRefresh=function(){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null)},xt.prototype.toImage=function(t){if("chartjs"===this.adapter){if(t&&t.background&&"transparent"!==t.background){var e=this.chart.canvas,r=this.chart.ctx,n=document.createElement("canvas"),o=n.getContext("2d");return n.width=r.canvas.width,n.height=r.canvas.height,o.fillStyle=t.background,o.fillRect(0,0,n.width,n.height),o.drawImage(e,0,0),n.toDataURL("image/png")}return this.chart.toBase64Image()}throw new Error("Feature only available for Chart.js")},xt.prototype.destroy=function(){this.destroyed=!0,this.stopRefresh(),this.__adapterObject&&this.__adapterObject.destroy(this),this.__enterEvent&&this.element.removeEventListener("mouseover",this.__enterEvent),this.__leaveEvent&&this.element.removeEventListener("mouseout",this.__leaveEvent)},xt.prototype.__updateOptions=function(t){var e=t.refresh&&t.refresh!==this.options.refresh;this.options=o(it.options,t),e&&(this.stopRefresh(),this.startRefresh())},xt.prototype.__render=function(){this.data=this.__processData(),bt(this.__chartName(),this)},xt.prototype.__config=function(){return it.config};var wt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.__processData=function(){return ct(this)},e.prototype.__chartName=function(){return"LineChart"},e}(xt),Ct=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.__processData=function(){return pt(this)},e.prototype.__chartName=function(){return"PieChart"},e}(xt),_t=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.__processData=function(){return ct(this,null,!0)},e.prototype.__chartName=function(){return"ColumnChart"},e}(xt),kt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.__processData=function(){return ct(this,null,!0)},e.prototype.__chartName=function(){return"BarChart"},e}(xt),St=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.__processData=function(){return ct(this)},e.prototype.__chartName=function(){return"AreaChart"},e}(xt),At=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.__processData=function(){return pt(this)},e.prototype.__chartName=function(){return"GeoChart"},e}(xt),Tt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.__processData=function(){return ct(this,"number")},e.prototype.__chartName=function(){return"ScatterChart"},e}(xt),Dt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.__processData=function(){return ct(this,"bubble")},e.prototype.__chartName=function(){return"BubbleChart"},e}(xt),Ot=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.__processData=function(){for(var t=this.rawData,e=0;e