UNPKG

highcharts

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