@d3plus/format 3.0.16 → 3.1.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.
@@ -4,112 +4,114 @@
4
4
  Copyright (c) 2026 D3plus - https://d3plus.org
5
5
  @license MIT
6
6
  */
7
- (e=>{"function"==typeof define&&define.amd?define(e):e()})(function(){if("undefined"!=typeof window){try{if("undefined"==typeof SVGElement||Boolean(SVGElement.prototype.innerHTML))return}catch(e){return}function r(e){switch(e.nodeType){case 1:var t=e,n="";return n+="<"+t.tagName,t.hasAttributes()&&[].forEach.call(t.attributes,function(e){n+=" "+e.name+'="'+e.value+'"'}),n+=">",t.hasChildNodes()&&[].forEach.call(t.childNodes,function(e){n+=r(e)}),n+="</"+t.tagName+">";case 3:return e.textContent.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");case 8:return"\x3c!--"+e.nodeValue+"--\x3e"}}Object.defineProperty(SVGElement.prototype,"innerHTML",{get:function(){var t="";return[].forEach.call(this.childNodes,function(e){t+=r(e)}),t},set:function(e){for(;this.firstChild;)this.removeChild(this.firstChild);try{var t=new DOMParser,n=(t.async=!1,"<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>"+e+"</svg>"),r=t.parseFromString(n,"text/xml").documentElement;[].forEach.call(r.childNodes,function(e){this.appendChild(this.ownerDocument.importNode(e,!0))}.bind(this))}catch(e){throw new Error("Error parsing markup string")}}}),Object.defineProperty(SVGElement.prototype,"innerSVG",{get:function(){return this.innerHTML},set:function(e){this.innerHTML=e}})}}),((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("@d3plus/format",["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).d3plus={})})(this,function(e){
7
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("@d3plus/format",["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).d3plus={})}(this,function(e){
8
8
  // Computes the decimal coefficient and exponent of the specified number x with
9
9
  // significant digits p, where x is positive and p is in [1, 21] or undefined.
10
10
  // For example, formatDecimalParts(1.23) returns ["123", 0].
11
- function s(e,t){var n;// NaN, ±Infinity
12
- return(t=(e=t?e.toExponential(t-1):e.toExponential()).indexOf("e"))<0?null:[1<(n=e.slice(0,t)).length?n[0]+n.slice(2):n,+e.slice(t+1)]}
11
+ function t(e,t){if(!isFinite(e)||0===e)return null;// NaN, ±Infinity, ±0
12
+ var n=(e=t?e.toExponential(t-1):e.toExponential()).indexOf("e"),r=e.slice(0,n);
13
+ // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
14
+ // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
15
+ return[r.length>1?r[0]+r.slice(2):r,+e.slice(n+1)]}
13
16
  // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
14
- var b,x=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Y(e){var t;if(t=x.exec(e))return new n({fill:t[1],align:t[2],sign:t[3],symbol:t[4],zero:t[5],width:t[6],comma:t[7],precision:t[8]&&t[8].slice(1),trim:t[9],type:t[10]});throw new Error("invalid format: "+e)}// instanceof
15
- function n(e){this.fill=void 0===e.fill?" ":e.fill+"",this.align=void 0===e.align?">":e.align+"",this.sign=void 0===e.sign?"-":e.sign+"",this.symbol=void 0===e.symbol?"":e.symbol+"",this.zero=!!e.zero,this.width=void 0===e.width?void 0:+e.width,this.comma=!!e.comma,this.precision=void 0===e.precision?void 0:+e.precision,this.trim=!!e.trim,this.type=void 0===e.type?"":e.type+""}function r(e,t){var n,t=s(e,t);return t?(n=t[0],(t=t[1])<0?"0."+new Array(-t).join("0")+n:n.length>t+1?n.slice(0,t+1)+"."+n.slice(t+1):n+new Array(t-n.length+2).join("0")):e+""}Y.prototype=n.prototype,n.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var S={"%":(e,t)=>(100*e).toFixed(t),b:e=>Math.round(e).toString(2),c:e=>e+"",d:function(e){return 1e21<=Math.abs(e=Math.round(e))?e.toLocaleString("en").replace(/,/g,""):e.toString(10)},e:(e,t)=>e.toExponential(t),f:(e,t)=>e.toFixed(t),g:(e,t)=>e.toPrecision(t),o:e=>Math.round(e).toString(8),p:(e,t)=>r(100*e,t),r:r,s:function(e,t){var n,r,i=s(e,t);return i?(n=i[0],(i=(i=i[1])-(b=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1)===(r=n.length)?n:r<i?n+new Array(i-r+1).join("0"):0<i?n.slice(0,i)+"."+n.slice(i):"0."+new Array(1-i).join("0")+s(e,Math.max(0,t+i-1))[0]):e+""},X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function c(e){return e}var t,N,k=Array.prototype.map,q=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Q(e){var t,a,l,U=void 0===e.grouping||void 0===e.thousands?c:(a=k.call(e.grouping,Number),l=e.thousands+"",function(e,t){for(var n=e.length,r=[],i=0,o=a[0],u=0;0<n&&0<o&&(t<u+o+1&&(o=Math.max(1,t-u)),r.push(e.substring(n-=o,n+o)),!((u+=o+1)>t));)o=a[i=(i+1)%a.length];return r.reverse().join(l)}),r=void 0===e.currency?"":e.currency[0]+"",i=void 0===e.currency?"":e.currency[1]+"",w=void 0===e.decimal?".":e.decimal+"",x=void 0===e.numerals?c:(t=k.call(e.numerals,String),function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}),o=void 0===e.percent?"%":e.percent+"",D=void 0===e.minus?"−":e.minus+"",F=void 0===e.nan?"NaN":e.nan+"";function u(e){var s=(e=Y(e)).fill,c=e.align,f=e.sign,t=e.symbol,g=e.zero,h=e.width,d=e.comma,m=e.precision,p=e.trim,y=e.type,M=(
17
+ var n,r=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function i(e){if(!(t=r.exec(e)))throw new Error("invalid format: "+e);var t;return new o({fill:t[1],align:t[2],sign:t[3],symbol:t[4],zero:t[5],width:t[6],comma:t[7],precision:t[8]&&t[8].slice(1),trim:t[9],type:t[10]})}// instanceof
18
+ function o(e){this.fill=void 0===e.fill?" ":e.fill+"",this.align=void 0===e.align?">":e.align+"",this.sign=void 0===e.sign?"-":e.sign+"",this.symbol=void 0===e.symbol?"":e.symbol+"",this.zero=!!e.zero,this.width=void 0===e.width?void 0:+e.width,this.comma=!!e.comma,this.precision=void 0===e.precision?void 0:+e.precision,this.trim=!!e.trim,this.type=void 0===e.type?"":e.type+""}function u(e,n){var r=t(e,n);if(!r)return e+"";var i=r[0],o=r[1];return o<0?"0."+new Array(-o).join("0")+i:i.length>o+1?i.slice(0,o+1)+"."+i.slice(o+1):i+new Array(o-i.length+2).join("0")}i.prototype=o.prototype,o.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var a={"%":(e,t)=>(100*e).toFixed(t),b:e=>Math.round(e).toString(2),c:e=>e+"",d:function(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)},e:(e,t)=>e.toExponential(t),f:(e,t)=>e.toFixed(t),g:(e,t)=>e.toPrecision(t),o:e=>Math.round(e).toString(8),p:(e,t)=>u(100*e,t),r:u,s:function(e,r){var i=t(e,r);if(!i)return n=void 0,e.toPrecision(r);var o=i[0],u=i[1],a=u-(n=3*Math.max(-8,Math.min(8,Math.floor(u/3))))+1,s=o.length;return a===s?o:a>s?o+new Array(a-s+1).join("0"):a>0?o.slice(0,a)+"."+o.slice(a):"0."+new Array(1-a).join("0")+t(e,Math.max(0,r+a-1))[0];// less than 1y!
19
+ },X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function s(e){return e}var c,l,f=Array.prototype.map,g=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function h(e){var r,o,u=void 0===e.grouping||void 0===e.thousands?s:(r=f.call(e.grouping,Number),o=e.thousands+"",function(e,t){for(var n=e.length,i=[],u=0,a=r[0],s=0;n>0&&a>0&&(s+a+1>t&&(a=Math.max(1,t-s)),i.push(e.substring(n-=a,n+a)),!((s+=a+1)>t));)a=r[u=(u+1)%r.length];return i.reverse().join(o)}),c=void 0===e.currency?"":e.currency[0]+"",l=void 0===e.currency?"":e.currency[1]+"",h=void 0===e.decimal?".":e.decimal+"",d=void 0===e.numerals?s:function(e){return function(t){return t.replace(/[0-9]/g,function(t){return e[+t]})}}(f.call(e.numerals,String)),m=void 0===e.percent?"%":e.percent+"",p=void 0===e.minus?"−":e.minus+"",y=void 0===e.nan?"NaN":e.nan+"";function M(e,t){var r=(e=i(e)).fill,o=e.align,s=e.sign,f=e.symbol,M=e.zero,v=e.width,T=e.comma,C=e.precision,U=e.trim,x=e.type;
16
20
  // The "n" type is an alias for ",g".
17
- "n"===y?(d=!0,y="g"):S[y]||(void 0===m&&(m=12),p=!0,y="g"),
21
+ "n"===x?(T=!0,x="g"):a[x]||(void 0===C&&(C=12),U=!0,x="g"),
18
22
  // If zero fill is specified, padding goes after sign and before digits.
19
- (g||"0"===s&&"="===c)&&(g=!0,s="0",c="="),"$"===t?r:"#"===t&&/[boxX]/.test(y)?"0"+y.toLowerCase():""),T="$"===t?i:/[%p]/.test(y)?o:"",C=S[y],v=/[defgprs%]/.test(y);function n(e){var t,n,r,i=M,o=T;if("c"===y)o=C(e)+o,e="";else{
23
+ (M||"0"===r&&"="===o)&&(M=!0,r="0",o="=");
24
+ // Compute the prefix and suffix.
25
+ // For SI-prefix, the suffix is lazily computed.
26
+ var D=(t&&void 0!==t.prefix?t.prefix:"")+("$"===f?c:"#"===f&&/[boxX]/.test(x)?"0"+x.toLowerCase():""),w=("$"===f?l:/[%p]/.test(x)?m:"")+(t&&void 0!==t.suffix?t.suffix:""),F=a[x],Y=/[defgprs%]/.test(x);
27
+ // What format function should we use?
28
+ // Is this an integer type?
29
+ // Can this type generate exponential notation?
30
+ function b(e){var t,i,a,c=D,l=w;if("c"===x)l=F(e)+l,e="";else{
20
31
  // Determine the sign. -0 is not less than 0, but 1 / -0 is!
21
- var u=(e=+e)<0||1/e<0;
32
+ var f=(e=+e)<0||1/e<0;
22
33
  // Perform the initial formatting.
23
34
  // Break the formatted value into the integer “value” part that can be
24
35
  // grouped, and fractional or exponential “suffix” part that is not.
25
- if(e=isNaN(e)?F:C(Math.abs(e),m),
36
+ if(e=isNaN(e)?y:F(Math.abs(e),C),
26
37
  // Trim insignificant zeros.
27
- p&&(e=(
38
+ U&&(e=
28
39
  // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
29
- e=>{e:for(var t,n=e.length,r=1,i=-1;r<n;++r)switch(e[r]){case".":i=t=r;break;case"0":0===i&&(i=r),t=r;break;default:if(!+e[r])break e;0<i&&(i=0)}return 0<i?e.slice(0,i)+e.slice(t+1):e})(e)),
30
- // Compute the prefix and suffix.
31
- i=((
40
+ function(e){e:for(var t,n=e.length,r=1,i=-1;r<n;++r)switch(e[r]){case".":i=t=r;break;case"0":0===i&&(i=r),t=r;break;default:if(!+e[r])break e;i>0&&(i=0)}return i>0?e.slice(0,i)+e.slice(t+1):e}(e)),
32
41
  // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
33
- u=u&&0==+e&&"+"!==f?!1:u)?"("===f?f:D:"-"===f||"("===f?"":f)+i,o=("s"===y?q[8+b/3]:"")+o+(u&&"("===f?")":""),v)for(t=-1,n=e.length;++t<n;)if((r=e.charCodeAt(t))<48||57<r){o=(46===r?w+e.slice(t+1):e.slice(t))+o,e=e.slice(0,t);break}}
42
+ f&&0===+e&&"+"!==s&&(f=!1),
43
+ // Compute the prefix and suffix.
44
+ c=(f?"("===s?s:p:"-"===s||"("===s?"":s)+c,l=("s"!==x||isNaN(e)||void 0===n?"":g[8+n/3])+l+(f&&"("===s?")":""),Y)for(t=-1,i=e.length;++t<i;)if(48>(a=e.charCodeAt(t))||a>57){l=(46===a?h+e.slice(t+1):e.slice(t))+l,e=e.slice(0,t);break}}
34
45
  // If the fill character is not "0", grouping is applied before padding.
35
- d&&!g&&(e=U(e,1/0));
46
+ T&&!M&&(e=u(e,1/0));
36
47
  // Compute the padding.
37
- var a=i.length+e.length+o.length,l=a<h?new Array(h-a+1).join(s):"";
48
+ var m=c.length+e.length+l.length,b=m<v?new Array(v-m+1).join(r):"";
38
49
  // If the fill character is "0", grouping is applied after padding.
39
50
  // Reconstruct the final output based on the desired alignment.
40
- switch(d&&g&&(e=U(l+e,l.length?h-o.length:1/0),l=""),c){case"<":e=i+e+o+l;break;case"=":e=i+l+e+o;break;case"^":e=l.slice(0,a=l.length>>1)+i+e+o+l.slice(a);break;default:e=l+i+e+o}return x(e)}
51
+ switch(T&&M&&(e=u(b+e,b.length?v-l.length:1/0),b=""),o){case"<":e=c+e+l+b;break;case"=":e=c+b+e+l;break;case"^":e=b.slice(0,m=b.length>>1)+c+e+l+b.slice(m);break;default:e=b+c+e+l}return d(e)}
41
52
  // Set the default precision if not specified,
42
53
  // or clamp the specified precision to the supported range.
43
54
  // For significant precision, it must be in [1, 21].
44
55
  // For fixed precision, it must be in [0, 20].
45
- return m=void 0===m?6:/[gprs]/.test(y)?Math.max(1,Math.min(21,m)):Math.max(0,Math.min(20,m)),n.toString=function(){return e+""},n}return{format:u,formatPrefix:function(e,t){var n=u(((e=Y(e)).type="f",e)),t=3*Math.max(-8,Math.min(8,Math.floor((e=t,((e=s(Math.abs(e)))?e[1]:NaN)/3)))),r=Math.pow(10,-t),i=q[8+t/3];return function(e){return n(r*e)+i}}}}function V(e){return t=Q(e),N=t.format,t}
56
+ return C=void 0===C?6:/[gprs]/.test(x)?Math.max(1,Math.min(21,C)):Math.max(0,Math.min(20,C)),b.toString=function(){return e+""},b}return{format:M,formatPrefix:function(e,n){var r,o=3*Math.max(-8,Math.min(8,Math.floor((r=n,((r=t(Math.abs(r)))?r[1]:NaN)/3)))),u=Math.pow(10,-o),a=M(((e=i(e)).type="f",e),{suffix:g[8+o/3]});return function(e){return a(u*e)}}}}function d(e){return c=h(e),l=c.format,c.formatPrefix,c}
46
57
  /**
47
58
  @namespace {Object} formatLocale
48
- @desc A set of default locale formatters used when assigning suffixes and currency in numbers.
49
- */V({thousands:",",grouping:[3],currency:["$",""]});var $={"ar-SA":{separator:"",suffixes:["y","z","a","f","p","n","µ","m",""," ألف"," مليون"," بليون"," تريليون"," كوادريليون"," كوينتيليون"," سكستليون","سبتيليون"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["SAR ",""]},"en-GB":{separator:"",suffixes:["y","z","a","f","p","n","µ","m","","k","M","B","T","q","Q","Z","Y"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["£",""]},"en-US":{separator:"",suffixes:["y","z","a","f","p","n","µ","m","","k","M","B","T","q","Q","Z","Y"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["$",""]},"en-SA":{separator:"",suffixes:["y","z","a","f","p","n","µ","m",""," thousand"," million"," billion"," trillion"," quadrillion"," quintillion"," sextillion","septillion"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["$",""]},"es-CL":{separator:"",suffixes:["y","z","a","f","p","n","µ","m","","k","M","MM","B","T","Q","Z","Y"],grouping:[3],delimiters:{thousands:".",decimal:","},currency:["$",""]},"es-MX":{separator:"",suffixes:["y","z","a","f","p","n","µ","m","","k","M","MM","B","T","Q","Z","Y"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["$",""]},"es-ES":{separator:"",suffixes:["y","z","a","f","p","n","µ","m","","k","mm","b","t","q","Q","Z","Y"],grouping:[3],delimiters:{thousands:".",decimal:","},currency:["€",""]},"et-EE":{separator:" ",suffixes:["y","z","a","f","p","n","µ","m","","tuhat","miljonit","miljardit","triljonit","q","Q","Z","Y"],grouping:[3],delimiters:{thousands:" ",decimal:","},currency:["","eurot"]},"fr-FR":{suffixes:["y","z","a","f","p","n","µ","m","","k","m","b","t","q","Q","Z","Y"],grouping:[3],delimiters:{thousands:" ",decimal:","},currency:["€",""]},"zh-CN":{separator:"",suffixes:["幺","","阿","飞","皮","纳","微","毫","","千","兆","吉","太","拍","艾","泽","尧"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["¥",""]}};let O=(e,t)=>parseFloat(Math.round(e*Math.pow(10,t))/Math.pow(10,t)).toFixed(t);
50
- /**
51
- * @private
52
- */
59
+ A set of default locale formatters used when assigning suffixes and currency in numbers.
60
+ */d({thousands:",",grouping:[3],currency:["$",""]});var m={"ar-SA":{separator:"",suffixes:["y","z","a","f","p","n","µ","m",""," ألف"," مليون"," بليون"," تريليون"," كوادريليون"," كوينتيليون"," سكستليون","سبتيليون"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["SAR ",""]},"en-GB":{separator:"",suffixes:["y","z","a","f","p","n","µ","m","","k","M","B","T","q","Q","Z","Y"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["£",""]},"en-US":{separator:"",suffixes:["y","z","a","f","p","n","µ","m","","k","M","B","T","q","Q","Z","Y"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["$",""]},"en-SA":{separator:"",suffixes:["y","z","a","f","p","n","µ","m",""," thousand"," million"," billion"," trillion"," quadrillion"," quintillion"," sextillion","septillion"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["$",""]},"es-CL":{separator:"",suffixes:["y","z","a","f","p","n","µ","m","","k","M","MM","B","T","Q","Z","Y"],grouping:[3],delimiters:{thousands:".",decimal:","},currency:["$",""]},"es-MX":{separator:"",suffixes:["y","z","a","f","p","n","µ","m","","k","M","MM","B","T","Q","Z","Y"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["$",""]},"es-ES":{separator:"",suffixes:["y","z","a","f","p","n","µ","m","","k","mm","b","t","q","Q","Z","Y"],grouping:[3],delimiters:{thousands:".",decimal:","},currency:["€",""]},"et-EE":{separator:" ",suffixes:["y","z","a","f","p","n","µ","m","","tuhat","miljonit","miljardit","triljonit","q","Q","Z","Y"],grouping:[3],delimiters:{thousands:" ",decimal:","},currency:["","eurot"]},"fr-FR":{suffixes:["y","z","a","f","p","n","µ","m","","k","m","b","t","q","Q","Z","Y"],grouping:[3],delimiters:{thousands:" ",decimal:","},currency:["€",""]},"zh-CN":{separator:"",suffixes:["幺","","阿","飞","皮","纳","微","毫","","千","兆","吉","太","拍","艾","泽","尧"],grouping:[3],delimiters:{thousands:",",decimal:"."},currency:["¥",""]}};
53
61
  /**
54
62
  * @private
55
- */function G(e,t){let n=Math.pow(10,3*Math.abs(8-t));return{scale:8<t?e=>e/n:e=>e*n,symbol:e}}
63
+ */
64
+ function p(e,t){const n=Math.pow(10,3*Math.abs(8-t));return{scale:t>8?e=>e/n:e=>e*n,symbol:e}}
56
65
  /**
57
- @function formatAbbreviate
58
- @desc Formats a number to an appropriate number of decimal places and rounding, adding suffixes if applicable (ie. `1200000` to `"1.2M"`).
59
- @param {Number|String} n The number to be formatted.
60
- @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.
61
- @returns {String}
62
- */function W(e,t="en-US",n=void 0){if(!isFinite(e))return"N/A";var r=(e*=1)<0,i=e.toString().split(".")[0].replace("-","").length,t="object"==typeof t?t:$[t]||$["en-US"],o=t.suffixes.map(G),u=t.delimiters.decimal||".",a=t.separator||"",l=t.delimiters.thousands||",",t=Q({currency:t.currency||["$",""],decimal:u,grouping:t.grouping||[3],thousands:l});let s;return s=n?t.format(n)(e):0===e?"0":3<=i?(l=((e,t,n)=>{let r=0,i=parseFloat(e.replace("−","-"),10);return i&&(i<0&&(i*=-1),r=1+Math.floor(1e-12+Math.log(i)/Math.LN10),r=Math.max(-24,Math.min(24,3*Math.floor((r-1)/3)))),e=n[8+r/3],{number:O(e.scale(i),t),symbol:e.symbol}})(t.format(".3r")(e),2,o),""+parseFloat(l.number).toString().replace(".",u)+a+l.symbol):(3===i?t.format(",f"):e<1&&-1<e?t.format(".2g"):t.format(".3g"))(e),((r&&"−"!==s.charAt(0)?"−":"")+s).replace(/−/g,"-").replace(/(\.[0]*[1-9]*)[0]*$/g,"$1").replace(/\.[0]*$/g,"");// removes any trailing decimal point
63
- }
66
+ Formats a number to an appropriate number of decimal places and rounding, adding suffixes if applicable (ie. `1200000` to `"1.2M"`).
67
+ @param n The number to be formatted.
68
+ @param locale The locale config to be used. If an object is provided, the function will format the numbers according to the object. The object must include `suffixes`, `delimiter` and `currency` properties.
69
+ @param precision Number of significant digits to display.
70
+ */function y(e,t="en-US",n){if(!isFinite(e))return"N/A";const r=(e*=1)<0,i=e.toString().split(".")[0].replace("-","").length,o="object"==typeof t?t:m[t]||m["en-US"],u=o.suffixes.map(p),a=o.delimiters.decimal||".",s=o.separator||"",c=o.delimiters.thousands||",",l=h({currency:o.currency||["$",""],decimal:a,grouping:o.grouping||[3],thousands:c});let f;if(n)f=l.format(n)(e);else if(0===e)f="0";else if(i>=3){const t=
64
71
  /**
65
- @function format
66
- @desc An extension to d3's [format](https://github.com/d3/d3-format#api-reference) function that adds more string formatting types and localizations.
67
- @param {String} specifier The string specifier used by the format function.
68
- @returns {Function}
69
- */var B=e=>".3~a"===e?W:N(e);
72
+ * @private
73
+ */
74
+ function(e,t,n){let r=0,i=parseFloat(e.replace("−","-"));i&&(i<0&&(i*=-1),r=1+Math.floor(1e-12+Math.log(i)/Math.LN10),r=Math.max(-24,Math.min(24,3*Math.floor((r-1)/3))));const o=n[8+r/3];return{number:(u=o.scale(i),a=t,parseFloat((Math.round(u*Math.pow(10,a))/Math.pow(10,a)).toString()).toFixed(a)),symbol:o.symbol};var u,a}(l.format(".3r")(e),2,u);f=`${parseFloat(t.number).toString().replace(".",a)}${s}${t.symbol}`}else f=3===i?l.format(",f")(e):e<1&&e>-1?l.format(".2g")(e):l.format(".3g")(e);return`${r&&"−"!==f.charAt(0)?"−":""}${f}`.replace(/\u2212/g,"-").replace(/(\.[0]*[1-9]*)[0]*$/g,"$1").replace(/\.[0]*$/g,"");// removes any trailing decimal point
75
+ }function M(e){return".3~a"===e?y:l(e)}
70
76
  /**
71
- @function formatDefaultLocale
72
- @desc An extension to d3's [formatDefaultLocale](https://github.com/d3/d3-format#api-reference) function that allows setting the locale globally for formatters.
73
- @param {Object} definition The localization definition.
74
- @returns {Object}
75
- */let i=new Date,l=new Date;function f(o,u,n,r){function a(e){return o(e=0===arguments.length?new Date:new Date(+e)),e}return a.floor=e=>(o(e=new Date(+e)),e),a.ceil=e=>(o(e=new Date(e-1)),u(e,1),o(e),e),a.round=e=>{var t=a(e),n=a.ceil(e);return e-t<n-e?t:n},a.offset=(e,t)=>(u(e=new Date(+e),null==t?1:Math.floor(t)),e),a.range=(e,t,n)=>{var r,i=[];if(e=a.ceil(e),n=null==n?1:Math.floor(n),e<t&&0<n)for(;i.push(r=new Date(+e)),u(e,n),o(e),r<e&&e<t;);// also handles Invalid Date
76
- return i},a.filter=n=>f(e=>{if(e<=e)for(;o(e),!n(e);)e.setTime(e-1)},(e,t)=>{if(e<=e)if(t<0)for(;++t<=0;)for(;u(e,-1),!n(e););// eslint-disable-line no-empty
77
- else for(;0<=--t;)for(;u(e,1),!n(e););// eslint-disable-line no-empty
78
- }),n&&(a.count=(e,t)=>(i.setTime(+e),l.setTime(+t),o(i),o(l),Math.floor(n(i,l))),a.every=t=>(t=Math.floor(t),isFinite(t)&&0<t?1<t?a.filter(r?e=>r(e)%t==0:e=>a.count(0,e)%t==0):a:null)),a}let o=6e4,u=36e5,a=864e5,X=(a,f(e=>{e.setTime(e-e.getMilliseconds())},(e,t)=>{e.setTime(+e+1e3*t)},(e,t)=>(t-e)/1e3,e=>e.getUTCSeconds())),P=(X.range,f(e=>{e.setTime(e-e.getMilliseconds()-1e3*e.getSeconds())},(e,t)=>{e.setTime(+e+t*o)},(e,t)=>(t-e)/o,e=>e.getMinutes())),I=(P.range,f(e=>{e.setUTCSeconds(0,0)},(e,t)=>{e.setTime(+e+t*o)},(e,t)=>(t-e)/o,e=>e.getUTCMinutes()).range,f(e=>{e.setTime(e-e.getMilliseconds()-1e3*e.getSeconds()-e.getMinutes()*o)},(e,t)=>{e.setTime(+e+t*u)},(e,t)=>(t-e)/u,e=>e.getHours())),D=(I.range,f(e=>{e.setUTCMinutes(0,0,0)},(e,t)=>{e.setTime(+e+t*u)},(e,t)=>(t-e)/u,e=>e.getUTCHours()).range,f(e=>e.setHours(0,0,0,0),(e,t)=>e.setDate(e.getDate()+t),(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*o)/a,e=>e.getDate()-1)),F=(D.range,f(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/a,e=>e.getUTCDate()-1));function g(t){return f(e=>{e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)},(e,t)=>{e.setDate(e.getDate()+7*t)},(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*o)/6048e5)}F.range,f(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/a,e=>Math.floor(e/a)).range;let J=g(0),H=g(1);var h=g(2),d=g(3);let m=g(4);var p=g(5),y=g(6);function M(t){return f(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+7*t)},(e,t)=>(t-e)/6048e5)}J.range,H.range,h.range,d.range,m.range,p.range,y.range;let R=M(0),A=M(1);h=M(2),d=M(3);let T=M(4);p=M(5),y=M(6);R.range,A.range,h.range,d.range,T.range,p.range,y.range;let _=f(e=>{e.setDate(1),e.setHours(0,0,0,0)},(e,t)=>{e.setMonth(e.getMonth()+t)},(e,t)=>t.getMonth()-e.getMonth()+12*(t.getFullYear()-e.getFullYear()),e=>e.getMonth()),C=(_.range,f(e=>{e.setUTCDate(1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCMonth(e.getUTCMonth()+t)},(e,t)=>t.getUTCMonth()-e.getUTCMonth()+12*(t.getUTCFullYear()-e.getUTCFullYear()),e=>e.getUTCMonth()).range,f(e=>{e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t)},(e,t)=>t.getFullYear()-e.getFullYear(),e=>e.getFullYear())),v=(
77
+ An extension to d3's [formatDefaultLocale](https://github.com/d3/d3-format#api-reference) function that allows setting the locale globally for formatters.
78
+ @param definition The localization definition.
79
+ */const v=new Date,T=new Date;function C(e,t,n,r){function i(t){return e(t=0===arguments.length?new Date:new Date(+t)),t}return i.floor=t=>(e(t=new Date(+t)),t),i.ceil=n=>(e(n=new Date(n-1)),t(n,1),e(n),n),i.round=e=>{const t=i(e),n=i.ceil(e);return e-t<n-e?t:n},i.offset=(e,n)=>(t(e=new Date(+e),null==n?1:Math.floor(n)),e),i.range=(n,r,o)=>{const u=[];if(n=i.ceil(n),o=null==o?1:Math.floor(o),!(n<r&&o>0))return u;// also handles Invalid Date
80
+ let a;do{u.push(a=new Date(+n)),t(n,o),e(n)}while(a<n&&n<r);return u},i.filter=n=>C(t=>{if(t>=t)for(;e(t),!n(t);)t.setTime(t-1)},(e,r)=>{if(e>=e)if(r<0)for(;++r<=0;)for(;t(e,-1),!n(e););// eslint-disable-line no-empty
81
+ else for(;--r>=0;)for(;t(e,1),!n(e););// eslint-disable-line no-empty
82
+ }),n&&(i.count=(t,r)=>(v.setTime(+t),T.setTime(+r),e(v),e(T),Math.floor(n(v,T))),i.every=e=>(e=Math.floor(e),isFinite(e)&&e>0?e>1?i.filter(r?t=>r(t)%e===0:t=>i.count(0,t)%e===0):i:null)),i}const U=1e3,x=6e4,D=36e5,w=864e5,F=6048e5,Y=C(e=>{e.setTime(e-e.getMilliseconds())},(e,t)=>{e.setTime(+e+t*U)},(e,t)=>(t-e)/U,e=>e.getUTCSeconds());Y.range;const b=C(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*U)},(e,t)=>{e.setTime(+e+t*x)},(e,t)=>(t-e)/x,e=>e.getMinutes());b.range;C(e=>{e.setUTCSeconds(0,0)},(e,t)=>{e.setTime(+e+t*x)},(e,t)=>(t-e)/x,e=>e.getUTCMinutes()).range;const S=C(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*U-e.getMinutes()*x)},(e,t)=>{e.setTime(+e+t*D)},(e,t)=>(t-e)/D,e=>e.getHours());S.range;C(e=>{e.setUTCMinutes(0,0,0)},(e,t)=>{e.setTime(+e+t*D)},(e,t)=>(t-e)/D,e=>e.getUTCHours()).range;const H=C(e=>e.setHours(0,0,0,0),(e,t)=>e.setDate(e.getDate()+t),(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*x)/w,e=>e.getDate()-1);H.range;const A=C(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/w,e=>e.getUTCDate()-1);A.range;function L(e){return C(t=>{t.setDate(t.getDate()-(t.getDay()+7-e)%7),t.setHours(0,0,0,0)},(e,t)=>{e.setDate(e.getDate()+7*t)},(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*x)/F)}C(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/w,e=>Math.floor(e/w)).range;const z=L(0),Z=L(1),$=L(2),j=L(3),q=L(4),Q=L(5),k=L(6);function N(e){return C(t=>{t.setUTCDate(t.getUTCDate()-(t.getUTCDay()+7-e)%7),t.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+7*t)},(e,t)=>(t-e)/F)}z.range,Z.range,$.range,j.range,q.range,Q.range,k.range;const W=N(0),E=N(1),V=N(2),X=N(3),B=N(4),O=N(5),P=N(6);W.range,E.range,V.range,X.range,B.range,O.range,P.range;const I=C(e=>{e.setDate(1),e.setHours(0,0,0,0)},(e,t)=>{e.setMonth(e.getMonth()+t)},(e,t)=>t.getMonth()-e.getMonth()+12*(t.getFullYear()-e.getFullYear()),e=>e.getMonth());I.range;C(e=>{e.setUTCDate(1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCMonth(e.getUTCMonth()+t)},(e,t)=>t.getUTCMonth()-e.getUTCMonth()+12*(t.getUTCFullYear()-e.getUTCFullYear()),e=>e.getUTCMonth()).range;const J=C(e=>{e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t)},(e,t)=>t.getFullYear()-e.getFullYear(),e=>e.getFullYear());
83
+ // An optimized implementation for this simple case.
84
+ J.every=e=>isFinite(e=Math.floor(e))&&e>0?C(t=>{t.setFullYear(Math.floor(t.getFullYear()/e)*e),t.setMonth(0,1),t.setHours(0,0,0,0)},(t,n)=>{t.setFullYear(t.getFullYear()+n*e)}):null,J.range;const G=C(e=>{e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t)},(e,t)=>t.getUTCFullYear()-e.getUTCFullYear(),e=>e.getUTCFullYear());
79
85
  // An optimized implementation for this simple case.
80
- C.every=n=>isFinite(n=Math.floor(n))&&0<n?f(e=>{e.setFullYear(Math.floor(e.getFullYear()/n)*n),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t*n)}):null,C,f(e=>{e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t)},(e,t)=>t.getUTCFullYear()-e.getUTCFullYear(),e=>e.getUTCFullYear()));function L(e){var t;return 0<=e.y&&e.y<100?((t=new Date(-1,e.m,e.d,e.H,e.M,e.S,e.L)).setFullYear(e.y),t):new Date(e.y,e.m,e.d,e.H,e.M,e.S,e.L)}function z(e){var t;return 0<=e.y&&e.y<100?((t=new Date(Date.UTC(-1,e.m,e.d,e.H,e.M,e.S,e.L))).setUTCFullYear(e.y),t):new Date(Date.UTC(e.y,e.m,e.d,e.H,e.M,e.S,e.L))}function E(e,t,n){return{y:e,m:t,d:n,H:0,M:0,S:0,L:0}}function K(e){var r=e.dateTime,i=e.date,o=e.time,t=e.periods,n=e.days,u=e.shortDays,a=e.months,l=e.shortMonths,s=Z(t),c=j(t),f=Z(n),g=j(n),h=Z(u),d=j(u),m=Z(a),p=j(a),y=Z(l),M=j(l),T={a:function(e){return u[e.getDay()]},A:function(e){return n[e.getDay()]},b:function(e){return l[e.getMonth()]},B:function(e){return a[e.getMonth()]},c:null,d:De,e:De,f:He,g:Ve,G:Oe,H:Fe,I:be,j:Ye,L:Se,m:Ae,M:Le,p:function(e){return t[+(12<=e.getHours())]},q:function(e){return 1+~~(e.getMonth()/3)},Q:gt,s:ht,S:ze,u:Ee,U:Ze,V:Ne,w:ke,W:qe,x:null,X:null,y:Qe,Y:$e,Z:Ge,"%":ft},C={a:function(e){return u[e.getUTCDay()]},A:function(e){return n[e.getUTCDay()]},b:function(e){return l[e.getUTCMonth()]},B:function(e){return a[e.getUTCMonth()]},c:null,d:We,e:We,f:Je,g:at,G:st,H:Be,I:Xe,j:Pe,L:Ie,m:Re,M:_e,p:function(e){return t[+(12<=e.getUTCHours())]},q:function(e){return 1+~~(e.getUTCMonth()/3)},Q:gt,s:ht,S:Ke,u:et,U:tt,V:rt,w:it,W:ot,x:null,X:null,y:ut,Y:lt,Z:ct,"%":ft},v={a:function(e,t,n){t=h.exec(t.slice(n));return t?(e.w=d.get(t[0].toLowerCase()),n+t[0].length):-1},A:function(e,t,n){t=f.exec(t.slice(n));return t?(e.w=g.get(t[0].toLowerCase()),n+t[0].length):-1},b:function(e,t,n){t=y.exec(t.slice(n));return t?(e.m=M.get(t[0].toLowerCase()),n+t[0].length):-1},B:function(e,t,n){t=m.exec(t.slice(n));return t?(e.m=p.get(t[0].toLowerCase()),n+t[0].length):-1},c:function(e,t,n){return x(e,r,t,n)},d:me,e:me,f:ve,g:fe,G:ce,H:ye,I:ye,j:pe,L:Ce,m:de,M:Me,p:function(e,t,n){t=s.exec(t.slice(n));return t?(e.p=c.get(t[0].toLowerCase()),n+t[0].length):-1},q:he,Q:we,s:xe,S:Te,u:ue,U:ae,V:le,w:oe,W:se,x:function(e,t,n){return x(e,i,t,n)},X:function(e,t,n){return x(e,o,t,n)},y:fe,Y:ce,Z:ge,"%":Ue};function U(l,s){return function(e){var t,n,r,i=[],o=-1,u=0,a=l.length;for(e instanceof Date||(e=new Date(+e));++o<a;)37===l.charCodeAt(o)&&(i.push(l.slice(u,o)),null!=(n=te[t=l.charAt(++o)])?t=l.charAt(++o):n="e"===t?" ":"0",(r=s[t])&&(t=r(e,n)),i.push(t),u=o+1);return i.push(l.slice(u,o)),i.join("")}}function w(i,o){return function(e){var t,n,r=E(1900,void 0,1);if(x(r,i,e+="",0)!=e.length)return null;
86
+ function R(e){if(0<=e.y&&e.y<100){var t=new Date(-1,e.m,e.d,e.H,e.M,e.S,e.L);return t.setFullYear(e.y),t}return new Date(e.y,e.m,e.d,e.H,e.M,e.S,e.L)}function _(e){if(0<=e.y&&e.y<100){var t=new Date(Date.UTC(-1,e.m,e.d,e.H,e.M,e.S,e.L));return t.setUTCFullYear(e.y),t}return new Date(Date.UTC(e.y,e.m,e.d,e.H,e.M,e.S,e.L))}function K(e,t,n){return{y:e,m:t,d:n,H:0,M:0,S:0,L:0}}G.every=e=>isFinite(e=Math.floor(e))&&e>0?C(t=>{t.setUTCFullYear(Math.floor(t.getUTCFullYear()/e)*e),t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,n)=>{t.setUTCFullYear(t.getUTCFullYear()+n*e)}):null,G.range;var ee,te,ne={"-":"",_:" ",0:"0"},re=/^\s*\d+/,ie=/^%/,oe=/[\\^$*+?|[\]().{}]/g;function ue(e,t,n){var r=e<0?"-":"",i=(r?-e:e)+"",o=i.length;return r+(o<n?new Array(n-o+1).join(t)+i:i)}function ae(e){return e.replace(oe,"\\$&")}function se(e){return new RegExp("^(?:"+e.map(ae).join("|")+")","i")}function ce(e){return new Map(e.map((e,t)=>[e.toLowerCase(),t]))}function le(e,t,n){var r=re.exec(t.slice(n,n+1));return r?(e.w=+r[0],n+r[0].length):-1}function fe(e,t,n){var r=re.exec(t.slice(n,n+1));return r?(e.u=+r[0],n+r[0].length):-1}function ge(e,t,n){var r=re.exec(t.slice(n,n+2));return r?(e.U=+r[0],n+r[0].length):-1}function he(e,t,n){var r=re.exec(t.slice(n,n+2));return r?(e.V=+r[0],n+r[0].length):-1}function de(e,t,n){var r=re.exec(t.slice(n,n+2));return r?(e.W=+r[0],n+r[0].length):-1}function me(e,t,n){var r=re.exec(t.slice(n,n+4));return r?(e.y=+r[0],n+r[0].length):-1}function pe(e,t,n){var r=re.exec(t.slice(n,n+2));return r?(e.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function ye(e,t,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(t.slice(n,n+6));return r?(e.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function Me(e,t,n){var r=re.exec(t.slice(n,n+1));return r?(e.q=3*r[0]-3,n+r[0].length):-1}function ve(e,t,n){var r=re.exec(t.slice(n,n+2));return r?(e.m=r[0]-1,n+r[0].length):-1}function Te(e,t,n){var r=re.exec(t.slice(n,n+2));return r?(e.d=+r[0],n+r[0].length):-1}function Ce(e,t,n){var r=re.exec(t.slice(n,n+3));return r?(e.m=0,e.d=+r[0],n+r[0].length):-1}function Ue(e,t,n){var r=re.exec(t.slice(n,n+2));return r?(e.H=+r[0],n+r[0].length):-1}function xe(e,t,n){var r=re.exec(t.slice(n,n+2));return r?(e.M=+r[0],n+r[0].length):-1}function De(e,t,n){var r=re.exec(t.slice(n,n+2));return r?(e.S=+r[0],n+r[0].length):-1}function we(e,t,n){var r=re.exec(t.slice(n,n+3));return r?(e.L=+r[0],n+r[0].length):-1}function Fe(e,t,n){var r=re.exec(t.slice(n,n+6));return r?(e.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function Ye(e,t,n){var r=ie.exec(t.slice(n,n+1));return r?n+r[0].length:-1}function be(e,t,n){var r=re.exec(t.slice(n));return r?(e.Q=+r[0],n+r[0].length):-1}function Se(e,t,n){var r=re.exec(t.slice(n));return r?(e.s=+r[0],n+r[0].length):-1}function He(e,t){return ue(e.getDate(),t,2)}function Ae(e,t){return ue(e.getHours(),t,2)}function Le(e,t){return ue(e.getHours()%12||12,t,2)}function ze(e,t){return ue(1+H.count(J(e),e),t,3)}function Ze(e,t){return ue(e.getMilliseconds(),t,3)}function $e(e,t){return Ze(e,t)+"000"}function je(e,t){return ue(e.getMonth()+1,t,2)}function qe(e,t){return ue(e.getMinutes(),t,2)}function Qe(e,t){return ue(e.getSeconds(),t,2)}function ke(e){var t=e.getDay();return 0===t?7:t}function Ne(e,t){return ue(z.count(J(e)-1,e),t,2)}function We(e){var t=e.getDay();return t>=4||0===t?q(e):q.ceil(e)}function Ee(e,t){return e=We(e),ue(q.count(J(e),e)+(4===J(e).getDay()),t,2)}function Ve(e){return e.getDay()}function Xe(e,t){return ue(Z.count(J(e)-1,e),t,2)}function Be(e,t){return ue(e.getFullYear()%100,t,2)}function Oe(e,t){return ue((e=We(e)).getFullYear()%100,t,2)}function Pe(e,t){return ue(e.getFullYear()%1e4,t,4)}function Ie(e,t){var n=e.getDay();return ue((e=n>=4||0===n?q(e):q.ceil(e)).getFullYear()%1e4,t,4)}function Je(e){var t=e.getTimezoneOffset();return(t>0?"-":(t*=-1,"+"))+ue(t/60|0,"0",2)+ue(t%60,"0",2)}function Ge(e,t){return ue(e.getUTCDate(),t,2)}function Re(e,t){return ue(e.getUTCHours(),t,2)}function _e(e,t){return ue(e.getUTCHours()%12||12,t,2)}function Ke(e,t){return ue(1+A.count(G(e),e),t,3)}function et(e,t){return ue(e.getUTCMilliseconds(),t,3)}function tt(e,t){return et(e,t)+"000"}function nt(e,t){return ue(e.getUTCMonth()+1,t,2)}function rt(e,t){return ue(e.getUTCMinutes(),t,2)}function it(e,t){return ue(e.getUTCSeconds(),t,2)}function ot(e){var t=e.getUTCDay();return 0===t?7:t}function ut(e,t){return ue(W.count(G(e)-1,e),t,2)}function at(e){var t=e.getUTCDay();return t>=4||0===t?B(e):B.ceil(e)}function st(e,t){return e=at(e),ue(B.count(G(e),e)+(4===G(e).getUTCDay()),t,2)}function ct(e){return e.getUTCDay()}function lt(e,t){return ue(E.count(G(e)-1,e),t,2)}function ft(e,t){return ue(e.getUTCFullYear()%100,t,2)}function gt(e,t){return ue((e=at(e)).getUTCFullYear()%100,t,2)}function ht(e,t){return ue(e.getUTCFullYear()%1e4,t,4)}function dt(e,t){var n=e.getUTCDay();return ue((e=n>=4||0===n?B(e):B.ceil(e)).getUTCFullYear()%1e4,t,4)}function mt(){return"+0000"}function pt(){return"%"}function yt(e){return+e}function Mt(e){return Math.floor(+e/1e3)}ee=function(e){var t=e.dateTime,n=e.date,r=e.time,i=e.periods,o=e.days,u=e.shortDays,a=e.months,s=e.shortMonths,c=se(i),l=ce(i),f=se(o),g=ce(o),h=se(u),d=ce(u),m=se(a),p=ce(a),y=se(s),M=ce(s),v={a:function(e){return u[e.getDay()]},A:function(e){return o[e.getDay()]},b:function(e){return s[e.getMonth()]},B:function(e){return a[e.getMonth()]},c:null,d:He,e:He,f:$e,g:Oe,G:Ie,H:Ae,I:Le,j:ze,L:Ze,m:je,M:qe,p:function(e){return i[+(e.getHours()>=12)]},q:function(e){return 1+~~(e.getMonth()/3)},Q:yt,s:Mt,S:Qe,u:ke,U:Ne,V:Ee,w:Ve,W:Xe,x:null,X:null,y:Be,Y:Pe,Z:Je,"%":pt},T={a:function(e){return u[e.getUTCDay()]},A:function(e){return o[e.getUTCDay()]},b:function(e){return s[e.getUTCMonth()]},B:function(e){return a[e.getUTCMonth()]},c:null,d:Ge,e:Ge,f:tt,g:gt,G:dt,H:Re,I:_e,j:Ke,L:et,m:nt,M:rt,p:function(e){return i[+(e.getUTCHours()>=12)]},q:function(e){return 1+~~(e.getUTCMonth()/3)},Q:yt,s:Mt,S:it,u:ot,U:ut,V:st,w:ct,W:lt,x:null,X:null,y:ft,Y:ht,Z:mt,"%":pt},C={a:function(e,t,n){var r=h.exec(t.slice(n));return r?(e.w=d.get(r[0].toLowerCase()),n+r[0].length):-1},A:function(e,t,n){var r=f.exec(t.slice(n));return r?(e.w=g.get(r[0].toLowerCase()),n+r[0].length):-1},b:function(e,t,n){var r=y.exec(t.slice(n));return r?(e.m=M.get(r[0].toLowerCase()),n+r[0].length):-1},B:function(e,t,n){var r=m.exec(t.slice(n));return r?(e.m=p.get(r[0].toLowerCase()),n+r[0].length):-1},c:function(e,n,r){return D(e,t,n,r)},d:Te,e:Te,f:Fe,g:pe,G:me,H:Ue,I:Ue,j:Ce,L:we,m:ve,M:xe,p:function(e,t,n){var r=c.exec(t.slice(n));return r?(e.p=l.get(r[0].toLowerCase()),n+r[0].length):-1},q:Me,Q:be,s:Se,S:De,u:fe,U:ge,V:he,w:le,W:de,x:function(e,t,r){return D(e,n,t,r)},X:function(e,t,n){return D(e,r,t,n)},y:pe,Y:me,Z:ye,"%":Ye};function U(e,t){return function(n){var r,i,o,u=[],a=-1,s=0,c=e.length;for(n instanceof Date||(n=new Date(+n));++a<c;)37===e.charCodeAt(a)&&(u.push(e.slice(s,a)),null!=(i=ne[r=e.charAt(++a)])?r=e.charAt(++a):i="e"===r?" ":"0",(o=t[r])&&(r=o(n,i)),u.push(r),s=a+1);return u.push(e.slice(s,a)),u.join("")}}function x(e,t){return function(n){var r,i,o=K(1900,void 0,1);if(D(o,e,n+="",0)!=n.length)return null;
81
87
  // If a UNIX timestamp is specified, return it.
82
- if("Q"in r)return new Date(r.Q);if("s"in r)return new Date(1e3*r.s+("L"in r?r.L:0));
88
+ if("Q"in o)return new Date(o.Q);if("s"in o)return new Date(1e3*o.s+("L"in o?o.L:0));
83
89
  // If this is utcParse, never use the local timezone.
84
90
  // Convert day-of-week and week-of-year to day-of-year.
85
- if(!o||"Z"in r||(r.Z=0),
91
+ if(t&&!("Z"in o)&&(o.Z=0),
86
92
  // The am-pm flag is 0 for AM, and 1 for PM.
87
- "p"in r&&(r.H=r.H%12+12*r.p),
93
+ "p"in o&&(o.H=o.H%12+12*o.p),
88
94
  // If the month was not specified, inherit from the quarter.
89
- void 0===r.m&&(r.m="q"in r?r.q:0),"V"in r){if(r.V<1||53<r.V)return null;"w"in r||(r.w=1),"Z"in r?(t=4<(n=(t=z(E(r.y,0,1))).getUTCDay())||0===n?A.ceil(t):A(t),t=F.offset(t,7*(r.V-1)),r.y=t.getUTCFullYear(),r.m=t.getUTCMonth(),r.d=t.getUTCDate()+(r.w+6)%7):(t=4<(n=(t=L(E(r.y,0,1))).getDay())||0===n?H.ceil(t):H(t),t=D.offset(t,7*(r.V-1)),r.y=t.getFullYear(),r.m=t.getMonth(),r.d=t.getDate()+(r.w+6)%7)}else("W"in r||"U"in r)&&("w"in r||(r.w="u"in r?r.u%7:"W"in r?1:0),n="Z"in r?z(E(r.y,0,1)).getUTCDay():L(E(r.y,0,1)).getDay(),r.m=0,r.d="W"in r?(r.w+6)%7+7*r.W-(n+5)%7:r.w+7*r.U-(n+6)%7);
95
+ void 0===o.m&&(o.m="q"in o?o.q:0),"V"in o){if(o.V<1||o.V>53)return null;"w"in o||(o.w=1),"Z"in o?(i=(r=_(K(o.y,0,1))).getUTCDay(),r=i>4||0===i?E.ceil(r):E(r),r=A.offset(r,7*(o.V-1)),o.y=r.getUTCFullYear(),o.m=r.getUTCMonth(),o.d=r.getUTCDate()+(o.w+6)%7):(i=(r=R(K(o.y,0,1))).getDay(),r=i>4||0===i?Z.ceil(r):Z(r),r=H.offset(r,7*(o.V-1)),o.y=r.getFullYear(),o.m=r.getMonth(),o.d=r.getDate()+(o.w+6)%7)}else("W"in o||"U"in o)&&("w"in o||(o.w="u"in o?o.u%7:"W"in o?1:0),i="Z"in o?_(K(o.y,0,1)).getUTCDay():R(K(o.y,0,1)).getDay(),o.m=0,o.d="W"in o?(o.w+6)%7+7*o.W-(i+5)%7:o.w+7*o.U-(i+6)%7);
90
96
  // If a time zone is specified, all fields are interpreted as UTC and then
91
97
  // offset according to the specified time zone.
92
- return("Z"in r?(r.H+=r.Z/100|0,r.M+=r.Z%100,z):L)(r);
98
+ return"Z"in o?(o.H+=o.Z/100|0,o.M+=o.Z%100,_(o)):R(o);
93
99
  // Otherwise, all fields are in local time.
94
- }}function x(e,t,n,r){for(var i,o,u=0,a=t.length,l=n.length;u<a;){if(l<=r)return-1;if(37===(i=t.charCodeAt(u++))){if(i=t.charAt(u++),!(o=v[i in te?t.charAt(u++):i])||(r=o(e,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}
100
+ }}function D(e,t,n,r){for(var i,o,u=0,a=t.length,s=n.length;u<a;){if(r>=s)return-1;if(37===(i=t.charCodeAt(u++))){if(i=t.charAt(u++),!(o=C[i in ne?t.charAt(u++):i])||(r=o(e,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}
95
101
  // These recursive directive definitions must be deferred.
96
- return T.x=U(i,T),T.X=U(o,T),T.c=U(r,T),C.x=U(i,C),C.X=U(o,C),C.c=U(r,C),{format:function(e){var t=U(e+="",T);return t.toString=function(){return e},t},parse:function(e){var t=w(e+="",!1);return t.toString=function(){return e},t},utcFormat:function(e){var t=U(e+="",C);return t.toString=function(){return e},t},utcParse:function(e){var t=w(e+="",!0);return t.toString=function(){return e},t}}}
97
- // An optimized implementation for this simple case.
98
- v.every=n=>isFinite(n=Math.floor(n))&&0<n?f(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/n)*n),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t*n)}):null,v;var ee,te={"-":"",_:" ",0:"0"},U=/^\s*\d+/,ne=/^%/,re=/[\\^$*+?|[\]().{}]/g;function w(e,t,n){var r=e<0?"-":"",e=(r?-e:e)+"",i=e.length;return r+(i<n?new Array(n-i+1).join(t)+e:e)}function ie(e){return e.replace(re,"\\$&")}function Z(e){return new RegExp("^(?:"+e.map(ie).join("|")+")","i")}function j(e){return new Map(e.map((e,t)=>[e.toLowerCase(),t]))}function oe(e,t,n){t=U.exec(t.slice(n,n+1));return t?(e.w=+t[0],n+t[0].length):-1}function ue(e,t,n){t=U.exec(t.slice(n,n+1));return t?(e.u=+t[0],n+t[0].length):-1}function ae(e,t,n){t=U.exec(t.slice(n,n+2));return t?(e.U=+t[0],n+t[0].length):-1}function le(e,t,n){t=U.exec(t.slice(n,n+2));return t?(e.V=+t[0],n+t[0].length):-1}function se(e,t,n){t=U.exec(t.slice(n,n+2));return t?(e.W=+t[0],n+t[0].length):-1}function ce(e,t,n){t=U.exec(t.slice(n,n+4));return t?(e.y=+t[0],n+t[0].length):-1}function fe(e,t,n){t=U.exec(t.slice(n,n+2));return t?(e.y=+t[0]+(68<+t[0]?1900:2e3),n+t[0].length):-1}function ge(e,t,n){t=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(t.slice(n,n+6));return t?(e.Z=t[1]?0:-(t[2]+(t[3]||"00")),n+t[0].length):-1}function he(e,t,n){t=U.exec(t.slice(n,n+1));return t?(e.q=3*t[0]-3,n+t[0].length):-1}function de(e,t,n){t=U.exec(t.slice(n,n+2));return t?(e.m=t[0]-1,n+t[0].length):-1}function me(e,t,n){t=U.exec(t.slice(n,n+2));return t?(e.d=+t[0],n+t[0].length):-1}function pe(e,t,n){t=U.exec(t.slice(n,n+3));return t?(e.m=0,e.d=+t[0],n+t[0].length):-1}function ye(e,t,n){t=U.exec(t.slice(n,n+2));return t?(e.H=+t[0],n+t[0].length):-1}function Me(e,t,n){t=U.exec(t.slice(n,n+2));return t?(e.M=+t[0],n+t[0].length):-1}function Te(e,t,n){t=U.exec(t.slice(n,n+2));return t?(e.S=+t[0],n+t[0].length):-1}function Ce(e,t,n){t=U.exec(t.slice(n,n+3));return t?(e.L=+t[0],n+t[0].length):-1}function ve(e,t,n){t=U.exec(t.slice(n,n+6));return t?(e.L=Math.floor(t[0]/1e3),n+t[0].length):-1}function Ue(e,t,n){t=ne.exec(t.slice(n,n+1));return t?n+t[0].length:-1}function we(e,t,n){t=U.exec(t.slice(n));return t?(e.Q=+t[0],n+t[0].length):-1}function xe(e,t,n){t=U.exec(t.slice(n));return t?(e.s=+t[0],n+t[0].length):-1}function De(e,t){return w(e.getDate(),t,2)}function Fe(e,t){return w(e.getHours(),t,2)}function be(e,t){return w(e.getHours()%12||12,t,2)}function Ye(e,t){return w(1+D.count(C(e),e),t,3)}function Se(e,t){return w(e.getMilliseconds(),t,3)}function He(e,t){return Se(e,t)+"000"}function Ae(e,t){return w(e.getMonth()+1,t,2)}function Le(e,t){return w(e.getMinutes(),t,2)}function ze(e,t){return w(e.getSeconds(),t,2)}function Ee(e){e=e.getDay();return 0===e?7:e}function Ze(e,t){return w(J.count(C(e)-1,e),t,2)}function je(e){var t=e.getDay();return 4<=t||0===t?m(e):m.ceil(e)}function Ne(e,t){return e=je(e),w(m.count(C(e),e)+(4===C(e).getDay()),t,2)}function ke(e){return e.getDay()}function qe(e,t){return w(H.count(C(e)-1,e),t,2)}function Qe(e,t){return w(e.getFullYear()%100,t,2)}function Ve(e,t){return w((e=je(e)).getFullYear()%100,t,2)}function $e(e,t){return w(e.getFullYear()%1e4,t,4)}function Oe(e,t){var n=e.getDay();return w((e=4<=n||0===n?m(e):m.ceil(e)).getFullYear()%1e4,t,4)}function Ge(e){e=e.getTimezoneOffset();return(0<e?"-":(e*=-1,"+"))+w(e/60|0,"0",2)+w(e%60,"0",2)}function We(e,t){return w(e.getUTCDate(),t,2)}function Be(e,t){return w(e.getUTCHours(),t,2)}function Xe(e,t){return w(e.getUTCHours()%12||12,t,2)}function Pe(e,t){return w(1+F.count(v(e),e),t,3)}function Ie(e,t){return w(e.getUTCMilliseconds(),t,3)}function Je(e,t){return Ie(e,t)+"000"}function Re(e,t){return w(e.getUTCMonth()+1,t,2)}function _e(e,t){return w(e.getUTCMinutes(),t,2)}function Ke(e,t){return w(e.getUTCSeconds(),t,2)}function et(e){e=e.getUTCDay();return 0===e?7:e}function tt(e,t){return w(R.count(v(e)-1,e),t,2)}function nt(e){var t=e.getUTCDay();return 4<=t||0===t?T(e):T.ceil(e)}function rt(e,t){return e=nt(e),w(T.count(v(e),e)+(4===v(e).getUTCDay()),t,2)}function it(e){return e.getUTCDay()}function ot(e,t){return w(A.count(v(e)-1,e),t,2)}function ut(e,t){return w(e.getUTCFullYear()%100,t,2)}function at(e,t){return w((e=nt(e)).getUTCFullYear()%100,t,2)}function lt(e,t){return w(e.getUTCFullYear()%1e4,t,4)}function st(e,t){var n=e.getUTCDay();return w((e=4<=n||0===n?T(e):T.ceil(e)).getUTCFullYear()%1e4,t,4)}function ct(){return"+0000"}function ft(){return"%"}function gt(e){return+e}function ht(e){return Math.floor(+e/1e3)}h=K({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}),ee=h.format,e.format=B,e.formatAbbreviate=W,e.formatDate=
102
+ return v.x=U(n,v),v.X=U(r,v),v.c=U(t,v),T.x=U(n,T),T.X=U(r,T),T.c=U(t,T),{format:function(e){var t=U(e+="",v);return t.toString=function(){return e},t},parse:function(e){var t=x(e+="",!1);return t.toString=function(){return e},t},utcFormat:function(e){var t=U(e+="",T);return t.toString=function(){return e},t},utcParse:function(e){var t=x(e+="",!0);return t.toString=function(){return e},t}}}({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}),te=ee.format,ee.parse,ee.utcFormat,ee.utcParse,e.format=M,e.formatAbbreviate=y,e.formatDate=
99
103
  /**
100
- @function formatDate
101
- @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.
102
- @param {Date} d The date string to be formatted.
103
- @param {Array} dataArray The full array of ordered Date Objects.
104
- @param {Function} [formatter = d3.timeFormat] An optional instance of d3.timeFormat to be used for localization.
105
- @returns {String}
106
- */function(t,u,e=ee){var n=e("%I %p"),r=e(".%L"),i=e("%I:%M"),o=e("%b"),a=e("%b %-d"),l=e("%b %-d, %Y"),s=e("%b %Y"),c=e("Q%q"),f=e("Q%q %Y"),g=e(":%S"),e=e("%Y"),h=0===(h=u.findIndex(e=>+e==+t))||h===u.length-1,d=u.length<=5,[m,p,y,M]=u.reduce((e,t,n)=>{
104
+ 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.
105
+ @param d The date to format.
106
+ @param dataArray The full array of ordered Date Objects.
107
+ @param formatter Optional custom format string or function.
108
+ */
109
+ function(e,t,n=te){const r=n("%I %p"),i=n(".%L"),o=n("%I:%M"),u=n("%b"),a=n("%b %-d"),s=n("%b %-d, %Y"),c=n("%b %Y"),l=n("Q%q"),f=n("Q%q %Y"),g=n(":%S"),h=n("%Y"),d=t.findIndex(t=>+t===+e),m=0===d||d===t.length-1,p=t.length<=5,[y,M,v,T]=t.reduce((e,n,r)=>(r&&(e[0].push(n.getFullYear()-t[r-1].getFullYear()),e[1].push(
107
110
  /**
108
- @function monthDiff
109
- @desc Returns the number of months between two Date objects
110
- @param {*} d1
111
- @param {*} d2
111
+ Returns the number of months between two Date objects
112
+
112
113
  @returns {Number} the number of months between the two Date objects
113
114
  @private
114
- */var r,i,o;return n&&(e[0].push(t.getFullYear()-u[n-1].getFullYear()),e[1].push((r=u[n-1],o=12*((i=t).getFullYear()-r.getFullYear()),(o=(o-=r.getMonth())+i.getMonth())<=0?0:o)),e[2].push(Math.round((t-u[n-1])/864e5)),e[3].push(Math.round((t-u[n-1])/36e5))),e},[[],[],[],[]]);return(m.every(e=>1<=e&&!(e%1))?e:p.every(e=>3<=e&&!(e%3))?+C(t)===t||h||d?f:c:p.every(e=>1<=e&&!(e%1))?+C(t)===t||h||d?s:o:y.every(e=>1<=e&&!(e%1))?+C(t)===t||h||d?l:a:M.every(e=>1<=e&&!(e%1))?h||d?l:+_(t)===t?a:n:X(t)<t?r:P(t)<t?g:I(t)<t?i:t)(t)},e.formatDefaultLocale=e=>{e=V(e);return e.format=B,e}});
115
+ */
116
+ function(e,t){let n;return n=12*(t.getFullYear()-e.getFullYear()),n-=e.getMonth(),n+=t.getMonth(),n<=0?0:n}(t[r-1],n)),e[2].push(Math.round((+n-+t[r-1])/864e5)),e[3].push(Math.round((+n-+t[r-1])/36e5))),e),[[],[],[],[]]);return(y.every(e=>e>=1&&!(e%1))?h:M.every(e=>e>=3&&!(e%3))?+J(e)===+e||m||p?f:l:M.every(e=>e>=1&&!(e%1))?+J(e)===+e||m||p?c:u:v.every(e=>e>=1&&!(e%1))?+J(e)===+e||m||p?s:a:T.every(e=>e>=1&&!(e%1))?m||p?s:+I(e)===+e?a:r:Y(e)<e?i:b(e)<e?g:S(e)<e?o:e=>e.toString())(e)},e.formatDefaultLocale=function(e){const t=d(e);return t.format=M,t}});
115
117
  //# sourceMappingURL=d3plus-format.full.js.map
@@ -4,122 +4,18 @@
4
4
  Copyright (c) 2026 D3plus - https://d3plus.org
5
5
  @license MIT
6
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
7
  (function (global, factory) {
112
8
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-format'), require('@d3plus/locales'), require('d3-time'), require('d3-time-format')) :
113
9
  typeof define === 'function' && define.amd ? define('@d3plus/format', ['exports', 'd3-format', '@d3plus/locales', 'd3-time', 'd3-time-format'], factory) :
114
10
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3plus = {}, global.d3Format, global.locales, global.d3Time, global.d3TimeFormat));
115
11
  })(this, (function (exports, d3Format, locales, d3Time, d3TimeFormat) { 'use strict';
116
12
 
117
- const round = (x, n)=>parseFloat(Math.round(x * Math.pow(10, n)) / Math.pow(10, n)).toFixed(n);
13
+ const round = (x, n)=>parseFloat((Math.round(x * Math.pow(10, n)) / Math.pow(10, n)).toString()).toFixed(n);
118
14
  /**
119
15
  * @private
120
- */ function formatSuffix(str, precision, suffixes) {
16
+ */ function formatSuffix(str, precision, suffixes) {
121
17
  let i = 0;
122
- let value = parseFloat(str.replace("", "-"), 10);
18
+ let value = parseFloat(str.replace("\u2212", "-"));
123
19
  if (value) {
124
20
  if (value < 0) value *= -1;
125
21
  i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
@@ -133,7 +29,7 @@
133
29
  }
134
30
  /**
135
31
  * @private
136
- */ function parseSuffixes(d, i) {
32
+ */ function parseSuffixes(d, i) {
137
33
  const k = Math.pow(10, Math.abs(8 - i) * 3);
138
34
  return {
139
35
  scale: i > 8 ? (d)=>d / k : (d)=>d * k,
@@ -141,13 +37,12 @@
141
37
  };
142
38
  }
143
39
  /**
144
- @function formatAbbreviate
145
- @desc Formats a number to an appropriate number of decimal places and rounding, adding suffixes if applicable (ie. `1200000` to `"1.2M"`).
146
- @param {Number|String} n The number to be formatted.
147
- @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.
148
- @returns {String}
149
- */ function abbreviate(n, locale = "en-US", precision = undefined) {
150
- if (isFinite(n)) n *= 1;
40
+ Formats a number to an appropriate number of decimal places and rounding, adding suffixes if applicable (ie. `1200000` to `"1.2M"`).
41
+ @param n The number to be formatted.
42
+ @param locale The locale config to be used. If an object is provided, the function will format the numbers according to the object. The object must include `suffixes`, `delimiter` and `currency` properties.
43
+ @param precision Number of significant digits to display.
44
+ */ function formatAbbreviate(n, locale = "en-US", precision) {
45
+ if (isFinite(n)) n = n * 1;
151
46
  else return "N/A";
152
47
  const negative = n < 0;
153
48
  const length = n.toString().split(".")[0].replace("-", "").length, localeConfig = typeof locale === "object" ? locale : locales.formatLocale[locale] || locales.formatLocale["en-US"], suffixes = localeConfig.suffixes.map(parseSuffixes);
@@ -174,39 +69,30 @@
174
69
  } else if (length === 3) val = d3plusFormatLocale.format(",f")(n);
175
70
  else if (n < 1 && n > -1) val = d3plusFormatLocale.format(".2g")(n);
176
71
  else val = d3plusFormatLocale.format(".3g")(n);
177
- return `${negative && val.charAt(0) !== "" ? "" : ""}${val}`.replace(/−/g, "-") // replace new d3 default minus sign () to hyphen-minus (-)
72
+ return `${negative && val.charAt(0) !== "\u2212" ? "\u2212" : ""}${val}`.replace(/\u2212/g, "-") // replace new d3 default minus sign (\u2212) to hyphen-minus (-)
178
73
  .replace(/(\.[0]*[1-9]*)[0]*$/g, "$1") // removes any trailing zeros
179
74
  .replace(/\.[0]*$/g, ""); // removes any trailing decimal point
180
75
  }
181
76
 
182
- /**
183
- @function format
184
- @desc An extension to d3's [format](https://github.com/d3/d3-format#api-reference) function that adds more string formatting types and localizations.
185
- @param {String} specifier The string specifier used by the format function.
186
- @returns {Function}
187
- */ var format = ((specifier)=>{
188
- if (specifier === ".3~a") return abbreviate;
77
+ function format(specifier) {
78
+ if (specifier === ".3~a") return formatAbbreviate;
189
79
  return d3Format.format(specifier);
190
- });
80
+ }
191
81
 
192
82
  /**
193
- @function formatDefaultLocale
194
- @desc An extension to d3's [formatDefaultLocale](https://github.com/d3/d3-format#api-reference) function that allows setting the locale globally for formatters.
195
- @param {Object} definition The localization definition.
196
- @returns {Object}
197
- */ var formatDefaultLocale = ((definition)=>{
83
+ An extension to d3's [formatDefaultLocale](https://github.com/d3/d3-format#api-reference) function that allows setting the locale globally for formatters.
84
+ @param definition The localization definition.
85
+ */ function formatDefaultLocale(definition) {
198
86
  const locale = d3Format.formatDefaultLocale(definition);
199
87
  locale.format = format;
200
88
  return locale;
201
- });
89
+ }
202
90
 
203
91
  /**
204
- @function formatDate
205
- @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.
206
- @param {Date} d The date string to be formatted.
207
- @param {Array} dataArray The full array of ordered Date Objects.
208
- @param {Function} [formatter = d3.timeFormat] An optional instance of d3.timeFormat to be used for localization.
209
- @returns {String}
92
+ 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.
93
+ @param d The date to format.
94
+ @param dataArray The full array of ordered Date Objects.
95
+ @param formatter Optional custom format string or function.
210
96
  */ function formatDate(d, dataArray, formatter = d3TimeFormat.timeFormat) {
211
97
  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");
212
98
  const labelIndex = dataArray.findIndex((a)=>+a === +d);
@@ -216,8 +102,8 @@
216
102
  if (i) {
217
103
  arr[0].push(d.getFullYear() - dataArray[i - 1].getFullYear());
218
104
  arr[1].push(monthDiff(dataArray[i - 1], d));
219
- arr[2].push(Math.round((d - dataArray[i - 1]) / (1000 * 60 * 60 * 24)));
220
- arr[3].push(Math.round((d - dataArray[i - 1]) / (1000 * 60 * 60)));
105
+ arr[2].push(Math.round((+d - +dataArray[i - 1]) / (1000 * 60 * 60 * 24)));
106
+ arr[3].push(Math.round((+d - +dataArray[i - 1]) / (1000 * 60 * 60)));
221
107
  }
222
108
  return arr;
223
109
  }, [
@@ -226,18 +112,16 @@
226
112
  [],
227
113
  []
228
114
  ]);
229
- return (yearlySteps.every((s)=>s >= 1 && !(s % 1)) // Yearly Data
115
+ return (yearlySteps.every((s)=>s >= 1 && !(s % 1)) // Yearly Data
230
116
  ? formatYear : monthlySteps.every((s)=>s >= 3 && !(s % 3)) // Quarterly Data
231
- ? +d3Time.timeYear(d) === d || firstOrLast || smallArray ? formatQuarterYear : formatQuarter : monthlySteps.every((s)=>s >= 1 && !(s % 1)) // Monthly Data
232
- ? +d3Time.timeYear(d) === d || firstOrLast || smallArray ? formatMonthYear : formatMonth : dailySteps.every((s)=>s >= 1 && !(s % 1)) // Daily Data
233
- ? +d3Time.timeYear(d) === d || firstOrLast || smallArray ? formatMonthDayYear : formatMonthDay : hourlySteps.every((s)=>s >= 1 && !(s % 1)) // Hourly Data
234
- ? firstOrLast || smallArray ? formatMonthDayYear : +d3Time.timeMonth(d) === d ? formatMonthDay : formatHour : d3Time.timeSecond(d) < d ? formatMillisecond : d3Time.timeMinute(d) < d ? formatSecond : d3Time.timeHour(d) < d ? formatMinute : d)(d);
117
+ ? +d3Time.timeYear(d) === +d || firstOrLast || smallArray ? formatQuarterYear : formatQuarter : monthlySteps.every((s)=>s >= 1 && !(s % 1)) // Monthly Data
118
+ ? +d3Time.timeYear(d) === +d || firstOrLast || smallArray ? formatMonthYear : formatMonth : dailySteps.every((s)=>s >= 1 && !(s % 1)) // Daily Data
119
+ ? +d3Time.timeYear(d) === +d || firstOrLast || smallArray ? formatMonthDayYear : formatMonthDay : hourlySteps.every((s)=>s >= 1 && !(s % 1)) // Hourly Data
120
+ ? firstOrLast || smallArray ? formatMonthDayYear : +d3Time.timeMonth(d) === +d ? formatMonthDay : formatHour : d3Time.timeSecond(d) < d ? formatMillisecond : d3Time.timeMinute(d) < d ? formatSecond : d3Time.timeHour(d) < d ? formatMinute : (_d)=>_d.toString())(d);
235
121
  }
236
122
  /**
237
- @function monthDiff
238
- @desc Returns the number of months between two Date objects
239
- @param {*} d1
240
- @param {*} d2
123
+ Returns the number of months between two Date objects
124
+
241
125
  @returns {Number} the number of months between the two Date objects
242
126
  @private
243
127
  */ function monthDiff(d1, d2) {
@@ -249,7 +133,7 @@
249
133
  }
250
134
 
251
135
  exports.format = format;
252
- exports.formatAbbreviate = abbreviate;
136
+ exports.formatAbbreviate = formatAbbreviate;
253
137
  exports.formatDate = formatDate;
254
138
  exports.formatDefaultLocale = formatDefaultLocale;
255
139