var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};Booyah.$charts=$(".booyah-chart"),Booyah.$charts.filter(".booyah-chart--bar").each(function(){var a=$(this);if(void 0!==a.data("url"))a.dataUrl=a.data("url");else{if(void 0===a.data("url-key"))return void console.warn("Keine URL für die Chart-Daten hinterlegt.");a.dataUrl=booyah.getAjaxRoute(a.data("url"))}a.$info=a.prev(".alert-info"),a.dataKey=a.data("key"),a.tmpId=Booyah.randomId,a.kpi=void 0===a.data("kpi")?"":a.data("kpi"),a.dateFormat=a.data("date-format"),a.timeFormat=a.data("time-format"),a.categoryLabels=[],a.init=function(){this.attr("id",this.tmpId);var t={type:"serial",theme:"light",dataProvider:[],gridAboveGraphs:!1,startDuration:1,thousandsSeparator:".",decimalSeparator:",",graphs:[{fillAlphas:.8,lineAlpha:.2,type:"column",valueField:"1",balloonFunction:a.balloonFunction}],chartCursor:{categoryBalloonEnabled:!1,cursorAlpha:0,zoomable:!1},categoryField:"date",categoryAxis:{gridPosition:"start",gridAlpha:0,tickPosition:"start",tickLength:0,labelFunction:function(t){var o="";if(void 0!==t&&""!==t.toString().trim())if(void 0!==a.categoryLabels[t])o=a.categoryLabels[t];else{var e=a.formatDate(moment(t,"YYYY-MM-DD HH:mm:SS").locale(Booyah.locale));"NaN"!==e.split(".")[0]&&(o=e)}return o}},valueAxes:[{labelFunction:a.valueAxesLabel}],export:{enabled:!1}};t.colors=[booyah.getThemeColor("primary"),booyah.getThemeColor("secondary"),booyah.getThemeColor("info"),booyah.getThemeColor("warning"),booyah.getThemeColor("danger")],this.chart=AmCharts.makeChart(a.tmpId,t)},a.onError=function(){},a.balloonFunction=function(t){var o=t.graph.valueField,e=parseFloat(t.dataContext[o]);return AmCharts.formatNumber(Math.abs(e),{precision:2,decimalSeparator:",",thousandsSeparator:"."})+" "+a.kpi},a.valueAxesLabel=function(t){return t+" "+a.kpi},a.formatDate=function(t){return void 0!==a.dateFormat&&void 0!==a.timeFormat?t.format(a.dateFormat+" "+a.timeFormat):void 0!==a.dateFormat?t.format(a.dateFormat):void 0!==a.timeFormat?t.format(a.timeFormat):t.format("DD.MM.YYYY")},a.update=function(t){if(void 0===t.data)return void a.onError();void 0!==t.kpi&&(this.kpi=t.kpi),void 0!==t.categoryLabels&&(this.categoryLabels=t.categoryLabels);var o=void 0!==t.dateRange?t.dateRange:"month",e=void 0!==t.graphAlpha?t.graphAlpha:1,r=[],i=[],n=[];$.each(t.data,function(t,o){var e={date:t};$.each(o,function(t,o){"object"===(void 0===o?"undefined":_typeof(o))?(e[t]=o.value,void 0!==o.color&&(e["color_"+t]=a.rgb2Hex(booyah.getThemeColor(o.color)))):e[t]=o,$.inArray(t,r)<=-1&&-1===$.inArray(t,["categoryLabel"])&&r.push(t)}),i.push(e)}),$.each(r,function(t,o){var r={id:t,fillAlphas:e,lineThickness:0,valueField:o,colorField:"color_"+o,dateFormat:"MM.YYYY",type:"column",balloonFunction:a.balloonFunction};n.push(r)});var l=[];if("object"===_typeof(t.days)){if("object"===_typeof(t.days.weekends)){var h=[];$.each(t.days.weekends,function(a,t){var o=Booyah.dateWithOffset(new Date(t)),e=Booyah.dateWithOffset(new Date(t));e.setDate(e.getDate()+1);var r=Booyah.dateWithOffset(new Date(t));r.setDate(r.getDate()-1),h.length&&Booyah.getDateString(o)===h[h.length-1].toDate?h[h.length-1].toDate=Booyah.getDateString(e):h.push({date:Booyah.getDateString(o),toDate:Booyah.getDateString(e),lineColor:booyah.getThemeColor("dark"),lineAlpha:0,fillAlpha:.075,fillColor:booyah.getThemeColor("dark"),dashLength:4,inside:!0,labelRotation:90,label:""})}),l=l.concat(l,h)}if("object"===_typeof(t.days.holidays)){var d=[];$.each(t.days.holidays,function(a,t){var o=Booyah.dateWithOffset(new Date(a)),e=Booyah.dateWithOffset(new Date(a));e.setDate(e.getDate()+1),d.push({date:Booyah.getDateString(o),toDate:Booyah.getDateString(e),lineColor:booyah.getThemeColor("danger"),lineAlpha:0,fillAlpha:.075,fillColor:booyah.getThemeColor("danger"),dashLength:4,inside:!0,labelRotation:90,label:t})}),l=l.concat(l,d)}}i.length&&n.length?(this.chart.graphs=n,this.chart.dataProvider=i,this.chart.guides=l,this.chart.categoryAxis.minPeriod="month"===o?"MM":"day"===o?"DD":"mm",this.chart.validateData(),a.show()):(this.chart.dataProvider=[],this.chart.validateData(),a.$info.length&&a.$info.removeClass("d-none"),a.hide())},a.rgb2Hex=function(a){return 0!==a.indexOf("rgb")?a:AmCharts.rgb2hex(a)},a.loadData=function(){a.$info.length&&a.$info.addClass("d-none"),Booyah.toggleCardLoader(a.parents(".card")),$.get(a.dataUrl).done(function(t){a.update(t)}).fail(function(){a.$info.length&&a.$info.addClass("d-none")}).always(function(){Booyah.toggleCardLoader(a.parents(".card"))})},a.init(),a.loadData()});
