package.dist.d3-scale.min.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of d3-scale Show documentation
Show all versions of d3-scale Show documentation
Encodings that map abstract data to visual representation.
The newest version!
// https://d3js.org/d3-scale/ v4.0.2 Copyright 2010-2021 Mike Bostock
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-array"),require("d3-interpolate"),require("d3-format"),require("d3-time"),require("d3-time-format")):"function"==typeof define&&define.amd?define(["exports","d3-array","d3-interpolate","d3-format","d3-time","d3-time-format"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).d3=n.d3||{},n.d3,n.d3,n.d3,n.d3,n.d3)}(this,(function(n,t,r,e,u,i){"use strict";function o(n,t){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(t).domain(n)}return this}function a(n,t){switch(arguments.length){case 0:break;case 1:"function"==typeof n?this.interpolator(n):this.range(n);break;default:this.domain(n),"function"==typeof t?this.interpolator(t):this.range(t)}return this}const c=Symbol("implicit");function l(){var n=new t.InternMap,r=[],e=[],u=c;function i(t){let i=n.get(t);if(void 0===i){if(u!==c)return u;n.set(t,i=r.push(t)-1)}return e[i%e.length]}return i.domain=function(e){if(!arguments.length)return r.slice();r=[],n=new t.InternMap;for(const t of e)n.has(t)||n.set(t,r.push(t)-1);return i},i.range=function(n){return arguments.length?(e=Array.from(n),i):e.slice()},i.unknown=function(n){return arguments.length?(u=n,i):u},i.copy=function(){return l(r,e).unknown(u)},o.apply(i,arguments),i}function f(){var n,r,e=l().unknown(void 0),u=e.domain,i=e.range,a=0,c=1,s=!1,p=0,h=0,g=.5;function m(){var e=u().length,o=ct&&(r=n,n=t,t=r),f=function(r){return Math.max(n,Math.min(t,r))}),u=e>2?y:d,i=o=null,m}function m(t){return null==t||isNaN(t=+t)?e:(i||(i=u(a.map(n),c,l)))(n(f(t)))}return m.invert=function(e){return f(t((o||(o=u(c,a.map(n),r.interpolateNumber)))(e)))},m.domain=function(n){return arguments.length?(a=Array.from(n,p),s()):a.slice()},m.range=function(n){return arguments.length?(c=Array.from(n),s()):c.slice()},m.rangeRound=function(n){return c=Array.from(n),l=r.interpolateRound,s()},m.clamp=function(n){return arguments.length?(f=!!n||g,s()):f!==g},m.interpolate=function(n){return arguments.length?(l=n,s()):l},m.unknown=function(n){return arguments.length?(e=n,m):e},function(r,e){return n=r,t=e,s()}}function k(){return M()(g,g)}function w(n,r,u,i){var o,a=t.tickStep(n,r,u);switch((i=e.formatSpecifier(null==i?",f":i)).type){case"s":var c=Math.max(Math.abs(n),Math.abs(r));return null!=i.precision||isNaN(o=e.precisionPrefix(a,c))||(i.precision=o),e.formatPrefix(i,c);case"":case"e":case"g":case"p":case"r":null!=i.precision||isNaN(o=e.precisionRound(a,Math.max(Math.abs(n),Math.abs(r))))||(i.precision=o-("e"===i.type));break;case"f":case"%":null!=i.precision||isNaN(o=e.precisionFixed(a))||(i.precision=o-2*("%"===i.type))}return e.format(i)}function N(n){var r=n.domain;return n.ticks=function(n){var e=r();return t.ticks(e[0],e[e.length-1],null==n?10:n)},n.tickFormat=function(n,t){var e=r();return w(e[0],e[e.length-1],null==n?10:n,t)},n.nice=function(e){null==e&&(e=10);var u,i,o=r(),a=0,c=o.length-1,l=o[a],f=o[c],s=10;for(f0;){if((i=t.tickIncrement(l,f,e))===u)return o[a]=l,o[c]=f,r(o);if(i>0)l=Math.floor(l/i)*i,f=Math.ceil(f/i)*i;else{if(!(i<0))break;l=Math.ceil(l*i)/i,f=Math.floor(f*i)/i}u=i}return n},n}function b(n,t){var r,e=0,u=(n=n.slice()).length-1,i=n[e],o=n[u];return o-n(-t,r)}function R(n){const r=n(x,q),u=r.domain;let i,o,a=10;function c(){return i=function(n){return n===Math.E?Math.log:10===n&&Math.log10||2===n&&Math.log2||(n=Math.log(n),t=>Math.log(t)/n)}(a),o=function(n){return 10===n?D:n===Math.E?Math.exp:t=>Math.pow(n,t)}(a),u()[0]<0?(i=I(i),o=I(o),n(S,A)):n(x,q),r}return r.base=function(n){return arguments.length?(a=+n,c()):a},r.domain=function(n){return arguments.length?(u(n),c()):u()},r.ticks=n=>{const r=u();let e=r[0],c=r[r.length-1];const l=c0){for(;p<=h;++p)for(f=1;fc)break;m.push(s)}}else for(;p<=h;++p)for(f=a-1;f>=1;--f)if(s=p>0?f/o(-p):f*o(p),!(sc)break;m.push(s)}2*m.length{if(null==n&&(n=10),null==t&&(t=10===a?"s":","),"function"!=typeof t&&(a%1||null!=(t=e.formatSpecifier(t)).precision||(t.trim=!0),t=e.format(t)),n===1/0)return t;const u=Math.max(1,a*n/r.ticks().length);return n=>{let r=n/o(Math.round(i(n)));return r*au(b(u(),{floor:n=>o(Math.floor(i(n))),ceil:n=>o(Math.ceil(i(n)))})),r}function T(n){return function(t){return Math.sign(t)*Math.log1p(Math.abs(t/n))}}function O(n){return function(t){return Math.sign(t)*Math.expm1(Math.abs(t))*n}}function F(n){var t=1,r=n(T(t),O(t));return r.constant=function(r){return arguments.length?n(T(t=+r),O(t)):t},N(r)}function P(n){return function(t){return t<0?-Math.pow(-t,n):Math.pow(t,n)}}function E(n){return n<0?-Math.sqrt(-n):Math.sqrt(n)}function L(n){return n<0?-n*n:n*n}function Q(n){var t=n(g,g),r=1;function e(){return 1===r?n(g,g):.5===r?n(E,L):n(P(r),P(1/r))}return t.exponent=function(n){return arguments.length?(r=+n,e()):r},N(t)}function U(){var n=Q(M());return n.copy=function(){return v(n,U()).exponent(n.exponent())},o.apply(n,arguments),n}function Y(n){return Math.sign(n)*n*n}function j(n){return Math.sign(n)*Math.sqrt(Math.abs(n))}function B(n){return new Date(n)}function C(n){return n instanceof Date?+n:+new Date(+n)}function H(n,t,r,e,u,i,o,a,c,l){var f=k(),s=f.invert,p=f.domain,h=l(".%L"),g=l(":%S"),m=l("%I:%M"),d=l("%I %p"),y=l("%a %d"),M=l("%b %d"),w=l("%B"),N=l("%Y");function x(n){return(c(n)v(t,n()).base(t.base()),o.apply(t,arguments),t},n.scaleOrdinal=l,n.scalePoint=function(){return s(f.apply(null,arguments).paddingInner(1))},n.scalePow=U,n.scaleQuantile=function n(){var r,e=[],u=[],i=[];function a(){var n=0,r=Math.max(1,u.length);for(i=new Array(r-1);++n0?i[t-1]:e[0],t=i?[a[i-1],u]:[a[t-1],a[t]]},l.unknown=function(n){return arguments.length?(r=n,l):l},l.thresholds=function(){return a.slice()},l.copy=function(){return n().domain([e,u]).range(c).unknown(r)},o.apply(N(l),arguments)},n.scaleRadial=function n(){var t,r=k(),e=[0,1],u=!1;function i(n){var e=j(r(n));return isNaN(e)?t:u?Math.round(e):e}return i.invert=function(n){return r.invert(Y(n))},i.domain=function(n){return arguments.length?(r.domain(n),i):r.domain()},i.range=function(n){return arguments.length?(r.range((e=Array.from(n,p)).map(Y)),i):e.slice()},i.rangeRound=function(n){return i.range(n).round(!0)},i.round=function(n){return arguments.length?(u=!!n,i):u},i.clamp=function(n){return arguments.length?(r.clamp(n),i):r.clamp()},i.unknown=function(n){return arguments.length?(t=n,i):t},i.copy=function(){return n(r.domain(),e).round(u).clamp(r.clamp()).unknown(t)},o.apply(i,arguments),N(i)},n.scaleSequential=function n(){var t=N(W()(g));return t.copy=function(){return _(t,n())},a.apply(t,arguments)},n.scaleSequentialLog=function n(){var t=R(W()).domain([1,10]);return t.copy=function(){return _(t,n()).base(t.base())},a.apply(t,arguments)},n.scaleSequentialPow=z,n.scaleSequentialQuantile=function n(){var r=[],e=g;function u(n){if(null!=n&&!isNaN(n=+n))return e((t.bisect(r,n,1)-1)/(r.length-1))}return u.domain=function(n){if(!arguments.length)return r.slice();r=[];for(let t of n)null==t||isNaN(t=+t)||r.push(t);return r.sort(t.ascending),u},u.interpolator=function(n){return arguments.length?(e=n,u):e},u.range=function(){return r.map(((n,t)=>e(t/(r.length-1))))},u.quantiles=function(n){return Array.from({length:n+1},((e,u)=>t.quantile(r,u/n)))},u.copy=function(){return n(e).domain(r)},a.apply(u,arguments)},n.scaleSequentialSqrt=function(){return z.apply(null,arguments).exponent(.5)},n.scaleSequentialSymlog=function n(){var t=F(W());return t.copy=function(){return _(t,n()).constant(t.constant())},a.apply(t,arguments)},n.scaleSqrt=function(){return U.apply(null,arguments).exponent(.5)},n.scaleSymlog=function n(){var t=F(M());return t.copy=function(){return v(t,n()).constant(t.constant())},o.apply(t,arguments)},n.scaleThreshold=function n(){var r,e=[.5],u=[0,1],i=1;function a(n){return null!=n&&n<=n?u[t.bisect(e,n,0,i)]:r}return a.domain=function(n){return arguments.length?(e=Array.from(n),i=Math.min(e.length,u.length-1),a):e.slice()},a.range=function(n){return arguments.length?(u=Array.from(n),i=Math.min(e.length,u.length-1),a):u.slice()},a.invertExtent=function(n){var t=u.indexOf(n);return[e[t-1],e[t]]},a.unknown=function(n){return arguments.length?(r=n,a):r},a.copy=function(){return n().domain(e).range(u).unknown(r)},o.apply(a,arguments)},n.scaleTime=function(){return o.apply(H(u.timeTicks,u.timeTickInterval,u.timeYear,u.timeMonth,u.timeWeek,u.timeDay,u.timeHour,u.timeMinute,u.timeSecond,i.timeFormat).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)},n.scaleUtc=function(){return o.apply(H(u.utcTicks,u.utcTickInterval,u.utcYear,u.utcMonth,u.utcWeek,u.utcDay,u.utcHour,u.utcMinute,u.utcSecond,i.utcFormat).domain([Date.UTC(2e3,0,1),Date.UTC(2e3,0,2)]),arguments)},n.tickFormat=w,Object.defineProperty(n,"__esModule",{value:!0})}));