highcharts
Version:
JavaScript charting framework
9 lines • 12.4 kB
JavaScript
/**
* Highcharts JS v11.3.0 (2024-01-10)
*
* Exporting module
*
* (c) 2010-2024 Torstein Honsi
*
* License: www.highcharts.com/license
*/!function(t){"object"==typeof module&&module.exports?(t.default=t,module.exports=t):"function"==typeof define&&define.amd?define("highcharts/modules/export-data",["highcharts","highcharts/modules/exporting"],function(e){return t(e),t.Highcharts=e,t}):t("undefined"!=typeof Highcharts?Highcharts:void 0)}(function(t){"use strict";var e=t?t._modules:{};function a(t,e,a,o){t.hasOwnProperty(e)||(t[e]=o.apply(null,a),"function"==typeof CustomEvent&&window.dispatchEvent(new CustomEvent("HighchartsModuleLoaded",{detail:{path:e,module:t[e]}})))}a(e,"Extensions/DownloadURL.js",[e["Core/Globals.js"]],function(t){let{isSafari:e,win:a,win:{document:o}}=t,n=a.URL||a.webkitURL||a;function i(t){let e=t.replace(/filename=.*;/,"").match(/data:([^;]*)(;base64)?,([0-9A-Za-z+/]+)/);if(e&&e.length>3&&a.atob&&a.ArrayBuffer&&a.Uint8Array&&a.Blob&&n.createObjectURL){let t=a.atob(e[3]),o=new a.ArrayBuffer(t.length),i=new a.Uint8Array(o);for(let e=0;e<i.length;++e)i[e]=t.charCodeAt(e);return n.createObjectURL(new a.Blob([i],{type:e[1]}))}}return{dataURLtoBlob:i,downloadURL:function(t,n){let r=a.navigator,s=o.createElement("a");if("string"!=typeof t&&!(t instanceof String)&&r.msSaveOrOpenBlob){r.msSaveOrOpenBlob(t,n);return}t=""+t;let l=/Edge\/\d+/.test(r.userAgent),h=e&&"string"==typeof t&&0===t.indexOf("data:application/pdf");if((h||l||t.length>2e6)&&!(t=i(t)||""))throw Error("Failed to convert to blob");if(void 0!==s.download)s.href=t,s.download=n,o.body.appendChild(s),s.click(),o.body.removeChild(s);else try{if(!a.open(t,"chart"))throw Error("Failed to open window")}catch{a.location.href=t}}}}),a(e,"Extensions/ExportData/ExportDataDefaults.js",[],function(){return{exporting:{csv:{annotations:{itemDelimiter:"; ",join:!1},columnHeaderFormatter:null,dateFormat:"%Y-%m-%d %H:%M:%S",decimalPoint:null,itemDelimiter:null,lineDelimiter:"\n"},showTable:!1,useMultiLevelHeaders:!0,useRowspanHeaders:!0,showExportInProgress:!0},lang:{downloadCSV:"Download CSV",downloadXLS:"Download XLS",exportData:{annotationHeader:"Annotations",categoryHeader:"Category",categoryDatetimeHeader:"DateTime"},viewData:"View data table",hideData:"Hide data table",exportInProgress:"Exporting..."}}}),a(e,"Extensions/ExportData/ExportData.js",[e["Core/Renderer/HTML/AST.js"],e["Core/Defaults.js"],e["Extensions/DownloadURL.js"],e["Extensions/ExportData/ExportDataDefaults.js"],e["Core/Globals.js"],e["Core/Series/SeriesRegistry.js"],e["Core/Utilities.js"]],function(t,e,a,o,n,i,r){let{getOptions:s,setOptions:l}=e,{downloadURL:h}=a,{composed:c,doc:d,win:p}=n,{series:u,seriesTypes:{arearange:m,gantt:g,map:x,mapbubble:f,treemap:b,xrange:y}}=i,{addEvent:w,defined:D,extend:T,find:v,fireEvent:E,isNumber:S,pick:C,pushUnique:L}=r;function A(t){let e=!!this.options.exporting?.showExportInProgress,a=p.requestAnimationFrame||setTimeout;a(()=>{e&&this.showLoading(this.options.lang.exportInProgress),a(()=>{try{t.call(this)}finally{e&&this.hideLoading()}})})}function R(){A.call(this,()=>{let t=this.getCSV(!0);h(B(t,"text/csv")||"data:text/csv,\uFEFF"+encodeURIComponent(t),this.getFilename()+".csv")})}function k(){A.call(this,()=>{let t='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>Ark1</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><style>td{border:none;font-family: Calibri, sans-serif;} .number{mso-number-format:"0.00";} .text{ mso-number-format:"@";}</style><meta name=ProgId content=Excel.Sheet><meta charset=UTF-8></head><body>'+this.getTable(!0)+"</body></html>";h(B(t,"application/vnd.ms-excel")||"data:application/vnd.ms-excel;base64,"+p.btoa(unescape(encodeURIComponent(t))),this.getFilename()+".xls")})}function H(t){let e="",a=this.getDataRows(),o=this.options.exporting.csv,n=C(o.decimalPoint,","!==o.itemDelimiter&&t?1.1.toLocaleString()[1]:"."),i=C(o.itemDelimiter,","===n?";":","),r=o.lineDelimiter;return a.forEach((t,o)=>{let s="",l=t.length;for(;l--;)"string"==typeof(s=t[l])&&(s=`"${s}"`),"number"==typeof s&&"."!==n&&(s=s.toString().replace(".",n)),t[l]=s;t.length=a.length?a[0].length:0,e+=t.join(i),o<a.length-1&&(e+=r)}),e}function O(t){let e,a;let o=this.hasParallelCoordinates,n=this.time,i=this.options.exporting&&this.options.exporting.csv||{},r=this.xAxis,s={},l=[],h=[],c=[],d=this.options.lang,p=d.exportData,m=p.categoryHeader,g=p.categoryDatetimeHeader,x=function(e,a,o){if(i.columnHeaderFormatter){let t=i.columnHeaderFormatter(e,a,o);if(!1!==t)return t}return e?e instanceof u?t?{columnTitle:o>1?a:e.name,topLevelColumnTitle:e.name}:e.name+(o>1?" ("+a+")":""):e.options.title&&e.options.title.text||(e.dateTime?g:m):m},f=function(t,e,a){let o={},n={};return e.forEach(function(e){let i=(t.keyToAxis&&t.keyToAxis[e]||e)+"Axis",r=S(a)?t.chart[i][a]:t[i];o[e]=r&&r.categories||[],n[e]=r&&r.dateTime}),{categoryMap:o,dateTimeValueAxisMap:n}},b=function(t,e){let a=t.pointArrayMap||["y"],o=t.data.some(t=>void 0!==t.y&&t.name);return o&&e&&!e.categories&&"name"!==t.exportKey?["x",...a]:a},y=[],w,T,L,A=0,R,k;for(R in this.series.forEach(function(e){let a=e.options.keys,l=e.xAxis,d=a||b(e,l),p=d.length,u=!e.requireSorting&&{},m=r.indexOf(l),g=f(e,d),w,D;if(!1!==e.options.includeInDataExport&&!e.options.isInternal&&!1!==e.visible){for(v(y,function(t){return t[0]===m})||y.push([m,A]),D=0;D<p;)L=x(e,d[D],d.length),c.push(L.columnTitle||L),t&&h.push(L.topLevelColumnTitle||L),D++;(w={chart:e.chart,autoIncrement:e.autoIncrement,options:e.options,pointArrayMap:e.pointArrayMap,index:e.index}).index,e.options.data.forEach(function(t,a){let r,h,c;let x={series:w};o&&(g=f(e,d,a)),e.pointClass.prototype.applyOptions.apply(x,[t]);let b=e.data[a]&&e.data[a].name;if(r=(x.x??"")+","+b,D=0,(!l||"name"===e.exportKey||!o&&l&&l.hasNames&&b)&&(r=b),u&&(u[r]&&(r+="|"+a),u[r]=!0),s[r]){let t=`${r},${s[r].pointers[e.index]}`,a=r;s[r].pointers[e.index]&&(s[t]||(s[t]=[],s[t].xValues=[],s[t].pointers=[]),r=t),s[a].pointers[e.index]+=1}else{s[r]=[],s[r].xValues=[];let t=[];for(let a=0;a<e.chart.series.length;a++)t[a]=0;s[r].pointers=t,s[r].pointers[e.index]=1}for(s[r].x=x.x,s[r].name=b,s[r].xValues[m]=x.x;D<p;)c=x[h=d[D]],s[r][A+D]=C(g.categoryMap[h][c],g.dateTimeValueAxisMap[h]?n.dateFormat(i.dateFormat,c):null,c),D++}),A+=D}}),s)Object.hasOwnProperty.call(s,R)&&l.push(s[R]);for(T=t?[h,c]:[c],A=y.length;A--;)e=y[A][0],a=y[A][1],w=r[e],l.sort(function(t,a){return t.xValues[e]-a.xValues[e]}),k=x(w),T[0].splice(a,0,k),t&&T[1]&&T[1].splice(a,0,k),l.forEach(function(t){let e=t.name;w&&!D(e)&&(w.dateTime?(t.x instanceof Date&&(t.x=t.x.getTime()),e=n.dateFormat(i.dateFormat,t.x)):e=w.categories?C(w.names[t.x],w.categories[t.x],t.x):t.x),t.splice(a,0,e)});return E(this,"exportData",{dataRows:T=T.concat(l)}),T}function j(t){let e=t=>{if(!t.tagName||"#text"===t.tagName)return t.textContent||"";let a=t.attributes,o=`<${t.tagName}`;return a&&Object.keys(a).forEach(t=>{let e=a[t];o+=` ${t}="${e}"`}),o+=">"+(t.textContent||""),(t.children||[]).forEach(t=>{o+=e(t)}),o+=`</${t.tagName}>`},a=this.getTableAST(t);return e(a)}function N(t){let e=0,a=[],o=this.options,n=t?1.1.toLocaleString()[1]:".",i=C(o.exporting.useMultiLevelHeaders,!0),r=this.getDataRows(i),s=i?r.shift():null,l=r.shift(),h=function(t,e){let a=t.length;if(e.length!==a)return!1;for(;a--;)if(t[a]!==e[a])return!1;return!0},c=function(t,e,a,o){let i=C(o,""),r="highcharts-text"+(e?" "+e:"");return"number"==typeof i?(i=i.toString(),","===n&&(i=i.replace(".",n)),r="highcharts-number"):o||(r="highcharts-empty"),{tagName:t,attributes:a=T({class:r},a),textContent:i}};!1!==o.exporting.tableCaption&&a.push({tagName:"caption",attributes:{class:"highcharts-table-caption"},textContent:C(o.exporting.tableCaption,o.title.text?o.title.text:"Chart")});for(let t=0,a=r.length;t<a;++t)r[t].length>e&&(e=r[t].length);a.push(function(t,e,a){let n=[],r=0,s=a||e&&e.length,l,d=0,p;if(i&&t&&e&&!h(t,e)){let a=[];for(;r<s;++r)if((l=t[r])===t[r+1])++d;else if(d)a.push(c("th","highcharts-table-topheading",{scope:"col",colspan:d+1},l)),d=0;else{l===e[r]?o.exporting.useRowspanHeaders?(p=2,delete e[r]):(p=1,e[r]=""):p=1;let t=c("th","highcharts-table-topheading",{scope:"col"},l);p>1&&t.attributes&&(t.attributes.valign="top",t.attributes.rowspan=p),a.push(t)}n.push({tagName:"tr",children:a})}if(e){let t=[];for(r=0,s=e.length;r<s;++r)void 0!==e[r]&&t.push(c("th",null,{scope:"col"},e[r]));n.push({tagName:"tr",children:t})}return{tagName:"thead",children:n}}(s,l,Math.max(e,l.length)));let d=[];r.forEach(function(t){let a=[];for(let o=0;o<e;o++)a.push(c(o?"td":"th",null,o?{}:{scope:"row"},t[o]));d.push({tagName:"tr",children:a})}),a.push({tagName:"tbody",children:d});let p={tree:{tagName:"table",id:`highcharts-data-table-${this.index}`,children:a}};return E(this,"aftergetTableAST",p),p.tree}function V(){this.toggleDataTable(!1)}function U(e){e=C(e,!this.isDataTableVisible);let a=e&&!this.dataTableDiv;if(a&&(this.dataTableDiv=d.createElement("div"),this.dataTableDiv.className="highcharts-data-table",this.renderTo.parentNode.insertBefore(this.dataTableDiv,this.renderTo.nextSibling)),this.dataTableDiv){let o=this.dataTableDiv.style,n=o.display;if(o.display=e?"block":"none",e){this.dataTableDiv.innerHTML=t.emptyHTML;let e=new t([this.getTableAST()]);e.addToDOM(this.dataTableDiv),E(this,"afterViewData",{element:this.dataTableDiv,wasHidden:a||n!==o.display})}else E(this,"afterHideData")}this.isDataTableVisible=e;let o=this.exportDivElements,n=this.options.exporting,i=n&&n.buttons&&n.buttons.contextButton.menuItems,r=this.options.lang;if(n&&n.menuItemDefinitions&&r&&r.viewData&&r.hideData&&i&&o){let e=o[i.indexOf("viewData")];e&&t.setElementHTML(e,this.isDataTableVisible?r.hideData:r.viewData)}}function F(){this.toggleDataTable(!0)}function B(t,e){let a=p.navigator,o=p.URL||p.webkitURL||p;try{if(a.msSaveOrOpenBlob&&p.MSBlobBuilder){let e=new p.MSBlobBuilder;return e.append(t),e.getBlob("image/svg+xml")}return o.createObjectURL(new p.Blob(["\uFEFF"+t],{type:e}))}catch(t){}}function I(){let t=this,e=t.dataTableDiv,a=(t,e)=>t.children[e].textContent,o=(t,e)=>(o,n)=>{var i,r;return i=a(e?o:n,t),r=a(e?n:o,t),""===i||""===r||isNaN(i)||isNaN(r)?i.toString().localeCompare(r):i-r};if(e&&t.options.exporting&&t.options.exporting.allowTableSorting){let a=e.querySelector("thead tr");a&&a.childNodes.forEach(a=>{let n=a.closest("table");a.addEventListener("click",function(){let i=[...e.querySelectorAll("tr:not(thead tr)")],r=[...a.parentNode.children];i.sort(o(r.indexOf(a),t.ascendingOrderInTable=!t.ascendingOrderInTable)).forEach(t=>{n.appendChild(t)}),r.forEach(t=>{["highcharts-sort-ascending","highcharts-sort-descending"].forEach(e=>{t.classList.contains(e)&&t.classList.remove(e)})}),a.classList.add(t.ascendingOrderInTable?"highcharts-sort-ascending":"highcharts-sort-descending")})})}}function M(){this.options&&this.options.exporting&&this.options.exporting.showTable&&!this.options.chart.forExport&&this.viewData()}return{compose:function t(e){if(L(c,t)){let t=e.prototype,a=s().exporting;w(e,"afterViewData",I),w(e,"render",M),t.downloadCSV=R,t.downloadXLS=k,t.getCSV=H,t.getDataRows=O,t.getTable=j,t.getTableAST=N,t.hideData=V,t.toggleDataTable=U,t.viewData=F,a&&(T(a.menuItemDefinitions,{downloadCSV:{textKey:"downloadCSV",onclick:function(){this.downloadCSV()}},downloadXLS:{textKey:"downloadXLS",onclick:function(){this.downloadXLS()}},viewData:{textKey:"viewData",onclick:function(){A.call(this,this.toggleDataTable)}}}),a.buttons&&a.buttons.contextButton.menuItems&&a.buttons.contextButton.menuItems.push("separator","downloadCSV","downloadXLS","viewData")),l(o),m&&(m.prototype.keyToAxis={low:"y",high:"y"}),g&&(g.prototype.exportKey="name",g.prototype.keyToAxis={start:"x",end:"x"}),y&&(y.prototype.keyToAxis={x2:"x"}),x&&(x.prototype.exportKey="name"),f&&(f.prototype.exportKey="name"),b&&(b.prototype.exportKey="name")}}}}),a(e,"masters/modules/export-data.src.js",[e["Core/Globals.js"],e["Extensions/DownloadURL.js"],e["Extensions/ExportData/ExportData.js"]],function(t,e,a){t.dataURLtoBlob=e.dataURLtoBlob,t.downloadURL=e.downloadURL,a.compose(t.Chart)})});