mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-18 20:59:39 +02:00
* Enhance cash flow dashboard with new cash flow period handling and improved Sankey diagram rendering. Update D3 and related dependencies for better performance and features. * Fix Rubocop offenses * Refactor Sankey chart controller to use Number.parseFloat for value formatting and improve code readability by restructuring conditional logic for node shapes.
4 lines
18 KiB
JavaScript
4 lines
18 KiB
JavaScript
// d3-scale@4.0.2 downloaded from https://ga.jspm.io/npm:d3-scale@4.0.2/src/index.js
|
|
|
|
import{InternMap as n,range as e,bisect as t,tickStep as r,ticks as a,tickIncrement as i,quantileSorted as o,ascending as l,quantile as u}from"d3-array";import{interpolate as c,interpolateNumber as s,interpolateRound as f,piecewise as g}from"d3-interpolate";import{formatSpecifier as p,precisionFixed as h,precisionRound as m,precisionPrefix as d,formatPrefix as y,format as v}from"d3-format";import{timeTicks as w,timeTickInterval as M,timeYear as q,timeMonth as k,timeWeek as b,timeDay as x,timeHour as $,timeMinute as N,timeSecond as S,utcTicks as I,utcTickInterval as R,utcYear as A,utcMonth as L,utcWeek as P,utcDay as D,utcHour as E,utcMinute as F,utcSecond as z}from"d3-time";import{timeFormat as O,utcFormat as Q}from"d3-time-format";function initRange(n,e){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(e).domain(n);break}return this}function initInterpolator(n,e){switch(arguments.length){case 0:break;case 1:"function"===typeof n?this.interpolator(n):this.range(n);break;default:this.domain(n);"function"===typeof e?this.interpolator(e):this.range(e);break}return this}const T=Symbol("implicit");function ordinal(){var e=new n,t=[],r=[],a=T;function scale(n){let i=e.get(n);if(void 0===i){if(a!==T)return a;e.set(n,i=t.push(n)-1)}return r[i%r.length]}scale.domain=function(r){if(!arguments.length)return t.slice();t=[],e=new n;for(const n of r)e.has(n)||e.set(n,t.push(n)-1);return scale};scale.range=function(n){return arguments.length?(r=Array.from(n),scale):r.slice()};scale.unknown=function(n){return arguments.length?(a=n,scale):a};scale.copy=function(){return ordinal(t,r).unknown(a)};initRange.apply(scale,arguments);return scale}function band(){var n,t,r=ordinal().unknown(void 0),a=r.domain,i=r.range,o=0,l=1,u=false,c=0,s=0,f=.5;delete r.unknown;function rescale(){var r=a().length,g=l<o,p=g?l:o,h=g?o:l;n=(h-p)/Math.max(1,r-c+2*s);u&&(n=Math.floor(n));p+=(h-p-n*(r-c))*f;t=n*(1-c);u&&(p=Math.round(p),t=Math.round(t));var m=e(r).map((function(e){return p+n*e}));return i(g?m.reverse():m)}r.domain=function(n){return arguments.length?(a(n),rescale()):a()};r.range=function(n){return arguments.length?([o,l]=n,o=+o,l=+l,rescale()):[o,l]};r.rangeRound=function(n){return[o,l]=n,o=+o,l=+l,u=true,rescale()};r.bandwidth=function(){return t};r.step=function(){return n};r.round=function(n){return arguments.length?(u=!!n,rescale()):u};r.padding=function(n){return arguments.length?(c=Math.min(1,s=+n),rescale()):c};r.paddingInner=function(n){return arguments.length?(c=Math.min(1,n),rescale()):c};r.paddingOuter=function(n){return arguments.length?(s=+n,rescale()):s};r.align=function(n){return arguments.length?(f=Math.max(0,Math.min(1,n)),rescale()):f};r.copy=function(){return band(a(),[o,l]).round(u).paddingInner(c).paddingOuter(s).align(f)};return initRange.apply(rescale(),arguments)}function pointish(n){var e=n.copy;n.padding=n.paddingOuter;delete n.paddingInner;delete n.paddingOuter;n.copy=function(){return pointish(e())};return n}function point(){return pointish(band.apply(null,arguments).paddingInner(1))}function constants(n){return function(){return n}}function number$1(n){return+n}var U=[0,1];function identity$1(n){return n}function normalize(n,e){return(e-=n=+n)?function(t){return(t-n)/e}:constants(isNaN(e)?NaN:.5)}function clamper(n,e){var t;n>e&&(t=n,n=e,e=t);return function(t){return Math.max(n,Math.min(e,t))}}function bimap(n,e,t){var r=n[0],a=n[1],i=e[0],o=e[1];a<r?(r=normalize(a,r),i=t(o,i)):(r=normalize(r,a),i=t(i,o));return function(n){return i(r(n))}}function polymap(n,e,r){var a=Math.min(n.length,e.length)-1,i=new Array(a),o=new Array(a),l=-1;if(n[a]<n[0]){n=n.slice().reverse();e=e.slice().reverse()}while(++l<a){i[l]=normalize(n[l],n[l+1]);o[l]=r(e[l],e[l+1])}return function(e){var r=t(n,e,1,a)-1;return o[r](i[r](e))}}function copy$1(n,e){return e.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function transformer$2(){var n,e,t,r,a,i,o=U,l=U,u=c,g=identity$1;function rescale(){var n=Math.min(o.length,l.length);g!==identity$1&&(g=clamper(o[0],o[n-1]));r=n>2?polymap:bimap;a=i=null;return scale}function scale(e){return null==e||isNaN(e=+e)?t:(a||(a=r(o.map(n),l,u)))(n(g(e)))}scale.invert=function(t){return g(e((i||(i=r(l,o.map(n),s)))(t)))};scale.domain=function(n){return arguments.length?(o=Array.from(n,number$1),rescale()):o.slice()};scale.range=function(n){return arguments.length?(l=Array.from(n),rescale()):l.slice()};scale.rangeRound=function(n){return l=Array.from(n),u=f,rescale()};scale.clamp=function(n){return arguments.length?(g=!!n||identity$1,rescale()):g!==identity$1};scale.interpolate=function(n){return arguments.length?(u=n,rescale()):u};scale.unknown=function(n){return arguments.length?(t=n,scale):t};return function(t,r){n=t,e=r;return rescale()}}function continuous(){return transformer$2()(identity$1,identity$1)}function tickFormat(n,e,t,a){var i,o=r(n,e,t);a=p(null==a?",f":a);switch(a.type){case"s":var l=Math.max(Math.abs(n),Math.abs(e));null!=a.precision||isNaN(i=d(o,l))||(a.precision=i);return y(a,l);case"":case"e":case"g":case"p":case"r":null!=a.precision||isNaN(i=m(o,Math.max(Math.abs(n),Math.abs(e))))||(a.precision=i-("e"===a.type));break;case"f":case"%":null!=a.precision||isNaN(i=h(o))||(a.precision=i-2*("%"===a.type));break}return v(a)}function linearish(n){var e=n.domain;n.ticks=function(n){var t=e();return a(t[0],t[t.length-1],null==n?10:n)};n.tickFormat=function(n,t){var r=e();return tickFormat(r[0],r[r.length-1],null==n?10:n,t)};n.nice=function(t){null==t&&(t=10);var r=e();var a=0;var o=r.length-1;var l=r[a];var u=r[o];var c;var s;var f=10;if(u<l){s=l,l=u,u=s;s=a,a=o,o=s}while(f-- >0){s=i(l,u,t);if(s===c){r[a]=l;r[o]=u;return e(r)}if(s>0){l=Math.floor(l/s)*s;u=Math.ceil(u/s)*s}else{if(!(s<0))break;l=Math.ceil(l*s)/s;u=Math.floor(u*s)/s}c=s}return n};return n}function linear(){var n=continuous();n.copy=function(){return copy$1(n,linear())};initRange.apply(n,arguments);return linearish(n)}function identity(n){var e;function scale(n){return null==n||isNaN(n=+n)?e:n}scale.invert=scale;scale.domain=scale.range=function(e){return arguments.length?(n=Array.from(e,number$1),scale):n.slice()};scale.unknown=function(n){return arguments.length?(e=n,scale):e};scale.copy=function(){return identity(n).unknown(e)};n=arguments.length?Array.from(n,number$1):[0,1];return linearish(scale)}function nice(n,e){n=n.slice();var t,r=0,a=n.length-1,i=n[r],o=n[a];if(o<i){t=r,r=a,a=t;t=i,i=o,o=t}n[r]=e.floor(i);n[a]=e.ceil(o);return n}function transformLog(n){return Math.log(n)}function transformExp(n){return Math.exp(n)}function transformLogn(n){return-Math.log(-n)}function transformExpn(n){return-Math.exp(-n)}function pow10(n){return isFinite(n)?+("1e"+n):n<0?0:n}function powp(n){return 10===n?pow10:n===Math.E?Math.exp:e=>Math.pow(n,e)}function logp(n){return n===Math.E?Math.log:10===n&&Math.log10||2===n&&Math.log2||(n=Math.log(n),e=>Math.log(e)/n)}function reflect(n){return(e,t)=>-n(-e,t)}function loggish(n){const e=n(transformLog,transformExp);const t=e.domain;let r=10;let i;let o;function rescale(){i=logp(r),o=powp(r);if(t()[0]<0){i=reflect(i),o=reflect(o);n(transformLogn,transformExpn)}else n(transformLog,transformExp);return e}e.base=function(n){return arguments.length?(r=+n,rescale()):r};e.domain=function(n){return arguments.length?(t(n),rescale()):t()};e.ticks=n=>{const e=t();let l=e[0];let u=e[e.length-1];const c=u<l;c&&([l,u]=[u,l]);let s=i(l);let f=i(u);let g;let p;const h=null==n?10:+n;let m=[];if(!(r%1)&&f-s<h){s=Math.floor(s),f=Math.ceil(f);if(l>0)for(;s<=f;++s)for(g=1;g<r;++g){p=s<0?g/o(-s):g*o(s);if(!(p<l)){if(p>u)break;m.push(p)}}else for(;s<=f;++s)for(g=r-1;g>=1;--g){p=s>0?g/o(-s):g*o(s);if(!(p<l)){if(p>u)break;m.push(p)}}2*m.length<h&&(m=a(l,u,h))}else m=a(s,f,Math.min(f-s,h)).map(o);return c?m.reverse():m};e.tickFormat=(n,t)=>{null==n&&(n=10);null==t&&(t=10===r?"s":",");if("function"!==typeof t){r%1||null!=(t=p(t)).precision||(t.trim=true);t=v(t)}if(Infinity===n)return t;const a=Math.max(1,r*n/e.ticks().length);return n=>{let e=n/o(Math.round(i(n)));e*r<r-.5&&(e*=r);return e<=a?t(n):""}};e.nice=()=>t(nice(t(),{floor:n=>o(Math.floor(i(n))),ceil:n=>o(Math.ceil(i(n)))}));return e}function log(){const n=loggish(transformer$2()).domain([1,10]);n.copy=()=>copy$1(n,log()).base(n.base());initRange.apply(n,arguments);return n}function transformSymlog(n){return function(e){return Math.sign(e)*Math.log1p(Math.abs(e/n))}}function transformSymexp(n){return function(e){return Math.sign(e)*Math.expm1(Math.abs(e))*n}}function symlogish(n){var e=1,t=n(transformSymlog(e),transformSymexp(e));t.constant=function(t){return arguments.length?n(transformSymlog(e=+t),transformSymexp(e)):e};return linearish(t)}function symlog(){var n=symlogish(transformer$2());n.copy=function(){return copy$1(n,symlog()).constant(n.constant())};return initRange.apply(n,arguments)}function transformPow(n){return function(e){return e<0?-Math.pow(-e,n):Math.pow(e,n)}}function transformSqrt(n){return n<0?-Math.sqrt(-n):Math.sqrt(n)}function transformSquare(n){return n<0?-n*n:n*n}function powish(n){var e=n(identity$1,identity$1),t=1;function rescale(){return 1===t?n(identity$1,identity$1):.5===t?n(transformSqrt,transformSquare):n(transformPow(t),transformPow(1/t))}e.exponent=function(n){return arguments.length?(t=+n,rescale()):t};return linearish(e)}function pow(){var n=powish(transformer$2());n.copy=function(){return copy$1(n,pow()).exponent(n.exponent())};initRange.apply(n,arguments);return n}function sqrt(){return pow.apply(null,arguments).exponent(.5)}function square(n){return Math.sign(n)*n*n}function unsquare(n){return Math.sign(n)*Math.sqrt(Math.abs(n))}function radial(){var n,e=continuous(),t=[0,1],r=false;function scale(t){var a=unsquare(e(t));return isNaN(a)?n:r?Math.round(a):a}scale.invert=function(n){return e.invert(square(n))};scale.domain=function(n){return arguments.length?(e.domain(n),scale):e.domain()};scale.range=function(n){return arguments.length?(e.range((t=Array.from(n,number$1)).map(square)),scale):t.slice()};scale.rangeRound=function(n){return scale.range(n).round(true)};scale.round=function(n){return arguments.length?(r=!!n,scale):r};scale.clamp=function(n){return arguments.length?(e.clamp(n),scale):e.clamp()};scale.unknown=function(e){return arguments.length?(n=e,scale):n};scale.copy=function(){return radial(e.domain(),t).round(r).clamp(e.clamp()).unknown(n)};initRange.apply(scale,arguments);return linearish(scale)}function quantile(){var n,e=[],r=[],a=[];function rescale(){var n=0,t=Math.max(1,r.length);a=new Array(t-1);while(++n<t)a[n-1]=o(e,n/t);return scale}function scale(e){return null==e||isNaN(e=+e)?n:r[t(a,e)]}scale.invertExtent=function(n){var t=r.indexOf(n);return t<0?[NaN,NaN]:[t>0?a[t-1]:e[0],t<a.length?a[t]:e[e.length-1]]};scale.domain=function(n){if(!arguments.length)return e.slice();e=[];for(let t of n)null==t||isNaN(t=+t)||e.push(t);e.sort(l);return rescale()};scale.range=function(n){return arguments.length?(r=Array.from(n),rescale()):r.slice()};scale.unknown=function(e){return arguments.length?(n=e,scale):n};scale.quantiles=function(){return a.slice()};scale.copy=function(){return quantile().domain(e).range(r).unknown(n)};return initRange.apply(scale,arguments)}function quantize(){var n,e=0,r=1,a=1,i=[.5],o=[0,1];function scale(e){return null!=e&&e<=e?o[t(i,e,0,a)]:n}function rescale(){var n=-1;i=new Array(a);while(++n<a)i[n]=((n+1)*r-(n-a)*e)/(a+1);return scale}scale.domain=function(n){return arguments.length?([e,r]=n,e=+e,r=+r,rescale()):[e,r]};scale.range=function(n){return arguments.length?(a=(o=Array.from(n)).length-1,rescale()):o.slice()};scale.invertExtent=function(n){var t=o.indexOf(n);return t<0?[NaN,NaN]:t<1?[e,i[0]]:t>=a?[i[a-1],r]:[i[t-1],i[t]]};scale.unknown=function(e){return arguments.length?(n=e,scale):scale};scale.thresholds=function(){return i.slice()};scale.copy=function(){return quantize().domain([e,r]).range(o).unknown(n)};return initRange.apply(linearish(scale),arguments)}function threshold(){var n,e=[.5],r=[0,1],a=1;function scale(i){return null!=i&&i<=i?r[t(e,i,0,a)]:n}scale.domain=function(n){return arguments.length?(e=Array.from(n),a=Math.min(e.length,r.length-1),scale):e.slice()};scale.range=function(n){return arguments.length?(r=Array.from(n),a=Math.min(e.length,r.length-1),scale):r.slice()};scale.invertExtent=function(n){var t=r.indexOf(n);return[e[t-1],e[t]]};scale.unknown=function(e){return arguments.length?(n=e,scale):n};scale.copy=function(){return threshold().domain(e).range(r).unknown(n)};return initRange.apply(scale,arguments)}function date(n){return new Date(n)}function number(n){return n instanceof Date?+n:+new Date(+n)}function calendar(n,e,t,r,a,i,o,l,u,c){var s=continuous(),f=s.invert,g=s.domain;var p=c(".%L"),h=c(":%S"),m=c("%I:%M"),d=c("%I %p"),y=c("%a %d"),v=c("%b %d"),w=c("%B"),M=c("%Y");function tickFormat(n){return(u(n)<n?p:l(n)<n?h:o(n)<n?m:i(n)<n?d:r(n)<n?a(n)<n?y:v:t(n)<n?w:M)(n)}s.invert=function(n){return new Date(f(n))};s.domain=function(n){return arguments.length?g(Array.from(n,number)):g().map(date)};s.ticks=function(e){var t=g();return n(t[0],t[t.length-1],null==e?10:e)};s.tickFormat=function(n,e){return null==e?tickFormat:c(e)};s.nice=function(n){var t=g();n&&"function"===typeof n.range||(n=e(t[0],t[t.length-1],null==n?10:n));return n?g(nice(t,n)):s};s.copy=function(){return copy$1(s,calendar(n,e,t,r,a,i,o,l,u,c))};return s}function time(){return initRange.apply(calendar(w,M,q,k,b,x,$,N,S,O).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}function utcTime(){return initRange.apply(calendar(I,R,A,L,P,D,E,F,z,Q).domain([Date.UTC(2e3,0,1),Date.UTC(2e3,0,2)]),arguments)}function transformer$1(){var n,e,t,r,a,i=0,o=1,l=identity$1,u=false;function scale(e){return null==e||isNaN(e=+e)?a:l(0===t?.5:(e=(r(e)-n)*t,u?Math.max(0,Math.min(1,e)):e))}scale.domain=function(a){return arguments.length?([i,o]=a,n=r(i=+i),e=r(o=+o),t=n===e?0:1/(e-n),scale):[i,o]};scale.clamp=function(n){return arguments.length?(u=!!n,scale):u};scale.interpolator=function(n){return arguments.length?(l=n,scale):l};function range(n){return function(e){var t,r;return arguments.length?([t,r]=e,l=n(t,r),scale):[l(0),l(1)]}}scale.range=range(c);scale.rangeRound=range(f);scale.unknown=function(n){return arguments.length?(a=n,scale):a};return function(a){r=a,n=a(i),e=a(o),t=n===e?0:1/(e-n);return scale}}function copy(n,e){return e.domain(n.domain()).interpolator(n.interpolator()).clamp(n.clamp()).unknown(n.unknown())}function sequential(){var n=linearish(transformer$1()(identity$1));n.copy=function(){return copy(n,sequential())};return initInterpolator.apply(n,arguments)}function sequentialLog(){var n=loggish(transformer$1()).domain([1,10]);n.copy=function(){return copy(n,sequentialLog()).base(n.base())};return initInterpolator.apply(n,arguments)}function sequentialSymlog(){var n=symlogish(transformer$1());n.copy=function(){return copy(n,sequentialSymlog()).constant(n.constant())};return initInterpolator.apply(n,arguments)}function sequentialPow(){var n=powish(transformer$1());n.copy=function(){return copy(n,sequentialPow()).exponent(n.exponent())};return initInterpolator.apply(n,arguments)}function sequentialSqrt(){return sequentialPow.apply(null,arguments).exponent(.5)}function sequentialQuantile(){var n=[],e=identity$1;function scale(r){if(null!=r&&!isNaN(r=+r))return e((t(n,r,1)-1)/(n.length-1))}scale.domain=function(e){if(!arguments.length)return n.slice();n=[];for(let t of e)null==t||isNaN(t=+t)||n.push(t);n.sort(l);return scale};scale.interpolator=function(n){return arguments.length?(e=n,scale):e};scale.range=function(){return n.map(((t,r)=>e(r/(n.length-1))))};scale.quantiles=function(e){return Array.from({length:e+1},((t,r)=>u(n,r/e)))};scale.copy=function(){return sequentialQuantile(e).domain(n)};return initInterpolator.apply(scale,arguments)}function transformer(){var n,e,t,r,a,i,o,l=0,u=.5,s=1,p=1,h=identity$1,m=false;function scale(n){return isNaN(n=+n)?o:(n=.5+((n=+i(n))-e)*(p*n<p*e?r:a),h(m?Math.max(0,Math.min(1,n)):n))}scale.domain=function(o){return arguments.length?([l,u,s]=o,n=i(l=+l),e=i(u=+u),t=i(s=+s),r=n===e?0:.5/(e-n),a=e===t?0:.5/(t-e),p=e<n?-1:1,scale):[l,u,s]};scale.clamp=function(n){return arguments.length?(m=!!n,scale):m};scale.interpolator=function(n){return arguments.length?(h=n,scale):h};function range(n){return function(e){var t,r,a;return arguments.length?([t,r,a]=e,h=g(n,[t,r,a]),scale):[h(0),h(.5),h(1)]}}scale.range=range(c);scale.rangeRound=range(f);scale.unknown=function(n){return arguments.length?(o=n,scale):o};return function(o){i=o,n=o(l),e=o(u),t=o(s),r=n===e?0:.5/(e-n),a=e===t?0:.5/(t-e),p=e<n?-1:1;return scale}}function diverging(){var n=linearish(transformer()(identity$1));n.copy=function(){return copy(n,diverging())};return initInterpolator.apply(n,arguments)}function divergingLog(){var n=loggish(transformer()).domain([.1,1,10]);n.copy=function(){return copy(n,divergingLog()).base(n.base())};return initInterpolator.apply(n,arguments)}function divergingSymlog(){var n=symlogish(transformer());n.copy=function(){return copy(n,divergingSymlog()).constant(n.constant())};return initInterpolator.apply(n,arguments)}function divergingPow(){var n=powish(transformer());n.copy=function(){return copy(n,divergingPow()).exponent(n.exponent())};return initInterpolator.apply(n,arguments)}function divergingSqrt(){return divergingPow.apply(null,arguments).exponent(.5)}export{band as scaleBand,diverging as scaleDiverging,divergingLog as scaleDivergingLog,divergingPow as scaleDivergingPow,divergingSqrt as scaleDivergingSqrt,divergingSymlog as scaleDivergingSymlog,identity as scaleIdentity,T as scaleImplicit,linear as scaleLinear,log as scaleLog,ordinal as scaleOrdinal,point as scalePoint,pow as scalePow,quantile as scaleQuantile,quantize as scaleQuantize,radial as scaleRadial,sequential as scaleSequential,sequentialLog as scaleSequentialLog,sequentialPow as scaleSequentialPow,sequentialQuantile as scaleSequentialQuantile,sequentialSqrt as scaleSequentialSqrt,sequentialSymlog as scaleSequentialSymlog,sqrt as scaleSqrt,symlog as scaleSymlog,threshold as scaleThreshold,time as scaleTime,utcTime as scaleUtc,tickFormat};
|
|
|