UNPKG

highcharts

Version:
14 lines 12.6 kB
/** * Highcharts JS v12.5.0 (2026-01-12) * @module highcharts/modules/export-data * @requires highcharts * @requires highcharts/modules/exporting * * Export data module * * (c) 2010-2026 Highsoft AS * Author: Torstein Honsi * * A commercial license may be required depending on use. * See www.highcharts.com/license */import*as t from"../highcharts.js";var e,a={};a.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return a.d(e,{a:e}),e},a.d=(t,e)=>{for(var o in e)a.o(e,o)&&!a.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},a.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);let o=t.default;var n=a.n(o);let{isSafari:i,win:r,win:{document:l}}=n(),{error:s}=n(),d=r.URL||r.webkitURL||r;function c(t){let e=t.replace(/filename=.*;/,"").match(/data:([^;]*)(;base64)?,([A-Z+\d\/]+)/i);if(e&&e.length>3&&r.atob&&r.ArrayBuffer&&r.Uint8Array&&r.Blob&&d.createObjectURL){let t=r.atob(e[3]),a=new r.ArrayBuffer(t.length),o=new r.Uint8Array(a);for(let e=0;e<o.length;++e)o[e]=t.charCodeAt(e);return d.createObjectURL(new r.Blob([o],{type:e[1]}))}}function h(t,e){let a=r.navigator,o=l.createElement("a");if("string"!=typeof t&&!(t instanceof String)&&a.msSaveOrOpenBlob)return void a.msSaveOrOpenBlob(t,e);if(t=""+t,a.userAgent.length>1e3)throw Error("Input too long");let n=/Edge\/\d+/.test(a.userAgent);if((i&&"string"==typeof t&&0===t.indexOf("data:application/pdf")||n||t.length>2e6)&&!(t=c(t)||""))throw Error("Failed to convert to blob");if(void 0!==o.download)o.href=t,o.download=e,l.body.appendChild(o),o.click(),l.body.removeChild(o);else try{if(!r.open(t,"chart"))throw Error("Failed to open window")}catch{r.location.href=t}}function p(t,e){let a=r.navigator,o=r.URL||r.webkitURL||r;try{if(a.msSaveOrOpenBlob&&r.MSBlobBuilder){let e=new r.MSBlobBuilder;return e.append(t),e.getBlob("image/svg+xml")}return o.createObjectURL(new r.Blob(["\uFEFF"+t],{type:e}))}catch(t){}}let u=t.default.AST;var g=a.n(u);let f=t.default.Chart;var m=a.n(f);let x={exporting:{csv:{annotations:{itemDelimiter:"; ",join:!1},columnHeaderFormatter:null,dateFormat:"%Y-%m-%d %H:%M:%S",decimalPoint:null,itemDelimiter:null,lineDelimiter:"\n"},menuItemDefinitions:{downloadCSV:{textKey:"downloadCSV",onclick:function(){this.exporting?.downloadCSV()}},downloadXLS:{textKey:"downloadXLS",onclick:function(){this.exporting?.downloadXLS()}},viewData:{textKey:"viewData",onclick:function(){this.exporting?.wrapLoading(this.exporting.toggleDataTable)}}},showExportInProgress:!0,showTable:!1,useMultiLevelHeaders:!0,useRowspanHeaders:!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..."}},{getOptions:b,setOptions:y}=n(),{composed:w,doc:T,win:D}=n(),{addEvent:v,defined:S,extend:L,find:E,fireEvent:C,isNumber:A,pick:V,pushUnique:k}=n();!function(t){function e(){this.wrapLoading(()=>{let t=this.getCSV(!0);h(p(t,"text/csv")||"data:text/csv,\uFEFF"+encodeURIComponent(t),this.getFilename()+".csv")})}function a(){this.wrapLoading(()=>{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>\x3c!--[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]--\x3e<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(p(t,"application/vnd.ms-excel")||"data:application/vnd.ms-excel;base64,"+D.btoa(unescape(encodeURIComponent(t))),this.getFilename()+".xls")})}function o(t){let e="",a=this.getDataRows(),o=this.options?.csv,n=V(o?.decimalPoint,o?.itemDelimiter!==","&&t?1.1.toLocaleString()[1]:"."),i=V(o?.itemDelimiter,","===n?";":","),r=o?.lineDelimiter;return a.forEach((t,o)=>{let l="",s=t.length;for(;s--;)"string"==typeof(l=t[s])&&(l=`"${l}"`),"number"==typeof l&&"."!==n&&(l=l.toString().replace(".",n)),t[s]=l;t.length=a.length?a[0].length:0,e+=t.join(i),o<a.length-1&&(e+=r)}),e}function n(t){let e,a,o=this.chart,n=o.hasParallelCoordinates,i=o.time,r=this.options?.csv||{},l=o.xAxis,s={},d=[],c=[],h=[],p=o.options.lang.exportData,u=p?.categoryHeader,g=p?.categoryDatetimeHeader,f=function(e,a,o){if(r.columnHeaderFormatter){let t=r.columnHeaderFormatter(e,a,o);if(!1!==t)return t}return!e&&u?u:!e.bindAxes&&g&&u?e.options.title&&e.options.title.text||(e.dateTime?g:u):t?{columnTitle:((o||0)>1?a:e.name)||"",topLevelColumnTitle:e.name}:e.name+((o||0)>1?" ("+a+")":"")},m=function(t,e,a){let o={},n={};return e.forEach(function(e){let i=(t.keyToAxis&&t.keyToAxis[e]||e)+"Axis",r=A(a)?t.chart[i][a]:t[i];o[e]=r&&r.categories||[],n[e]=r&&r.dateTime}),{categoryMap:o,dateTimeValueAxisMap:n}},x=function(t,e){let a=t.pointArrayMap||["y"];return t.data.some(t=>void 0!==t.y&&t.name)&&e&&!e.categories&&"name"!==t.exportKey?["x",...a]:a},b=[],y,w,T,D=0,v,L;for(v in o.series.forEach(function(e){let a=e.options.keys,o=e.xAxis,d=a||x(e,o),p=d.length,u=!e.requireSorting&&{},g=l.indexOf(o),y=m(e,d),w,v;if(!1!==e.options.includeInDataExport&&!e.options.isInternal&&!1!==e.visible){for(E(b,function(t){return t[0]===g})||b.push([g,D]),v=0;v<p;)T=f(e,d[v],d.length),h.push(T.columnTitle||T),t&&c.push(T.topLevelColumnTitle||T),v++;w={chart:e.chart,autoIncrement:e.autoIncrement,options:e.options,pointArrayMap:e.pointArrayMap,index:e.index},e.options.data?.forEach(function(t,a){let l,c,h,f={series:w};n&&(y=m(e,d,a)),e.pointClass.prototype.applyOptions.apply(f,[t]);let x=e.data[a]&&e.data[a].name;if(l=(f.x??"")+","+x,v=0,(!o||"name"===e.exportKey||!n&&o&&o.hasNames&&x)&&(l=x),u&&(u[l]&&(l+="|"+a),u[l]=!0),s[l]){let t=`${l},${s[l].pointers[e.index]}`,a=l;s[l].pointers[e.index]&&(s[t]||(s[t]=[],s[t].xValues=[],s[t].pointers=[]),l=t),s[a].pointers[e.index]+=1}else{s[l]=[],s[l].xValues=[];let t=[];for(let a=0;a<e.chart.series.length;a++)t[a]=0;s[l].pointers=t,s[l].pointers[e.index]=1}for(s[l].x=f.x,s[l].name=x,s[l].xValues[g]=f.x;v<p;)c=d[v],h=e.pointClass.prototype.getNestedProperty.apply(f,[c]),s[l][D+v]=V(y.categoryMap[c][h],y.dateTimeValueAxisMap[c]?i.dateFormat(r.dateFormat,h):null,h),v++}),D+=v}}),s)Object.hasOwnProperty.call(s,v)&&d.push(s[v]);for(w=t?[c,h]:[h],D=b.length;D--;)e=b[D][0],a=b[D][1],y=l[e],d.sort(function(t,a){return t.xValues[e]-a.xValues[e]}),L=f(y),w[0].splice(a,0,L),t&&w[1]&&w[1].splice(a,0,L),d.forEach(function(t){let e=t.name;y&&!S(e)&&(y.dateTime?(t.x instanceof Date&&(t.x=t.x.getTime()),e=i.dateFormat(r.dateFormat,t.x)):e=y.categories?V(y.names[t.x],y.categories[t.x],t.x):t.x),t.splice(a,0,e)});return C(o,"exportData",{dataRows:w=w.concat(d)}),w}function i(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+=">",o+=t.textContent||"",(t.children||[]).forEach(t=>{o+=e(t)}),o+=`</${t.tagName}>`};return e(this.getTableAST(t))}function r(t){let e=0,a=[],o=this,n=o.chart,i=n.options,r=t?1.1.toLocaleString()[1]:".",l=V(o.options.useMultiLevelHeaders,!0),s=o.getDataRows(l),d=l?s.shift():null,c=s.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},p=function(t,e,a,o){let i=V(o,""),l="highcharts-text"+(e?" "+e:"");return"number"==typeof i?(i=n.numberFormatter(i,-1,r,"th"===t?"":void 0),l="highcharts-number"):o||(l="highcharts-empty"),{tagName:t,attributes:a=L({class:l},a),textContent:i}},{tableCaption:u}=o.options||{};!1!==u&&a.push({tagName:"caption",attributes:{class:"highcharts-table-caption"},textContent:"string"==typeof u?u:i.title?.text||i.lang.chartTitle});for(let t=0,a=s.length;t<a;++t)s[t].length>e&&(e=s[t].length);a.push(function(t,e,a){let n=[],i=0,r=a||e&&e.length,s,d=0,c;if(l&&t&&e&&!h(t,e)){let a=[];for(;i<r;++i)if((s=t[i])===t[i+1])++d;else if(d)a.push(p("th","highcharts-table-topheading",{scope:"col",colspan:d+1},s)),d=0;else{s===e[i]?o.options.useRowspanHeaders?(c=2,delete e[i]):(c=1,e[i]=""):c=1;let t=p("th","highcharts-table-topheading",{scope:"col"},s);c>1&&t.attributes&&(t.attributes.valign="top",t.attributes.rowspan=c),a.push(t)}n.push({tagName:"tr",children:a})}if(e){let t=[];for(i=0,r=e.length;i<r;++i)void 0!==e[i]&&t.push(p("th",null,{scope:"col"},e[i]));n.push({tagName:"tr",children:t})}return{tagName:"thead",children:n}}(d,c||[],Math.max(e,c?.length||0)));let g=[];s.forEach(function(t){let a=[];for(let o=0;o<e;o++)a.push(p(o?"td":"th",null,o?{}:{scope:"row"},t[o]));g.push({tagName:"tr",children:a})}),a.push({tagName:"tbody",children:g});let f={tree:{tagName:"table",id:`highcharts-data-table-${n.index}`,children:a}};return C(n,"afterGetTableAST",f),f.tree}function l(){this.toggleDataTable(!1)}function s(t){let e=this.chart,a=(t=V(t,!this.isDataTableVisible))&&!this.dataTableDiv;if(a&&(this.dataTableDiv=T.createElement("div"),this.dataTableDiv.className="highcharts-data-table",e.renderTo.parentNode.insertBefore(this.dataTableDiv,e.renderTo.nextSibling)),this.dataTableDiv){let o=this.dataTableDiv.style,n=o.display;o.display=t?"block":"none",t?(this.dataTableDiv.innerHTML=g().emptyHTML,new(g())([this.getTableAST()]).addToDOM(this.dataTableDiv),C(e,"afterViewData",{element:this.dataTableDiv,wasHidden:a||n!==o.display})):C(e,"afterHideData")}this.isDataTableVisible=t;let o=this.divElements,n=this.options,i=n.buttons?.contextButton.menuItems,r=e.options.lang;if(n&&n.menuItemDefinitions&&r&&r.viewData&&r.hideData&&i&&o){let t=o[i.indexOf("viewData")];t&&g().setElementHTML(t,this.isDataTableVisible?r.hideData:r.viewData)}}function d(){this.toggleDataTable(!0)}function c(t){let e=this.chart,a=!!this.options.showExportInProgress,o=D.requestAnimationFrame||setTimeout;o(()=>{a&&e.showLoading(e.options.lang.exportInProgress),o(()=>{try{t.call(this)}finally{a&&e.hideLoading()}})})}function u(){let t=this.exporting,e=t?.dataTableDiv,a=(t,e)=>t.children[e].textContent;if(e&&t.options.allowTableSorting){let o=e.querySelector("thead tr");o&&o.childNodes.forEach(o=>{let n=e.querySelector("tbody");o.addEventListener("click",function(){let i=[...e.querySelectorAll("tr:not(thead tr)")],r=[...o.parentNode.children];if(t){let e,l;i.sort((e=r.indexOf(o),l=t.ascendingOrderInTable=!t.ascendingOrderInTable,(t,o)=>{let n,i;return n=a(l?t:o,e),i=a(l?o:t,e),""===n||""===i||isNaN(n)||isNaN(i)?n.toString().localeCompare(i):n-i})).forEach(t=>{n?.appendChild(t)}),r.forEach(t=>{["highcharts-sort-ascending","highcharts-sort-descending"].forEach(e=>{t.classList.contains(e)&&t.classList.remove(e)})}),o.classList.add(t.ascendingOrderInTable?"highcharts-sort-ascending":"highcharts-sort-descending")}})})}}function f(){this.options?.exporting?.showTable&&!this.options.chart.forExport&&this.exporting?.viewData()}function O(){this.exporting?.dataTableDiv?.remove()}t.compose=function(t,h,p){if(!k(w,"ExportData"))return;L(m().prototype,{downloadCSV:function(){return this.exporting?.downloadCSV()},downloadXLS:function(){return this.exporting?.downloadXLS()},getCSV:function(t){return this.exporting?.getCSV(t)},getDataRows:function(t){return this.exporting?.getDataRows(t)},getTable:function(t){return this.exporting?.getTable(t)},getTableAST:function(t){return this.exporting?.getTableAST(t)},hideData:function(){return this.exporting?.hideData()},toggleDataTable:function(t){return this.exporting?.toggleDataTable(t)},viewData:function(){return this.exporting?.viewData()}});let g=h.prototype;if(!g.downloadCSV){v(t,"afterViewData",u),v(t,"render",f),v(t,"destroy",O),g.downloadCSV=e,g.downloadXLS=a,g.getCSV=o,g.getDataRows=n,g.getTable=i,g.getTableAST=r,g.hideData=l,g.toggleDataTable=s,g.wrapLoading=c,g.viewData=d,y(x);let h=b().exporting?.buttons?.contextButton?.menuItems;h&&h.push("separator","downloadCSV","downloadXLS","viewData");let{arearange:m,gantt:w,map:T,mapbubble:D,treemap:S,xrange:L}=p.types;m&&(m.prototype.keyToAxis={low:"y",high:"y"}),w&&(w.prototype.exportKey="name",w.prototype.keyToAxis={start:"x",end:"x"}),T&&(T.prototype.exportKey="name"),D&&(D.prototype.exportKey="name"),S&&(S.prototype.exportKey="name"),L&&(L.prototype.keyToAxis={x2:"x"})}}}(e||(e={}));let O=e,N=n();N.dataURLtoBlob=N.dataURLtoBlob||c,N.downloadURL=N.downloadURL||h,O.compose(N.Chart,N.Exporting,N.Series);let R=n();export{R as default};