mirror of
https://github.com/flarum/framework.git
synced 2024-12-13 23:53:42 +08:00
2 lines
50 KiB
JavaScript
2 lines
50 KiB
JavaScript
module.exports=function(t){var e={};function s(i){if(e[i])return e[i].exports;var a=e[i]={i:i,l:!1,exports:{}};return t[i].call(a.exports,a,a.exports,s),a.l=!0,a.exports}return s.m=t,s.c=e,s.d=function(t,e,i){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,e){if(1&e&&(t=s(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var a in t)s.d(i,a,function(e){return t[e]}.bind(null,a));return i},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="",s(s.s=8)}([function(t,e){t.exports=flarum.core.compat["utils/abbreviateNumber"]},function(t,e){t.exports=flarum.core.compat.app},function(t,e){t.exports=flarum.core.compat.extend},function(t,e){t.exports=flarum.core.compat["components/DashboardPage"]},function(t,e){t.exports=flarum.core.compat["components/DashboardWidget"]},function(t,e){t.exports=flarum.core.compat["components/SelectDropdown"]},function(t,e){t.exports=flarum.core.compat["components/Button"]},function(t,e){t.exports=flarum.core.compat["helpers/icon"]},function(t,e,s){"use strict";s.r(e);var i=s(1),a=s.n(i),n=s(2),r=s(3),o=s.n(r);var l=s(4),h=s.n(l),d=s(5),c=s.n(d),p=s(6),u=s.n(p),f=s(7),g=s.n(f),y=s(0),b=s.n(y);function x(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function v(t){let e=t.getBoundingClientRect();return{top:e.top+(document.documentElement.scrollTop||document.body.scrollTop),left:e.left+(document.documentElement.scrollLeft||document.body.scrollLeft)}}x.create=(t,e)=>{var s=document.createElement(t);for(var i in e){var a=e[i];if("inside"===i)x(a).appendChild(s);else if("around"===i){var n=x(a);n.parentNode.insertBefore(s,n),s.appendChild(n)}else"styles"===i?"object"==typeof a&&Object.keys(a).map(t=>{s.style[t]=a[t]}):i in s?s[i]=a:s.setAttribute(i,a)}return s};const w={margins:{top:10,bottom:10,left:20,right:20},paddings:{top:20,bottom:40,left:30,right:10},baseHeight:240,titleHeight:20,legendHeight:30,titleFontSize:12};function A(t){return t.titleHeight+t.margins.top+t.paddings.top}function P(t){return t.margins.left+t.paddings.left}function k(t){return t.margins.top+t.margins.bottom+t.paddings.top+t.paddings.bottom+t.titleHeight+t.legendHeight}function C(t){return t.margins.left+t.margins.right+t.paddings.left+t.paddings.right}const D=["line","bar"],L=["light-blue","blue","violet","red","orange","yellow","green","light-green","purple","magenta","light-grey","dark-grey"],T={bar:L,line:L,pie:L,percentage:L,heatmap:["#ebedf0","#c6e48b","#7bc96f","#239a3b","#196127"]},M=Math.PI/180;class N{constructor({parent:t=null,colors:e=[]}){this.parent=t,this.colors=e,this.titleName="",this.titleValue="",this.listValues=[],this.titleValueFirst=0,this.x=0,this.y=0,this.top=0,this.left=0,this.setup()}setup(){this.makeTooltip()}refresh(){this.fill(),this.calcPosition()}makeTooltip(){this.container=x.create("div",{inside:this.parent,className:"graph-svg-tip comparison",innerHTML:'<span class="title"></span>\n\t\t\t\t<ul class="data-point-list"></ul>\n\t\t\t\t<div class="svg-pointer"></div>'}),this.hideTip(),this.title=this.container.querySelector(".title"),this.dataPointList=this.container.querySelector(".data-point-list"),this.parent.addEventListener("mouseleave",()=>{this.hideTip()})}fill(){let t;this.index&&this.container.setAttribute("data-point-index",this.index),t=this.titleValueFirst?`<strong>${this.titleValue}</strong>${this.titleName}`:`${this.titleName}<strong>${this.titleValue}</strong>`,this.title.innerHTML=t,this.dataPointList.innerHTML="",this.listValues.map((t,e)=>{const s=this.colors[e]||"black";let i=0===t.formatted||t.formatted?t.formatted:t.value,a=x.create("li",{styles:{"border-top":"3px solid "+s},innerHTML:`<strong style="display: block;">${0===i||i?i:""}</strong>\n\t\t\t\t\t${t.title?t.title:""}`});this.dataPointList.appendChild(a)})}calcPosition(){let t=this.container.offsetWidth;this.top=this.y-this.container.offsetHeight-5,this.left=this.x-t/2;let e=this.parent.offsetWidth-t,s=this.container.querySelector(".svg-pointer");if(this.left<0)s.style.left=`calc(50% - ${-1*this.left}px)`,this.left=0;else if(this.left>e){let t=`calc(50% + ${this.left-e}px)`;s.style.left=t,this.left=e}else s.style.left="50%"}setValues(t,e,s={},i=[],a=-1){this.titleName=s.name,this.titleValue=s.value,this.listValues=i,this.x=t,this.y=e,this.titleValueFirst=s.valueFirst||0,this.index=a,this.refresh()}hideTip(){this.container.style.top="0px",this.container.style.left="0px",this.container.style.opacity="0"}showTip(){this.container.style.top=this.top+"px",this.container.style.left=this.left+"px",this.container.style.opacity="1"}}function O(t){return parseFloat(t.toFixed(2))}function E(t,e,s,i=!1){s||(s=i?t[0]:t[t.length-1]);let a=new Array(Math.abs(e)).fill(s);return t=i?a.concat(t):t.concat(a)}function S(t,e){return(t+"").length*e}function z(t,e){return{x:Math.sin(t*M)*e,y:Math.cos(t*M)*e}}function W(t,e){let s,i;return t<=e?(s=e-t,i=t):(s=t-e,i=e),[s,i]}function $(t,e,s=e.length-t.length){return s>0?t=E(t,s):e=E(e,s),[t,e]}const H={"light-blue":"#7cd6fd",blue:"#5e64ff",violet:"#743ee2",red:"#ff5858",orange:"#ffa00a",yellow:"#feef72",green:"#28a745","light-green":"#98d85b",purple:"#b554ff",magenta:"#ffa3ef",black:"#36114C",grey:"#bdd3e6","light-grey":"#f0f4f7","dark-grey":"#b8c2cc"};function F(t){return t>255?255:t<0?0:t}function j(t,e){let s=I(t),i=!1;"#"==s[0]&&(s=s.slice(1),i=!0);let a=parseInt(s,16),n=F((a>>16)+e),r=F((a>>8&255)+e);return(i?"#":"")+(F((255&a)+e)|r<<8|n<<16).toString(16)}const I=t=>H[t]||t;function R(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function Y(t,e){var s=document.createElementNS("http://www.w3.org/2000/svg",t);for(var i in e){var a=e[i];if("inside"===i)R(a).appendChild(s);else if("around"===i){var n=R(a);n.parentNode.insertBefore(s,n),s.appendChild(n)}else"styles"===i?"object"==typeof a&&Object.keys(a).map(t=>{s.style[t]=a[t]}):("className"===i&&(i="class"),"innerHTML"===i?s.textContent=a:s.setAttribute(i,a))}return s}function _(t,e,s,i){return Y("stop",{inside:t,style:"stop-color: "+s,offset:e,"stop-opacity":i})}function B(t,e="",s){let i={className:t,transform:e};return s&&(i.inside=s),Y("g",i)}function V(t,e="",s="none",i="none"){return Y("path",{className:e,d:t,styles:{stroke:s,fill:i}})}function U(t,e,s=!1){let i="path-fill-gradient-"+e+"-"+(s?"lighter":"default"),a=function(t,e){return Y("linearGradient",{inside:t,id:e,x1:0,x2:0,y1:0,y2:1})}(t,i),n=[1,.6,.2];return s&&(n=[.4,.2,0]),_(a,"0%",e,n[0]),_(a,"50%",e,n[1]),_(a,"100%",e,n[2]),i}function G(t,e,s,i,a="none",n={}){let r={className:t,x:e,y:s,width:i,height:i,fill:a};return Object.keys(n).map(t=>{r[t]=n[t]}),Y("rect",r)}function q(t,e,s,i,a={}){let n=a.fontSize||10;return Y("text",{className:t,x:e,y:s,dy:(void 0!==a.dy?a.dy:n/2)+"px","font-size":n+"px",fill:a.fill||"#555b51","text-anchor":a.textAnchor||"start",innerHTML:i})}function X(t,e,s,i,a={}){a.stroke||(a.stroke="#dadada"),a.lineType||(a.lineType="");let n=Y("line",{className:"line-horizontal "+a.className+("dashed"===a.lineType?"dashed":""),x1:s,x2:i,y1:0,y2:0,styles:{stroke:a.stroke}}),r=Y("text",{x:s<i?s-4:s+4,y:0,dy:"3px","font-size":"10px","text-anchor":s<i?"end":"start",innerHTML:e+""}),o=Y("g",{transform:`translate(0, ${t})`,"stroke-opacity":1});return 0!==r&&"0"!==r||(o.style.stroke="rgba(27, 31, 35, 0.6)"),o.appendChild(n),o.appendChild(r),o}function J(t,e,s,i={}){i.pos||(i.pos="bottom"),i.offset||(i.offset=0),i.mode||(i.mode="span"),i.stroke||(i.stroke="#dadada"),i.className||(i.className="");let a=s+6,n="span"===i.mode?-6:s;return"tick"===i.mode&&"top"===i.pos&&(a=-6,n=0),function(t,e,s,i,a={}){a.stroke||(a.stroke="#dadada");let n=Y("line",{className:"line-vertical "+a.className,x1:0,x2:0,y1:s,y2:i,styles:{stroke:a.stroke}}),r=Y("text",{x:0,y:s>i?s+4:s-4-10,dy:"10px","font-size":"10px","text-anchor":"middle",innerHTML:e+""}),o=Y("g",{transform:`translate(${t}, 0)`});return o.appendChild(n),o.appendChild(r),o}(t,e,a,n,{stroke:i.stroke,className:i.className,lineType:i.lineType})}let K={bar:t=>{let e;"rect"!==t.nodeName&&(e=t.getAttribute("transform"),t=t.childNodes[0]);let s=t.cloneNode();return s.style.fill="#000000",s.style.opacity="0.4",e&&s.setAttribute("transform",e),s},dot:t=>{let e;"circle"!==t.nodeName&&(e=t.getAttribute("transform"),t=t.childNodes[0]);let s=t.cloneNode(),i=t.getAttribute("r"),a=t.getAttribute("fill");return s.setAttribute("r",parseInt(i)+4),s.setAttribute("fill",a),s.style.opacity="0.6",e&&s.setAttribute("transform",e),s},heat_square:t=>{let e;"circle"!==t.nodeName&&(e=t.getAttribute("transform"),t=t.childNodes[0]);let s=t.cloneNode(),i=t.getAttribute("r"),a=t.getAttribute("fill");return s.setAttribute("r",parseInt(i)+4),s.setAttribute("fill",a),s.style.opacity="0.6",e&&s.setAttribute("transform",e),s}},Q={bar:(t,e)=>{let s;"rect"!==t.nodeName&&(s=t.getAttribute("transform"),t=t.childNodes[0]);let i=["x","y","width","height"];Object.values(t.attributes).filter(t=>i.includes(t.name)&&t.specified).map(t=>{e.setAttribute(t.name,t.nodeValue)}),s&&e.setAttribute("transform",s)},dot:(t,e)=>{let s;"circle"!==t.nodeName&&(s=t.getAttribute("transform"),t=t.childNodes[0]);let i=["cx","cy"];Object.values(t.attributes).filter(t=>i.includes(t.name)&&t.specified).map(t=>{e.setAttribute(t.name,t.nodeValue)}),s&&e.setAttribute("transform",s)},heat_square:(t,e)=>{let s;"circle"!==t.nodeName&&(s=t.getAttribute("transform"),t=t.childNodes[0]);let i=["cx","cy"];Object.values(t.attributes).filter(t=>i.includes(t.name)&&t.specified).map(t=>{e.setAttribute(t.name,t.nodeValue)}),s&&e.setAttribute("transform",s)}};function Z(t,e,s,i){let a="string"==typeof e?e:e.join(", ");return[t,{transform:s.join(", ")},i,"easein","translate",{transform:a}]}function tt(t,e,s){return Z(t,[0,s],[0,e],350)}const et={ease:"0.25 0.1 0.25 1",linear:"0 0 1 1",easein:"0.1 0.8 0.2 1",easeout:"0 0 0.58 1",easeinout:"0.42 0 0.58 1"};function st(t,e){t.style.transform=e,t.style.webkitTransform=e,t.style.msTransform=e,t.style.mozTransform=e,t.style.oTransform=e}function it(t,e){let s=[],i=[];e.map(t=>{let e,a,n=t[0],r=n.parentNode;t[0]=n,[e,a]=function(t,e,s,i="linear",a,n={}){let r=t.cloneNode(!0),o=t.cloneNode(!0);for(var l in e){let d;d="transform"===l?document.createElementNS("http://www.w3.org/2000/svg","animateTransform"):document.createElementNS("http://www.w3.org/2000/svg","animate");let c=n[l]||t.getAttribute(l),p=e[l],u={attributeName:l,from:c,to:p,begin:"0s",dur:s/1e3+"s",values:c+";"+p,keySplines:et[i],keyTimes:"0;1",calcMode:"spline",fill:"freeze"};for(var h in a&&(u.type=a),u)d.setAttribute(h,u[h]);r.appendChild(d),a?o.setAttribute(l,`translate(${p})`):o.setAttribute(l,p)}return[r,o]}(...t),s.push(a),i.push([e,r]),r.replaceChild(e,n)});let a=t.cloneNode(!0);return i.map((t,i)=>{t[1].replaceChild(s[i],t[0]),e[i][0]=s[i]}),a}let at;class nt{constructor(t,e){if(this.parent="string"==typeof t?document.querySelector(t):t,!(this.parent instanceof HTMLElement))throw new Error("No `parent` element to render on was provided.");this.rawChartArgs=e,this.title=e.title||"",this.type=e.type||"",this.realData=this.prepareData(e.data),this.data=this.prepareFirstData(this.realData),this.colors=this.validateColors(e.colors,this.type),this.config={showTooltip:1,showLegend:1,isNavigable:e.isNavigable||0,animate:1},this.measures=JSON.parse(JSON.stringify(w));let s=this.measures;this.setMeasures(e),this.title.length||(s.titleHeight=0),this.config.showLegend||(s.legendHeight=0),this.argHeight=e.height||s.baseHeight,this.state={},this.options={},this.initTimeout=700,this.config.isNavigable&&(this.overlays=[]),this.configure(e)}prepareData(t){return t}prepareFirstData(t){return t}validateColors(t,e){const s=[];return(t=(t||[]).concat(T[e])).forEach(t=>{const e=I(t);!function(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)}(e)?console.warn('"'+t+'" is not a valid color.'):s.push(e)}),s}setMeasures(){}configure(){let t=this.argHeight;this.baseHeight=t,this.height=t-k(this.measures),at=this.boundDrawFn.bind(this),window.addEventListener("resize",at),window.addEventListener("orientationchange",this.boundDrawFn.bind(this))}boundDrawFn(){this.draw(!0)}unbindWindowEvents(){window.removeEventListener("resize",at),window.removeEventListener("orientationchange",this.boundDrawFn.bind(this))}setup(){this.makeContainer(),this.updateWidth(),this.makeTooltip(),this.draw(!1,!0)}makeContainer(){this.parent.innerHTML="";let t={inside:this.parent,className:"chart-container"};this.independentWidth&&(t.styles={width:this.independentWidth+"px"}),this.container=x.create("div",t)}makeTooltip(){this.tip=new N({parent:this.container,colors:this.colors}),this.bindTooltip()}bindTooltip(){}draw(t=!1,e=!1){this.updateWidth(),this.calc(t),this.makeChartArea(),this.setupComponents(),this.components.forEach(t=>t.setup(this.drawArea)),this.render(this.components,!1),e&&(this.data=this.realData,setTimeout(()=>{this.update(this.data)},this.initTimeout)),this.renderLegend(),this.setupNavigation(e)}calc(){}updateWidth(){var t,e,s;this.baseWidth=(t=this.parent,e=window.getComputedStyle(t),s=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight),t.clientWidth-s),this.width=this.baseWidth-C(this.measures)}makeChartArea(){this.svg&&this.container.removeChild(this.svg);let t=this.measures;var e,s,i,a;this.svg=(e=this.container,s="frappe-chart chart",i=this.baseWidth,a=this.baseHeight,Y("svg",{className:s,inside:e,width:i,height:a})),this.svgDefs=Y("defs",{inside:this.svg}),this.title.length&&(this.titleEL=q("title",t.margins.left,t.margins.top,this.title,{fontSize:t.titleFontSize,fill:"#666666",dy:t.titleFontSize}));let n=A(t);this.drawArea=B(this.type+"-chart chart-draw-area",`translate(${P(t)}, ${n})`),this.config.showLegend&&(n+=this.height+t.paddings.bottom,this.legendArea=B("chart-legend",`translate(${P(t)}, ${n})`)),this.title.length&&this.svg.appendChild(this.titleEL),this.svg.appendChild(this.drawArea),this.config.showLegend&&this.svg.appendChild(this.legendArea),this.updateTipOffset(P(t),A(t))}updateTipOffset(t,e){this.tip.offset={x:t,y:e}}setupComponents(){this.components=new Map}update(t){t||console.error("No data to update."),this.data=this.prepareData(t),this.calc(),this.render()}render(t=this.components,e=!0){this.config.isNavigable&&this.overlays.map(t=>t.parentNode.removeChild(t));let s=[];t.forEach(t=>{s=s.concat(t.update(e))}),s.length>0?(!function(t,e,s){if(0===s.length)return;let i=it(e,s);e.parentNode==t&&(t.removeChild(e),t.appendChild(i)),setTimeout(()=>{i.parentNode==t&&(t.removeChild(i),t.appendChild(e))},250)}(this.container,this.svg,s),setTimeout(()=>{t.forEach(t=>t.make()),this.updateNav()},400)):(t.forEach(t=>t.make()),this.updateNav())}updateNav(){this.config.isNavigable&&(this.makeOverlay(),this.bindUnits())}renderLegend(){}setupNavigation(t=!1){this.config.isNavigable&&t&&(this.bindOverlay(),this.keyActions={13:this.onEnterKey.bind(this),37:this.onLeftArrow.bind(this),38:this.onUpArrow.bind(this),39:this.onRightArrow.bind(this),40:this.onDownArrow.bind(this)},document.addEventListener("keydown",t=>{var e,s;e=this.container,(s=e.getBoundingClientRect()).top>=0&&s.left>=0&&s.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&s.right<=(window.innerWidth||document.documentElement.clientWidth)&&(t=t||window.event,this.keyActions[t.keyCode]&&this.keyActions[t.keyCode]())}))}makeOverlay(){}updateOverlay(){}bindOverlay(){}bindUnits(){}onLeftArrow(){}onRightArrow(){}onUpArrow(){}onDownArrow(){}onEnterKey(){}addDataPoint(){}removeDataPoint(){}getDataPoint(){}setCurrentDataPoint(){}updateDataset(){}export(){let t=function(t){let e=t.cloneNode(!0);e.classList.add("chart-container"),e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");let s=x.create("style",{innerHTML:".chart-container{position:relative;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Roboto','Oxygen','Ubuntu','Cantarell','Fira Sans','Droid Sans','Helvetica Neue',sans-serif}.chart-container .axis,.chart-container .chart-label{fill:#555b51}.chart-container .axis line,.chart-container .chart-label line{stroke:#dadada}.chart-container .dataset-units circle{stroke:#fff;stroke-width:2}.chart-container .dataset-units path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container .dataset-path{stroke-width:2px}.chart-container .path-group path{fill:none;stroke-opacity:1;stroke-width:2px}.chart-container line.dashed{stroke-dasharray:5,3}.chart-container .axis-line .specific-value{text-anchor:start}.chart-container .axis-line .y-line{text-anchor:end}.chart-container .axis-line .x-line{text-anchor:middle}.chart-container .legend-dataset-text{fill:#6c7680;font-weight:600}.graph-svg-tip{position:absolute;z-index:99999;padding:10px;font-size:12px;color:#959da5;text-align:center;background:rgba(0,0,0,.8);border-radius:3px}.graph-svg-tip ul{padding-left:0;display:flex}.graph-svg-tip ol{padding-left:0;display:flex}.graph-svg-tip ul.data-point-list li{min-width:90px;flex:1;font-weight:600}.graph-svg-tip strong{color:#dfe2e5;font-weight:600}.graph-svg-tip .svg-pointer{position:absolute;height:5px;margin:0 0 0 -5px;content:' ';border:5px solid transparent;border-top-color:rgba(0,0,0,.8)}.graph-svg-tip.comparison{padding:0;text-align:left;pointer-events:none}.graph-svg-tip.comparison .title{display:block;padding:10px;margin:0;font-weight:600;line-height:1;pointer-events:none}.graph-svg-tip.comparison ul{margin:0;white-space:nowrap;list-style:none}.graph-svg-tip.comparison li{display:inline-block;padding:5px 10px}"});e.insertBefore(s,e.firstChild);let i=x.create("div");return i.appendChild(e),i.innerHTML}(this.svg);!function(t,e){var s=document.createElement("a");s.style="display: none";var i=new Blob(e,{type:"image/svg+xml; charset=utf-8"}),a=window.URL.createObjectURL(i);s.href=a,s.download=t,document.body.appendChild(s),s.click(),setTimeout((function(){document.body.removeChild(s),window.URL.revokeObjectURL(a)}),300)}(this.title||"Chart",[t])}}class rt extends nt{constructor(t,e){super(t,e)}configure(t){super.configure(t),this.config.maxSlices=t.maxSlices||20,this.config.maxLegendPoints=t.maxLegendPoints||20}calc(){let t=this.state,e=this.config.maxSlices;t.sliceTotals=[];let s=this.data.labels.map((t,e)=>{let s=0;return this.data.datasets.map(t=>{s+=t.values[e]}),[s,t]}).filter(t=>t[0]>=0),i=s;if(s.length>e){s.sort((t,e)=>e[0]-t[0]),i=s.slice(0,e-1);let t=s.slice(e-1),a=0;t.map(t=>{a+=t[0]}),i.push([a,"Rest"]),this.colors[e-1]="grey"}t.labels=[],i.map(e=>{t.sliceTotals.push(e[0]),t.labels.push(e[1])}),t.grandTotal=t.sliceTotals.reduce((t,e)=>t+e,0),this.center={x:this.width/2,y:this.height/2}}renderLegend(){let t=this.state;this.legendArea.textContent="",this.legendTotals=t.sliceTotals.slice(0,this.config.maxLegendPoints);let e=0,s=0;this.legendTotals.map((i,a)=>{let n=Math.floor((this.width-C(this.measures))/110);e>n&&(e=0,s+=20);let r=function(t,e,s,i="none",a){let n={className:"legend-dot",cx:0,cy:0,r:s,fill:i},r=Y("text",{className:"legend-dataset-text",x:0,y:0,dx:"10px",dy:10/3+"px","font-size":"12px","text-anchor":"start",fill:"#555b51",innerHTML:a}),o=Y("g",{transform:`translate(${t}, ${e})`});return o.appendChild(Y("circle",n)),o.appendChild(r),o}(110*e+5,s,5,this.colors[a],`${t.labels[a]}: ${i}`);this.legendArea.appendChild(r),e++})}}const ot=["January","February","March","April","May","June","July","August","September","October","November","December"],lt=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function ht(t){let e=new Date(t);return e.setMinutes(e.getMinutes()-e.getTimezoneOffset()),e}function dt(t){let e=t.getDate(),s=t.getMonth()+1;return[t.getFullYear(),(s>9?"":"0")+s,(e>9?"":"0")+e].join("-")}function ct(t){return new Date(t.getTime())}function pt(t,e){let s=gt(t);return Math.ceil(function(t,e){return(ht(e)-ht(t))/864e5}(s,e)/7)}function ut(t,e){return t.getMonth()===e.getMonth()&&t.getFullYear()===e.getFullYear()}function mt(t,e=!1){let s=ot[t];return e?s.slice(0,3):s}function ft(t,e){return new Date(e,t+1,0)}function gt(t){let e=ct(t);const s=e.getDay();return 0!==s&&yt(e,-1*s),e}function yt(t,e){t.setDate(t.getDate()+e)}class bt{constructor({layerClass:t="",layerTransform:e="",constants:s,getData:i,makeElements:a,animateElements:n}){this.layerTransform=e,this.constants=s,this.makeElements=a,this.getData=i,this.animateElements=n,this.store=[],this.labels=[],this.layerClass=t,this.layerClass="function"==typeof this.layerClass?this.layerClass():this.layerClass,this.refresh()}refresh(t){this.data=t||this.getData()}setup(t){this.layer=B(this.layerClass,this.layerTransform,t)}make(){this.render(this.data),this.oldData=this.data}render(t){this.store=this.makeElements(t),this.layer.textContent="",this.store.forEach(t=>{this.layer.appendChild(t)}),this.labels.forEach(t=>{this.layer.appendChild(t)})}update(t=!0){this.refresh();let e=[];return t&&(e=this.animateElements(this.data)||[]),e}}let xt={pieSlices:{layerClass:"pie-slices",makeElements:t=>t.sliceStrings.map((e,s)=>{let i=V(e,"pie-path","none",t.colors[s]);return i.style.transition="transform .3s;",i}),animateElements(t){return this.store.map((e,s)=>{return i=e,a=t.sliceStrings[s],[i,{d:a},350,"easein"];var i,a})}},percentageBars:{layerClass:"percentage-bars",makeElements(t){return t.xPositions.map((e,s)=>function(t,e,s,i,a=2,n="none"){return Y("rect",{className:"percentage-bar",x:t,y:e,width:s,height:i,fill:n,styles:{stroke:j(n,-25),"stroke-dasharray":`0, ${i+s}, ${s}, ${i}`,"stroke-width":a}})}(e,0,t.widths[s],this.constants.barHeight,this.constants.barDepth,t.colors[s]))},animateElements(t){if(t)return[]}},yAxis:{layerClass:"y axis",makeElements(t){return t.positions.map((e,s)=>function(t,e,s,i={}){i.pos||(i.pos="left"),i.offset||(i.offset=0),i.mode||(i.mode="span"),i.stroke||(i.stroke="#dadada"),i.className||(i.className="");let a=-6,n="span"===i.mode?s+6:0;return"tick"===i.mode&&"right"===i.pos&&(a=s+6,n=s),a+=i.offset,n+=i.offset,X(t,e,a,n,{stroke:i.stroke,className:i.className,lineType:i.lineType})}(e,t.labels[s],this.constants.width,{mode:this.constants.mode,pos:this.constants.pos}))},animateElements(t){let e=t.positions,s=t.labels,i=this.oldData.positions,a=this.oldData.labels;return[i,e]=$(i,e),[a,s]=$(a,s),this.render({positions:i,labels:s}),this.store.map((t,s)=>tt(t,e[s],i[s]))}},xAxis:{layerClass:"x axis",makeElements(t){return t.positions.map((e,s)=>J(e,t.calcLabels[s],this.constants.height,{mode:this.constants.mode,pos:this.constants.pos}))},animateElements(t){let e=t.positions,s=t.calcLabels,i=this.oldData.positions,a=this.oldData.calcLabels;return[i,e]=$(i,e),[a,s]=$(a,s),this.render({positions:i,calcLabels:s}),this.store.map((t,s)=>function(t,e,s){return Z(t,[s,0],[e,0],350)}(t,e[s],i[s]))}},yMarkers:{layerClass:"y-markers",makeElements(t){return t.map(t=>function(t,e,s,i={}){i.labelPos||(i.labelPos="right");let a=Y("text",{className:"chart-label",x:"left"===i.labelPos?4:s-S(e,5)-4,y:0,dy:"-5px","font-size":"10px","text-anchor":"start",innerHTML:e+""}),n=X(t,"",0,s,{stroke:i.stroke||"#dadada",className:i.className||"",lineType:i.lineType});return n.appendChild(a),n}(t.position,t.label,this.constants.width,{labelPos:t.options.labelPos,mode:"span",lineType:"dashed"}))},animateElements(t){[this.oldData,t]=$(this.oldData,t);let e=t.map(t=>t.position),s=t.map(t=>t.label),i=t.map(t=>t.options),a=this.oldData.map(t=>t.position);return this.render(a.map((t,e)=>({position:a[e],label:s[e],options:i[e]}))),this.store.map((t,s)=>tt(t,e[s],a[s]))}},yRegions:{layerClass:"y-regions",makeElements(t){return t.map(t=>function(t,e,s,i,a={}){let n=t-e,r=Y("rect",{className:"bar mini",styles:{fill:"rgba(228, 234, 239, 0.49)",stroke:"#dadada","stroke-dasharray":`${s}, ${n}`},x:0,y:0,width:s,height:n});a.labelPos||(a.labelPos="right");let o=Y("text",{className:"chart-label",x:"left"===a.labelPos?4:s-S(i+"",4.5)-4,y:0,dy:"-5px","font-size":"10px","text-anchor":"start",innerHTML:i+""}),l=Y("g",{transform:`translate(0, ${e})`});return l.appendChild(r),l.appendChild(o),l}(t.startPos,t.endPos,this.constants.width,t.label,{labelPos:t.options.labelPos}))},animateElements(t){[this.oldData,t]=$(this.oldData,t);let e=t.map(t=>t.endPos),s=t.map(t=>t.label),i=t.map(t=>t.startPos),a=t.map(t=>t.options),n=this.oldData.map(t=>t.endPos),r=this.oldData.map(t=>t.startPos);this.render(n.map((t,e)=>({startPos:r[e],endPos:n[e],label:s[e],options:a[e]})));let o=[];return this.store.map((t,s)=>{o=o.concat(function(t,e,s,i){let a=e-s,n=t.childNodes[0],r=n.getAttribute("width");return[[n,{height:a,"stroke-dasharray":`${r}, ${a}`},350,"easein"],Z(t,[0,i],[0,s],350)]}(t,i[s],e[s],n[s]))}),o}},heatDomain:{layerClass:function(){return"heat-domain domain-"+this.constants.index},makeElements(t){let{index:e,colWidth:s,rowHeight:i,squareSize:a,xTranslate:n}=this.constants,r=n,o=0;return this.serializedSubDomains=[],t.cols.map((t,n)=>{1===n&&this.labels.push(q("domain-name",r,-12,mt(e,!0).toUpperCase(),{fontSize:9})),t.map((t,e)=>{if(t.fill){let s={"data-date":t.yyyyMmDd,"data-value":t.dataValue,"data-day":e},i=G("day",r,o,a,t.fill,s);this.serializedSubDomains.push(i)}o+=i}),o=0,r+=s}),this.serializedSubDomains},animateElements(t){if(t)return[]}},barGraph:{layerClass:function(){return"dataset-units dataset-bars dataset-"+this.constants.index},makeElements(t){let e=this.constants;return this.unitType="bar",this.units=t.yPositions.map((s,i)=>function(t,e,s,i,a="",n=0,r=0,o={}){let[l,h]=W(e,o.zeroLine);h-=r,0===l&&(l=o.minHeight,h-=o.minHeight);let d=Y("rect",{className:"bar mini",style:"fill: "+i,"data-point-index":n,x:t,y:h,width:s,height:l});if((a+="")||a.length){d.setAttribute("y",0),d.setAttribute("x",0);let e=Y("text",{className:"data-point-value",x:s/2,y:0,dy:"-5px","font-size":"10px","text-anchor":"middle",innerHTML:a}),i=Y("g",{"data-point-index":n,transform:`translate(${t}, ${h})`});return i.appendChild(d),i.appendChild(e),i}return d}(t.xPositions[i],s,t.barWidth,e.color,t.labels[i],i,t.offsets[i],{zeroLine:t.zeroLine,barsWidth:t.barsWidth,minHeight:e.minHeight})),this.units},animateElements(t){let e=t.xPositions,s=t.yPositions,i=t.offsets,a=t.labels,n=this.oldData.xPositions,r=this.oldData.yPositions,o=this.oldData.offsets,l=this.oldData.labels;[n,e]=$(n,e),[r,s]=$(r,s),[o,i]=$(o,i),[l,a]=$(l,a),this.render({xPositions:n,yPositions:r,offsets:o,labels:a,zeroLine:this.oldData.zeroLine,barsWidth:this.oldData.barsWidth,barWidth:this.oldData.barWidth});let h=[];return this.store.map((a,n)=>{h=h.concat(function(t,e,s,i,a=0,n={}){let[r,o]=W(s,n.zeroLine);if(o-=a,"rect"!==t.nodeName){let s=[t.childNodes[0],{width:i,height:r},350,"easein"],a=t.getAttribute("transform").split("(")[1].slice(0,-1);return[s,Z(t,a,[e,o],350)]}return[[t,{width:i,height:r,x:e,y:o},350,"easein"]]}(a,e[n],s[n],t.barWidth,i[n],{zeroLine:t.zeroLine}))}),h}},lineGraph:{layerClass:function(){return"dataset-units dataset-line dataset-"+this.constants.index},makeElements(t){let e=this.constants;return this.unitType="dot",this.paths={},e.hideLine||(this.paths=function(t,e,s,i={},a={}){let n=e.map((e,s)=>t[s]+","+e).join("L"),r=V("M"+n,"line-graph-path",s);if(i.heatline){let t=U(a.svgDefs,s);r.style.stroke=`url(#${t})`}let o={path:r};if(i.regionFill){let e=U(a.svgDefs,s,!0),i=`M${t[0]},${a.zeroLine}L`+n+`L${t.slice(-1)[0]},${a.zeroLine}`;o.region=V(i,"region-fill","none",`url(#${e})`)}return o}(t.xPositions,t.yPositions,e.color,{heatline:e.heatline,regionFill:e.regionFill},{svgDefs:e.svgDefs,zeroLine:t.zeroLine})),this.units=[],e.hideDots||(this.units=t.yPositions.map((s,i)=>function(t,e,s,i,a="",n=0){let r=Y("circle",{style:"fill: "+i,"data-point-index":n,cx:t,cy:e,r:s});if((a+="")||a.length){r.setAttribute("cy",0),r.setAttribute("cx",0);let i=Y("text",{className:"data-point-value",x:0,y:0,dy:-5-s+"px","font-size":"10px","text-anchor":"middle",innerHTML:a}),o=Y("g",{"data-point-index":n,transform:`translate(${t}, ${e})`});return o.appendChild(r),o.appendChild(i),o}return r}(t.xPositions[i],s,t.radius,e.color,e.valuesOverPoints?t.values[i]:"",i))),Object.values(this.paths).concat(this.units)},animateElements(t){let e=t.xPositions,s=t.yPositions,i=t.values,a=this.oldData.xPositions,n=this.oldData.yPositions,r=this.oldData.values;[a,e]=$(a,e),[n,s]=$(n,s),[r,i]=$(r,i),this.render({xPositions:a,yPositions:n,values:i,zeroLine:this.oldData.zeroLine,radius:this.oldData.radius});let o=[];return Object.keys(this.paths).length&&(o=o.concat(function(t,e,s,i){let a=[],n=s.map((t,s)=>e[s]+","+t).join("L");const r=[t.path,{d:"M"+n},350,"easein"];if(a.push(r),t.region){let s=`${e[0]},${i}L`,r=`L${e.slice(-1)[0]}, ${i}`;const o=[t.region,{d:"M"+s+n+r},350,"easein"];a.push(o)}return a}(this.paths,e,s,t.zeroLine))),this.units.length&&this.units.map((t,i)=>{o=o.concat(function(t,e,s){if("circle"!==t.nodeName){let i=t.getAttribute("transform").split("(")[1].slice(0,-1);return[Z(t,i,[e,s],350)]}return[[t,{cx:e,cy:s},350,"easein"]]}(t,e[i],s[i]))}),o}}};function vt(t,e,s){let i=Object.keys(xt).filter(e=>t.includes(e)),a=xt[i[0]];return Object.assign(a,{constants:e,getData:s}),new bt(a)}function wt(t){if(0===t)return[0,0];if(isNaN(t))return{mantissa:-6755399441055744,exponent:972};var e=t>0?1:-1;if(!isFinite(t))return{mantissa:4503599627370496*e,exponent:972};t=Math.abs(t);var s=Math.floor(Math.log10(t));return[e*(t/Math.pow(10,s)),s]}function At(t,e=0){let[s,i]=wt(t),a=e?e/Math.pow(10,i):0;s=s.toFixed(6);let n=function(t,e=0){let s=Math.ceil(t),i=Math.floor(e),a=s-i,n=a,r=1;a>5&&(a%2!=0&&(s++,a=s-i),n=a/2,r=2),a<=2&&(n=4,r=a/n),0===a&&(n=5,r=1);let o=[];for(var l=0;l<=n;l++)o.push(i+r*l);return o}(s,a);return n=n.map(t=>t*Math.pow(10,i)),n}function Pt(t){return t[1]-t[0]}function kt(t,e){return O(e.zeroLine-t*e.scaleMultiplier)}class Ct extends nt{constructor(t,e){super(t,e),this.barOptions=e.barOptions||{},this.lineOptions=e.lineOptions||{},this.type=e.type||"line",this.init=1,this.setup()}setMeasures(){this.data.datasets.length<=1&&(this.config.showLegend=0,this.measures.paddings.bottom=30)}configure(t){super.configure(t),t.axisOptions=t.axisOptions||{},t.tooltipOptions=t.tooltipOptions||{},this.config.xAxisMode=t.axisOptions.xAxisMode||"span",this.config.yAxisMode=t.axisOptions.yAxisMode||"span",this.config.xIsSeries=t.axisOptions.xIsSeries||0,this.config.formatTooltipX=t.tooltipOptions.formatTooltipX,this.config.formatTooltipY=t.tooltipOptions.formatTooltipY,this.config.valuesOverPoints=t.valuesOverPoints}prepareData(t=this.data){return function(t,e){t.labels=t.labels||[];let s=t.labels.length,i=t.datasets,a=new Array(s).fill(0);return i||(i=[{values:a}]),i.map(t=>{if(t.values){let e=t.values;e=e.map(t=>isNaN(t)?0:t),e=e.length>s?e.slice(0,s):E(e,s-e.length,0)}else t.values=a;t.chartType||(D.includes(e),t.chartType=e)}),t.yRegions&&t.yRegions.map(t=>{t.end<t.start&&([t.start,t.end]=[t.end,t.start])}),t}(t,this.type)}prepareFirstData(t=this.data){return function(t){let e=t.labels.length,s=new Array(e).fill(0),i={labels:t.labels.slice(0,-1),datasets:t.datasets.map(t=>({name:"",values:s.slice(0,-1),chartType:t.chartType}))};return t.yMarkers&&(i.yMarkers=[{value:0,label:""}]),t.yRegions&&(i.yRegions=[{start:0,end:0,label:""}]),i}(t)}calc(t=!1){this.calcXPositions(),t||this.calcYAxisParameters(this.getAllYValues(),"line"===this.type),this.makeDataByIndex()}calcXPositions(){let t=this.state,e=this.data.labels;t.datasetLength=e.length,t.unitWidth=this.width/t.datasetLength,t.xOffset=t.unitWidth/2,t.xAxis={labels:e,positions:e.map((e,s)=>O(t.xOffset+s*t.unitWidth))}}calcYAxisParameters(t,e="false"){const s=function(t,e=!1){let s=Math.max(...t),i=Math.min(...t),a=0,n=[];function r(t,e){let s=At(t),i=s[1]-s[0],a=0;for(var n=1;a<e;n++)a+=i,s.unshift(-1*a);return s}if(s>=0&&i>=0)a=wt(s)[1],n=e?At(s,i):At(s);else if(s>0&&i<0){let t=Math.abs(i);if(s>=t)a=wt(s)[1],n=r(s,t);else{a=wt(t)[1],n=r(t,s).map(t=>-1*t)}}else if(s<=0&&i<=0){let t=Math.abs(i),r=Math.abs(s);a=wt(t)[1],n=e?At(t,r):At(t),n=n.reverse().map(t=>-1*t)}return n}(t,e),i=this.height/((a=s)[a.length-1]-a[0]);var a;const n=Pt(s)*i,r=this.height-function(t){let e,s=Pt(t);if(t.indexOf(0)>=0)e=t.indexOf(0);else if(t[0]>0){e=-1*t[0]/s}else{e=-1*t[t.length-1]/s+(t.length-1)}return e}(s)*n;this.state.yAxis={labels:s,positions:s.map(t=>r-t*i),scaleMultiplier:i,zeroLine:r},this.calcDatasetPoints(),this.calcYExtremes(),this.calcYRegions()}calcDatasetPoints(){let t=this.state,e=e=>e.map(e=>kt(e,t.yAxis));t.datasets=this.data.datasets.map((t,s)=>{let i=t.values,a=t.cumulativeYs||[];return{name:t.name,index:s,chartType:t.chartType,values:i,yPositions:e(i),cumulativeYs:a,cumulativeYPos:e(a)}})}calcYExtremes(){let t=this.state;this.barOptions.stacked?t.yExtremes=t.datasets[t.datasets.length-1].cumulativeYPos:(t.yExtremes=new Array(t.datasetLength).fill(9999),t.datasets.map(e=>{e.yPositions.map((e,s)=>{e<t.yExtremes[s]&&(t.yExtremes[s]=e)})}))}calcYRegions(){let t=this.state;this.data.yMarkers&&(this.state.yMarkers=this.data.yMarkers.map(e=>(e.position=kt(e.value,t.yAxis),e.options||(e.options={}),e))),this.data.yRegions&&(this.state.yRegions=this.data.yRegions.map(e=>(e.startPos=kt(e.start,t.yAxis),e.endPos=kt(e.end,t.yAxis),e.options||(e.options={}),e)))}getAllYValues(){let t="values";if(this.barOptions.stacked){t="cumulativeYs";let e=new Array(this.state.datasetLength).fill(0);this.data.datasets.map((s,i)=>{let a=this.data.datasets[i].values;s[t]=e=e.map((t,e)=>t+a[e])})}let e=this.data.datasets.map(e=>e[t]);return this.data.yMarkers&&e.push(this.data.yMarkers.map(t=>t.value)),this.data.yRegions&&this.data.yRegions.map(t=>{e.push([t.end,t.start])}),[].concat(...e)}setupComponents(){let t=[["yAxis",{mode:this.config.yAxisMode,width:this.width},function(){return this.state.yAxis}.bind(this)],["xAxis",{mode:this.config.xAxisMode,height:this.height},function(){let t=this.state;return t.xAxis.calcLabels=function(t,e=[],s=!0){let i=t/e.length;i<=0&&(i=1);let a=i/7;return e.map((t,e)=>{if((t+="").length>a)if(s){e%Math.ceil(t.length/a)!=0&&(t="")}else t=a-3>0?t.slice(0,a-3)+" ...":t.slice(0,a)+"..";return t})}(this.width,t.xAxis.labels,this.config.xIsSeries),t.xAxis}.bind(this)],["yRegions",{width:this.width,pos:"right"},function(){return this.state.yRegions}.bind(this)]],e=this.state.datasets.filter(t=>"bar"===t.chartType),s=this.state.datasets.filter(t=>"line"===t.chartType),i=e.map(t=>{let s=t.index;return["barGraph-"+t.index,{index:s,color:this.colors[s],stacked:this.barOptions.stacked,valuesOverPoints:this.config.valuesOverPoints,minHeight:.01*this.height},function(){let t=this.state,i=t.datasets[s],a=this.barOptions.stacked,n=this.barOptions.spaceRatio||.5,r=t.unitWidth*(1-n),o=r/(a?1:e.length),l=t.xAxis.positions.map(t=>t-r/2);a||(l=l.map(t=>t+o*s));let h=new Array(t.datasetLength).fill("");this.config.valuesOverPoints&&(h=a&&i.index===t.datasets.length-1?i.cumulativeYs:i.values);let d=new Array(t.datasetLength).fill(0);return a&&(d=i.yPositions.map((t,e)=>t-i.cumulativeYPos[e])),{xPositions:l,yPositions:i.yPositions,offsets:d,labels:h,zeroLine:t.yAxis.zeroLine,barsWidth:r,barWidth:o}}.bind(this)]}),a=s.map(t=>{let e=t.index;return["lineGraph-"+t.index,{index:e,color:this.colors[e],svgDefs:this.svgDefs,heatline:this.lineOptions.heatline,regionFill:this.lineOptions.regionFill,hideDots:this.lineOptions.hideDots,hideLine:this.lineOptions.hideLine,valuesOverPoints:this.config.valuesOverPoints},function(){let t=this.state,s=t.datasets[e],i=t.yAxis.positions[0]<t.yAxis.zeroLine?t.yAxis.positions[0]:t.yAxis.zeroLine;return{xPositions:t.xAxis.positions,yPositions:s.yPositions,values:s.values,zeroLine:i,radius:this.lineOptions.dotSize||4}}.bind(this)]}),n=[["yMarkers",{width:this.width,pos:"right"},function(){return this.state.yMarkers}.bind(this)]];t=t.concat(i,a,n);let r=["yMarkers","yRegions"];this.dataUnitComponents=[],this.components=new Map(t.filter(t=>!r.includes(t[0])||this.state[t[0]]).map(t=>{let e=vt(...t);return(t[0].includes("lineGraph")||t[0].includes("barGraph"))&&this.dataUnitComponents.push(e),[t[0],e]}))}makeDataByIndex(){this.dataByIndex={};let t=this.state,e=this.config.formatTooltipX,s=this.config.formatTooltipY;t.xAxis.labels.map((i,a)=>{let n=this.state.datasets.map((t,e)=>{let i=t.values[a];return{title:t.name,value:i,yPos:t.yPositions[a],color:this.colors[e],formatted:s?s(i):i}});this.dataByIndex[a]={label:i,formattedLabel:e?e(i):i,xPos:t.xAxis.positions[a],values:n,yExtreme:t.yExtremes[a]}})}bindTooltip(){this.container.addEventListener("mousemove",t=>{let e=this.measures,s=v(this.container),i=t.pageX-s.left-P(e),a=t.pageY-s.top;a<this.height+A(e)&&a>A(e)?this.mapTooltipXPosition(i):this.tip.hideTip()})}mapTooltipXPosition(t){let e=this.state;if(!e.yExtremes)return;let s=function(t,e,s=!1){let i=e.reduce((function(e,s){return Math.abs(s-t)<Math.abs(e-t)?s:e}));return s?e.indexOf(i):i}(t,e.xAxis.positions,!0),i=this.dataByIndex[s];this.tip.setValues(i.xPos+this.tip.offset.x,i.yExtreme+this.tip.offset.y,{name:i.formattedLabel,value:""},i.values,s),this.tip.showTip()}renderLegend(){let t=this.data;t.datasets.length>1&&(this.legendArea.textContent="",t.datasets.map((t,e)=>{let s=function(t,e,s,i="none",a){let n={className:"legend-bar",x:0,y:0,width:s,height:"2px",fill:i},r=Y("text",{className:"legend-dataset-text",x:0,y:0,dy:"20px","font-size":"12px","text-anchor":"start",fill:"#555b51",innerHTML:a}),o=Y("g",{transform:`translate(${t}, ${e})`});return o.appendChild(Y("rect",n)),o.appendChild(r),o}(100*e,"0",100,this.colors[e],t.name);this.legendArea.appendChild(s)}))}makeOverlay(){this.init?this.init=0:(this.overlayGuides&&this.overlayGuides.forEach(t=>{let e=t.overlay;e.parentNode.removeChild(e)}),this.overlayGuides=this.dataUnitComponents.map(t=>({type:t.unitType,overlay:void 0,units:t.units})),void 0===this.state.currentIndex&&(this.state.currentIndex=this.state.datasetLength-1),this.overlayGuides.map(t=>{let e=t.units[this.state.currentIndex];t.overlay=K[t.type](e),this.drawArea.appendChild(t.overlay)}))}updateOverlayGuides(){this.overlayGuides&&this.overlayGuides.forEach(t=>{let e=t.overlay;e.parentNode.removeChild(e)})}bindOverlay(){this.parent.addEventListener("data-select",()=>{this.updateOverlay()})}bindUnits(){this.dataUnitComponents.map(t=>{t.units.map(t=>{t.addEventListener("click",()=>{let e=t.getAttribute("data-point-index");this.setCurrentDataPoint(e)})})}),this.tip.container.addEventListener("click",()=>{let t=this.tip.container.getAttribute("data-point-index");this.setCurrentDataPoint(t)})}updateOverlay(){this.overlayGuides.map(t=>{let e=t.units[this.state.currentIndex];Q[t.type](e,t.overlay)})}onLeftArrow(){this.setCurrentDataPoint(this.state.currentIndex-1)}onRightArrow(){this.setCurrentDataPoint(this.state.currentIndex+1)}getDataPoint(t=this.state.currentIndex){let e=this.state;return{index:t,label:e.xAxis.labels[t],values:e.datasets.map(e=>e.values[t])}}setCurrentDataPoint(t){let e=this.state;(t=parseInt(t))<0&&(t=0),t>=e.xAxis.labels.length&&(t=e.xAxis.labels.length-1),t!==e.currentIndex&&(e.currentIndex=t,function(t,e,s){var i=document.createEvent("HTMLEvents");for(var a in i.initEvent(e,!0,!0),s)i[a]=s[a];t.dispatchEvent(i)}(this.parent,"data-select",this.getDataPoint()))}addDataPoint(t,e,s=this.state.datasetLength){super.addDataPoint(t,e,s),this.data.labels.splice(s,0,t),this.data.datasets.map((t,i)=>{t.values.splice(s,0,e[i])}),this.update(this.data)}removeDataPoint(t=this.state.datasetLength-1){this.data.labels.length<=1||(super.removeDataPoint(t),this.data.labels.splice(t,1),this.data.datasets.map(e=>{e.values.splice(t,1)}),this.update(this.data))}updateDataset(t,e=0){this.data.datasets[e].values=t,this.update(this.data)}updateDatasets(t){this.data.datasets.map((e,s)=>{t[s]&&(e.values=t[s])}),this.update(this.data)}}const Dt={bar:Ct,line:Ct,percentage:class extends rt{constructor(t,e){super(t,e),this.type="percentage",this.setup()}setMeasures(t){let e=this.measures;this.barOptions=t.barOptions||{};let s=this.barOptions;s.height=s.height||20,s.depth=s.depth||2,e.paddings.right=30,e.legendHeight=80,e.baseHeight=8*(s.height+.5*s.depth)}setupComponents(){let t=this.state,e=[["percentageBars",{barHeight:this.barOptions.height,barDepth:this.barOptions.depth},function(){return{xPositions:t.xPositions,widths:t.widths,colors:this.colors}}.bind(this)]];this.components=new Map(e.map(t=>{let e=vt(...t);return[t[0],e]}))}calc(){super.calc();let t=this.state;t.xPositions=[],t.widths=[];let e=0;t.sliceTotals.map(s=>{let i=this.width*s/t.grandTotal;t.widths.push(i),t.xPositions.push(e),e+=i})}makeDataByIndex(){}bindTooltip(){let t=this.state;this.container.addEventListener("mousemove",e=>{let s=this.components.get("percentageBars").store,i=e.target;if(s.includes(i)){let e=s.indexOf(i),a=v(this.container),n=v(i),r=n.left-a.left+parseInt(i.getAttribute("width"))/2,o=n.top-a.top,l=(this.formattedLabels&&this.formattedLabels.length>0?this.formattedLabels[e]:this.state.labels[e])+": ",h=t.sliceTotals[e]/t.grandTotal;this.tip.setValues(r,o,{name:l,value:(100*h).toFixed(1)+"%"}),this.tip.showTip()}})}},heatmap:class extends nt{constructor(t,e){super(t,e),this.type="heatmap",this.countLabel=e.countLabel||"";let s=["Sunday","Monday"],i=s.includes(e.startSubDomain)?e.startSubDomain:"Sunday";this.startSubDomainIndex=s.indexOf(i),this.setup()}setMeasures(t){let e=this.measures;this.discreteDomains=0===t.discreteDomains?0:1,e.paddings.top=36,e.paddings.bottom=0,e.legendHeight=24,e.baseHeight=84+k(e);let s=this.data,i=this.discreteDomains?12:0;this.independentWidth=12*(pt(s.start,s.end)+i)+C(e)}updateWidth(){let t=this.discreteDomains?12:0,e=this.state.noOfWeeks?this.state.noOfWeeks:52;this.baseWidth=12*(e+t)+C(this.measures)}prepareData(t=this.data){if(t.start&&t.end&&t.start>t.end)throw new Error("Start date cannot be greater than end date.");if(t.start||(t.start=new Date,t.start.setFullYear(t.start.getFullYear()-1)),t.end||(t.end=new Date),t.dataPoints=t.dataPoints||{},parseInt(Object.keys(t.dataPoints)[0])>1e5){let e={};Object.keys(t.dataPoints).forEach(s=>{let i=new Date(1e3*s);e[dt(i)]=t.dataPoints[s]}),t.dataPoints=e}return t}calc(){let t=this.state;t.start=ct(this.data.start),t.end=ct(this.data.end),t.firstWeekStart=ct(t.start),t.noOfWeeks=pt(t.start,t.end),t.distribution=function(t,e){let s=Math.max(...t),i=1/(e-1),a=[];for(var n=0;n<e;n++){let t=s*(i*n);a.push(t)}return a}(Object.values(this.data.dataPoints),5),t.domainConfigs=this.getDomains()}setupComponents(){let t=this.state,e=this.discreteDomains?0:1,s=t.domainConfigs.map((s,i)=>["heatDomain",{index:s.index,colWidth:12,rowHeight:12,squareSize:10,xTranslate:12*t.domainConfigs.filter((t,e)=>e<i).map(t=>t.cols.length-e).reduce((t,e)=>t+e,0)},function(){return t.domainConfigs[i]}.bind(this)]);this.components=new Map(s.map((t,e)=>{let s=vt(...t);return[t[0]+"-"+e,s]}));let i=0;lt.forEach((t,e)=>{if([1,3,5].includes(e)){let e=q("subdomain-name",-6,i,t,{fontSize:10,dy:8,textAnchor:"end"});this.drawArea.appendChild(e)}i+=12})}update(t){t||console.error("No data to update."),this.data=this.prepareData(t),this.draw(),this.bindTooltip()}bindTooltip(){this.container.addEventListener("mousemove",t=>{this.components.forEach(e=>{let s=e.store,i=t.target;if(s.includes(i)){let e=i.getAttribute("data-value"),s=i.getAttribute("data-date").split("-"),a=mt(parseInt(s[1])-1,!0),n=this.container.getBoundingClientRect(),r=i.getBoundingClientRect(),o=parseInt(t.target.getAttribute("width")),l=r.left-n.left+o/2,h=r.top-n.top,d=e+" "+this.countLabel,c=" on "+a+" "+s[0]+", "+s[2];this.tip.setValues(l,h,{name:c,value:d,valueFirst:1},[]),this.tip.showTip()}})})}renderLegend(){this.legendArea.textContent="";let t=0,e=q("subdomain-name",t,12,"Less",{fontSize:11,dy:9});t=30,this.legendArea.appendChild(e),this.colors.slice(0,5).map((e,s)=>{const i=G("heatmap-legend-unit",t+15*s,12,10,e);this.legendArea.appendChild(i)});let s=q("subdomain-name",t+75+3,12,"More",{fontSize:11,dy:9});this.legendArea.appendChild(s)}getDomains(){let t=this.state;const[e,s]=[t.start.getMonth(),t.start.getFullYear()],[i,a]=[t.end.getMonth(),t.end.getFullYear()],n=i-e+1+12*(a-s);let r=[],o=ct(t.start);for(var l=0;l<n;l++){let e=t.end;if(!ut(o,t.end)){let[t,s]=[o.getMonth(),o.getFullYear()];e=ft(t,s)}r.push(this.getDomainConfig(o,e)),yt(e,1),o=e}return r}getDomainConfig(t,e=""){let[s,i]=[t.getMonth(),t.getFullYear()],a=gt(t),n={index:s,cols:[]};yt(e=ct(e)||ft(s,i),1);let r,o=pt(a,e),l=[];for(var h=0;h<o;h++)r=this.getCol(a,s),l.push(r),a=new Date(r[6].yyyyMmDd),yt(a,1);return void 0!==r[6].dataValue&&(yt(a,1),l.push(this.getCol(a,s,!0))),n.cols=l,n}getCol(t,e,s=!1){let i=this.state,a=ct(t),n=[];for(var r=0;r<7;r++,yt(a,1)){let t={},r=a>=i.start&&a<=i.end;s||a.getMonth()!==e||!r?t.yyyyMmDd=dt(a):t=this.getSubDomainConfig(a),n.push(t)}return n}getSubDomainConfig(t){let e=dt(t),s=this.data.dataPoints[e];var i,a;return{yyyyMmDd:e,dataValue:s||0,fill:this.colors[(i=s,a=this.state.distribution,a.filter(t=>t<i).length)]}}},pie:class extends rt{constructor(t,e){super(t,e),this.type="pie",this.initTimeout=0,this.init=1,this.setup()}configure(t){super.configure(t),this.mouseMove=this.mouseMove.bind(this),this.mouseLeave=this.mouseLeave.bind(this),this.hoverRadio=t.hoverRadio||.1,this.config.startAngle=t.startAngle||0,this.clockWise=t.clockWise||!1}calc(){super.calc();let t=this.state;this.radius=this.height>this.width?this.center.x:this.center.y;const{radius:e,clockWise:s}=this,i=t.slicesProperties||[];t.sliceStrings=[],t.slicesProperties=[];let a=180-this.config.startAngle;t.sliceTotals.map((n,r)=>{const o=a,l=n/t.grandTotal*360,h=s?-l:l,d=a+=h,c=z(o,e),p=z(d,e),u=this.init&&i[r];let m,f;this.init?(m=u?u.startPosition:c,f=u?u.endPosition:c):(m=c,f=p);const g=function(t,e,s,i,a=1){let[n,r]=[s.x+t.x,s.y+t.y],[o,l]=[s.x+e.x,s.y+e.y];return`M${s.x} ${s.y}\n\t\tL${n} ${r}\n\t\tA ${i} ${i} 0 0 ${a?1:0}\n\t\t${o} ${l} z`}(m,f,this.center,this.radius,this.clockWise);t.sliceStrings.push(g),t.slicesProperties.push({startPosition:c,endPosition:p,value:n,total:t.grandTotal,startAngle:o,endAngle:d,angle:h})}),this.init=0}setupComponents(){let t=this.state,e=[["pieSlices",{},function(){return{sliceStrings:t.sliceStrings,colors:this.colors}}.bind(this)]];this.components=new Map(e.map(t=>{let e=vt(...t);return[t[0],e]}))}calTranslateByAngle(t){const{radius:e,hoverRadio:s}=this,i=z(t.startAngle+t.angle/2,e);return`translate3d(${i.x*s}px,${i.y*s}px,0)`}hoverSlice(t,e,s,i){if(!t)return;const a=this.colors[e];if(s){st(t,this.calTranslateByAngle(this.state.slicesProperties[e])),t.style.fill=j(a,50);let s=v(this.svg),n=i.pageX-s.left+10,r=i.pageY-s.top-10,o=(this.formatted_labels&&this.formatted_labels.length>0?this.formatted_labels[e]:this.state.labels[e])+": ",l=(100*this.state.sliceTotals[e]/this.state.grandTotal).toFixed(1);this.tip.setValues(n,r,{name:o,value:l+"%"}),this.tip.showTip()}else st(t,"translate3d(0,0,0)"),this.tip.hideTip(),t.style.fill=a}bindTooltip(){this.container.addEventListener("mousemove",this.mouseMove),this.container.addEventListener("mouseleave",this.mouseLeave)}mouseMove(t){const e=t.target;let s=this.components.get("pieSlices").store,i=this.curActiveSliceIndex,a=this.curActiveSlice;if(s.includes(e)){let n=s.indexOf(e);this.hoverSlice(a,i,!1),this.curActiveSlice=e,this.curActiveSliceIndex=n,this.hoverSlice(e,n,!0,t)}else this.mouseLeave()}mouseLeave(){this.hoverSlice(this.curActiveSlice,this.curActiveSliceIndex,!1)}}};class Lt{constructor(t,e){return function(t="line",e,s){return"axis-mixed"===t?(s.type="line",new Ct(e,s)):Dt[t]?new Dt[t](e,s):void console.error("Undefined chart type: "+t)}(e.type,t,e)}}var Tt=function(t){var e,s;function i(){return t.apply(this,arguments)||this}s=t,(e=i).prototype=Object.create(s.prototype),e.prototype.constructor=e,e.__proto__=s;var a=i.prototype;return a.init=function(){t.prototype.init.call(this);var e=new Date;e.setTime(e.getTime()+1e3*app.data.statistics.timezoneOffset),e.setUTCHours(0,0,0,0),e.setTime(e.getTime()-1e3*app.data.statistics.timezoneOffset),e/=1e3,this.entities=["users","discussions","posts"],this.periods={today:{start:e,end:e+86400,step:3600},last_7_days:{start:e-604800,end:e,step:86400},last_28_days:{start:e-2419200,end:e,step:86400},last_12_months:{start:e-31449600,end:e,step:604800}},this.selectedEntity="users",this.selectedPeriod="last_7_days"},a.className=function(){return"StatisticsWidget"},a.content=function(){var t=this,e=this.periods[this.selectedPeriod];return m("div",{className:"StatisticsWidget-table"},m("div",{className:"StatisticsWidget-labels"},m("div",{className:"StatisticsWidget-label"},app.translator.trans("flarum-statistics.admin.statistics.total_label")),m("div",{className:"StatisticsWidget-label"},m(c.a,{buttonClassName:"Button Button--text",caretIcon:"fas fa-caret-down"},Object.keys(this.periods).map((function(e){return m(u.a,{active:e===t.selectedPeriod,onclick:t.changePeriod.bind(t,e),icon:e!==t.selectedPeriod||"fas fa-check"},app.translator.trans("flarum-statistics.admin.statistics."+e+"_label"))}))))),this.entities.map((function(s){var i=t.getTotalCount(s),a=t.getPeriodCount(s,e),n=t.getPeriodCount(s,t.getLastPeriod(e)),r=n>0&&(a-n)/n*100;return m("a",{className:"StatisticsWidget-entity"+(t.selectedEntity===s?" active":""),onclick:t.changeEntity.bind(t,s)},m("h3",{className:"StatisticsWidget-heading"},app.translator.trans("flarum-statistics.admin.statistics."+s+"_heading")),m("div",{className:"StatisticsWidget-total",title:i},b()(i)),m("div",{className:"StatisticsWidget-period",title:a},b()(a)," ",r?m("span",{className:"StatisticsWidget-change StatisticsWidget-change--"+(r>0?"up":"down")},g()("fas fa-arrow-"+(r>0?"up":"down")),Math.abs(r.toFixed(1)),"%"):""))})),m("div",{className:"StatisticsWidget-chart",config:this.drawChart.bind(this)}))},a.drawChart=function(t,e,s){if(!s.chart||s.entity!==this.selectedEntity||s.period!==this.selectedPeriod){for(var i=app.data.statistics.timezoneOffset,a=this.periods[this.selectedPeriod],n=a.end-a.start,r=[],o=[],l=[],h=a.start;h<a.end;h+=a.step){var d=void 0;a.step<86400?d=dayjs.unix(h+i).format("h A"):(d=dayjs.unix(h+i).format("D MMM"),a.step>86400&&(d+=" - "+dayjs.unix(h+i+a.step-1).format("D MMM"))),r.push(d),o.push(this.getPeriodCount(this.selectedEntity,{start:h,end:h+a.step})),l.push(this.getPeriodCount(this.selectedEntity,{start:h-n,end:h-n+a.step}))}var c={labels:r,datasets:[{values:l},{values:o}]};s.chart?s.chart.update(c):s.chart=new Lt(t,{data:c,type:"line",height:280,axisOptions:{xAxisMode:"tick",yAxisMode:"span",xIsSeries:!0},lineOptions:{hideDots:1},colors:["black",app.forum.attribute("themePrimaryColor")]}),s.entity=this.selectedEntity,s.period=this.selectedPeriod}},a.changeEntity=function(t){this.selectedEntity=t},a.changePeriod=function(t){this.selectedPeriod=t},a.getTotalCount=function(t){return app.data.statistics[t].total},a.getPeriodCount=function(t,e){var s=app.data.statistics[t].timed,i=0;for(var a in s)a>=e.start&&a<e.end&&(i+=s[a]);return i},a.getLastPeriod=function(t){return{start:t.start-(t.end-t.start),end:t.start}},i}(h.a);a.a.initializers.add("flarum-statistics",(function(){Object(n.extend)(o.a.prototype,"availableWidgets",(function(t){t.push(m(Tt,null))}))}))}]);
|
|
//# sourceMappingURL=admin.js.map
|