@d3plus/format 3.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1745 @@
1
+ /*
2
+ @d3plus/format v3.0.0
3
+ JavaScript formatters for localized numbers and dates.
4
+ Copyright (c) 2025 D3plus - https://d3plus.org
5
+ @license MIT
6
+ */
7
+
8
+ (function (factory) {
9
+ typeof define === 'function' && define.amd ? define(factory) :
10
+ factory();
11
+ })((function () { 'use strict';
12
+
13
+ if (typeof window !== "undefined") {
14
+ (function () {
15
+ try {
16
+ if (typeof SVGElement === 'undefined' || Boolean(SVGElement.prototype.innerHTML)) {
17
+ return;
18
+ }
19
+ } catch (e) {
20
+ return;
21
+ }
22
+
23
+ function serializeNode (node) {
24
+ switch (node.nodeType) {
25
+ case 1:
26
+ return serializeElementNode(node);
27
+ case 3:
28
+ return serializeTextNode(node);
29
+ case 8:
30
+ return serializeCommentNode(node);
31
+ }
32
+ }
33
+
34
+ function serializeTextNode (node) {
35
+ return node.textContent.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
36
+ }
37
+
38
+ function serializeCommentNode (node) {
39
+ return '<!--' + node.nodeValue + '-->'
40
+ }
41
+
42
+ function serializeElementNode (node) {
43
+ var output = '';
44
+
45
+ output += '<' + node.tagName;
46
+
47
+ if (node.hasAttributes()) {
48
+ [].forEach.call(node.attributes, function(attrNode) {
49
+ output += ' ' + attrNode.name + '="' + attrNode.value + '"';
50
+ });
51
+ }
52
+
53
+ output += '>';
54
+
55
+ if (node.hasChildNodes()) {
56
+ [].forEach.call(node.childNodes, function(childNode) {
57
+ output += serializeNode(childNode);
58
+ });
59
+ }
60
+
61
+ output += '</' + node.tagName + '>';
62
+
63
+ return output;
64
+ }
65
+
66
+ Object.defineProperty(SVGElement.prototype, 'innerHTML', {
67
+ get: function () {
68
+ var output = '';
69
+
70
+ [].forEach.call(this.childNodes, function(childNode) {
71
+ output += serializeNode(childNode);
72
+ });
73
+
74
+ return output;
75
+ },
76
+ set: function (markup) {
77
+ while (this.firstChild) {
78
+ this.removeChild(this.firstChild);
79
+ }
80
+
81
+ try {
82
+ var dXML = new DOMParser();
83
+ dXML.async = false;
84
+
85
+ var sXML = '<svg xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\'>' + markup + '</svg>';
86
+ var svgDocElement = dXML.parseFromString(sXML, 'text/xml').documentElement;
87
+
88
+ [].forEach.call(svgDocElement.childNodes, function(childNode) {
89
+ this.appendChild(this.ownerDocument.importNode(childNode, true));
90
+ }.bind(this));
91
+ } catch (e) {
92
+ throw new Error('Error parsing markup string');
93
+ }
94
+ }
95
+ });
96
+
97
+ Object.defineProperty(SVGElement.prototype, 'innerSVG', {
98
+ get: function () {
99
+ return this.innerHTML;
100
+ },
101
+ set: function (markup) {
102
+ this.innerHTML = markup;
103
+ }
104
+ });
105
+
106
+ })();
107
+ }
108
+
109
+ }));
110
+
111
+ (function (global, factory) {
112
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
113
+ typeof define === 'function' && define.amd ? define('@d3plus/format', ['exports'], factory) :
114
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3plus = {}));
115
+ })(this, (function (exports) {
116
+ function formatDecimal(x) {
117
+ return Math.abs(x = Math.round(x)) >= 1e21 ? x.toLocaleString("en").replace(/,/g, "") : x.toString(10);
118
+ }
119
+ // Computes the decimal coefficient and exponent of the specified number x with
120
+ // significant digits p, where x is positive and p is in [1, 21] or undefined.
121
+ // For example, formatDecimalParts(1.23) returns ["123", 0].
122
+ function formatDecimalParts(x, p) {
123
+ if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
124
+ var i, coefficient = x.slice(0, i);
125
+ // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
126
+ // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
127
+ return [
128
+ coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
129
+ +x.slice(i + 1)
130
+ ];
131
+ }
132
+
133
+ function exponent(x) {
134
+ return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;
135
+ }
136
+
137
+ function formatGroup(grouping, thousands) {
138
+ return function(value, width) {
139
+ var i = value.length, t = [], j = 0, g = grouping[0], length = 0;
140
+ while(i > 0 && g > 0){
141
+ if (length + g + 1 > width) g = Math.max(1, width - length);
142
+ t.push(value.substring(i -= g, i + g));
143
+ if ((length += g + 1) > width) break;
144
+ g = grouping[j = (j + 1) % grouping.length];
145
+ }
146
+ return t.reverse().join(thousands);
147
+ };
148
+ }
149
+
150
+ function formatNumerals(numerals) {
151
+ return function(value) {
152
+ return value.replace(/[0-9]/g, function(i) {
153
+ return numerals[+i];
154
+ });
155
+ };
156
+ }
157
+
158
+ // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
159
+ var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
160
+ function formatSpecifier(specifier) {
161
+ if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
162
+ var match;
163
+ return new FormatSpecifier({
164
+ fill: match[1],
165
+ align: match[2],
166
+ sign: match[3],
167
+ symbol: match[4],
168
+ zero: match[5],
169
+ width: match[6],
170
+ comma: match[7],
171
+ precision: match[8] && match[8].slice(1),
172
+ trim: match[9],
173
+ type: match[10]
174
+ });
175
+ }
176
+ formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
177
+ function FormatSpecifier(specifier) {
178
+ this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
179
+ this.align = specifier.align === undefined ? ">" : specifier.align + "";
180
+ this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
181
+ this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
182
+ this.zero = !!specifier.zero;
183
+ this.width = specifier.width === undefined ? undefined : +specifier.width;
184
+ this.comma = !!specifier.comma;
185
+ this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
186
+ this.trim = !!specifier.trim;
187
+ this.type = specifier.type === undefined ? "" : specifier.type + "";
188
+ }
189
+ FormatSpecifier.prototype.toString = function() {
190
+ return this.fill + this.align + this.sign + this.symbol + (this.zero ? "0" : "") + (this.width === undefined ? "" : Math.max(1, this.width | 0)) + (this.comma ? "," : "") + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0)) + (this.trim ? "~" : "") + this.type;
191
+ };
192
+
193
+ // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
194
+ function formatTrim(s) {
195
+ out: for(var n = s.length, i = 1, i0 = -1, i1; i < n; ++i){
196
+ switch(s[i]){
197
+ case ".":
198
+ i0 = i1 = i;
199
+ break;
200
+ case "0":
201
+ if (i0 === 0) i0 = i;
202
+ i1 = i;
203
+ break;
204
+ default:
205
+ if (!+s[i]) break out;
206
+ if (i0 > 0) i0 = 0;
207
+ break;
208
+ }
209
+ }
210
+ return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
211
+ }
212
+
213
+ var prefixExponent;
214
+ function formatPrefixAuto(x, p) {
215
+ var d = formatDecimalParts(x, p);
216
+ if (!d) return x + "";
217
+ var coefficient = d[0], exponent = d[1], i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1, n = coefficient.length;
218
+ return i === n ? coefficient : i > n ? coefficient + new Array(i - n + 1).join("0") : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i) : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
219
+ }
220
+
221
+ function formatRounded(x, p) {
222
+ var d = formatDecimalParts(x, p);
223
+ if (!d) return x + "";
224
+ var coefficient = d[0], exponent = d[1];
225
+ return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1) : coefficient + new Array(exponent - coefficient.length + 2).join("0");
226
+ }
227
+
228
+ var formatTypes = {
229
+ "%": (x, p)=>(x * 100).toFixed(p),
230
+ "b": (x)=>Math.round(x).toString(2),
231
+ "c": (x)=>x + "",
232
+ "d": formatDecimal,
233
+ "e": (x, p)=>x.toExponential(p),
234
+ "f": (x, p)=>x.toFixed(p),
235
+ "g": (x, p)=>x.toPrecision(p),
236
+ "o": (x)=>Math.round(x).toString(8),
237
+ "p": (x, p)=>formatRounded(x * 100, p),
238
+ "r": formatRounded,
239
+ "s": formatPrefixAuto,
240
+ "X": (x)=>Math.round(x).toString(16).toUpperCase(),
241
+ "x": (x)=>Math.round(x).toString(16)
242
+ };
243
+
244
+ function identity(x) {
245
+ return x;
246
+ }
247
+
248
+ var map = Array.prototype.map, prefixes = [
249
+ "y",
250
+ "z",
251
+ "a",
252
+ "f",
253
+ "p",
254
+ "n",
255
+ "µ",
256
+ "m",
257
+ "",
258
+ "k",
259
+ "M",
260
+ "G",
261
+ "T",
262
+ "P",
263
+ "E",
264
+ "Z",
265
+ "Y"
266
+ ];
267
+ function formatLocale$1(locale) {
268
+ var group = locale.grouping === undefined || locale.thousands === undefined ? identity : formatGroup(map.call(locale.grouping, Number), locale.thousands + ""), currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "", currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "", decimal = locale.decimal === undefined ? "." : locale.decimal + "", numerals = locale.numerals === undefined ? identity : formatNumerals(map.call(locale.numerals, String)), percent = locale.percent === undefined ? "%" : locale.percent + "", minus = locale.minus === undefined ? "−" : locale.minus + "", nan = locale.nan === undefined ? "NaN" : locale.nan + "";
269
+ function newFormat(specifier) {
270
+ specifier = formatSpecifier(specifier);
271
+ var fill = specifier.fill, align = specifier.align, sign = specifier.sign, symbol = specifier.symbol, zero = specifier.zero, width = specifier.width, comma = specifier.comma, precision = specifier.precision, trim = specifier.trim, type = specifier.type;
272
+ // The "n" type is an alias for ",g".
273
+ if (type === "n") comma = true, type = "g";
274
+ else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
275
+ // If zero fill is specified, padding goes after sign and before digits.
276
+ if (zero || fill === "0" && align === "=") zero = true, fill = "0", align = "=";
277
+ // Compute the prefix and suffix.
278
+ // For SI-prefix, the suffix is lazily computed.
279
+ var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "", suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
280
+ // What format function should we use?
281
+ // Is this an integer type?
282
+ // Can this type generate exponential notation?
283
+ var formatType = formatTypes[type], maybeSuffix = /[defgprs%]/.test(type);
284
+ // Set the default precision if not specified,
285
+ // or clamp the specified precision to the supported range.
286
+ // For significant precision, it must be in [1, 21].
287
+ // For fixed precision, it must be in [0, 20].
288
+ precision = precision === undefined ? 6 : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision)) : Math.max(0, Math.min(20, precision));
289
+ function format(value) {
290
+ var valuePrefix = prefix, valueSuffix = suffix, i, n, c;
291
+ if (type === "c") {
292
+ valueSuffix = formatType(value) + valueSuffix;
293
+ value = "";
294
+ } else {
295
+ value = +value;
296
+ // Determine the sign. -0 is not less than 0, but 1 / -0 is!
297
+ var valueNegative = value < 0 || 1 / value < 0;
298
+ // Perform the initial formatting.
299
+ value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
300
+ // Trim insignificant zeros.
301
+ if (trim) value = formatTrim(value);
302
+ // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
303
+ if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
304
+ // Compute the prefix and suffix.
305
+ valuePrefix = (valueNegative ? sign === "(" ? sign : minus : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
306
+ valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
307
+ // Break the formatted value into the integer “value” part that can be
308
+ // grouped, and fractional or exponential “suffix” part that is not.
309
+ if (maybeSuffix) {
310
+ i = -1, n = value.length;
311
+ while(++i < n){
312
+ if (c = value.charCodeAt(i), 48 > c || c > 57) {
313
+ valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
314
+ value = value.slice(0, i);
315
+ break;
316
+ }
317
+ }
318
+ }
319
+ }
320
+ // If the fill character is not "0", grouping is applied before padding.
321
+ if (comma && !zero) value = group(value, Infinity);
322
+ // Compute the padding.
323
+ var length = valuePrefix.length + value.length + valueSuffix.length, padding = length < width ? new Array(width - length + 1).join(fill) : "";
324
+ // If the fill character is "0", grouping is applied after padding.
325
+ if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
326
+ // Reconstruct the final output based on the desired alignment.
327
+ switch(align){
328
+ case "<":
329
+ value = valuePrefix + value + valueSuffix + padding;
330
+ break;
331
+ case "=":
332
+ value = valuePrefix + padding + value + valueSuffix;
333
+ break;
334
+ case "^":
335
+ value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length);
336
+ break;
337
+ default:
338
+ value = padding + valuePrefix + value + valueSuffix;
339
+ break;
340
+ }
341
+ return numerals(value);
342
+ }
343
+ format.toString = function() {
344
+ return specifier + "";
345
+ };
346
+ return format;
347
+ }
348
+ function formatPrefix(specifier, value) {
349
+ var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)), e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3, k = Math.pow(10, -e), prefix = prefixes[8 + e / 3];
350
+ return function(value) {
351
+ return f(k * value) + prefix;
352
+ };
353
+ }
354
+ return {
355
+ format: newFormat,
356
+ formatPrefix: formatPrefix
357
+ };
358
+ }
359
+
360
+ var locale$1;
361
+ var format$1;
362
+ defaultLocale$2({
363
+ thousands: ",",
364
+ grouping: [
365
+ 3
366
+ ],
367
+ currency: [
368
+ "$",
369
+ ""
370
+ ]
371
+ });
372
+ function defaultLocale$2(definition) {
373
+ locale$1 = formatLocale$1(definition);
374
+ format$1 = locale$1.format;
375
+ locale$1.formatPrefix;
376
+ return locale$1;
377
+ }
378
+
379
+ /**
380
+ @namespace {Object} formatLocale
381
+ @desc A set of default locale formatters used when assigning suffixes and currency in numbers.
382
+ *
383
+ * | Name | Default | Description |
384
+ * |---|---|---|
385
+ * | separator | "" | Separation between the number with the suffix. |
386
+ * | suffixes | [] | List of suffixes used to format numbers. |
387
+ * | grouping | [3] | The array of group sizes, |
388
+ * | delimiters | {thousands: ",", decimal: "."} | Decimal and group separators. |
389
+ * | currency | ["$", ""] | The currency prefix and suffix. |
390
+ */ var defaultLocale$1 = {
391
+ "ar-SA": {
392
+ separator: "",
393
+ suffixes: [
394
+ "y",
395
+ "z",
396
+ "a",
397
+ "f",
398
+ "p",
399
+ "n",
400
+ "µ",
401
+ "m",
402
+ "",
403
+ " ألف",
404
+ " مليون",
405
+ " بليون",
406
+ " تريليون",
407
+ " كوادريليون",
408
+ " كوينتيليون",
409
+ " سكستليون",
410
+ "سبتيليون"
411
+ ],
412
+ grouping: [
413
+ 3
414
+ ],
415
+ delimiters: {
416
+ thousands: ",",
417
+ decimal: "."
418
+ },
419
+ currency: [
420
+ "SAR ",
421
+ ""
422
+ ]
423
+ },
424
+ "en-GB": {
425
+ separator: "",
426
+ suffixes: [
427
+ "y",
428
+ "z",
429
+ "a",
430
+ "f",
431
+ "p",
432
+ "n",
433
+ "µ",
434
+ "m",
435
+ "",
436
+ "k",
437
+ "M",
438
+ "B",
439
+ "T",
440
+ "q",
441
+ "Q",
442
+ "Z",
443
+ "Y"
444
+ ],
445
+ grouping: [
446
+ 3
447
+ ],
448
+ delimiters: {
449
+ thousands: ",",
450
+ decimal: "."
451
+ },
452
+ currency: [
453
+ "£",
454
+ ""
455
+ ]
456
+ },
457
+ "en-US": {
458
+ separator: "",
459
+ suffixes: [
460
+ "y",
461
+ "z",
462
+ "a",
463
+ "f",
464
+ "p",
465
+ "n",
466
+ "µ",
467
+ "m",
468
+ "",
469
+ "k",
470
+ "M",
471
+ "B",
472
+ "T",
473
+ "q",
474
+ "Q",
475
+ "Z",
476
+ "Y"
477
+ ],
478
+ grouping: [
479
+ 3
480
+ ],
481
+ delimiters: {
482
+ thousands: ",",
483
+ decimal: "."
484
+ },
485
+ currency: [
486
+ "$",
487
+ ""
488
+ ]
489
+ },
490
+ "en-SA": {
491
+ separator: "",
492
+ suffixes: [
493
+ "y",
494
+ "z",
495
+ "a",
496
+ "f",
497
+ "p",
498
+ "n",
499
+ "µ",
500
+ "m",
501
+ "",
502
+ " thousand",
503
+ " million",
504
+ " billion",
505
+ " trillion",
506
+ " quadrillion",
507
+ " quintillion",
508
+ " sextillion",
509
+ "septillion"
510
+ ],
511
+ grouping: [
512
+ 3
513
+ ],
514
+ delimiters: {
515
+ thousands: ",",
516
+ decimal: "."
517
+ },
518
+ currency: [
519
+ "$",
520
+ ""
521
+ ]
522
+ },
523
+ "es-CL": {
524
+ separator: "",
525
+ suffixes: [
526
+ "y",
527
+ "z",
528
+ "a",
529
+ "f",
530
+ "p",
531
+ "n",
532
+ "µ",
533
+ "m",
534
+ "",
535
+ "k",
536
+ "M",
537
+ "MM",
538
+ "B",
539
+ "T",
540
+ "Q",
541
+ "Z",
542
+ "Y"
543
+ ],
544
+ grouping: [
545
+ 3
546
+ ],
547
+ delimiters: {
548
+ thousands: ".",
549
+ decimal: ","
550
+ },
551
+ currency: [
552
+ "$",
553
+ ""
554
+ ]
555
+ },
556
+ "es-MX": {
557
+ separator: "",
558
+ suffixes: [
559
+ "y",
560
+ "z",
561
+ "a",
562
+ "f",
563
+ "p",
564
+ "n",
565
+ "µ",
566
+ "m",
567
+ "",
568
+ "k",
569
+ "M",
570
+ "MM",
571
+ "B",
572
+ "T",
573
+ "Q",
574
+ "Z",
575
+ "Y"
576
+ ],
577
+ grouping: [
578
+ 3
579
+ ],
580
+ delimiters: {
581
+ thousands: ",",
582
+ decimal: "."
583
+ },
584
+ currency: [
585
+ "$",
586
+ ""
587
+ ]
588
+ },
589
+ "es-ES": {
590
+ separator: "",
591
+ suffixes: [
592
+ "y",
593
+ "z",
594
+ "a",
595
+ "f",
596
+ "p",
597
+ "n",
598
+ "µ",
599
+ "m",
600
+ "",
601
+ "k",
602
+ "mm",
603
+ "b",
604
+ "t",
605
+ "q",
606
+ "Q",
607
+ "Z",
608
+ "Y"
609
+ ],
610
+ grouping: [
611
+ 3
612
+ ],
613
+ delimiters: {
614
+ thousands: ".",
615
+ decimal: ","
616
+ },
617
+ currency: [
618
+ "€",
619
+ ""
620
+ ]
621
+ },
622
+ "et-EE": {
623
+ separator: " ",
624
+ suffixes: [
625
+ "y",
626
+ "z",
627
+ "a",
628
+ "f",
629
+ "p",
630
+ "n",
631
+ "µ",
632
+ "m",
633
+ "",
634
+ "tuhat",
635
+ "miljonit",
636
+ "miljardit",
637
+ "triljonit",
638
+ "q",
639
+ "Q",
640
+ "Z",
641
+ "Y"
642
+ ],
643
+ grouping: [
644
+ 3
645
+ ],
646
+ delimiters: {
647
+ thousands: " ",
648
+ decimal: ","
649
+ },
650
+ currency: [
651
+ "",
652
+ "eurot"
653
+ ]
654
+ },
655
+ "fr-FR": {
656
+ suffixes: [
657
+ "y",
658
+ "z",
659
+ "a",
660
+ "f",
661
+ "p",
662
+ "n",
663
+ "µ",
664
+ "m",
665
+ "",
666
+ "k",
667
+ "m",
668
+ "b",
669
+ "t",
670
+ "q",
671
+ "Q",
672
+ "Z",
673
+ "Y"
674
+ ],
675
+ grouping: [
676
+ 3
677
+ ],
678
+ delimiters: {
679
+ thousands: " ",
680
+ decimal: ","
681
+ },
682
+ currency: [
683
+ "€",
684
+ ""
685
+ ]
686
+ },
687
+ "zh-CN": {
688
+ separator: "",
689
+ suffixes: [
690
+ "幺",
691
+ "仄",
692
+ "阿",
693
+ "飞",
694
+ "皮",
695
+ "纳",
696
+ "微",
697
+ "毫",
698
+ "",
699
+ "千",
700
+ "兆",
701
+ "吉",
702
+ "太",
703
+ "拍",
704
+ "艾",
705
+ "泽",
706
+ "尧"
707
+ ],
708
+ grouping: [
709
+ 3
710
+ ],
711
+ delimiters: {
712
+ thousands: ",",
713
+ decimal: "."
714
+ },
715
+ currency: [
716
+ "¥",
717
+ ""
718
+ ]
719
+ }
720
+ };
721
+
722
+ const round = (x, n)=>parseFloat(Math.round(x * Math.pow(10, n)) / Math.pow(10, n)).toFixed(n);
723
+ /**
724
+ * @private
725
+ */ function formatSuffix(str, precision, suffixes) {
726
+ let i = 0;
727
+ let value = parseFloat(str.replace("−", "-"), 10);
728
+ if (value) {
729
+ if (value < 0) value *= -1;
730
+ i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
731
+ i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
732
+ }
733
+ const d = suffixes[8 + i / 3];
734
+ return {
735
+ number: round(d.scale(value), precision),
736
+ symbol: d.symbol
737
+ };
738
+ }
739
+ /**
740
+ * @private
741
+ */ function parseSuffixes(d, i) {
742
+ const k = Math.pow(10, Math.abs(8 - i) * 3);
743
+ return {
744
+ scale: i > 8 ? (d)=>d / k : (d)=>d * k,
745
+ symbol: d
746
+ };
747
+ }
748
+ /**
749
+ @function formatAbbreviate
750
+ @desc Formats a number to an appropriate number of decimal places and rounding, adding suffixes if applicable (ie. `1200000` to `"1.2M"`).
751
+ @param {Number|String} n The number to be formatted.
752
+ @param {Object|String} locale The locale config to be used. If *value* is an object, the function will format the numbers according the object. The object must include `suffixes`, `delimiter` and `currency` properties.
753
+ @returns {String}
754
+ */ function abbreviate(n, locale = "en-US", precision = undefined) {
755
+ if (isFinite(n)) n *= 1;
756
+ else return "N/A";
757
+ const negative = n < 0;
758
+ const length = n.toString().split(".")[0].replace("-", "").length, localeConfig = typeof locale === "object" ? locale : defaultLocale$1[locale] || defaultLocale$1["en-US"], suffixes = localeConfig.suffixes.map(parseSuffixes);
759
+ const decimal = localeConfig.delimiters.decimal || ".", separator = localeConfig.separator || "", thousands = localeConfig.delimiters.thousands || ",";
760
+ const d3plusFormatLocale = formatLocale$1({
761
+ currency: localeConfig.currency || [
762
+ "$",
763
+ ""
764
+ ],
765
+ decimal,
766
+ grouping: localeConfig.grouping || [
767
+ 3
768
+ ],
769
+ thousands
770
+ });
771
+ let val;
772
+ if (precision) val = d3plusFormatLocale.format(precision)(n);
773
+ else if (n === 0) val = "0";
774
+ else if (length >= 3) {
775
+ const f = formatSuffix(d3plusFormatLocale.format(".3r")(n), 2, suffixes);
776
+ const num = parseFloat(f.number).toString().replace(".", decimal);
777
+ const char = f.symbol;
778
+ val = `${num}${separator}${char}`;
779
+ } else if (length === 3) val = d3plusFormatLocale.format(",f")(n);
780
+ else if (n < 1 && n > -1) val = d3plusFormatLocale.format(".2g")(n);
781
+ else val = d3plusFormatLocale.format(".3g")(n);
782
+ return `${negative && val.charAt(0) !== "−" ? "−" : ""}${val}`.replace(/−/g, "-") // replace new d3 default minus sign (−) to hyphen-minus (-)
783
+ .replace(/(\.[0]*[1-9]*)[0]*$/g, "$1") // removes any trailing zeros
784
+ .replace(/\.[0]*$/g, ""); // removes any trailing decimal point
785
+ }
786
+
787
+ /**
788
+ @function format
789
+ @desc An extension to d3's [format](https://github.com/d3/d3-format#api-reference) function that adds more string formatting types and localizations.
790
+
791
+ The new specifier strings added by d3plus-format are:
792
+ - `.3~a` - abbreviated decimal notation with a numeric suffix (ie. "k", "M", "B", etc). This is an alias of the `formatAbbreviate` function.
793
+ @param {String} specifier The string specifier used by the format function.
794
+ @returns {Function}
795
+ */ var format = ((specifier)=>{
796
+ if (specifier === ".3~a") return abbreviate;
797
+ return format$1(specifier);
798
+ });
799
+
800
+ /**
801
+ @function formatDefaultLocale
802
+ @desc An extension to d3's [formatDefaultLocale](https://github.com/d3/d3-format#api-reference) function that allows setting the locale globally for formatters.
803
+ @param {Object} definition The localization definition.
804
+ @returns {Object}
805
+ */ var formatDefaultLocale = ((definition)=>{
806
+ const locale = defaultLocale$2(definition);
807
+ locale.format = format;
808
+ return locale;
809
+ });
810
+
811
+ const t0 = new Date, t1 = new Date;
812
+ function timeInterval(floori, offseti, count, field) {
813
+ function interval(date) {
814
+ return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
815
+ }
816
+ interval.floor = (date)=>{
817
+ return floori(date = new Date(+date)), date;
818
+ };
819
+ interval.ceil = (date)=>{
820
+ return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
821
+ };
822
+ interval.round = (date)=>{
823
+ const d0 = interval(date), d1 = interval.ceil(date);
824
+ return date - d0 < d1 - date ? d0 : d1;
825
+ };
826
+ interval.offset = (date, step)=>{
827
+ return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
828
+ };
829
+ interval.range = (start, stop, step)=>{
830
+ const range = [];
831
+ start = interval.ceil(start);
832
+ step = step == null ? 1 : Math.floor(step);
833
+ if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
834
+ let previous;
835
+ do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
836
+ while (previous < start && start < stop)
837
+ return range;
838
+ };
839
+ interval.filter = (test)=>{
840
+ return timeInterval((date)=>{
841
+ if (date >= date) while(floori(date), !test(date))date.setTime(date - 1);
842
+ }, (date, step)=>{
843
+ if (date >= date) {
844
+ if (step < 0) while(++step <= 0){
845
+ while(offseti(date, -1), !test(date)){} // eslint-disable-line no-empty
846
+ }
847
+ else while(--step >= 0){
848
+ while(offseti(date, 1), !test(date)){} // eslint-disable-line no-empty
849
+ }
850
+ }
851
+ });
852
+ };
853
+ if (count) {
854
+ interval.count = (start, end)=>{
855
+ t0.setTime(+start), t1.setTime(+end);
856
+ floori(t0), floori(t1);
857
+ return Math.floor(count(t0, t1));
858
+ };
859
+ interval.every = (step)=>{
860
+ step = Math.floor(step);
861
+ return !isFinite(step) || !(step > 0) ? null : !(step > 1) ? interval : interval.filter(field ? (d)=>field(d) % step === 0 : (d)=>interval.count(0, d) % step === 0);
862
+ };
863
+ }
864
+ return interval;
865
+ }
866
+
867
+ const durationSecond = 1000;
868
+ const durationMinute = durationSecond * 60;
869
+ const durationHour = durationMinute * 60;
870
+ const durationDay = durationHour * 24;
871
+ const durationWeek = durationDay * 7;
872
+
873
+ const second = timeInterval((date)=>{
874
+ date.setTime(date - date.getMilliseconds());
875
+ }, (date, step)=>{
876
+ date.setTime(+date + step * durationSecond);
877
+ }, (start, end)=>{
878
+ return (end - start) / durationSecond;
879
+ }, (date)=>{
880
+ return date.getUTCSeconds();
881
+ });
882
+ second.range;
883
+
884
+ const timeMinute = timeInterval((date)=>{
885
+ date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
886
+ }, (date, step)=>{
887
+ date.setTime(+date + step * durationMinute);
888
+ }, (start, end)=>{
889
+ return (end - start) / durationMinute;
890
+ }, (date)=>{
891
+ return date.getMinutes();
892
+ });
893
+ timeMinute.range;
894
+ const utcMinute = timeInterval((date)=>{
895
+ date.setUTCSeconds(0, 0);
896
+ }, (date, step)=>{
897
+ date.setTime(+date + step * durationMinute);
898
+ }, (start, end)=>{
899
+ return (end - start) / durationMinute;
900
+ }, (date)=>{
901
+ return date.getUTCMinutes();
902
+ });
903
+ utcMinute.range;
904
+
905
+ const timeHour = timeInterval((date)=>{
906
+ date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
907
+ }, (date, step)=>{
908
+ date.setTime(+date + step * durationHour);
909
+ }, (start, end)=>{
910
+ return (end - start) / durationHour;
911
+ }, (date)=>{
912
+ return date.getHours();
913
+ });
914
+ timeHour.range;
915
+ const utcHour = timeInterval((date)=>{
916
+ date.setUTCMinutes(0, 0, 0);
917
+ }, (date, step)=>{
918
+ date.setTime(+date + step * durationHour);
919
+ }, (start, end)=>{
920
+ return (end - start) / durationHour;
921
+ }, (date)=>{
922
+ return date.getUTCHours();
923
+ });
924
+ utcHour.range;
925
+
926
+ const timeDay = timeInterval((date)=>date.setHours(0, 0, 0, 0), (date, step)=>date.setDate(date.getDate() + step), (start, end)=>(end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay, (date)=>date.getDate() - 1);
927
+ timeDay.range;
928
+ const utcDay = timeInterval((date)=>{
929
+ date.setUTCHours(0, 0, 0, 0);
930
+ }, (date, step)=>{
931
+ date.setUTCDate(date.getUTCDate() + step);
932
+ }, (start, end)=>{
933
+ return (end - start) / durationDay;
934
+ }, (date)=>{
935
+ return date.getUTCDate() - 1;
936
+ });
937
+ utcDay.range;
938
+ const unixDay = timeInterval((date)=>{
939
+ date.setUTCHours(0, 0, 0, 0);
940
+ }, (date, step)=>{
941
+ date.setUTCDate(date.getUTCDate() + step);
942
+ }, (start, end)=>{
943
+ return (end - start) / durationDay;
944
+ }, (date)=>{
945
+ return Math.floor(date / durationDay);
946
+ });
947
+ unixDay.range;
948
+
949
+ function timeWeekday(i) {
950
+ return timeInterval((date)=>{
951
+ date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
952
+ date.setHours(0, 0, 0, 0);
953
+ }, (date, step)=>{
954
+ date.setDate(date.getDate() + step * 7);
955
+ }, (start, end)=>{
956
+ return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
957
+ });
958
+ }
959
+ const timeSunday = timeWeekday(0);
960
+ const timeMonday = timeWeekday(1);
961
+ const timeTuesday = timeWeekday(2);
962
+ const timeWednesday = timeWeekday(3);
963
+ const timeThursday = timeWeekday(4);
964
+ const timeFriday = timeWeekday(5);
965
+ const timeSaturday = timeWeekday(6);
966
+ timeSunday.range;
967
+ timeMonday.range;
968
+ timeTuesday.range;
969
+ timeWednesday.range;
970
+ timeThursday.range;
971
+ timeFriday.range;
972
+ timeSaturday.range;
973
+ function utcWeekday(i) {
974
+ return timeInterval((date)=>{
975
+ date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
976
+ date.setUTCHours(0, 0, 0, 0);
977
+ }, (date, step)=>{
978
+ date.setUTCDate(date.getUTCDate() + step * 7);
979
+ }, (start, end)=>{
980
+ return (end - start) / durationWeek;
981
+ });
982
+ }
983
+ const utcSunday = utcWeekday(0);
984
+ const utcMonday = utcWeekday(1);
985
+ const utcTuesday = utcWeekday(2);
986
+ const utcWednesday = utcWeekday(3);
987
+ const utcThursday = utcWeekday(4);
988
+ const utcFriday = utcWeekday(5);
989
+ const utcSaturday = utcWeekday(6);
990
+ utcSunday.range;
991
+ utcMonday.range;
992
+ utcTuesday.range;
993
+ utcWednesday.range;
994
+ utcThursday.range;
995
+ utcFriday.range;
996
+ utcSaturday.range;
997
+
998
+ const timeMonth = timeInterval((date)=>{
999
+ date.setDate(1);
1000
+ date.setHours(0, 0, 0, 0);
1001
+ }, (date, step)=>{
1002
+ date.setMonth(date.getMonth() + step);
1003
+ }, (start, end)=>{
1004
+ return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
1005
+ }, (date)=>{
1006
+ return date.getMonth();
1007
+ });
1008
+ timeMonth.range;
1009
+ const utcMonth = timeInterval((date)=>{
1010
+ date.setUTCDate(1);
1011
+ date.setUTCHours(0, 0, 0, 0);
1012
+ }, (date, step)=>{
1013
+ date.setUTCMonth(date.getUTCMonth() + step);
1014
+ }, (start, end)=>{
1015
+ return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
1016
+ }, (date)=>{
1017
+ return date.getUTCMonth();
1018
+ });
1019
+ utcMonth.range;
1020
+
1021
+ const timeYear = timeInterval((date)=>{
1022
+ date.setMonth(0, 1);
1023
+ date.setHours(0, 0, 0, 0);
1024
+ }, (date, step)=>{
1025
+ date.setFullYear(date.getFullYear() + step);
1026
+ }, (start, end)=>{
1027
+ return end.getFullYear() - start.getFullYear();
1028
+ }, (date)=>{
1029
+ return date.getFullYear();
1030
+ });
1031
+ // An optimized implementation for this simple case.
1032
+ timeYear.every = (k)=>{
1033
+ return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date)=>{
1034
+ date.setFullYear(Math.floor(date.getFullYear() / k) * k);
1035
+ date.setMonth(0, 1);
1036
+ date.setHours(0, 0, 0, 0);
1037
+ }, (date, step)=>{
1038
+ date.setFullYear(date.getFullYear() + step * k);
1039
+ });
1040
+ };
1041
+ timeYear.range;
1042
+ const utcYear = timeInterval((date)=>{
1043
+ date.setUTCMonth(0, 1);
1044
+ date.setUTCHours(0, 0, 0, 0);
1045
+ }, (date, step)=>{
1046
+ date.setUTCFullYear(date.getUTCFullYear() + step);
1047
+ }, (start, end)=>{
1048
+ return end.getUTCFullYear() - start.getUTCFullYear();
1049
+ }, (date)=>{
1050
+ return date.getUTCFullYear();
1051
+ });
1052
+ // An optimized implementation for this simple case.
1053
+ utcYear.every = (k)=>{
1054
+ return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date)=>{
1055
+ date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
1056
+ date.setUTCMonth(0, 1);
1057
+ date.setUTCHours(0, 0, 0, 0);
1058
+ }, (date, step)=>{
1059
+ date.setUTCFullYear(date.getUTCFullYear() + step * k);
1060
+ });
1061
+ };
1062
+ utcYear.range;
1063
+
1064
+ function localDate(d) {
1065
+ if (0 <= d.y && d.y < 100) {
1066
+ var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
1067
+ date.setFullYear(d.y);
1068
+ return date;
1069
+ }
1070
+ return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
1071
+ }
1072
+ function utcDate(d) {
1073
+ if (0 <= d.y && d.y < 100) {
1074
+ var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
1075
+ date.setUTCFullYear(d.y);
1076
+ return date;
1077
+ }
1078
+ return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
1079
+ }
1080
+ function newDate(y, m, d) {
1081
+ return {
1082
+ y: y,
1083
+ m: m,
1084
+ d: d,
1085
+ H: 0,
1086
+ M: 0,
1087
+ S: 0,
1088
+ L: 0
1089
+ };
1090
+ }
1091
+ function formatLocale(locale) {
1092
+ var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_weekdays = locale.days, locale_shortWeekdays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths;
1093
+ var periodRe = formatRe(locale_periods), periodLookup = formatLookup(locale_periods), weekdayRe = formatRe(locale_weekdays), weekdayLookup = formatLookup(locale_weekdays), shortWeekdayRe = formatRe(locale_shortWeekdays), shortWeekdayLookup = formatLookup(locale_shortWeekdays), monthRe = formatRe(locale_months), monthLookup = formatLookup(locale_months), shortMonthRe = formatRe(locale_shortMonths), shortMonthLookup = formatLookup(locale_shortMonths);
1094
+ var formats = {
1095
+ "a": formatShortWeekday,
1096
+ "A": formatWeekday,
1097
+ "b": formatShortMonth,
1098
+ "B": formatMonth,
1099
+ "c": null,
1100
+ "d": formatDayOfMonth,
1101
+ "e": formatDayOfMonth,
1102
+ "f": formatMicroseconds,
1103
+ "g": formatYearISO,
1104
+ "G": formatFullYearISO,
1105
+ "H": formatHour24,
1106
+ "I": formatHour12,
1107
+ "j": formatDayOfYear,
1108
+ "L": formatMilliseconds,
1109
+ "m": formatMonthNumber,
1110
+ "M": formatMinutes,
1111
+ "p": formatPeriod,
1112
+ "q": formatQuarter,
1113
+ "Q": formatUnixTimestamp,
1114
+ "s": formatUnixTimestampSeconds,
1115
+ "S": formatSeconds,
1116
+ "u": formatWeekdayNumberMonday,
1117
+ "U": formatWeekNumberSunday,
1118
+ "V": formatWeekNumberISO,
1119
+ "w": formatWeekdayNumberSunday,
1120
+ "W": formatWeekNumberMonday,
1121
+ "x": null,
1122
+ "X": null,
1123
+ "y": formatYear,
1124
+ "Y": formatFullYear,
1125
+ "Z": formatZone,
1126
+ "%": formatLiteralPercent
1127
+ };
1128
+ var utcFormats = {
1129
+ "a": formatUTCShortWeekday,
1130
+ "A": formatUTCWeekday,
1131
+ "b": formatUTCShortMonth,
1132
+ "B": formatUTCMonth,
1133
+ "c": null,
1134
+ "d": formatUTCDayOfMonth,
1135
+ "e": formatUTCDayOfMonth,
1136
+ "f": formatUTCMicroseconds,
1137
+ "g": formatUTCYearISO,
1138
+ "G": formatUTCFullYearISO,
1139
+ "H": formatUTCHour24,
1140
+ "I": formatUTCHour12,
1141
+ "j": formatUTCDayOfYear,
1142
+ "L": formatUTCMilliseconds,
1143
+ "m": formatUTCMonthNumber,
1144
+ "M": formatUTCMinutes,
1145
+ "p": formatUTCPeriod,
1146
+ "q": formatUTCQuarter,
1147
+ "Q": formatUnixTimestamp,
1148
+ "s": formatUnixTimestampSeconds,
1149
+ "S": formatUTCSeconds,
1150
+ "u": formatUTCWeekdayNumberMonday,
1151
+ "U": formatUTCWeekNumberSunday,
1152
+ "V": formatUTCWeekNumberISO,
1153
+ "w": formatUTCWeekdayNumberSunday,
1154
+ "W": formatUTCWeekNumberMonday,
1155
+ "x": null,
1156
+ "X": null,
1157
+ "y": formatUTCYear,
1158
+ "Y": formatUTCFullYear,
1159
+ "Z": formatUTCZone,
1160
+ "%": formatLiteralPercent
1161
+ };
1162
+ var parses = {
1163
+ "a": parseShortWeekday,
1164
+ "A": parseWeekday,
1165
+ "b": parseShortMonth,
1166
+ "B": parseMonth,
1167
+ "c": parseLocaleDateTime,
1168
+ "d": parseDayOfMonth,
1169
+ "e": parseDayOfMonth,
1170
+ "f": parseMicroseconds,
1171
+ "g": parseYear,
1172
+ "G": parseFullYear,
1173
+ "H": parseHour24,
1174
+ "I": parseHour24,
1175
+ "j": parseDayOfYear,
1176
+ "L": parseMilliseconds,
1177
+ "m": parseMonthNumber,
1178
+ "M": parseMinutes,
1179
+ "p": parsePeriod,
1180
+ "q": parseQuarter,
1181
+ "Q": parseUnixTimestamp,
1182
+ "s": parseUnixTimestampSeconds,
1183
+ "S": parseSeconds,
1184
+ "u": parseWeekdayNumberMonday,
1185
+ "U": parseWeekNumberSunday,
1186
+ "V": parseWeekNumberISO,
1187
+ "w": parseWeekdayNumberSunday,
1188
+ "W": parseWeekNumberMonday,
1189
+ "x": parseLocaleDate,
1190
+ "X": parseLocaleTime,
1191
+ "y": parseYear,
1192
+ "Y": parseFullYear,
1193
+ "Z": parseZone,
1194
+ "%": parseLiteralPercent
1195
+ };
1196
+ // These recursive directive definitions must be deferred.
1197
+ formats.x = newFormat(locale_date, formats);
1198
+ formats.X = newFormat(locale_time, formats);
1199
+ formats.c = newFormat(locale_dateTime, formats);
1200
+ utcFormats.x = newFormat(locale_date, utcFormats);
1201
+ utcFormats.X = newFormat(locale_time, utcFormats);
1202
+ utcFormats.c = newFormat(locale_dateTime, utcFormats);
1203
+ function newFormat(specifier, formats) {
1204
+ return function(date) {
1205
+ var string = [], i = -1, j = 0, n = specifier.length, c, pad, format;
1206
+ if (!(date instanceof Date)) date = new Date(+date);
1207
+ while(++i < n){
1208
+ if (specifier.charCodeAt(i) === 37) {
1209
+ string.push(specifier.slice(j, i));
1210
+ if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
1211
+ else pad = c === "e" ? " " : "0";
1212
+ if (format = formats[c]) c = format(date, pad);
1213
+ string.push(c);
1214
+ j = i + 1;
1215
+ }
1216
+ }
1217
+ string.push(specifier.slice(j, i));
1218
+ return string.join("");
1219
+ };
1220
+ }
1221
+ function newParse(specifier, Z) {
1222
+ return function(string) {
1223
+ var d = newDate(1900, undefined, 1), i = parseSpecifier(d, specifier, string += "", 0), week, day;
1224
+ if (i != string.length) return null;
1225
+ // If a UNIX timestamp is specified, return it.
1226
+ if ("Q" in d) return new Date(d.Q);
1227
+ if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
1228
+ // If this is utcParse, never use the local timezone.
1229
+ if (Z && !("Z" in d)) d.Z = 0;
1230
+ // The am-pm flag is 0 for AM, and 1 for PM.
1231
+ if ("p" in d) d.H = d.H % 12 + d.p * 12;
1232
+ // If the month was not specified, inherit from the quarter.
1233
+ if (d.m === undefined) d.m = "q" in d ? d.q : 0;
1234
+ // Convert day-of-week and week-of-year to day-of-year.
1235
+ if ("V" in d) {
1236
+ if (d.V < 1 || d.V > 53) return null;
1237
+ if (!("w" in d)) d.w = 1;
1238
+ if ("Z" in d) {
1239
+ week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
1240
+ week = day > 4 || day === 0 ? utcMonday.ceil(week) : utcMonday(week);
1241
+ week = utcDay.offset(week, (d.V - 1) * 7);
1242
+ d.y = week.getUTCFullYear();
1243
+ d.m = week.getUTCMonth();
1244
+ d.d = week.getUTCDate() + (d.w + 6) % 7;
1245
+ } else {
1246
+ week = localDate(newDate(d.y, 0, 1)), day = week.getDay();
1247
+ week = day > 4 || day === 0 ? timeMonday.ceil(week) : timeMonday(week);
1248
+ week = timeDay.offset(week, (d.V - 1) * 7);
1249
+ d.y = week.getFullYear();
1250
+ d.m = week.getMonth();
1251
+ d.d = week.getDate() + (d.w + 6) % 7;
1252
+ }
1253
+ } else if ("W" in d || "U" in d) {
1254
+ if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
1255
+ day = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
1256
+ d.m = 0;
1257
+ d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
1258
+ }
1259
+ // If a time zone is specified, all fields are interpreted as UTC and then
1260
+ // offset according to the specified time zone.
1261
+ if ("Z" in d) {
1262
+ d.H += d.Z / 100 | 0;
1263
+ d.M += d.Z % 100;
1264
+ return utcDate(d);
1265
+ }
1266
+ // Otherwise, all fields are in local time.
1267
+ return localDate(d);
1268
+ };
1269
+ }
1270
+ function parseSpecifier(d, specifier, string, j) {
1271
+ var i = 0, n = specifier.length, m = string.length, c, parse;
1272
+ while(i < n){
1273
+ if (j >= m) return -1;
1274
+ c = specifier.charCodeAt(i++);
1275
+ if (c === 37) {
1276
+ c = specifier.charAt(i++);
1277
+ parse = parses[c in pads ? specifier.charAt(i++) : c];
1278
+ if (!parse || (j = parse(d, string, j)) < 0) return -1;
1279
+ } else if (c != string.charCodeAt(j++)) {
1280
+ return -1;
1281
+ }
1282
+ }
1283
+ return j;
1284
+ }
1285
+ function parsePeriod(d, string, i) {
1286
+ var n = periodRe.exec(string.slice(i));
1287
+ return n ? (d.p = periodLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
1288
+ }
1289
+ function parseShortWeekday(d, string, i) {
1290
+ var n = shortWeekdayRe.exec(string.slice(i));
1291
+ return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
1292
+ }
1293
+ function parseWeekday(d, string, i) {
1294
+ var n = weekdayRe.exec(string.slice(i));
1295
+ return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
1296
+ }
1297
+ function parseShortMonth(d, string, i) {
1298
+ var n = shortMonthRe.exec(string.slice(i));
1299
+ return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
1300
+ }
1301
+ function parseMonth(d, string, i) {
1302
+ var n = monthRe.exec(string.slice(i));
1303
+ return n ? (d.m = monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
1304
+ }
1305
+ function parseLocaleDateTime(d, string, i) {
1306
+ return parseSpecifier(d, locale_dateTime, string, i);
1307
+ }
1308
+ function parseLocaleDate(d, string, i) {
1309
+ return parseSpecifier(d, locale_date, string, i);
1310
+ }
1311
+ function parseLocaleTime(d, string, i) {
1312
+ return parseSpecifier(d, locale_time, string, i);
1313
+ }
1314
+ function formatShortWeekday(d) {
1315
+ return locale_shortWeekdays[d.getDay()];
1316
+ }
1317
+ function formatWeekday(d) {
1318
+ return locale_weekdays[d.getDay()];
1319
+ }
1320
+ function formatShortMonth(d) {
1321
+ return locale_shortMonths[d.getMonth()];
1322
+ }
1323
+ function formatMonth(d) {
1324
+ return locale_months[d.getMonth()];
1325
+ }
1326
+ function formatPeriod(d) {
1327
+ return locale_periods[+(d.getHours() >= 12)];
1328
+ }
1329
+ function formatQuarter(d) {
1330
+ return 1 + ~~(d.getMonth() / 3);
1331
+ }
1332
+ function formatUTCShortWeekday(d) {
1333
+ return locale_shortWeekdays[d.getUTCDay()];
1334
+ }
1335
+ function formatUTCWeekday(d) {
1336
+ return locale_weekdays[d.getUTCDay()];
1337
+ }
1338
+ function formatUTCShortMonth(d) {
1339
+ return locale_shortMonths[d.getUTCMonth()];
1340
+ }
1341
+ function formatUTCMonth(d) {
1342
+ return locale_months[d.getUTCMonth()];
1343
+ }
1344
+ function formatUTCPeriod(d) {
1345
+ return locale_periods[+(d.getUTCHours() >= 12)];
1346
+ }
1347
+ function formatUTCQuarter(d) {
1348
+ return 1 + ~~(d.getUTCMonth() / 3);
1349
+ }
1350
+ return {
1351
+ format: function(specifier) {
1352
+ var f = newFormat(specifier += "", formats);
1353
+ f.toString = function() {
1354
+ return specifier;
1355
+ };
1356
+ return f;
1357
+ },
1358
+ parse: function(specifier) {
1359
+ var p = newParse(specifier += "", false);
1360
+ p.toString = function() {
1361
+ return specifier;
1362
+ };
1363
+ return p;
1364
+ },
1365
+ utcFormat: function(specifier) {
1366
+ var f = newFormat(specifier += "", utcFormats);
1367
+ f.toString = function() {
1368
+ return specifier;
1369
+ };
1370
+ return f;
1371
+ },
1372
+ utcParse: function(specifier) {
1373
+ var p = newParse(specifier += "", true);
1374
+ p.toString = function() {
1375
+ return specifier;
1376
+ };
1377
+ return p;
1378
+ }
1379
+ };
1380
+ }
1381
+ var pads = {
1382
+ "-": "",
1383
+ "_": " ",
1384
+ "0": "0"
1385
+ }, numberRe = /^\s*\d+/, percentRe = /^%/, requoteRe = /[\\^$*+?|[\]().{}]/g;
1386
+ function pad(value, fill, width) {
1387
+ var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
1388
+ return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
1389
+ }
1390
+ function requote(s) {
1391
+ return s.replace(requoteRe, "\\$&");
1392
+ }
1393
+ function formatRe(names) {
1394
+ return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
1395
+ }
1396
+ function formatLookup(names) {
1397
+ return new Map(names.map((name, i)=>[
1398
+ name.toLowerCase(),
1399
+ i
1400
+ ]));
1401
+ }
1402
+ function parseWeekdayNumberSunday(d, string, i) {
1403
+ var n = numberRe.exec(string.slice(i, i + 1));
1404
+ return n ? (d.w = +n[0], i + n[0].length) : -1;
1405
+ }
1406
+ function parseWeekdayNumberMonday(d, string, i) {
1407
+ var n = numberRe.exec(string.slice(i, i + 1));
1408
+ return n ? (d.u = +n[0], i + n[0].length) : -1;
1409
+ }
1410
+ function parseWeekNumberSunday(d, string, i) {
1411
+ var n = numberRe.exec(string.slice(i, i + 2));
1412
+ return n ? (d.U = +n[0], i + n[0].length) : -1;
1413
+ }
1414
+ function parseWeekNumberISO(d, string, i) {
1415
+ var n = numberRe.exec(string.slice(i, i + 2));
1416
+ return n ? (d.V = +n[0], i + n[0].length) : -1;
1417
+ }
1418
+ function parseWeekNumberMonday(d, string, i) {
1419
+ var n = numberRe.exec(string.slice(i, i + 2));
1420
+ return n ? (d.W = +n[0], i + n[0].length) : -1;
1421
+ }
1422
+ function parseFullYear(d, string, i) {
1423
+ var n = numberRe.exec(string.slice(i, i + 4));
1424
+ return n ? (d.y = +n[0], i + n[0].length) : -1;
1425
+ }
1426
+ function parseYear(d, string, i) {
1427
+ var n = numberRe.exec(string.slice(i, i + 2));
1428
+ return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
1429
+ }
1430
+ function parseZone(d, string, i) {
1431
+ var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
1432
+ return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
1433
+ }
1434
+ function parseQuarter(d, string, i) {
1435
+ var n = numberRe.exec(string.slice(i, i + 1));
1436
+ return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
1437
+ }
1438
+ function parseMonthNumber(d, string, i) {
1439
+ var n = numberRe.exec(string.slice(i, i + 2));
1440
+ return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
1441
+ }
1442
+ function parseDayOfMonth(d, string, i) {
1443
+ var n = numberRe.exec(string.slice(i, i + 2));
1444
+ return n ? (d.d = +n[0], i + n[0].length) : -1;
1445
+ }
1446
+ function parseDayOfYear(d, string, i) {
1447
+ var n = numberRe.exec(string.slice(i, i + 3));
1448
+ return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
1449
+ }
1450
+ function parseHour24(d, string, i) {
1451
+ var n = numberRe.exec(string.slice(i, i + 2));
1452
+ return n ? (d.H = +n[0], i + n[0].length) : -1;
1453
+ }
1454
+ function parseMinutes(d, string, i) {
1455
+ var n = numberRe.exec(string.slice(i, i + 2));
1456
+ return n ? (d.M = +n[0], i + n[0].length) : -1;
1457
+ }
1458
+ function parseSeconds(d, string, i) {
1459
+ var n = numberRe.exec(string.slice(i, i + 2));
1460
+ return n ? (d.S = +n[0], i + n[0].length) : -1;
1461
+ }
1462
+ function parseMilliseconds(d, string, i) {
1463
+ var n = numberRe.exec(string.slice(i, i + 3));
1464
+ return n ? (d.L = +n[0], i + n[0].length) : -1;
1465
+ }
1466
+ function parseMicroseconds(d, string, i) {
1467
+ var n = numberRe.exec(string.slice(i, i + 6));
1468
+ return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
1469
+ }
1470
+ function parseLiteralPercent(d, string, i) {
1471
+ var n = percentRe.exec(string.slice(i, i + 1));
1472
+ return n ? i + n[0].length : -1;
1473
+ }
1474
+ function parseUnixTimestamp(d, string, i) {
1475
+ var n = numberRe.exec(string.slice(i));
1476
+ return n ? (d.Q = +n[0], i + n[0].length) : -1;
1477
+ }
1478
+ function parseUnixTimestampSeconds(d, string, i) {
1479
+ var n = numberRe.exec(string.slice(i));
1480
+ return n ? (d.s = +n[0], i + n[0].length) : -1;
1481
+ }
1482
+ function formatDayOfMonth(d, p) {
1483
+ return pad(d.getDate(), p, 2);
1484
+ }
1485
+ function formatHour24(d, p) {
1486
+ return pad(d.getHours(), p, 2);
1487
+ }
1488
+ function formatHour12(d, p) {
1489
+ return pad(d.getHours() % 12 || 12, p, 2);
1490
+ }
1491
+ function formatDayOfYear(d, p) {
1492
+ return pad(1 + timeDay.count(timeYear(d), d), p, 3);
1493
+ }
1494
+ function formatMilliseconds(d, p) {
1495
+ return pad(d.getMilliseconds(), p, 3);
1496
+ }
1497
+ function formatMicroseconds(d, p) {
1498
+ return formatMilliseconds(d, p) + "000";
1499
+ }
1500
+ function formatMonthNumber(d, p) {
1501
+ return pad(d.getMonth() + 1, p, 2);
1502
+ }
1503
+ function formatMinutes(d, p) {
1504
+ return pad(d.getMinutes(), p, 2);
1505
+ }
1506
+ function formatSeconds(d, p) {
1507
+ return pad(d.getSeconds(), p, 2);
1508
+ }
1509
+ function formatWeekdayNumberMonday(d) {
1510
+ var day = d.getDay();
1511
+ return day === 0 ? 7 : day;
1512
+ }
1513
+ function formatWeekNumberSunday(d, p) {
1514
+ return pad(timeSunday.count(timeYear(d) - 1, d), p, 2);
1515
+ }
1516
+ function dISO(d) {
1517
+ var day = d.getDay();
1518
+ return day >= 4 || day === 0 ? timeThursday(d) : timeThursday.ceil(d);
1519
+ }
1520
+ function formatWeekNumberISO(d, p) {
1521
+ d = dISO(d);
1522
+ return pad(timeThursday.count(timeYear(d), d) + (timeYear(d).getDay() === 4), p, 2);
1523
+ }
1524
+ function formatWeekdayNumberSunday(d) {
1525
+ return d.getDay();
1526
+ }
1527
+ function formatWeekNumberMonday(d, p) {
1528
+ return pad(timeMonday.count(timeYear(d) - 1, d), p, 2);
1529
+ }
1530
+ function formatYear(d, p) {
1531
+ return pad(d.getFullYear() % 100, p, 2);
1532
+ }
1533
+ function formatYearISO(d, p) {
1534
+ d = dISO(d);
1535
+ return pad(d.getFullYear() % 100, p, 2);
1536
+ }
1537
+ function formatFullYear(d, p) {
1538
+ return pad(d.getFullYear() % 10000, p, 4);
1539
+ }
1540
+ function formatFullYearISO(d, p) {
1541
+ var day = d.getDay();
1542
+ d = day >= 4 || day === 0 ? timeThursday(d) : timeThursday.ceil(d);
1543
+ return pad(d.getFullYear() % 10000, p, 4);
1544
+ }
1545
+ function formatZone(d) {
1546
+ var z = d.getTimezoneOffset();
1547
+ return (z > 0 ? "-" : (z *= -1, "+")) + pad(z / 60 | 0, "0", 2) + pad(z % 60, "0", 2);
1548
+ }
1549
+ function formatUTCDayOfMonth(d, p) {
1550
+ return pad(d.getUTCDate(), p, 2);
1551
+ }
1552
+ function formatUTCHour24(d, p) {
1553
+ return pad(d.getUTCHours(), p, 2);
1554
+ }
1555
+ function formatUTCHour12(d, p) {
1556
+ return pad(d.getUTCHours() % 12 || 12, p, 2);
1557
+ }
1558
+ function formatUTCDayOfYear(d, p) {
1559
+ return pad(1 + utcDay.count(utcYear(d), d), p, 3);
1560
+ }
1561
+ function formatUTCMilliseconds(d, p) {
1562
+ return pad(d.getUTCMilliseconds(), p, 3);
1563
+ }
1564
+ function formatUTCMicroseconds(d, p) {
1565
+ return formatUTCMilliseconds(d, p) + "000";
1566
+ }
1567
+ function formatUTCMonthNumber(d, p) {
1568
+ return pad(d.getUTCMonth() + 1, p, 2);
1569
+ }
1570
+ function formatUTCMinutes(d, p) {
1571
+ return pad(d.getUTCMinutes(), p, 2);
1572
+ }
1573
+ function formatUTCSeconds(d, p) {
1574
+ return pad(d.getUTCSeconds(), p, 2);
1575
+ }
1576
+ function formatUTCWeekdayNumberMonday(d) {
1577
+ var dow = d.getUTCDay();
1578
+ return dow === 0 ? 7 : dow;
1579
+ }
1580
+ function formatUTCWeekNumberSunday(d, p) {
1581
+ return pad(utcSunday.count(utcYear(d) - 1, d), p, 2);
1582
+ }
1583
+ function UTCdISO(d) {
1584
+ var day = d.getUTCDay();
1585
+ return day >= 4 || day === 0 ? utcThursday(d) : utcThursday.ceil(d);
1586
+ }
1587
+ function formatUTCWeekNumberISO(d, p) {
1588
+ d = UTCdISO(d);
1589
+ return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
1590
+ }
1591
+ function formatUTCWeekdayNumberSunday(d) {
1592
+ return d.getUTCDay();
1593
+ }
1594
+ function formatUTCWeekNumberMonday(d, p) {
1595
+ return pad(utcMonday.count(utcYear(d) - 1, d), p, 2);
1596
+ }
1597
+ function formatUTCYear(d, p) {
1598
+ return pad(d.getUTCFullYear() % 100, p, 2);
1599
+ }
1600
+ function formatUTCYearISO(d, p) {
1601
+ d = UTCdISO(d);
1602
+ return pad(d.getUTCFullYear() % 100, p, 2);
1603
+ }
1604
+ function formatUTCFullYear(d, p) {
1605
+ return pad(d.getUTCFullYear() % 10000, p, 4);
1606
+ }
1607
+ function formatUTCFullYearISO(d, p) {
1608
+ var day = d.getUTCDay();
1609
+ d = day >= 4 || day === 0 ? utcThursday(d) : utcThursday.ceil(d);
1610
+ return pad(d.getUTCFullYear() % 10000, p, 4);
1611
+ }
1612
+ function formatUTCZone() {
1613
+ return "+0000";
1614
+ }
1615
+ function formatLiteralPercent() {
1616
+ return "%";
1617
+ }
1618
+ function formatUnixTimestamp(d) {
1619
+ return +d;
1620
+ }
1621
+ function formatUnixTimestampSeconds(d) {
1622
+ return Math.floor(+d / 1000);
1623
+ }
1624
+
1625
+ var locale;
1626
+ var timeFormat;
1627
+ defaultLocale({
1628
+ dateTime: "%x, %X",
1629
+ date: "%-m/%-d/%Y",
1630
+ time: "%-I:%M:%S %p",
1631
+ periods: [
1632
+ "AM",
1633
+ "PM"
1634
+ ],
1635
+ days: [
1636
+ "Sunday",
1637
+ "Monday",
1638
+ "Tuesday",
1639
+ "Wednesday",
1640
+ "Thursday",
1641
+ "Friday",
1642
+ "Saturday"
1643
+ ],
1644
+ shortDays: [
1645
+ "Sun",
1646
+ "Mon",
1647
+ "Tue",
1648
+ "Wed",
1649
+ "Thu",
1650
+ "Fri",
1651
+ "Sat"
1652
+ ],
1653
+ months: [
1654
+ "January",
1655
+ "February",
1656
+ "March",
1657
+ "April",
1658
+ "May",
1659
+ "June",
1660
+ "July",
1661
+ "August",
1662
+ "September",
1663
+ "October",
1664
+ "November",
1665
+ "December"
1666
+ ],
1667
+ shortMonths: [
1668
+ "Jan",
1669
+ "Feb",
1670
+ "Mar",
1671
+ "Apr",
1672
+ "May",
1673
+ "Jun",
1674
+ "Jul",
1675
+ "Aug",
1676
+ "Sep",
1677
+ "Oct",
1678
+ "Nov",
1679
+ "Dec"
1680
+ ]
1681
+ });
1682
+ function defaultLocale(definition) {
1683
+ locale = formatLocale(definition);
1684
+ timeFormat = locale.format;
1685
+ locale.parse;
1686
+ locale.utcFormat;
1687
+ locale.utcParse;
1688
+ return locale;
1689
+ }
1690
+
1691
+ /**
1692
+ @function formatDate
1693
+ @desc A default set of date formatters, which takes into account both the interval in between in each data point but also the start/end data points.
1694
+ @param {Date} d The date string to be formatted.
1695
+ @param {Array} dataArray The full array of ordered Date Objects.
1696
+ @param {Function} [formatter = d3.timeFormat] An optional instance of d3.timeFormat to be used for localization.
1697
+ @returns {String}
1698
+ */ function formatDate(d, dataArray, formatter = timeFormat) {
1699
+ const formatHour = formatter("%I %p"), formatMillisecond = formatter(".%L"), formatMinute = formatter("%I:%M"), formatMonth = formatter("%b"), formatMonthDay = formatter("%b %-d"), formatMonthDayYear = formatter("%b %-d, %Y"), formatMonthYear = formatter("%b %Y"), formatQuarter = formatter("Q%q"), formatQuarterYear = formatter("Q%q %Y"), formatSecond = formatter(":%S"), formatYear = formatter("%Y");
1700
+ const labelIndex = dataArray.findIndex((a)=>+a === +d);
1701
+ const firstOrLast = labelIndex === 0 || labelIndex === dataArray.length - 1;
1702
+ const smallArray = dataArray.length <= 5;
1703
+ const [yearlySteps, monthlySteps, dailySteps, hourlySteps] = dataArray.reduce((arr, d, i)=>{
1704
+ if (i) {
1705
+ arr[0].push(d.getFullYear() - dataArray[i - 1].getFullYear());
1706
+ arr[1].push(monthDiff(dataArray[i - 1], d));
1707
+ arr[2].push(Math.round((d - dataArray[i - 1]) / (1000 * 60 * 60 * 24)));
1708
+ arr[3].push(Math.round((d - dataArray[i - 1]) / (1000 * 60 * 60)));
1709
+ }
1710
+ return arr;
1711
+ }, [
1712
+ [],
1713
+ [],
1714
+ [],
1715
+ []
1716
+ ]);
1717
+ return (yearlySteps.every((s)=>s >= 1 && !(s % 1)) // Yearly Data
1718
+ ? formatYear : monthlySteps.every((s)=>s >= 3 && !(s % 3)) // Quarterly Data
1719
+ ? +timeYear(d) === d || firstOrLast || smallArray ? formatQuarterYear : formatQuarter : monthlySteps.every((s)=>s >= 1 && !(s % 1)) // Monthly Data
1720
+ ? +timeYear(d) === d || firstOrLast || smallArray ? formatMonthYear : formatMonth : dailySteps.every((s)=>s >= 1 && !(s % 1)) // Daily Data
1721
+ ? +timeYear(d) === d || firstOrLast || smallArray ? formatMonthDayYear : formatMonthDay : hourlySteps.every((s)=>s >= 1 && !(s % 1)) // Hourly Data
1722
+ ? firstOrLast || smallArray ? formatMonthDayYear : +timeMonth(d) === d ? formatMonthDay : formatHour : second(d) < d ? formatMillisecond : timeMinute(d) < d ? formatSecond : timeHour(d) < d ? formatMinute : d)(d);
1723
+ }
1724
+ /**
1725
+ @function monthDiff
1726
+ @desc Returns the number of months between two Date objects
1727
+ @param {*} d1
1728
+ @param {*} d2
1729
+ @returns {Number} the number of months between the two Date objects
1730
+ @private
1731
+ */ function monthDiff(d1, d2) {
1732
+ let months;
1733
+ months = (d2.getFullYear() - d1.getFullYear()) * 12;
1734
+ months -= d1.getMonth();
1735
+ months += d2.getMonth();
1736
+ return months <= 0 ? 0 : months;
1737
+ }
1738
+
1739
+ exports.format = format;
1740
+ exports.formatAbbreviate = abbreviate;
1741
+ exports.formatDate = formatDate;
1742
+ exports.formatDefaultLocale = formatDefaultLocale;
1743
+
1744
+ }));
1745
+ //# sourceMappingURL=d3plus-format.full.js.map