PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / js / admin / statistics / chart.min.js

chart.min.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.8, at assets/js/admin/statistics/chart.min.js

1 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import Chart from"chart.js/auto";import{getStatsConfig,getStatsI18n}from"./api.js";const DEFAULT_COLORS=["#2271b1","#00a32a"],EMPTY_STATE_CLASS="lp-stats-chart-empty",toggleEmptyState=(t,e)=>{const a=t.parentElement;if(!a)return;let n=a.querySelector(`.${EMPTY_STATE_CLASS}`);e&&!n&&(n=document.createElement("p"),n.className=EMPTY_STATE_CLASS,n.textContent=getStatsI18n("noData","No data for this period."),a.appendChild(n)),n&&(n.style.display=e?"":"none"),t.style.display=e?"none":"block"};export const intlFormat=(t,e)=>new Intl.DateTimeFormat(void 0,e).format(t);const daysWithinOneMonth=t=>{const e=t.map(t=>String(t).slice(0,7));return e.every(t=>t===e[0])};export const granularityLabelFormatter=(t,e=[])=>{switch(t){case"hour":return t=>`${t}h`;case"day":{const t=e.length<=7&&daysWithinOneMonth(e)?{weekday:"short",day:"numeric"}:{month:"short",day:"numeric"},a=new Intl.DateTimeFormat(void 0,t);return t=>{const e=new Date(`${t}T00:00:00`);return isNaN(e.getTime())?String(t):a.format(e)}}case"month":{const t=new Intl.DateTimeFormat(void 0,{month:"short",year:"2-digit"});return e=>{const a=String(e).split("-"),n=parseInt(a[0],10);return 2===a.length&&n>=1&&n<=12?t.format(new Date(parseInt(a[1],10),n-1,1)):String(e)}}default:return null}};export const renderLineChart=(t,e={},a={})=>{const n=document.querySelector(t);if(!n)return null;const{datasets:r=[],xLabel:o="",granularity:s=""}=e;let{labels:l=[]}=e;if(!(r.length>0&&r.some(t=>(t.data||[]).length>0))){const t=Chart.getChart(n);return t&&t.destroy(),toggleEmptyState(n,!0),null}toggleEmptyState(n,!1);const i="function"==typeof a.formatLabel?a.formatLabel:granularityLabelFormatter(s,l);i&&(l=l.map((t,e)=>i(t,e)));const c=r.length>1,d=a.yCurrency??c,m=getStatsConfig().currencySymbol||"",g=r.map((t,e)=>{const a=t.color||DEFAULT_COLORS[e%DEFAULT_COLORS.length];return{label:t.label||"",data:t.data||[],borderColor:a,backgroundColor:a,borderWidth:2,yAxisID:t.yAxisID||(c&&e>0?"y1":"y")}}),p={y:{min:0,position:"left",ticks:d?{callback:t=>m+t}:{}},x:{title:{display:!!o,text:o,align:"end"}}};c&&(p.y1={min:0,position:"right",grid:{drawOnChartArea:!1},ticks:{precision:0}});const y=Chart.getChart(n);if(y){if(y.data.datasets.length===g.length)return y.data.labels=l,g.forEach((t,e)=>{y.data.datasets[e].data=t.data,y.data.datasets[e].label=t.label}),y.config.options.scales.x.title.text=o,y.update(),y;y.destroy()}return new Chart(n,{type:"line",data:{labels:l,datasets:g},options:{responsive:!0,maintainAspectRatio:!1,aspectRatio:.8,plugins:{legend:{display:c}},scales:p}})};