1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 21:29:38 +02:00
Maybe/vendor/javascript/d3-format.js
Zach Gollwitzer 3ec9c9b56b
Scaffold out the UI for individual account page (#461)
* Add `AccountBalance` table for account views

* Scaffold out account UI

* Add D3 line chart scaffolding

* Style fixes
2024-02-14 13:02:11 -05:00

2 lines
5.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function formatDecimal(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)}function formatDecimalParts(t,r){if((i=(t=r?t.toExponential(r-1):t.toExponential()).indexOf("e"))<0)return null;var i,e=t.slice(0,i);return[e.length>1?e[0]+e.slice(2):e,+t.slice(i+1)]}function exponent(t){return t=formatDecimalParts(Math.abs(t)),t?t[1]:NaN}function formatGroup(t,r){return function(i,e){var n=i.length,a=[],o=0,c=t[0],f=0;while(n>0&&c>0){f+c+1>e&&(c=Math.max(1,e-f));a.push(i.substring(n-=c,n+c));if((f+=c+1)>e)break;c=t[o=(o+1)%t.length]}return a.reverse().join(r)}}function formatNumerals(t){return function(r){return r.replace(/[0-9]/g,(function(r){return t[+r]}))}}var t=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function formatSpecifier(r){if(!(i=t.exec(r)))throw new Error("invalid format: "+r);var i;return new FormatSpecifier({fill:i[1],align:i[2],sign:i[3],symbol:i[4],zero:i[5],width:i[6],comma:i[7],precision:i[8]&&i[8].slice(1),trim:i[9],type:i[10]})}formatSpecifier.prototype=FormatSpecifier.prototype;function FormatSpecifier(t){this.fill=void 0===t.fill?" ":t.fill+"";this.align=void 0===t.align?">":t.align+"";this.sign=void 0===t.sign?"-":t.sign+"";this.symbol=void 0===t.symbol?"":t.symbol+"";this.zero=!!t.zero;this.width=void 0===t.width?void 0:+t.width;this.comma=!!t.comma;this.precision=void 0===t.precision?void 0:+t.precision;this.trim=!!t.trim;this.type=void 0===t.type?"":t.type+""}FormatSpecifier.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};function formatTrim(t){t:for(var r,i=t.length,e=1,n=-1;e<i;++e)switch(t[e]){case".":n=r=e;break;case"0":0===n&&(n=e);r=e;break;default:if(!+t[e])break t;n>0&&(n=0);break}return n>0?t.slice(0,n)+t.slice(r+1):t}var r;function formatPrefixAuto(t,i){var e=formatDecimalParts(t,i);if(!e)return t+"";var n=e[0],a=e[1],o=a-(r=3*Math.max(-8,Math.min(8,Math.floor(a/3))))+1,c=n.length;return o===c?n:o>c?n+new Array(o-c+1).join("0"):o>0?n.slice(0,o)+"."+n.slice(o):"0."+new Array(1-o).join("0")+formatDecimalParts(t,Math.max(0,i+o-1))[0]}function formatRounded(t,r){var i=formatDecimalParts(t,r);if(!i)return t+"";var e=i[0],n=i[1];return n<0?"0."+new Array(-n).join("0")+e:e.length>n+1?e.slice(0,n+1)+"."+e.slice(n+1):e+new Array(n-e.length+2).join("0")}var i={"%":(t,r)=>(100*t).toFixed(r),b:t=>Math.round(t).toString(2),c:t=>t+"",d:formatDecimal,e:(t,r)=>t.toExponential(r),f:(t,r)=>t.toFixed(r),g:(t,r)=>t.toPrecision(r),o:t=>Math.round(t).toString(8),p:(t,r)=>formatRounded(100*t,r),r:formatRounded,s:formatPrefixAuto,X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function identity(t){return t}var e=Array.prototype.map,n=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function formatLocale(t){var a=void 0===t.grouping||void 0===t.thousands?identity:formatGroup(e.call(t.grouping,Number),t.thousands+""),o=void 0===t.currency?"":t.currency[0]+"",c=void 0===t.currency?"":t.currency[1]+"",f=void 0===t.decimal?".":t.decimal+"",s=void 0===t.numerals?identity:formatNumerals(e.call(t.numerals,String)),m=void 0===t.percent?"%":t.percent+"",l=void 0===t.minus?"":t.minus+"",u=void 0===t.nan?"NaN":t.nan+"";function newFormat(t){t=formatSpecifier(t);var e=t.fill,h=t.align,p=t.sign,d=t.symbol,g=t.zero,v=t.width,x=t.comma,y=t.precision,M=t.trim,b=t.type;"n"===b?(x=true,b="g"):i[b]||(void 0===y&&(y=12),M=true,b="g");(g||"0"===e&&"="===h)&&(g=true,e="0",h="=");var w="$"===d?o:"#"===d&&/[boxX]/.test(b)?"0"+b.toLowerCase():"",S="$"===d?c:/[%p]/.test(b)?m:"";var P=i[b],F=/[defgprs%]/.test(b);y=void 0===y?6:/[gprs]/.test(b)?Math.max(1,Math.min(21,y)):Math.max(0,Math.min(20,y));function format(t){var i,o,c,m=w,d=S;if("c"===b){d=P(t)+d;t=""}else{t=+t;var k=t<0||1/t<0;t=isNaN(t)?u:P(Math.abs(t),y);M&&(t=formatTrim(t));k&&0===+t&&"+"!==p&&(k=false);m=(k?"("===p?p:l:"-"===p||"("===p?"":p)+m;d=("s"===b?n[8+r/3]:"")+d+(k&&"("===p?")":"");if(F){i=-1,o=t.length;while(++i<o)if(c=t.charCodeAt(i),48>c||c>57){d=(46===c?f+t.slice(i+1):t.slice(i))+d;t=t.slice(0,i);break}}}x&&!g&&(t=a(t,Infinity));var A=m.length+t.length+d.length,L=A<v?new Array(v-A+1).join(e):"";x&&g&&(t=a(L+t,L.length?v-d.length:Infinity),L="");switch(h){case"<":t=m+t+d+L;break;case"=":t=m+L+t+d;break;case"^":t=L.slice(0,A=L.length>>1)+m+t+d+L.slice(A);break;default:t=L+m+t+d;break}return s(t)}format.toString=function(){return t+""};return format}function formatPrefix(t,r){var i=newFormat((t=formatSpecifier(t),t.type="f",t)),e=3*Math.max(-8,Math.min(8,Math.floor(exponent(r)/3))),a=Math.pow(10,-e),o=n[8+e/3];return function(t){return i(a*t)+o}}return{format:newFormat,formatPrefix:formatPrefix}}var a;var o;var c;defaultLocale({thousands:",",grouping:[3],currency:["$",""]});function defaultLocale(t){a=formatLocale(t);o=a.format;c=a.formatPrefix;return a}function precisionFixed(t){return Math.max(0,-exponent(Math.abs(t)))}function precisionPrefix(t,r){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(exponent(r)/3)))-exponent(Math.abs(t)))}function precisionRound(t,r){t=Math.abs(t),r=Math.abs(r)-t;return Math.max(0,exponent(r)-exponent(t))+1}export{FormatSpecifier,o as format,defaultLocale as formatDefaultLocale,formatLocale,c as formatPrefix,formatSpecifier,precisionFixed,precisionPrefix,precisionRound};