/
Data.ts
2863 lines (2546 loc) · 89.5 KB
/
Data.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* *
*
* Data module
*
* (c) 2012-2021 Torstein Honsi
*
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* */
'use strict';
/* *
*
* Imports
*
* */
import type Options from '../Core/Options';
import type SeriesOptions from '../Core/Series/SeriesOptions';
import Chart from '../Core/Chart/Chart.js';
import G from '../Core/Globals.js';
const { doc } = G;
import HU from '../Core/HttpUtilities.js';
const { ajax } = HU;
import Point from '../Core/Series/Point.js';
import SeriesRegistry from '../Core/Series/SeriesRegistry.js';
const { seriesTypes } = SeriesRegistry;
import U from '../Core/Utilities.js';
import D from '../Core/DefaultOptions.js';
const { getOptions } = D;
const {
addEvent,
defined,
extend,
fireEvent,
isNumber,
merge,
objectEach,
pick,
splat
} = U;
/* *
*
* Declarations
*
* */
declare module '../Core/Chart/ChartLike'{
interface ChartLike {
data?: Highcharts.Data;
hasDataDef?: boolean;
liveDataURL?: string;
}
}
declare module '../Core/Options' {
interface Options {
data?: Highcharts.DataOptions;
}
}
/**
* Internal types
* @private
*/
declare global {
namespace Highcharts {
type DataValueType = (number|string|null);
interface DataAfterCompleteCallbackFunction {
(dataOptions?: Partial<Options>): void;
}
interface DataBeforeParseCallbackFunction {
(csv: string): string;
}
interface DataCompleteCallbackFunction {
(chartOptions: Partial<Options>): void;
}
interface DataDateFormatCallbackFunction {
(match: ReturnType<string['match']>): number;
}
interface DataDateFormatObject {
alternative?: string;
parser: DataDateFormatCallbackFunction;
regex: RegExp;
}
interface DataOptions {
afterComplete?: DataAfterCompleteCallbackFunction;
beforeParse?: DataBeforeParseCallbackFunction;
columns?: Array<Array<DataValueType>>;
columnsURL?: string;
columnTypes?: Array<string>;
complete?: DataCompleteCallbackFunction;
csv?: string;
csvURL?: string;
dataRefreshRate?: number;
dateFormat?: string;
dateFormats?: undefined;
decimalPoint?: string;
enablePolling?: boolean;
endColumn?: number;
endRow?: number;
error?: Function;
firstRowAsNames?: boolean;
googleAPIKey?: string;
googleSpreadsheetKey?: string;
googleSpreadsheetRange?: string;
itemDelimiter?: string;
lineDelimiter?: string;
parsed?: DataParsedCallbackFunction;
parseDate?: DataParseDateCallbackFunction;
rows?: Array<Array<DataValueType>>;
rowsURL?: string;
seriesMapping?: Array<Record<string, number>>;
sort?: boolean;
startColumn?: number;
startRow?: number;
switchRowsAndColumns?: boolean;
table?: (string|HTMLElement);
}
interface DataParseDateCallbackFunction {
(dateValue: string): number;
}
interface DataParsedCallbackFunction {
(columns: Array<Array<DataValueType>>): (boolean|undefined);
}
interface DataValueCountObject {
global: number;
globalPointArrayMap: Array<string>;
individual: Array<number>;
seriesBuilders: Array<SeriesBuilder>;
xColumns: Array<number>;
}
interface SeriesBuilderReaderObject {
columnIndex: (number|undefined);
configName: string;
}
class Data {
public constructor(
dataOptions: DataOptions,
chartOptions?: Partial<Options>,
chart?: Chart
);
public alternativeFormat?: string;
public chart: Chart;
public chartOptions: Options;
public columns?: Array<Array<DataValueType>>;
public dateFormat?: string;
public dateFormats: Record<string, Highcharts.DataDateFormatObject>;
public decimalRegex?: RegExp;
public firstRowAsNames: boolean;
public liveDataTimeout?: number;
public rawColumns: Array<Array<string>>;
public options: DataOptions;
public valueCount?: DataValueCountObject;
public complete(): void;
public dataFound(): void;
public fetchLiveData(): (boolean|string);
public getColumnDistribution(): void;
public getData(): (Array<Array<DataValueType>>|undefined);
public getFreeIndexes(
numberOfColumns: number,
seriesBuilders: Array<SeriesBuilder>
): Array<number>;
public hasURLOption(options: DataOptions): boolean;
public init(
options: DataOptions,
chartOptions?: Options,
chart?: Chart
): void;
public parseColumn(column: Array<DataValueType>, col: number): void;
public parseCSV(
inOptions?: Highcharts.DataOptions
): Array<Array<(number|string)>>;
public parsed(): (boolean|undefined);
public parseDate(val: string): number;
public parseGoogleSpreadsheet(): boolean;
public parseTable(): Array<Array<(number|string)>>;
public parseTypes(): void;
public rowsToColumns(
rows: (Array<Array<DataValueType>>|undefined)
): (Array<Array<DataValueType>>|undefined);
public trim(str: string, inside?: boolean): string;
}
class SeriesBuilder {
public name?: string;
public readers: Array<SeriesBuilderReaderObject>;
public pointIsArray: boolean;
public addColumnReader(
columnIndex: (number|undefined),
configName: string
): void;
public getReferencedColumnIndexes(): Array<number>;
public hasReader(configName: string): (boolean|undefined);
public populateColumns(freeIndexes: Array<number>): boolean;
public read<DataItemType>(
columns: Array<Array<DataItemType>>,
rowIndex: number
): (Array<DataItemType>|Record<string, DataItemType>);
}
function data(
dataOptions: DataOptions,
chartOptions?: Options,
chart?: Chart
): Data;
}
}
/**
* Callback function to modify the CSV before parsing it by the data module.
*
* @callback Highcharts.DataBeforeParseCallbackFunction
*
* @param {string} csv
* The CSV to modify.
*
* @return {string}
* The CSV to parse.
*/
/**
* Callback function that gets called after parsing data.
*
* @callback Highcharts.DataCompleteCallbackFunction
*
* @param {Highcharts.Options} chartOptions
* The chart options that were used.
*/
/**
* Callback function that returns the correspondig Date object to a match.
*
* @callback Highcharts.DataDateFormatCallbackFunction
*
* @param {Array<number>} match
*
* @return {number}
*/
/**
* Structure for alternative date formats to parse.
*
* @interface Highcharts.DataDateFormatObject
*//**
* @name Highcharts.DataDateFormatObject#alternative
* @type {string|undefined}
*//**
* @name Highcharts.DataDateFormatObject#parser
* @type {Highcharts.DataDateFormatCallbackFunction}
*//**
* @name Highcharts.DataDateFormatObject#regex
* @type {global.RegExp}
*/
/**
* Possible types for a data item in a column or row.
*
* @typedef {number|string|null} Highcharts.DataValueType
*/
/**
* Callback function to parse string representations of dates into
* JavaScript timestamps (milliseconds since 1.1.1970).
*
* @callback Highcharts.DataParseDateCallbackFunction
*
* @param {string} dateValue
*
* @return {number}
* Timestamp (milliseconds since 1.1.1970) as integer for Date class.
*/
/**
* Callback function to access the parsed columns, the two-dimentional
* input data array directly, before they are interpreted into series
* data and categories.
*
* @callback Highcharts.DataParsedCallbackFunction
*
* @param {Array<Array<*>>} columns
* The parsed columns by the data module.
*
* @return {boolean|undefined}
* Return `false` to stop completion, or call `this.complete()` to
* continue async.
*/
/**
* The Data module provides a simplified interface for adding data to
* a chart from sources like CVS, HTML tables or grid views. See also
* the [tutorial article on the Data module](
* https://www.highcharts.com/docs/working-with-data/data-module).
*
* It requires the `modules/data.js` file to be loaded.
*
* Please note that the default way of adding data in Highcharts, without
* the need of a module, is through the [series._type_.data](#series.line.data)
* option.
*
* @sample {highcharts} highcharts/demo/column-parsed/
* HTML table
* @sample {highcharts} highcharts/data/csv/
* CSV
*
* @since 4.0
* @requires modules/data
* @apioption data
*/
/**
* A callback function to modify the CSV before parsing it. Return the modified
* string.
*
* @sample {highcharts} highcharts/demo/line-ajax/
* Modify CSV before parse
*
* @type {Highcharts.DataBeforeParseCallbackFunction}
* @since 6.1
* @apioption data.beforeParse
*/
/**
* A two-dimensional array representing the input data on tabular form.
* This input can be used when the data is already parsed, for example
* from a grid view component. Each cell can be a string or number.
* If not switchRowsAndColumns is set, the columns are interpreted as
* series.
*
* @see [data.rows](#data.rows)
*
* @sample {highcharts} highcharts/data/columns/
* Columns
*
* @type {Array<Array<Highcharts.DataValueType>>}
* @since 4.0
* @apioption data.columns
*/
/**
* The callback that is evaluated when the data is finished loading,
* optionally from an external source, and parsed. The first argument
* passed is a finished chart options object, containing the series.
* These options can be extended with additional options and passed
* directly to the chart constructor.
*
* @see [data.parsed](#data.parsed)
*
* @sample {highcharts} highcharts/data/complete/
* Modify data on complete
*
* @type {Highcharts.DataCompleteCallbackFunction}
* @since 4.0
* @apioption data.complete
*/
/**
* A comma delimited string to be parsed. Related options are [startRow](
* #data.startRow), [endRow](#data.endRow), [startColumn](#data.startColumn)
* and [endColumn](#data.endColumn) to delimit what part of the table
* is used. The [lineDelimiter](#data.lineDelimiter) and [itemDelimiter](
* #data.itemDelimiter) options define the CSV delimiter formats.
*
* The built-in CSV parser doesn't support all flavours of CSV, so in
* some cases it may be necessary to use an external CSV parser. See
* [this example](https://jsfiddle.net/highcharts/u59176h4/) of parsing
* CSV through the MIT licensed [Papa Parse](http://papaparse.com/)
* library.
*
* @sample {highcharts} highcharts/data/csv/
* Data from CSV
*
* @type {string}
* @since 4.0
* @apioption data.csv
*/
/**
* Which of the predefined date formats in Date.prototype.dateFormats
* to use to parse date values. Defaults to a best guess based on what
* format gives valid and ordered dates. Valid options include: `YYYY/mm/dd`,
* `dd/mm/YYYY`, `mm/dd/YYYY`, `dd/mm/YY`, `mm/dd/YY`.
*
* @see [data.parseDate](#data.parseDate)
*
* @sample {highcharts} highcharts/data/dateformat-auto/
* Best guess date format
*
* @type {string}
* @since 4.0
* @validvalue ["YYYY/mm/dd", "dd/mm/YYYY", "mm/dd/YYYY", "dd/mm/YYYY",
* "dd/mm/YY", "mm/dd/YY"]
* @apioption data.dateFormat
*/
/**
* The decimal point used for parsing numbers in the CSV.
*
* If both this and data.delimiter is set to `undefined`, the parser will
* attempt to deduce the decimal point automatically.
*
* @sample {highcharts} highcharts/data/delimiters/
* Comma as decimal point
*
* @type {string}
* @default .
* @since 4.1.0
* @apioption data.decimalPoint
*/
/**
* In tabular input data, the last column (indexed by 0) to use. Defaults
* to the last column containing data.
*
* @sample {highcharts} highcharts/data/start-end/
* Limited data
*
* @type {number}
* @since 4.0
* @apioption data.endColumn
*/
/**
* In tabular input data, the last row (indexed by 0) to use. Defaults
* to the last row containing data.
*
* @sample {highcharts} highcharts/data/start-end/
* Limited data
*
* @type {number}
* @since 4.0.4
* @apioption data.endRow
*/
/**
* Whether to use the first row in the data set as series names.
*
* @sample {highcharts} highcharts/data/start-end/
* Don't get series names from the CSV
* @sample {highstock} highcharts/data/start-end/
* Don't get series names from the CSV
*
* @type {boolean}
* @default true
* @since 4.1.0
* @product highcharts highstock gantt
* @apioption data.firstRowAsNames
*/
/**
* The Google Spreadsheet API key required for access generated at [API Services
* / Credentials](https://console.cloud.google.com/apis/credentials). See a
* comprehensive tutorial for setting up the key at the
* [Hands-On Data Visualization](https://handsondataviz.org/google-sheets-api-key.html)
* book website.
*
* @sample {highcharts} highcharts/data/google-spreadsheet/
* Load a Google Spreadsheet
*
* @type {string}
* @since 9.2.2
* @apioption data.googleAPIKey
*/
/**
* The key or `spreadsheetId` value for a Google Spreadsheet to load. See
* [developers.google.com](https://developers.google.com/sheets/api/guides/concepts)
* for how to find the `spreadsheetId`.
*
* In order for Google Sheets to load, a valid [googleAPIKey](#data.googleAPIKey)
* must also be given.
*
* @sample {highcharts} highcharts/data/google-spreadsheet/
* Load a Google Spreadsheet
*
* @type {string}
* @since 4.0
* @apioption data.googleSpreadsheetKey
*/
/**
* The Google Spreadsheet `range` to use in combination with
* [googleSpreadsheetKey](#data.googleSpreadsheetKey). See
* [developers.google.com](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get)
* for details.
*
* If given, it takes precedence over `startColumn`, `endColumn`, `startRow` and
* `endRow`.
*
* @example
* googleSpreadsheetRange: 'Fruit Consumption' // Load a named worksheet
* googleSpreadsheetRange: 'A:Z' // Load columns A to Z
*
* @sample {highcharts} highcharts/data/google-spreadsheet/
* Load a Google Spreadsheet
*
* @type {string|undefined}
* @since 9.2.2
* @apioption data.googleSpreadsheetRange
*/
/**
* No longer works since v9.2.2, that uses Google Sheets API v4. Instead, use
* the [googleSpreadsheetRange](#data.googleSpreadsheetRange) option to load a
* specific sheet.
*
* @deprecated
* @type {string}
* @since 4.0
* @apioption data.googleSpreadsheetWorksheet
*/
/**
* Item or cell delimiter for parsing CSV. Defaults to the tab character
* `\t` if a tab character is found in the CSV string, if not it defaults
* to `,`.
*
* If this is set to false or undefined, the parser will attempt to deduce
* the delimiter automatically.
*
* @sample {highcharts} highcharts/data/delimiters/
* Delimiters
*
* @type {string}
* @since 4.0
* @apioption data.itemDelimiter
*/
/**
* Line delimiter for parsing CSV.
*
* @sample {highcharts} highcharts/data/delimiters/
* Delimiters
*
* @type {string}
* @default \n
* @since 4.0
* @apioption data.lineDelimiter
*/
/**
* A callback function to access the parsed columns, the two-dimentional
* input data array directly, before they are interpreted into series
* data and categories. Return `false` to stop completion, or call
* `this.complete()` to continue async.
*
* @see [data.complete](#data.complete)
*
* @sample {highcharts} highcharts/data/parsed/
* Modify data after parse
*
* @type {Highcharts.DataParsedCallbackFunction}
* @since 4.0
* @apioption data.parsed
*/
/**
* A callback function to parse string representations of dates into
* JavaScript timestamps. Should return an integer timestamp on success.
*
* @see [dateFormat](#data.dateFormat)
*
* @type {Highcharts.DataParseDateCallbackFunction}
* @since 4.0
* @apioption data.parseDate
*/
/**
* The same as the columns input option, but defining rows intead of
* columns.
*
* @see [data.columns](#data.columns)
*
* @sample {highcharts} highcharts/data/rows/
* Data in rows
*
* @type {Array<Array<Highcharts.DataValueType>>}
* @since 4.0
* @apioption data.rows
*/
/**
* An array containing dictionaries for each series. A dictionary exists of
* Point property names as the key and the CSV column index as the value.
*
* @sample {highcharts} highcharts/data/seriesmapping-label/
* Label from data set
*
* @type {Array<Highcharts.Dictionary<number>>}
* @since 4.0.4
* @apioption data.seriesMapping
*/
/**
* In tabular input data, the first column (indexed by 0) to use.
*
* @sample {highcharts} highcharts/data/start-end/
* Limited data
*
* @type {number}
* @default 0
* @since 4.0
* @apioption data.startColumn
*/
/**
* In tabular input data, the first row (indexed by 0) to use.
*
* @sample {highcharts} highcharts/data/start-end/
* Limited data
*
* @type {number}
* @default 0
* @since 4.0
* @apioption data.startRow
*/
/**
* Switch rows and columns of the input data, so that `this.columns`
* effectively becomes the rows of the data set, and the rows are interpreted
* as series.
*
* @sample {highcharts} highcharts/data/switchrowsandcolumns/
* Switch rows and columns
*
* @type {boolean}
* @default false
* @since 4.0
* @apioption data.switchRowsAndColumns
*/
/**
* An HTML table or the id of such to be parsed as input data. Related
* options are `startRow`, `endRow`, `startColumn` and `endColumn` to
* delimit what part of the table is used.
*
* @sample {highcharts} highcharts/demo/column-parsed/
* Parsed table
*
* @type {string|global.HTMLElement}
* @since 4.0
* @apioption data.table
*/
/**
* An URL to a remote CSV dataset. Will be fetched when the chart is created
* using Ajax.
*
* @sample highcharts/data/livedata-columns
* Categorized bar chart with CSV and live polling
* @sample highcharts/data/livedata-csv
* Time based line chart with CSV and live polling
*
* @type {string}
* @apioption data.csvURL
*/
/**
* A URL to a remote JSON dataset, structured as a row array.
* Will be fetched when the chart is created using Ajax.
*
* @sample highcharts/data/livedata-rows
* Rows with live polling
*
* @type {string}
* @apioption data.rowsURL
*/
/**
* A URL to a remote JSON dataset, structured as a column array.
* Will be fetched when the chart is created using Ajax.
*
* @sample highcharts/data/livedata-columns
* Columns with live polling
*
* @type {string}
* @apioption data.columnsURL
*/
/**
* Sets the refresh rate for data polling when importing remote dataset by
* setting [data.csvURL](data.csvURL), [data.rowsURL](data.rowsURL),
* [data.columnsURL](data.columnsURL), or
* [data.googleSpreadsheetKey](data.googleSpreadsheetKey).
*
* Note that polling must be enabled by setting
* [data.enablePolling](data.enablePolling) to true.
*
* The value is the number of seconds between pollings.
* It cannot be set to less than 1 second.
*
* @sample highcharts/demo/live-data
* Live data with user set refresh rate
*
* @default 1
* @type {number}
* @apioption data.dataRefreshRate
*/
/**
* Enables automatic refetching of remote datasets every _n_ seconds (defined by
* setting [data.dataRefreshRate](data.dataRefreshRate)).
*
* Only works when either [data.csvURL](data.csvURL),
* [data.rowsURL](data.rowsURL), [data.columnsURL](data.columnsURL), or
* [data.googleSpreadsheetKey](data.googleSpreadsheetKey).
*
* @sample highcharts/demo/live-data
* Live data
* @sample highcharts/data/livedata-columns
* Categorized bar chart with CSV and live polling
*
* @type {boolean}
* @default false
* @apioption data.enablePolling
*/
/* eslint-disable valid-jsdoc */
/**
* The Data class
*
* @requires module:modules/data
*
* @class
* @name Highcharts.Data
*
* @param {Highcharts.DataOptions} dataOptions
*
* @param {Highcharts.Options} [chartOptions]
*
* @param {Highcharts.Chart} [chart]
*/
class Data {
/* *
*
* Constructors
*
* */
public constructor(
dataOptions: Highcharts.DataOptions,
chartOptions?: Options,
chart?: Chart
) {
this.init(dataOptions, chartOptions, chart);
}
/* *
*
* Properties
*
* */
public alternativeFormat?: string;
public chart: Chart = void 0 as any;
public chartOptions: Options = void 0 as any;
public columns?: Array<Array<Highcharts.DataValueType>>;
public dateFormat?: string;
public decimalRegex?: RegExp;
public firstRowAsNames: boolean = void 0 as any;
public liveDataTimeout?: number;
public rawColumns: Array<Array<string>> = void 0 as any;
public options: Highcharts.DataOptions = void 0 as any;
public valueCount?: Highcharts.DataValueCountObject;
/* *
*
* Functions
*
* */
/**
* Initialize the Data object with the given options
*
* @private
* @function Highcharts.Data#init
*/
public init(
options: Highcharts.DataOptions,
chartOptions?: Options,
chart?: Chart
): void {
let decimalPoint = options.decimalPoint,
hasData;
if (chartOptions) {
this.chartOptions = chartOptions;
}
if (chart) {
this.chart = chart;
}
if (decimalPoint !== '.' && decimalPoint !== ',') {
decimalPoint = void 0;
}
this.options = options;
this.columns = (
options.columns ||
this.rowsToColumns(options.rows) ||
[]
);
this.firstRowAsNames = pick(
options.firstRowAsNames,
this.firstRowAsNames,
true
);
this.decimalRegex = (
decimalPoint &&
new RegExp('^(-?[0-9]+)' + decimalPoint + '([0-9]+)$')
);
// Always stop old polling when we have new options
if (this.liveDataTimeout !== void 0) {
clearTimeout(this.liveDataTimeout);
}
// This is a two-dimensional array holding the raw, trimmed string
// values with the same organisation as the columns array. It makes it
// possible for example to revert from interpreted timestamps to
// string-based categories.
this.rawColumns = [];
// No need to parse or interpret anything
if (this.columns.length) {
this.dataFound();
hasData = !this.hasURLOption(options);
}
if (!hasData) {
// Fetch live data
hasData = this.fetchLiveData();
}
if (!hasData) {
// Parse a CSV string if options.csv is given. The parseCSV function
// returns a columns array, if it has no length, we have no data
hasData = Boolean(this.parseCSV().length);
}
if (!hasData) {
// Parse a HTML table if options.table is given
hasData = Boolean(this.parseTable().length);
}
if (!hasData) {
// Parse a Google Spreadsheet
hasData = this.parseGoogleSpreadsheet();
}
if (!hasData && options.afterComplete) {
options.afterComplete();
}
}
public hasURLOption(options: Highcharts.DataOptions): boolean {
return Boolean(
options &&
(options.rowsURL || options.csvURL || options.columnsURL)
);
}
/**
* Get the column distribution. For example, a line series takes a single
* column for Y values. A range series takes two columns for low and high
* values respectively, and an OHLC series takes four columns.
*
* @function Highcharts.Data#getColumnDistribution
*/
public getColumnDistribution(): void {
let chartOptions = this.chartOptions,
options = this.options,
xColumns: Array<number> = [],
getValueCount = function (type: string): number {
return (
seriesTypes[type || 'line'].prototype.pointArrayMap || [0]
).length;
},
getPointArrayMap = function (
type: string
): (Array<string>|undefined) {
return seriesTypes[type || 'line'].prototype.pointArrayMap;
},
globalType: string = (
chartOptions &&
chartOptions.chart &&
chartOptions.chart.type
) as any,
individualCounts: Array<number> = [],
seriesBuilders: Array<Highcharts.SeriesBuilder> = [],
seriesIndex = 0,
// If no series mapping is defined, check if the series array is
// defined with types.
seriesMapping = (
(options && options.seriesMapping) ||
(
chartOptions &&
chartOptions.series &&
chartOptions.series.map(function (
): Record<string, number> {
return { x: 0 };
})
) ||
[]
),
i;
((chartOptions && chartOptions.series) || []).forEach(
function (series): void {
individualCounts.push(getValueCount(series.type || globalType));
}
);
// Collect the x-column indexes from seriesMapping
seriesMapping.forEach(function (
mapping: Record<string, number>
): void {
xColumns.push(mapping.x || 0);
});
// If there are no defined series with x-columns, use the first column
// as x column
if (xColumns.length === 0) {
xColumns.push(0);
}
// Loop all seriesMappings and constructs SeriesBuilders from
// the mapping options.
seriesMapping.forEach(function (
mapping: Record<string, number>
): void {
const builder = new SeriesBuilder(),
numberOfValueColumnsNeeded = individualCounts[seriesIndex] ||
getValueCount(globalType),
seriesArr = (chartOptions && chartOptions.series) || [],
series = seriesArr[seriesIndex] || {},
defaultPointArrayMap = getPointArrayMap(
series.type || globalType
),
pointArrayMap = defaultPointArrayMap || ['y'];
if (
// User-defined x.mapping
defined(mapping.x) ||
// All non cartesian don't need 'x'
(series as any).isCartesian ||
// Except pie series:
!defaultPointArrayMap
) {
// Add an x reader from the x property or from an undefined
// column if the property is not set. It will then be auto
// populated later.
builder.addColumnReader(mapping.x, 'x');
}
// Add all column mappings
objectEach(mapping, function (val: number, name: string): void {
if (name !== 'x') {
builder.addColumnReader(val, name);
}
});
// Add missing columns
for (i = 0; i < numberOfValueColumnsNeeded; i++) {
if (!builder.hasReader(pointArrayMap[i])) {
// Create and add a column reader for the next free column
// index
builder.addColumnReader(void 0, pointArrayMap[i]);
}
}
seriesBuilders.push(builder);
seriesIndex++;
});
let globalPointArrayMap = getPointArrayMap(globalType);
if (typeof globalPointArrayMap === 'undefined') {
globalPointArrayMap = ['y'];
}
this.valueCount = {
global: getValueCount(globalType as any),
xColumns: xColumns,
individual: individualCounts,
seriesBuilders: seriesBuilders,
globalPointArrayMap: globalPointArrayMap
};
}
/**
* When the data is parsed into columns, either by CSV, table, GS or direct