UNPKG

highcharts

Version:
11 lines 16 kB
/** * Highcharts JS v12.3.0 (2025-06-21) * @module highcharts/modules/data * @requires highcharts * * Data module * * (c) 2012-2025 Torstein Honsi * * License: www.highcharts.com/license */import*as e from"../highcharts.js";var t={};t.n=e=>{var s=e&&e.__esModule?()=>e.default:()=>e;return t.d(s,{a:s}),s},t.d=(e,s)=>{for(var a in s)t.o(s,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:s[a]})},t.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let s=e.default;var a=t.n(s);let{win:i}=a(),{discardElement:r,objectEach:n}=a(),o={ajax:function(e){let t={json:"application/json",xml:"application/xml",text:"text/plain",octet:"application/octet-stream"},s=new XMLHttpRequest;function a(t,s){e.error&&e.error(t,s)}if(!e.url)return!1;s.open((e.type||"get").toUpperCase(),e.url,!0),e.headers?.["Content-Type"]||s.setRequestHeader("Content-Type",t[e.dataType||"json"]||t.text),n(e.headers,function(e,t){s.setRequestHeader(t,e)}),e.responseType&&(s.responseType=e.responseType),s.onreadystatechange=function(){let t;if(4===s.readyState){if(200===s.status){if("blob"!==e.responseType&&(t=s.responseText,"json"===e.dataType))try{t=JSON.parse(t)}catch(e){if(e instanceof Error)return a(s,e)}return e.success?.(t,s)}a(s,s.responseText)}},e.data&&"string"!=typeof e.data&&(e.data=JSON.stringify(e.data)),s.send(e.data)},getJSON:function(e,t){o.ajax({url:e,success:t,dataType:"json",headers:{"Content-Type":"text/plain"}})},post:async function(e,t,s){let a=new i.FormData;n(t,function(e,t){a.append(t,e)}),a.append("b64","true");let o=await i.fetch(e,{method:"POST",body:a,...s});if(o.ok){let e=await o.text(),s=document.createElement("a");s.href=`data:${t.type};base64,${e}`,s.download=t.filename,s.click(),r(s)}}},l=e.default.Axis;var u=t.n(l);let d=e.default.Chart;var h=t.n(d);let p=e.default.Point;var m=t.n(p);let c=e.default.SeriesRegistry;var f=t.n(c);let{getOptions:g}=a(),{doc:x}=a(),{ajax:y}=o,{seriesTypes:v}=f(),{addEvent:T,defined:C,extend:N,fireEvent:R,isNumber:A,merge:Y,objectEach:D,pick:w,splat:U}=a();function F(e){return!!(e&&(e.rowsURL||e.csvURL||e.columnsURL))}class O{static data(e,t={},s){return new O(e,t,s)}static rowsToColumns(e){let t,s,a,i,r;if(e)for(t=0,r=[],s=e.length;t<s;t++)for(a=0,i=e[t].length;a<i;a++)r[a]||(r[a]=[]),r[a][t]=e[t][a];return r}constructor(e,t={},s){this.rowsToColumns=O.rowsToColumns,this.dateFormats={"YYYY/mm/dd":{regex:/^(\d{4})[\-\/\.](\d{1,2})[\-\/\.](\d{1,2})$/,parser:function(e){return e?Date.UTC(+e[1],e[2]-1,+e[3]):NaN}},"dd/mm/YYYY":{regex:/^(\d{1,2})[\-\/\.](\d{1,2})[\-\/\.](\d{4})$/,parser:function(e){return e?Date.UTC(+e[3],e[2]-1,+e[1]):NaN},alternative:"mm/dd/YYYY"},"mm/dd/YYYY":{regex:/^(\d{1,2})[\-\/\.](\d{1,2})[\-\/\.](\d{4})$/,parser:function(e){return e?Date.UTC(+e[3],e[1]-1,+e[2]):NaN}},"dd/mm/YY":{regex:/^(\d{1,2})[\-\/\.](\d{1,2})[\-\/\.](\d{2})$/,parser:function(e){if(!e)return NaN;let t=new Date,s=+e[3];return s>t.getFullYear()-2e3?s+=1900:s+=2e3,Date.UTC(s,e[2]-1,+e[1])},alternative:"mm/dd/YY"},"mm/dd/YY":{regex:/^(\d{1,2})[\-\/\.](\d{1,2})[\-\/\.](\d{2})$/,parser:function(e){return e?Date.UTC(+e[3]+2e3,e[1]-1,+e[2]):NaN}}},this.chart=s,this.chartOptions=t,this.options=e,this.rawColumns=[],this.init(e,t,s)}init(e,t,s){let a=e.decimalPoint,i;t&&(this.chartOptions=t),s&&(this.chart=s),"."!==a&&","!==a&&(a=void 0),this.options=e,this.columns=e.columns||this.rowsToColumns(e.rows)||[],this.firstRowAsNames=w(e.firstRowAsNames,this.firstRowAsNames,!0),this.decimalRegex=a&&RegExp("^(-?[0-9]+)"+a+"([0-9]+)$"),void 0!==this.liveDataTimeout&&clearTimeout(this.liveDataTimeout),this.rawColumns=[],this.columns.length&&(this.dataFound(),i=!F(e)),i||(i=this.fetchLiveData()),i||(i=!!this.parseCSV().length),i||(i=!!this.parseTable().length),i||(i=this.parseGoogleSpreadsheet()),!i&&e.afterComplete&&e.afterComplete(this)}getColumnDistribution(){let e=this.chartOptions,t=this.options,s=[],a=function(e="line"){return(v[e].prototype.pointArrayMap||[0]).length},i=function(e="line"){return v[e].prototype.pointArrayMap},r=e?.chart?.type,n=[],o=[],l=t?.seriesMapping||e?.series?.map(function(){return{x:0}})||[],u=0;(e?.series||[]).forEach(e=>{n.push(a(e.type||r))}),l.forEach(e=>{s.push(e.x||0)}),0===s.length&&s.push(0),l.forEach(t=>{let s=new b,l=n[u]||a(r),d=(e?.series??[])[u]??{},h=i(d.type||r),p=h??["y"];(C(t.x)||d.isCartesian||!h)&&s.addColumnReader(t.x,"x"),D(t,function(e,t){"x"!==t&&s.addColumnReader(e,t)});for(let e=0;e<l;e++)s.hasReader(p[e])||s.addColumnReader(void 0,p[e]);o.push(s),u++});let d=i(r);void 0===d&&(d=["y"]),this.valueCount={global:a(r),xColumns:s,individual:n,seriesBuilders:o,globalPointArrayMap:d}}dataFound(){this.options.switchRowsAndColumns&&(this.columns=this.rowsToColumns(this.columns)),this.getColumnDistribution(),this.parseTypes(),!1!==this.parsed()&&this.complete()}parseCSV(e){let t=this,s=this.columns=[],a=e||this.options,i=a.startColumn||0,r=a.endColumn||Number.MAX_VALUE,n=[],o={",":0,";":0," ":0},l=a.csv,u=a.startRow||0,d=a.endRow||Number.MAX_VALUE,h,p,m=0;if(l&&a.beforeParse&&(l=a.beforeParse.call(this,l)),l){if(p=l.replace(/\r\n/g,"\n").replace(/\r/g,"\n").split(a.lineDelimiter||"\n"),(!u||u<0)&&(u=0),(!d||d>=p.length)&&(d=p.length-1),a.itemDelimiter)h=a.itemDelimiter;else{let e,s,i;e=0,s=0,i=!1,p.some(function(t,a){let i=!1,r,n,l,u="";if(a>13)return!0;for(let a=0;a<t.length;a++){if(r=t[a],n=t[a+1],l=t[a-1],"#"===r)return;if('"'===r)if(i){if('"'!==l&&'"'!==n){for(;" "===n&&a<t.length;)n=t[++a];void 0!==o[n]&&o[n]++,i=!1}}else i=!0;else void 0!==o[r]?(isNaN(Date.parse(u=u.trim()))?(isNaN(u)||!isFinite(u))&&o[r]++:o[r]++,u=""):u+=r;","===r&&s++,"."===r&&e++}}),o[";"]>o[","]?i=";":(o[","],o[";"],i=","),a.decimalPoint||(e>s?a.decimalPoint=".":a.decimalPoint=",",t.decimalRegex=RegExp("^(-?[0-9]+)"+a.decimalPoint+"([0-9]+)$")),h=i}let e=0;for(m=u;m<=d;m++)"#"===p[m][0]?e++:function(e,t,o,l){let u=0,d="",p="",m="",c="",f=0,g=0;function x(t){d=e[t],p=e[t-1],m=e[t+1]}function y(e){n.length<g+1&&n.push([e]),n[g][n[g].length-1]!==e&&n[g].push(e)}function v(){if(i>f||f>r){++f,c="";return}a.columnTypes||(!isNaN(parseFloat(c))&&isFinite(c)?(c=parseFloat(c),y("number")):isNaN(Date.parse(c))?y("string"):(c=c.replace(/\//g,"-"),y("date"))),s.length<g+1&&s.push([]),s[g][t]=c,c="",++g,++f}if(e.trim().length&&"#"!==e.trim()[0]){for(;u<e.length;u++)if(x(u),'"'===d)for(x(++u);u<e.length&&('"'!==d||'"'===p||'"'===m);)('"'!==d||'"'===d&&'"'!==p)&&(c+=d),x(++u);else d===h?v():c+=d;v()}}(p[m],m-u-e);(!a.columnTypes||0===a.columnTypes.length)&&n.length&&n[0].length&&"date"===n[0][1]&&!a.dateFormat&&(a.dateFormat=function(e,s){let i="YYYY/mm/dd",r=[],n=[],o,l=[],u,d=0,h=!1,p;for((!s||s>e.length)&&(s=e.length);d<s;d++)if(void 0!==e[d]&&e[d]?.length)for(p=0,o=e[d].trim().replace(/\//g," ").replace(/\-/g," ").replace(/\./g," ").split(" "),l=["","",""];p<o.length;p++)p<l.length&&(o[p]=parseInt(o[p],10),o[p]&&(n[p]=!n[p]||n[p]<o[p]?o[p]:n[p],void 0!==r[p]?r[p]!==o[p]&&(r[p]=!1):r[p]=o[p],o[p]>31?o[p]<100?l[p]="YY":l[p]="YYYY":o[p]>12&&o[p]<=31?(l[p]="dd",h=!0):l[p].length||(l[p]="mm")));if(h){for(p=0;p<r.length;p++)!1!==r[p]?n[p]>12&&"YY"!==l[p]&&"YYYY"!==l[p]&&(l[p]="YY"):n[p]>12&&"mm"===l[p]&&(l[p]="dd");return(3===l.length&&"dd"===l[1]&&"dd"===l[2]&&(l[2]="YY"),u=l.join("/"),(a.dateFormats||t.dateFormats)[u])?u:(R(t,"deduceDateFailed"),i)}return i}(s[0])),this.dataFound()}return s}parseTable(){let e=this.options,t=this.columns||[],s=e.startRow||0,a=e.endRow||Number.MAX_VALUE,i=e.startColumn||0,r=e.endColumn||Number.MAX_VALUE;if(e.table){let n=e.table;"string"==typeof n&&(n=x.getElementById(n)),[].forEach.call(n.getElementsByTagName("tr"),(e,n)=>{n>=s&&n<=a&&[].forEach.call(e.children,(e,a)=>{let o=t[a-i],l=1;if(("TD"===e.tagName||"TH"===e.tagName)&&a>=i&&a<=r)for(t[a-i]||(t[a-i]=[]),t[a-i][n-s]=e.innerHTML;n-s>=l&&void 0===o[n-s-l];)o[n-s-l]=null,l++})}),this.dataFound()}return t}fetchLiveData(){let e=this,t=this.chart,s=this.options,a=s.enablePolling,i=Y(s),r=0,n=1e3*(s.dataRefreshRate||2);return!!F(s)&&(n<1e3&&(n=1e3),delete s.csvURL,delete s.rowsURL,delete s.columnsURL,!function o(l){function u(i,u,d){if(!i||!/^(http|\/|\.\/|\.\.\/)/.test(i))return i&&s.error&&s.error("Invalid URL"),!1;function h(){a&&t.liveDataURL===i&&(e.liveDataTimeout=setTimeout(o,n))}return l&&(clearTimeout(e.liveDataTimeout),t.liveDataURL=i),y({url:i,dataType:d||"json",success:function(e){t?.series&&u(e),h()},error:function(e,t){return++r<3&&h(),s.error?.(t,e)}}),!0}u(i.csvURL,function(e){t.update({data:{csv:e}})},"text")||u(i.rowsURL,function(e){t.update({data:{rows:e}})})||u(i.columnsURL,function(e){t.update({data:{columns:e}})})}(!0),F(s))}parseGoogleSpreadsheet(){let e=this,t=this.options,s=t.googleSpreadsheetKey,a=this.chart,i=Math.max(1e3*(t.dataRefreshRate||2),4e3),r=()=>{if(t.googleSpreadsheetRange)return t.googleSpreadsheetRange;let e="ABCDEFGHIJKLMNOPQRSTUVWXYZ",s=(e.charAt(t.startColumn||0)||"A")+((t.startRow||0)+1),a=e.charAt(w(t.endColumn,-1))||"ZZ";return C(t.endRow)&&(a+=t.endRow+1),`${s}:${a}`};return s&&(delete t.googleSpreadsheetKey,!function a(n){y({url:["https://sheets.googleapis.com/v4/spreadsheets",s,"values",r(),"?alt=json&majorDimension=COLUMNS&valueRenderOption=UNFORMATTED_VALUE&dateTimeRenderOption=FORMATTED_STRING&key="+t.googleAPIKey].join("/"),dataType:"json",success:function(s){n(s),t.enablePolling&&(e.liveDataTimeout=setTimeout(function(){a(n)},i))},error:function(e,s){return t.error?.(s,e)}})}(function(t){let s=t.values;if(!s||0===s.length)return!1;let i=s.reduce((e,t)=>Math.max(e,t.length),0);s.forEach(e=>{for(let t=0;t<i;t++)void 0===e[t]&&(e[t]=null)}),a?.series?a.update({data:{columns:s}}):(e.columns=s,e.dataFound())})),!1}trim(e,t){return"string"==typeof e&&(e=e.replace(/^\s+|\s+$/g,""),t&&/[\d\s]+/.test(e)&&(e=e.replace(/\s/g,"")),this.decimalRegex&&(e=e.replace(this.decimalRegex,"$1.$2"))),e}parseTypes(){let e=this.columns||[],t=e.length;for(;t--;)this.parseColumn(e[t],t)}parseColumn(e,t){let s=this.rawColumns,a=this.columns=this.columns||[],i=this.firstRowAsNames,r=this.valueCount?.xColumns.indexOf(t)!==-1,n=[],o=this.chartOptions,l=(this.options.columnTypes||[])[t],u=r&&o?.xAxis&&"category"===U(o.xAxis)[0].type||"string"===l,d=C(e.name),h=e.length,p,m,c,f,g,x,y;for(s[t]||(s[t]=[]);h--;)p=n[h]||e[h],c=this.trim(p),m=parseFloat(f=this.trim(p,!0)),void 0===s[t][h]&&(s[t][h]=c),u||0===h&&i&&!d?e[h]=""+c:+f===m?(e[h]=m,m>31536e6&&"float"!==l?e.isDatetime=!0:e.isNumeric=!0,void 0!==e[h+1]&&(y=m>e[h+1])):(c?.length&&(g=this.parseDate(p)),r&&A(g)&&"float"!==l?(n[h]=p,e[h]=g,e.isDatetime=!0,void 0!==e[h+1]&&((x=g>e[h+1])!==y&&void 0!==y&&(this.alternativeFormat?(this.dateFormat=this.alternativeFormat,h=e.length,this.alternativeFormat=this.dateFormats[this.dateFormat].alternative):e.unsorted=!0),y=x)):(e[h]=""===c?null:c,0!==h&&(e.isDatetime||e.isNumeric)&&(e.mixed=!0)));if(r&&e.mixed&&(a[t]=s[t]),r&&y&&this.options.sort){for(t=0;t<a.length;t++)if(a[t].reverse(),i){let e=a[t].pop();e&&a[t].unshift(e)}}}parseDate(e){let t=this.options.parseDate,s,a,i,r=this.options.dateFormat||this.dateFormat,n;if(t)s=t(e);else if("string"==typeof e){if(r)(i=this.dateFormats[r])||(i=this.dateFormats["YYYY/mm/dd"]),(n=e.match(i.regex))&&(s=i.parser(n));else for(a in this.dateFormats)if(i=this.dateFormats[a],n=e.match(i.regex)){this.dateFormat=r=a,this.alternativeFormat=i.alternative,s=i.parser(n);break}!n&&(e.match(/:.+(GMT|UTC|[Z+\-])/)&&(e=e.replace(/\s*(?:GMT|UTC)?([+\-])(\d\d)(\d\d)$/,"$1$2:$3").replace(/(?:\s+|GMT|UTC)([+\-])/,"$1").replace(/(\d)\s*(?:GMT|UTC|Z)$/,"$1+00:00")),"object"==typeof(n=Date.parse(e))&&null!==n&&n.getTime?s=n.getTime()-6e4*n.getTimezoneOffset():A(n)&&(s=n-6e4*new Date(n).getTimezoneOffset()))}return s}getData(){if(this.columns)return this.rowsToColumns(this.columns)?.slice(1)}parsed(){if(this.options.parsed)return this.options.parsed.call(this,this.columns)}complete(){let e=this.columns=this.columns||[],t=this.options,s=[],a="linear",i,r,n,o,l,u,d,h,p,m,c;if([].length=e.length,t.complete||t.afterComplete){if(this.firstRowAsNames)for(n=0;n<e.length;n++){let t=e[n];C(t.name)||(t.name=w(t.shift(),"").toString())}for(u=0,i=[],p=function(e,t){let s,a,i,r=[],n=[];for(a=0;a<e;a+=1)r.push(!0);for(s=0;s<t.length;s+=1)for(a=0,i=t[s].getReferencedColumnIndexes();a<i.length;a+=1)r[i[a]]=!1;for(a=0;a<r.length;a+=1)r[a]&&n.push(a);return n}(e?.length||0,this.valueCount.seriesBuilders);u<this.valueCount.seriesBuilders.length;u++)(h=this.valueCount.seriesBuilders[u]).populateColumns(p)&&s.push(h);for(;p.length>0;){for((h=new b).addColumnReader(0,"x"),-1!==(c=p.indexOf(0))&&p.splice(c,1),n=0;n<this.valueCount.global;n++)h.addColumnReader(void 0,this.valueCount.globalPointArrayMap[n]);h.populateColumns(p)&&s.push(h)}if(s.length>0&&s[0].readers.length>0&&void 0!==(m=e?.[s[0].readers[0].columnIndex??-1])&&(m.isDatetime?a="datetime":m.isNumeric||(a="category")),"category"===a)for(u=0;u<s.length;u++)for(l=0,h=s[u];l<h.readers.length;l++)"x"===h.readers[l].configName&&(h.readers[l].configName="name");for(u=0;u<s.length;u++){for(o=0,h=s[u],r=[];o<e[0].length;o++)r[o]=h.read(e,o);i[u]={data:r,pointStart:r[0]&&(h.pointIsArray?r[0]?.[0]:r[0]?.x)||void 0},h.name&&(i[u].name=h.name),"category"===a&&(i[u].turboThreshold=0,i[u].pointStart=0)}d={series:i},"linear"!==a||this.xAxisOptions&&this.xAxisOptions.type!==a?(this.xAxisOptions={type:a},"category"===a&&(this.xAxisOptions.uniqueNames=!1)):a=this.xAxisOptions=void 0,this.chart||Y(!0,d,{xAxis:this.xAxisOptions||{}}),t.complete?.(d),t.afterComplete?.(this,d)}}xAxisUpdateHandler(e){let t=this.xAxisOptions;t&&(!e.options.type&&t.type&&(e.type=t.type),e.options.uniqueNames||!1!==t.uniqueNames||(e.uniqueNames=t.uniqueNames))}update(e,t){let s=this.chart,a=s.options;e&&(e.afterComplete=function(e,a){if(!a)return;let i=s.xAxis[0],r=e.xAxisOptions;r&&i&&(i.type!==r.type&&!i.options.type||i.uniqueNames&&!1===r.uniqueNames&&void 0===i.options.uniqueNames)?i.update({},!1):(a?.series||[]).forEach(function(e){delete e.pointStart}),s.update(a,t,!0)},Y(!0,a.data,e),a.data?.googleSpreadsheetKey&&!e.columns&&delete a.data.columns,this.init(a.data||{},a))}}T(u(),"afterSetOptions",function(){this.isXAxis&&(!this.chart.xAxis.length||this.chart.xAxis[0]===this)&&this.chart.data?.xAxisUpdateHandler(this)}),T(h(),"init",function(e){let t=this,s=e.args[1],a=g().data,i=e.args[0]||{};(a||i&&i.data)&&!t.hasDataDef&&(t.hasDataDef=!0,t.data=new O(N(Y(a,i.data),{afterComplete:function(e,a){let r,n;if(Object.hasOwnProperty.call(i,"series"))if("object"==typeof i.series)for(r=Math.max(i.series.length,a?.series?.length??0);r--;)n=i.series[r]||{},i.series[r]=Y(n,a?.series?.[r]??{});else delete i.series;i=Y(a,i),t.data=e,t.init(i,s)}}),i,t),e.preventDefault())});class b{constructor(){this.readers=[],this.pointIsArray=!0}populateColumns(e){let t=!0;return this.readers.forEach(t=>{void 0===t.columnIndex&&(t.columnIndex=e.shift())}),this.readers.forEach(e=>{void 0===e.columnIndex&&(t=!1)}),t}read(e,t){let s=this.pointIsArray,a=s?[]:{};if(this.readers.forEach(i=>{let r=e[i.columnIndex][t];s?a.push(r):i.configName.indexOf(".")>0?m().prototype.setNestedProperty(a,r,i.configName):a[i.configName]=r}),void 0===this.name&&this.readers.length>=2){let t=[];this.readers.forEach(function(e){("x"===e.configName||"name"===e.configName||"y"===e.configName)&&void 0!==e.columnIndex&&t.push(e.columnIndex)}),t.length>=2&&(t.shift(),t.sort(function(e,t){return e-t})),this.name=e[w(t.shift(),0)].name}return a}addColumnReader(e,t){this.readers.push({columnIndex:e,configName:t}),"x"!==t&&"y"!==t&&void 0!==t&&(this.pointIsArray=!1)}getReferencedColumnIndexes(){let e,t,s=[];for(e=0;e<this.readers.length;e+=1)void 0!==(t=this.readers[e]).columnIndex&&s.push(t.columnIndex);return s}hasReader(e){let t;for(t=0;t<this.readers.length;t+=1)if(this.readers[t].configName===e)return!0}}let E=a();E.Data=E.Data||O,E.HttpUtilities=E.HttpUtilities||o,E.ajax=E.HttpUtilities.ajax,E.data=E.Data.data,E.getJSON=E.HttpUtilities.getJSON,E.post=E.HttpUtilities.post;let S=a();export{S as default};