Comparing version 2.1.2 to 2.2.0
@@ -1,8 +0,26 @@ | ||
// https://d3js.org/d3-scale/ v2.1.2 Copyright 2018 Mike Bostock | ||
// https://d3js.org/d3-scale/ v2.2.0 Copyright 2019 Mike Bostock | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-collection'), require('d3-array'), require('d3-interpolate'), require('d3-format'), require('d3-time'), require('d3-time-format')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-collection', 'd3-array', 'd3-interpolate', 'd3-format', 'd3-time', 'd3-time-format'], factory) : | ||
(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3,global.d3,global.d3,global.d3)); | ||
}(this, (function (exports,d3Collection,d3Array,d3Interpolate,d3Format,d3Time,d3TimeFormat) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('d3-interpolate'), require('d3-format'), require('d3-time'), require('d3-time-format')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-array', 'd3-interpolate', 'd3-format', 'd3-time', 'd3-time-format'], factory) : | ||
(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3,global.d3,global.d3)); | ||
}(this, (function (exports,d3Array,d3Interpolate,d3Format,d3Time,d3TimeFormat) { 'use strict'; | ||
function initRange(domain, range) { | ||
switch (arguments.length) { | ||
case 0: break; | ||
case 1: this.range(domain); break; | ||
default: this.range(range).domain(domain); break; | ||
} | ||
return this; | ||
} | ||
function initInterpolator(domain, interpolator) { | ||
switch (arguments.length) { | ||
case 0: break; | ||
case 1: this.interpolator(domain); break; | ||
default: this.interpolator(interpolator).domain(domain); break; | ||
} | ||
return this; | ||
} | ||
var array = Array.prototype; | ||
@@ -15,9 +33,8 @@ | ||
function ordinal(range) { | ||
var index = d3Collection.map(), | ||
function ordinal() { | ||
var index = new Map, | ||
domain = [], | ||
range = [], | ||
unknown = implicit; | ||
range = range == null ? [] : slice.call(range); | ||
function scale(d) { | ||
@@ -34,3 +51,3 @@ var key = d + "", i = index.get(key); | ||
if (!arguments.length) return domain.slice(); | ||
domain = [], index = d3Collection.map(); | ||
domain = [], index = new Map(); | ||
var i = -1, n = _.length, d, key; | ||
@@ -50,8 +67,7 @@ while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d)); | ||
scale.copy = function() { | ||
return ordinal() | ||
.domain(domain) | ||
.range(range) | ||
.unknown(unknown); | ||
return ordinal(domain, range).unknown(unknown); | ||
}; | ||
initRange.apply(scale, arguments); | ||
return scale; | ||
@@ -113,11 +129,11 @@ } | ||
scale.padding = function(_) { | ||
return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner; | ||
return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner; | ||
}; | ||
scale.paddingInner = function(_) { | ||
return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner; | ||
return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner; | ||
}; | ||
scale.paddingOuter = function(_) { | ||
return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter; | ||
return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter; | ||
}; | ||
@@ -130,5 +146,3 @@ | ||
scale.copy = function() { | ||
return band() | ||
.domain(domain()) | ||
.range(range) | ||
return band(domain(), range) | ||
.round(round) | ||
@@ -140,3 +154,3 @@ .paddingInner(paddingInner) | ||
return rescale(); | ||
return initRange.apply(rescale(), arguments); | ||
} | ||
@@ -159,3 +173,3 @@ | ||
function point() { | ||
return pointish(band().paddingInner(1)); | ||
return pointish(band.apply(null, arguments).paddingInner(1)); | ||
} | ||
@@ -175,30 +189,28 @@ | ||
function deinterpolateLinear(a, b) { | ||
function identity(x) { | ||
return x; | ||
} | ||
function normalize(a, b) { | ||
return (b -= (a = +a)) | ||
? function(x) { return (x - a) / b; } | ||
: constant(b); | ||
: constant(isNaN(b) ? NaN : 0.5); | ||
} | ||
function deinterpolateClamp(deinterpolate) { | ||
return function(a, b) { | ||
var d = deinterpolate(a = +a, b = +b); | ||
return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); }; | ||
}; | ||
function clamper(domain) { | ||
var a = domain[0], b = domain[domain.length - 1], t; | ||
if (a > b) t = a, a = b, b = t; | ||
return function(x) { return Math.max(a, Math.min(b, x)); }; | ||
} | ||
function reinterpolateClamp(reinterpolate) { | ||
return function(a, b) { | ||
var r = reinterpolate(a = +a, b = +b); | ||
return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); }; | ||
}; | ||
} | ||
function bimap(domain, range, deinterpolate, reinterpolate) { | ||
// normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1]. | ||
// interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b]. | ||
function bimap(domain, range, interpolate) { | ||
var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1]; | ||
if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0); | ||
else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1); | ||
if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0); | ||
else d0 = normalize(d0, d1), r0 = interpolate(r0, r1); | ||
return function(x) { return r0(d0(x)); }; | ||
} | ||
function polymap(domain, range, deinterpolate, reinterpolate) { | ||
function polymap(domain, range, interpolate) { | ||
var j = Math.min(domain.length, range.length) - 1, | ||
@@ -216,4 +228,4 @@ d = new Array(j), | ||
while (++i < j) { | ||
d[i] = deinterpolate(domain[i], domain[i + 1]); | ||
r[i] = reinterpolate(range[i], range[i + 1]); | ||
d[i] = normalize(domain[i], domain[i + 1]); | ||
r[i] = interpolate(range[i], range[i + 1]); | ||
} | ||
@@ -232,12 +244,14 @@ | ||
.interpolate(source.interpolate()) | ||
.clamp(source.clamp()); | ||
.clamp(source.clamp()) | ||
.unknown(source.unknown()); | ||
} | ||
// deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1]. | ||
// reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b]. | ||
function continuous(deinterpolate, reinterpolate) { | ||
function transformer() { | ||
var domain = unit, | ||
range = unit, | ||
interpolate = d3Interpolate.interpolate, | ||
clamp = false, | ||
transform, | ||
untransform, | ||
unknown, | ||
clamp = identity, | ||
piecewise, | ||
@@ -254,11 +268,11 @@ output, | ||
function scale(x) { | ||
return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate)))(+x); | ||
return isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x))); | ||
} | ||
scale.invert = function(y) { | ||
return (input || (input = piecewise(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y); | ||
return clamp(untransform((input || (input = piecewise(range, domain.map(transform), d3Interpolate.interpolateNumber)))(y))); | ||
}; | ||
scale.domain = function(_) { | ||
return arguments.length ? (domain = map.call(_, number), rescale()) : domain.slice(); | ||
return arguments.length ? (domain = map.call(_, number), clamp === identity || (clamp = clamper(domain)), rescale()) : domain.slice(); | ||
}; | ||
@@ -275,3 +289,3 @@ | ||
scale.clamp = function(_) { | ||
return arguments.length ? (clamp = !!_, rescale()) : clamp; | ||
return arguments.length ? (clamp = _ ? clamper(domain) : identity, scale) : clamp !== identity; | ||
}; | ||
@@ -283,9 +297,18 @@ | ||
return rescale(); | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
return function(t, u) { | ||
transform = t, untransform = u; | ||
return rescale(); | ||
}; | ||
} | ||
function tickFormat(domain, count, specifier) { | ||
var start = domain[0], | ||
stop = domain[domain.length - 1], | ||
step = d3Array.tickStep(start, stop, count == null ? 10 : count), | ||
function continuous(transform, untransform) { | ||
return transformer()(transform, untransform); | ||
} | ||
function tickFormat(start, stop, count, specifier) { | ||
var step = d3Array.tickStep(start, stop, count), | ||
precision; | ||
@@ -325,3 +348,4 @@ specifier = d3Format.formatSpecifier(specifier == null ? ",f" : specifier); | ||
scale.tickFormat = function(count, specifier) { | ||
return tickFormat(domain(), count, specifier); | ||
var d = domain(); | ||
return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier); | ||
}; | ||
@@ -373,3 +397,3 @@ | ||
function linear() { | ||
var scale = continuous(deinterpolateLinear, d3Interpolate.interpolateNumber); | ||
var scale = continuous(identity, identity); | ||
@@ -380,10 +404,12 @@ scale.copy = function() { | ||
initRange.apply(scale, arguments); | ||
return linearish(scale); | ||
} | ||
function identity() { | ||
var domain = [0, 1]; | ||
function identity$1(domain) { | ||
var unknown; | ||
function scale(x) { | ||
return +x; | ||
return isNaN(x = +x) ? unknown : x; | ||
} | ||
@@ -397,6 +423,12 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
scale.copy = function() { | ||
return identity().domain(domain); | ||
return identity$1(domain).unknown(unknown); | ||
}; | ||
domain = arguments.length ? map.call(domain, number) : [0, 1]; | ||
return linearish(scale); | ||
@@ -424,14 +456,18 @@ } | ||
function deinterpolate(a, b) { | ||
return (b = Math.log(b / a)) | ||
? function(x) { return Math.log(x / a) / b; } | ||
: constant(b); | ||
function transformLog(x) { | ||
return Math.log(x); | ||
} | ||
function reinterpolate(a, b) { | ||
return a < 0 | ||
? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); } | ||
: function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); }; | ||
function transformExp(x) { | ||
return Math.exp(x); | ||
} | ||
function transformLogn(x) { | ||
return -Math.log(-x); | ||
} | ||
function transformExpn(x) { | ||
return -Math.exp(-x); | ||
} | ||
function pow10(x) { | ||
@@ -460,12 +496,17 @@ return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x; | ||
function log() { | ||
var scale = continuous(deinterpolate, reinterpolate).domain([1, 10]), | ||
function loggish(transform) { | ||
var scale = transform(transformLog, transformExp), | ||
domain = scale.domain, | ||
base = 10, | ||
logs = logp(10), | ||
pows = powp(10); | ||
logs, | ||
pows; | ||
function rescale() { | ||
logs = logp(base), pows = powp(base); | ||
if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows); | ||
if (domain()[0] < 0) { | ||
logs = reflect(logs), pows = reflect(pows); | ||
transform(transformLogn, transformExpn); | ||
} else { | ||
transform(transformLog, transformExp); | ||
} | ||
return scale; | ||
@@ -542,42 +583,94 @@ } | ||
return scale; | ||
} | ||
function log() { | ||
var scale = loggish(transformer()).domain([1, 10]); | ||
scale.copy = function() { | ||
return copy(scale, log().base(base)); | ||
return copy(scale, log()).base(scale.base()); | ||
}; | ||
initRange.apply(scale, arguments); | ||
return scale; | ||
} | ||
function raise(x, exponent) { | ||
return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent); | ||
function transformSymlog(c) { | ||
return function(x) { | ||
return Math.sign(x) * Math.log1p(Math.abs(x / c)); | ||
}; | ||
} | ||
function pow() { | ||
var exponent = 1, | ||
scale = continuous(deinterpolate, reinterpolate), | ||
domain = scale.domain; | ||
function transformSymexp(c) { | ||
return function(x) { | ||
return Math.sign(x) * Math.expm1(Math.abs(x)) * c; | ||
}; | ||
} | ||
function deinterpolate(a, b) { | ||
return (b = raise(b, exponent) - (a = raise(a, exponent))) | ||
? function(x) { return (raise(x, exponent) - a) / b; } | ||
: constant(b); | ||
} | ||
function symlogish(transform) { | ||
var c = 1, scale = transform(transformSymlog(c), transformSymexp(c)); | ||
function reinterpolate(a, b) { | ||
b = raise(b, exponent) - (a = raise(a, exponent)); | ||
return function(t) { return raise(a + b * t, 1 / exponent); }; | ||
scale.constant = function(_) { | ||
return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c; | ||
}; | ||
return linearish(scale); | ||
} | ||
function symlog() { | ||
var scale = symlogish(transformer()); | ||
scale.copy = function() { | ||
return copy(scale, symlog()).constant(scale.constant()); | ||
}; | ||
return initRange.apply(scale, arguments); | ||
} | ||
function transformPow(exponent) { | ||
return function(x) { | ||
return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent); | ||
}; | ||
} | ||
function transformSqrt(x) { | ||
return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x); | ||
} | ||
function transformSquare(x) { | ||
return x < 0 ? -x * x : x * x; | ||
} | ||
function powish(transform) { | ||
var scale = transform(identity, identity), | ||
exponent = 1; | ||
function rescale() { | ||
return exponent === 1 ? transform(identity, identity) | ||
: exponent === 0.5 ? transform(transformSqrt, transformSquare) | ||
: transform(transformPow(exponent), transformPow(1 / exponent)); | ||
} | ||
scale.exponent = function(_) { | ||
return arguments.length ? (exponent = +_, domain(domain())) : exponent; | ||
return arguments.length ? (exponent = +_, rescale()) : exponent; | ||
}; | ||
return linearish(scale); | ||
} | ||
function pow() { | ||
var scale = powish(transformer()); | ||
scale.copy = function() { | ||
return copy(scale, pow().exponent(exponent)); | ||
return copy(scale, pow()).exponent(scale.exponent()); | ||
}; | ||
return linearish(scale); | ||
initRange.apply(scale, arguments); | ||
return scale; | ||
} | ||
function sqrt() { | ||
return pow().exponent(0.5); | ||
return pow.apply(null, arguments).exponent(0.5); | ||
} | ||
@@ -588,3 +681,4 @@ | ||
range = [], | ||
thresholds = []; | ||
thresholds = [], | ||
unknown; | ||
@@ -599,3 +693,3 @@ function rescale() { | ||
function scale(x) { | ||
if (!isNaN(x = +x)) return range[d3Array.bisect(thresholds, x)]; | ||
return isNaN(x = +x) ? unknown : range[d3Array.bisect(thresholds, x)]; | ||
} | ||
@@ -623,2 +717,6 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
scale.quantiles = function() { | ||
@@ -631,6 +729,7 @@ return thresholds.slice(); | ||
.domain(domain) | ||
.range(range); | ||
.range(range) | ||
.unknown(unknown); | ||
}; | ||
return scale; | ||
return initRange.apply(scale, arguments); | ||
} | ||
@@ -643,6 +742,7 @@ | ||
domain = [0.5], | ||
range = [0, 1]; | ||
range = [0, 1], | ||
unknown; | ||
function scale(x) { | ||
if (x <= x) return range[d3Array.bisect(domain, x, 0, n)]; | ||
return x <= x ? range[d3Array.bisect(domain, x, 0, n)] : unknown; | ||
} | ||
@@ -673,9 +773,18 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : scale; | ||
}; | ||
scale.thresholds = function() { | ||
return domain.slice(); | ||
}; | ||
scale.copy = function() { | ||
return quantize() | ||
.domain([x0, x1]) | ||
.range(range); | ||
.range(range) | ||
.unknown(unknown); | ||
}; | ||
return linearish(scale); | ||
return initRange.apply(linearish(scale), arguments); | ||
} | ||
@@ -686,6 +795,7 @@ | ||
range = [0, 1], | ||
unknown, | ||
n = 1; | ||
function scale(x) { | ||
if (x <= x) return range[d3Array.bisect(domain, x, 0, n)]; | ||
return x <= x ? range[d3Array.bisect(domain, x, 0, n)] : unknown; | ||
} | ||
@@ -706,9 +816,14 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
scale.copy = function() { | ||
return threshold() | ||
.domain(domain) | ||
.range(range); | ||
.range(range) | ||
.unknown(unknown); | ||
}; | ||
return scale; | ||
return initRange.apply(scale, arguments); | ||
} | ||
@@ -733,3 +848,3 @@ | ||
function calendar(year, month, week, day, hour, minute, second, millisecond, format) { | ||
var scale = continuous(deinterpolateLinear, d3Interpolate.interpolateNumber), | ||
var scale = continuous(identity, identity), | ||
invert = scale.invert, | ||
@@ -842,22 +957,26 @@ domain = scale.domain; | ||
function time() { | ||
return calendar(d3Time.timeYear, d3Time.timeMonth, d3Time.timeWeek, d3Time.timeDay, d3Time.timeHour, d3Time.timeMinute, d3Time.timeSecond, d3Time.timeMillisecond, d3TimeFormat.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]); | ||
return initRange.apply(calendar(d3Time.timeYear, d3Time.timeMonth, d3Time.timeWeek, d3Time.timeDay, d3Time.timeHour, d3Time.timeMinute, d3Time.timeSecond, d3Time.timeMillisecond, d3TimeFormat.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments); | ||
} | ||
function utcTime() { | ||
return calendar(d3Time.utcYear, d3Time.utcMonth, d3Time.utcWeek, d3Time.utcDay, d3Time.utcHour, d3Time.utcMinute, d3Time.utcSecond, d3Time.utcMillisecond, d3TimeFormat.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]); | ||
return initRange.apply(calendar(d3Time.utcYear, d3Time.utcMonth, d3Time.utcWeek, d3Time.utcDay, d3Time.utcHour, d3Time.utcMinute, d3Time.utcSecond, d3Time.utcMillisecond, d3TimeFormat.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments); | ||
} | ||
function sequential(interpolator) { | ||
function transformer$1() { | ||
var x0 = 0, | ||
x1 = 1, | ||
k10 = 1, | ||
clamp = false; | ||
t0, | ||
t1, | ||
k10, | ||
transform, | ||
interpolator = identity, | ||
clamp = false, | ||
unknown; | ||
function scale(x) { | ||
var t = (x - x0) * k10; | ||
return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t); | ||
return isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x)); | ||
} | ||
scale.domain = function(_) { | ||
return arguments.length ? (x0 = +_[0], x1 = +_[1], k10 = x0 === x1 ? 0 : 1 / (x1 - x0), scale) : [x0, x1]; | ||
return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1]; | ||
}; | ||
@@ -873,24 +992,111 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
return function(t) { | ||
transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0); | ||
return scale; | ||
}; | ||
} | ||
function copy$1(source, target) { | ||
return target | ||
.domain(source.domain()) | ||
.interpolator(source.interpolator()) | ||
.clamp(source.clamp()) | ||
.unknown(source.unknown()); | ||
} | ||
function sequential() { | ||
var scale = linearish(transformer$1()(identity)); | ||
scale.copy = function() { | ||
return sequential(interpolator).domain([x0, x1]).clamp(clamp); | ||
return copy$1(scale, sequential()); | ||
}; | ||
return linearish(scale); | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
function diverging(interpolator) { | ||
function sequentialLog() { | ||
var scale = loggish(transformer$1()).domain([1, 10]); | ||
scale.copy = function() { | ||
return copy$1(scale, sequentialLog()).base(scale.base()); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
function sequentialSymlog() { | ||
var scale = symlogish(transformer$1()); | ||
scale.copy = function() { | ||
return copy$1(scale, sequentialSymlog()).constant(scale.constant()); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
function sequentialPow() { | ||
var scale = powish(transformer$1()); | ||
scale.copy = function() { | ||
return copy$1(scale, sequentialPow()).exponent(scale.exponent()); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
function sequentialSqrt() { | ||
return sequentialPow.apply(null, arguments).exponent(0.5); | ||
} | ||
function sequentialQuantile() { | ||
var domain = [], | ||
interpolator = identity; | ||
function scale(x) { | ||
if (!isNaN(x = +x)) return interpolator((d3Array.bisect(domain, x) - 1) / (domain.length - 1)); | ||
} | ||
scale.domain = function(_) { | ||
if (!arguments.length) return domain.slice(); | ||
domain = []; | ||
for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d); | ||
domain.sort(d3Array.ascending); | ||
return scale; | ||
}; | ||
scale.interpolator = function(_) { | ||
return arguments.length ? (interpolator = _, scale) : interpolator; | ||
}; | ||
scale.copy = function() { | ||
return sequentialQuantile(interpolator).domain(domain); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
function transformer$2() { | ||
var x0 = 0, | ||
x1 = 0.5, | ||
x2 = 1, | ||
k10 = 1, | ||
k21 = 1, | ||
clamp = false; | ||
t0, | ||
t1, | ||
t2, | ||
k10, | ||
k21, | ||
interpolator = identity, | ||
transform, | ||
clamp = false, | ||
unknown; | ||
function scale(x) { | ||
var t = 0.5 + ((x = +x) - x1) * (x < x1 ? k10 : k21); | ||
return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t); | ||
return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (x < t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x)); | ||
} | ||
scale.domain = function(_) { | ||
return arguments.length ? (x0 = +_[0], x1 = +_[1], x2 = +_[2], k10 = x0 === x1 ? 0 : 0.5 / (x1 - x0), k21 = x1 === x2 ? 0 : 0.5 / (x2 - x1), scale) : [x0, x1, x2]; | ||
return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), t2 = transform(x2 = +_[2]), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), scale) : [x0, x1, x2]; | ||
}; | ||
@@ -906,14 +1112,52 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
return function(t) { | ||
transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1); | ||
return scale; | ||
}; | ||
} | ||
function diverging() { | ||
var scale = linearish(transformer$2()(identity)); | ||
scale.copy = function() { | ||
return diverging(interpolator).domain([x0, x1, x2]).clamp(clamp); | ||
return copy$1(scale, diverging()); | ||
}; | ||
return linearish(scale); | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
function divergingLog() { | ||
var scale = loggish(transformer$2()).domain([0.1, 1, 10]); | ||
scale.copy = function() { | ||
return copy$1(scale, divergingLog()).base(scale.base()); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
function divergingPow() { | ||
var scale = powish(transformer$2()); | ||
scale.copy = function() { | ||
return copy$1(scale, divergingPow()).exponent(scale.exponent()); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
function divergingSqrt() { | ||
return divergingPow.apply(null, arguments).exponent(0.5); | ||
} | ||
exports.scaleBand = band; | ||
exports.scalePoint = point; | ||
exports.scaleIdentity = identity; | ||
exports.scaleIdentity = identity$1; | ||
exports.scaleLinear = linear; | ||
exports.scaleLog = log; | ||
exports.scaleSymlog = symlog; | ||
exports.scaleOrdinal = ordinal; | ||
@@ -929,3 +1173,12 @@ exports.scaleImplicit = implicit; | ||
exports.scaleSequential = sequential; | ||
exports.scaleSequentialLog = sequentialLog; | ||
exports.scaleSequentialPow = sequentialPow; | ||
exports.scaleSequentialSqrt = sequentialSqrt; | ||
exports.scaleSequentialSymlog = sequentialSymlog; | ||
exports.scaleSequentialQuantile = sequentialQuantile; | ||
exports.scaleDiverging = diverging; | ||
exports.scaleDivergingLog = divergingLog; | ||
exports.scaleDivergingPow = divergingPow; | ||
exports.scaleDivergingSqrt = divergingSqrt; | ||
exports.tickFormat = tickFormat; | ||
@@ -932,0 +1185,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,2 +0,2 @@ | ||
// https://d3js.org/d3-scale/ v2.1.2 Copyright 2018 Mike Bostock | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-collection"),require("d3-array"),require("d3-interpolate"),require("d3-format"),require("d3-time"),require("d3-time-format")):"function"==typeof define&&define.amd?define(["exports","d3-collection","d3-array","d3-interpolate","d3-format","d3-time","d3-time-format"],t):t(n.d3=n.d3||{},n.d3,n.d3,n.d3,n.d3,n.d3,n.d3)}(this,function(n,t,e,r,i,u,o){"use strict";var a=Array.prototype,c=a.map,l=a.slice,f={name:"implicit"};function h(n){var e=t.map(),r=[],i=f;function u(t){var u=t+"",o=e.get(u);if(!o){if(i!==f)return i;e.set(u,o=r.push(t))}return n[(o-1)%n.length]}return n=null==n?[]:l.call(n),u.domain=function(n){if(!arguments.length)return r.slice();r=[],e=t.map();for(var i,o,a=-1,c=n.length;++a<c;)e.has(o=(i=n[a])+"")||e.set(o,r.push(i));return u},u.range=function(t){return arguments.length?(n=l.call(t),u):n.slice()},u.unknown=function(n){return arguments.length?(i=n,u):i},u.copy=function(){return h().domain(r).range(n).unknown(i)},u}function d(){var n,t,r=h().unknown(void 0),i=r.domain,u=r.range,o=[0,1],a=!1,c=0,l=0,f=.5;function s(){var r=i().length,h=o[1]<o[0],d=o[h-0],s=o[1-h];n=(s-d)/Math.max(1,r-c+2*l),a&&(n=Math.floor(n)),d+=(s-d-n*(r-c))*f,t=n*(1-c),a&&(d=Math.round(d),t=Math.round(t));var m=e.range(r).map(function(t){return d+n*t});return u(h?m.reverse():m)}return delete r.unknown,r.domain=function(n){return arguments.length?(i(n),s()):i()},r.range=function(n){return arguments.length?(o=[+n[0],+n[1]],s()):o.slice()},r.rangeRound=function(n){return o=[+n[0],+n[1]],a=!0,s()},r.bandwidth=function(){return t},r.step=function(){return n},r.round=function(n){return arguments.length?(a=!!n,s()):a},r.padding=function(n){return arguments.length?(c=l=Math.max(0,Math.min(1,n)),s()):c},r.paddingInner=function(n){return arguments.length?(c=Math.max(0,Math.min(1,n)),s()):c},r.paddingOuter=function(n){return arguments.length?(l=Math.max(0,Math.min(1,n)),s()):l},r.align=function(n){return arguments.length?(f=Math.max(0,Math.min(1,n)),s()):f},r.copy=function(){return d().domain(i()).range(o).round(a).paddingInner(c).paddingOuter(l).align(f)},s()}function s(n){return function(){return n}}function m(n){return+n}var g=[0,1];function p(n,t){return(t-=n=+n)?function(e){return(e-n)/t}:s(t)}function M(n,t,e,r){var i=n[0],u=n[1],o=t[0],a=t[1];return u<i?(i=e(u,i),o=r(a,o)):(i=e(i,u),o=r(o,a)),function(n){return o(i(n))}}function v(n,t,r,i){var u=Math.min(n.length,t.length)-1,o=new Array(u),a=new Array(u),c=-1;for(n[u]<n[0]&&(n=n.slice().reverse(),t=t.slice().reverse());++c<u;)o[c]=r(n[c],n[c+1]),a[c]=i(t[c],t[c+1]);return function(t){var r=e.bisect(n,t,1,u)-1;return a[r](o[r](t))}}function y(n,t){return t.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp())}function x(n,t){var e,i,u,o=g,a=g,f=r.interpolate,h=!1;function d(){return e=Math.min(o.length,a.length)>2?v:M,i=u=null,s}function s(t){return(i||(i=e(o,a,h?function(n){return function(t,e){var r=n(t=+t,e=+e);return function(n){return n<=t?0:n>=e?1:r(n)}}}(n):n,f)))(+t)}return s.invert=function(n){return(u||(u=e(a,o,p,h?function(n){return function(t,e){var r=n(t=+t,e=+e);return function(n){return n<=0?t:n>=1?e:r(n)}}}(t):t)))(+n)},s.domain=function(n){return arguments.length?(o=c.call(n,m),d()):o.slice()},s.range=function(n){return arguments.length?(a=l.call(n),d()):a.slice()},s.rangeRound=function(n){return a=l.call(n),f=r.interpolateRound,d()},s.clamp=function(n){return arguments.length?(h=!!n,d()):h},s.interpolate=function(n){return arguments.length?(f=n,d()):f},d()}function k(n){var t=n.domain;return n.ticks=function(n){var r=t();return e.ticks(r[0],r[r.length-1],null==n?10:n)},n.tickFormat=function(n,r){return function(n,t,r){var u,o=n[0],a=n[n.length-1],c=e.tickStep(o,a,null==t?10:t);switch((r=i.formatSpecifier(null==r?",f":r)).type){case"s":var l=Math.max(Math.abs(o),Math.abs(a));return null!=r.precision||isNaN(u=i.precisionPrefix(c,l))||(r.precision=u),i.formatPrefix(r,l);case"":case"e":case"g":case"p":case"r":null!=r.precision||isNaN(u=i.precisionRound(c,Math.max(Math.abs(o),Math.abs(a))))||(r.precision=u-("e"===r.type));break;case"f":case"%":null!=r.precision||isNaN(u=i.precisionFixed(c))||(r.precision=u-2*("%"===r.type))}return i.format(r)}(t(),n,r)},n.nice=function(r){null==r&&(r=10);var i,u=t(),o=0,a=u.length-1,c=u[o],l=u[a];return l<c&&(i=c,c=l,l=i,i=o,o=a,a=i),(i=e.tickIncrement(c,l,r))>0?(c=Math.floor(c/i)*i,l=Math.ceil(l/i)*i,i=e.tickIncrement(c,l,r)):i<0&&(c=Math.ceil(c*i)/i,l=Math.floor(l*i)/i,i=e.tickIncrement(c,l,r)),i>0?(u[o]=Math.floor(c/i)*i,u[a]=Math.ceil(l/i)*i,t(u)):i<0&&(u[o]=Math.ceil(c*i)/i,u[a]=Math.floor(l*i)/i,t(u)),n},n}function w(n,t){var e,r=0,i=(n=n.slice()).length-1,u=n[r],o=n[i];return o<u&&(e=r,r=i,i=e,e=u,u=o,o=e),n[r]=t.floor(u),n[i]=t.ceil(o),n}function b(n,t){return(t=Math.log(t/n))?function(e){return Math.log(e/n)/t}:s(t)}function N(n,t){return n<0?function(e){return-Math.pow(-t,e)*Math.pow(-n,1-e)}:function(e){return Math.pow(t,e)*Math.pow(n,1-e)}}function D(n){return isFinite(n)?+("1e"+n):n<0?0:n}function I(n){return 10===n?D:n===Math.E?Math.exp:function(t){return Math.pow(n,t)}}function q(n){return n===Math.E?Math.log:10===n&&Math.log10||2===n&&Math.log2||(n=Math.log(n),function(t){return Math.log(t)/n})}function O(n){return function(t){return-n(-t)}}function S(n,t){return n<0?-Math.pow(-n,t):Math.pow(n,t)}function F(){var n=1,t=x(function(t,e){return(e=S(e,n)-(t=S(t,n)))?function(r){return(S(r,n)-t)/e}:s(e)},function(t,e){return e=S(e,n)-(t=S(t,n)),function(r){return S(t+e*r,1/n)}}),e=t.domain;return t.exponent=function(t){return arguments.length?(n=+t,e(e())):n},t.copy=function(){return y(t,F().exponent(n))},k(t)}var A=1e3,E=60*A,P=60*E,R=24*P,T=7*R,L=30*R,U=365*R;function Y(n){return new Date(n)}function j(n){return n instanceof Date?+n:+new Date(+n)}function B(n,t,i,u,o,a,l,f,h){var d=x(p,r.interpolateNumber),s=d.invert,m=d.domain,g=h(".%L"),M=h(":%S"),v=h("%I:%M"),k=h("%I %p"),b=h("%a %d"),N=h("%b %d"),D=h("%B"),I=h("%Y"),q=[[l,1,A],[l,5,5*A],[l,15,15*A],[l,30,30*A],[a,1,E],[a,5,5*E],[a,15,15*E],[a,30,30*E],[o,1,P],[o,3,3*P],[o,6,6*P],[o,12,12*P],[u,1,R],[u,2,2*R],[i,1,T],[t,1,L],[t,3,3*L],[n,1,U]];function O(e){return(l(e)<e?g:a(e)<e?M:o(e)<e?v:u(e)<e?k:t(e)<e?i(e)<e?b:N:n(e)<e?D:I)(e)}function S(t,r,i,u){if(null==t&&(t=10),"number"==typeof t){var o=Math.abs(i-r)/t,a=e.bisector(function(n){return n[2]}).right(q,o);a===q.length?(u=e.tickStep(r/U,i/U,t),t=n):a?(u=(a=q[o/q[a-1][2]<q[a][2]/o?a-1:a])[1],t=a[0]):(u=Math.max(e.tickStep(r,i,t),1),t=f)}return null==u?t:t.every(u)}return d.invert=function(n){return new Date(s(n))},d.domain=function(n){return arguments.length?m(c.call(n,j)):m().map(Y)},d.ticks=function(n,t){var e,r=m(),i=r[0],u=r[r.length-1],o=u<i;return o&&(e=i,i=u,u=e),e=(e=S(n,i,u,t))?e.range(i,u+1):[],o?e.reverse():e},d.tickFormat=function(n,t){return null==t?O:h(t)},d.nice=function(n,t){var e=m();return(n=S(n,e[0],e[e.length-1],t))?m(w(e,n)):d},d.copy=function(){return y(d,B(n,t,i,u,o,a,l,f,h))},d}n.scaleBand=d,n.scalePoint=function(){return function n(t){var e=t.copy;return t.padding=t.paddingOuter,delete t.paddingInner,delete t.paddingOuter,t.copy=function(){return n(e())},t}(d().paddingInner(1))},n.scaleIdentity=function n(){var t=[0,1];function e(n){return+n}return e.invert=e,e.domain=e.range=function(n){return arguments.length?(t=c.call(n,m),e):t.slice()},e.copy=function(){return n().domain(t)},k(e)},n.scaleLinear=function n(){var t=x(p,r.interpolateNumber);return t.copy=function(){return y(t,n())},k(t)},n.scaleLog=function n(){var t=x(b,N).domain([1,10]),r=t.domain,u=10,o=q(10),a=I(10);function c(){return o=q(u),a=I(u),r()[0]<0&&(o=O(o),a=O(a)),t}return t.base=function(n){return arguments.length?(u=+n,c()):u},t.domain=function(n){return arguments.length?(r(n),c()):r()},t.ticks=function(n){var t,i=r(),c=i[0],l=i[i.length-1];(t=l<c)&&(s=c,c=l,l=s);var f,h,d,s=o(c),m=o(l),g=null==n?10:+n,p=[];if(!(u%1)&&m-s<g){if(s=Math.round(s)-1,m=Math.round(m)+1,c>0){for(;s<m;++s)for(h=1,f=a(s);h<u;++h)if(!((d=f*h)<c)){if(d>l)break;p.push(d)}}else for(;s<m;++s)for(h=u-1,f=a(s);h>=1;--h)if(!((d=f*h)<c)){if(d>l)break;p.push(d)}}else p=e.ticks(s,m,Math.min(m-s,g)).map(a);return t?p.reverse():p},t.tickFormat=function(n,e){if(null==e&&(e=10===u?".0e":","),"function"!=typeof e&&(e=i.format(e)),n===1/0)return e;null==n&&(n=10);var r=Math.max(1,u*n/t.ticks().length);return function(n){var t=n/a(Math.round(o(n)));return t*u<u-.5&&(t*=u),t<=r?e(n):""}},t.nice=function(){return r(w(r(),{floor:function(n){return a(Math.floor(o(n)))},ceil:function(n){return a(Math.ceil(o(n)))}}))},t.copy=function(){return y(t,n().base(u))},t},n.scaleOrdinal=h,n.scaleImplicit=f,n.scalePow=F,n.scaleSqrt=function(){return F().exponent(.5)},n.scaleQuantile=function n(){var t=[],r=[],i=[];function u(){var n=0,u=Math.max(1,r.length);for(i=new Array(u-1);++n<u;)i[n-1]=e.quantile(t,n/u);return o}function o(n){if(!isNaN(n=+n))return r[e.bisect(i,n)]}return o.invertExtent=function(n){var e=r.indexOf(n);return e<0?[NaN,NaN]:[e>0?i[e-1]:t[0],e<i.length?i[e]:t[t.length-1]]},o.domain=function(n){if(!arguments.length)return t.slice();t=[];for(var r,i=0,o=n.length;i<o;++i)null==(r=n[i])||isNaN(r=+r)||t.push(r);return t.sort(e.ascending),u()},o.range=function(n){return arguments.length?(r=l.call(n),u()):r.slice()},o.quantiles=function(){return i.slice()},o.copy=function(){return n().domain(t).range(r)},o},n.scaleQuantize=function n(){var t=0,r=1,i=1,u=[.5],o=[0,1];function a(n){if(n<=n)return o[e.bisect(u,n,0,i)]}function c(){var n=-1;for(u=new Array(i);++n<i;)u[n]=((n+1)*r-(n-i)*t)/(i+1);return a}return a.domain=function(n){return arguments.length?(t=+n[0],r=+n[1],c()):[t,r]},a.range=function(n){return arguments.length?(i=(o=l.call(n)).length-1,c()):o.slice()},a.invertExtent=function(n){var e=o.indexOf(n);return e<0?[NaN,NaN]:e<1?[t,u[0]]:e>=i?[u[i-1],r]:[u[e-1],u[e]]},a.copy=function(){return n().domain([t,r]).range(o)},k(a)},n.scaleThreshold=function n(){var t=[.5],r=[0,1],i=1;function u(n){if(n<=n)return r[e.bisect(t,n,0,i)]}return u.domain=function(n){return arguments.length?(t=l.call(n),i=Math.min(t.length,r.length-1),u):t.slice()},u.range=function(n){return arguments.length?(r=l.call(n),i=Math.min(t.length,r.length-1),u):r.slice()},u.invertExtent=function(n){var e=r.indexOf(n);return[t[e-1],t[e]]},u.copy=function(){return n().domain(t).range(r)},u},n.scaleTime=function(){return B(u.timeYear,u.timeMonth,u.timeWeek,u.timeDay,u.timeHour,u.timeMinute,u.timeSecond,u.timeMillisecond,o.timeFormat).domain([new Date(2e3,0,1),new Date(2e3,0,2)])},n.scaleUtc=function(){return B(u.utcYear,u.utcMonth,u.utcWeek,u.utcDay,u.utcHour,u.utcMinute,u.utcSecond,u.utcMillisecond,o.utcFormat).domain([Date.UTC(2e3,0,1),Date.UTC(2e3,0,2)])},n.scaleSequential=function n(t){var e=0,r=1,i=1,u=!1;function o(n){var r=(n-e)*i;return t(u?Math.max(0,Math.min(1,r)):r)}return o.domain=function(n){return arguments.length?(e=+n[0],r=+n[1],i=e===r?0:1/(r-e),o):[e,r]},o.clamp=function(n){return arguments.length?(u=!!n,o):u},o.interpolator=function(n){return arguments.length?(t=n,o):t},o.copy=function(){return n(t).domain([e,r]).clamp(u)},k(o)},n.scaleDiverging=function n(t){var e=0,r=.5,i=1,u=1,o=1,a=!1;function c(n){var e=.5+((n=+n)-r)*(n<r?u:o);return t(a?Math.max(0,Math.min(1,e)):e)}return c.domain=function(n){return arguments.length?(e=+n[0],r=+n[1],i=+n[2],u=e===r?0:.5/(r-e),o=r===i?0:.5/(i-r),c):[e,r,i]},c.clamp=function(n){return arguments.length?(a=!!n,c):a},c.interpolator=function(n){return arguments.length?(t=n,c):t},c.copy=function(){return n(t).domain([e,r,i]).clamp(a)},k(c)},Object.defineProperty(n,"__esModule",{value:!0})}); | ||
// https://d3js.org/d3-scale/ v2.2.0 Copyright 2019 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.d3=n.d3||{},n.d3,n.d3,n.d3,n.d3,n.d3)}(this,function(n,t,e,r,u,i){"use strict";function a(n,t){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(t).domain(n)}return this}function o(n,t){switch(arguments.length){case 0:break;case 1:this.interpolator(n);break;default:this.interpolator(t).domain(n)}return this}var c=Array.prototype,l=c.map,f=c.slice,p={name:"implicit"};function h(){var n=new Map,t=[],e=[],r=p;function u(u){var i=u+"",a=n.get(i);if(!a){if(r!==p)return r;n.set(i,a=t.push(u))}return e[(a-1)%e.length]}return u.domain=function(e){if(!arguments.length)return t.slice();t=[],n=new Map;for(var r,i,a=-1,o=e.length;++a<o;)n.has(i=(r=e[a])+"")||n.set(i,t.push(r));return u},u.range=function(n){return arguments.length?(e=f.call(n),u):e.slice()},u.unknown=function(n){return arguments.length?(r=n,u):r},u.copy=function(){return h(t,e).unknown(r)},a.apply(u,arguments),u}function s(){var n,e,r=h().unknown(void 0),u=r.domain,i=r.range,o=[0,1],c=!1,l=0,f=0,p=.5;function g(){var r=u().length,a=o[1]<o[0],h=o[a-0],s=o[1-a];n=(s-h)/Math.max(1,r-l+2*f),c&&(n=Math.floor(n)),h+=(s-h-n*(r-l))*p,e=n*(1-l),c&&(h=Math.round(h),e=Math.round(e));var g=t.range(r).map(function(t){return h+n*t});return i(a?g.reverse():g)}return delete r.unknown,r.domain=function(n){return arguments.length?(u(n),g()):u()},r.range=function(n){return arguments.length?(o=[+n[0],+n[1]],g()):o.slice()},r.rangeRound=function(n){return o=[+n[0],+n[1]],c=!0,g()},r.bandwidth=function(){return e},r.step=function(){return n},r.round=function(n){return arguments.length?(c=!!n,g()):c},r.padding=function(n){return arguments.length?(l=Math.min(1,f=+n),g()):l},r.paddingInner=function(n){return arguments.length?(l=Math.min(1,n),g()):l},r.paddingOuter=function(n){return arguments.length?(f=+n,g()):f},r.align=function(n){return arguments.length?(p=Math.max(0,Math.min(1,n)),g()):p},r.copy=function(){return s(u(),o).round(c).paddingInner(l).paddingOuter(f).align(p)},a.apply(g(),arguments)}function g(n){return+n}var d=[0,1];function m(n){return n}function v(n,t){return(t-=n=+n)?function(e){return(e-n)/t}:(e=isNaN(t)?NaN:.5,function(){return e});var e}function M(n){var t,e=n[0],r=n[n.length-1];return e>r&&(t=e,e=r,r=t),function(n){return Math.max(e,Math.min(r,n))}}function y(n,t,e){var r=n[0],u=n[1],i=t[0],a=t[1];return u<r?(r=v(u,r),i=e(a,i)):(r=v(r,u),i=e(i,a)),function(n){return i(r(n))}}function k(n,e,r){var u=Math.min(n.length,e.length)-1,i=new Array(u),a=new Array(u),o=-1;for(n[u]<n[0]&&(n=n.slice().reverse(),e=e.slice().reverse());++o<u;)i[o]=v(n[o],n[o+1]),a[o]=r(e[o],e[o+1]);return function(e){var r=t.bisect(n,e,1,u)-1;return a[r](i[r](e))}}function w(n,t){return t.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function x(){var n,t,r,u,i,a,o=d,c=d,p=e.interpolate,h=m;function s(){return u=Math.min(o.length,c.length)>2?k:y,i=a=null,v}function v(t){return isNaN(t=+t)?r:(i||(i=u(o.map(n),c,p)))(n(h(t)))}return v.invert=function(r){return h(t((a||(a=u(c,o.map(n),e.interpolateNumber)))(r)))},v.domain=function(n){return arguments.length?(o=l.call(n,g),h===m||(h=M(o)),s()):o.slice()},v.range=function(n){return arguments.length?(c=f.call(n),s()):c.slice()},v.rangeRound=function(n){return c=f.call(n),p=e.interpolateRound,s()},v.clamp=function(n){return arguments.length?(h=n?M(o):m,v):h!==m},v.interpolate=function(n){return arguments.length?(p=n,s()):p},v.unknown=function(n){return arguments.length?(r=n,v):r},function(e,r){return n=e,t=r,s()}}function N(n,t){return x()(n,t)}function b(n,e,u,i){var a,o=t.tickStep(n,e,u);switch((i=r.formatSpecifier(null==i?",f":i)).type){case"s":var c=Math.max(Math.abs(n),Math.abs(e));return null!=i.precision||isNaN(a=r.precisionPrefix(o,c))||(i.precision=a),r.formatPrefix(i,c);case"":case"e":case"g":case"p":case"r":null!=i.precision||isNaN(a=r.precisionRound(o,Math.max(Math.abs(n),Math.abs(e))))||(i.precision=a-("e"===i.type));break;case"f":case"%":null!=i.precision||isNaN(a=r.precisionFixed(o))||(i.precision=a-2*("%"===i.type))}return r.format(i)}function q(n){var e=n.domain;return n.ticks=function(n){var r=e();return t.ticks(r[0],r[r.length-1],null==n?10:n)},n.tickFormat=function(n,t){var r=e();return b(r[0],r[r.length-1],null==n?10:n,t)},n.nice=function(r){null==r&&(r=10);var u,i=e(),a=0,o=i.length-1,c=i[a],l=i[o];return l<c&&(u=c,c=l,l=u,u=a,a=o,o=u),(u=t.tickIncrement(c,l,r))>0?(c=Math.floor(c/u)*u,l=Math.ceil(l/u)*u,u=t.tickIncrement(c,l,r)):u<0&&(c=Math.ceil(c*u)/u,l=Math.floor(l*u)/u,u=t.tickIncrement(c,l,r)),u>0?(i[a]=Math.floor(c/u)*u,i[o]=Math.ceil(l/u)*u,e(i)):u<0&&(i[a]=Math.ceil(c*u)/u,i[o]=Math.floor(l*u)/u,e(i)),n},n}function S(n,t){var e,r=0,u=(n=n.slice()).length-1,i=n[r],a=n[u];return a<i&&(e=r,r=u,u=e,e=i,i=a,a=e),n[r]=t.floor(i),n[u]=t.ceil(a),n}function D(n){return Math.log(n)}function I(n){return Math.exp(n)}function O(n){return-Math.log(-n)}function F(n){return-Math.exp(-n)}function P(n){return isFinite(n)?+("1e"+n):n<0?0:n}function A(n){return function(t){return-n(-t)}}function E(n){var e,u,i=n(D,I),a=i.domain,o=10;function c(){return e=function(n){return n===Math.E?Math.log:10===n&&Math.log10||2===n&&Math.log2||(n=Math.log(n),function(t){return Math.log(t)/n})}(o),u=function(n){return 10===n?P:n===Math.E?Math.exp:function(t){return Math.pow(n,t)}}(o),a()[0]<0?(e=A(e),u=A(u),n(O,F)):n(D,I),i}return i.base=function(n){return arguments.length?(o=+n,c()):o},i.domain=function(n){return arguments.length?(a(n),c()):a()},i.ticks=function(n){var r,i=a(),c=i[0],l=i[i.length-1];(r=l<c)&&(s=c,c=l,l=s);var f,p,h,s=e(c),g=e(l),d=null==n?10:+n,m=[];if(!(o%1)&&g-s<d){if(s=Math.round(s)-1,g=Math.round(g)+1,c>0){for(;s<g;++s)for(p=1,f=u(s);p<o;++p)if(!((h=f*p)<c)){if(h>l)break;m.push(h)}}else for(;s<g;++s)for(p=o-1,f=u(s);p>=1;--p)if(!((h=f*p)<c)){if(h>l)break;m.push(h)}}else m=t.ticks(s,g,Math.min(g-s,d)).map(u);return r?m.reverse():m},i.tickFormat=function(n,t){if(null==t&&(t=10===o?".0e":","),"function"!=typeof t&&(t=r.format(t)),n===1/0)return t;null==n&&(n=10);var a=Math.max(1,o*n/i.ticks().length);return function(n){var r=n/u(Math.round(e(n)));return r*o<o-.5&&(r*=o),r<=a?t(n):""}},i.nice=function(){return a(S(a(),{floor:function(n){return u(Math.floor(e(n)))},ceil:function(n){return u(Math.ceil(e(n)))}}))},i}function L(n){return function(t){return Math.sign(t)*Math.log1p(Math.abs(t/n))}}function R(n){return function(t){return Math.sign(t)*Math.expm1(Math.abs(t))*n}}function T(n){var t=1,e=n(L(t),R(t));return e.constant=function(e){return arguments.length?n(L(t=+e),R(t)):t},q(e)}function Q(n){return function(t){return t<0?-Math.pow(-t,n):Math.pow(t,n)}}function U(n){return n<0?-Math.sqrt(-n):Math.sqrt(n)}function Y(n){return n<0?-n*n:n*n}function j(n){var t=n(m,m),e=1;return t.exponent=function(t){return arguments.length?1===(e=+t)?n(m,m):.5===e?n(U,Y):n(Q(e),Q(1/e)):e},q(t)}function B(){var n=j(x());return n.copy=function(){return w(n,B()).exponent(n.exponent())},a.apply(n,arguments),n}var C=1e3,H=60*C,W=60*H,_=24*W,z=7*_,G=30*_,J=365*_;function K(n){return new Date(n)}function V(n){return n instanceof Date?+n:+new Date(+n)}function X(n,e,r,u,i,a,o,c,f){var p=N(m,m),h=p.invert,s=p.domain,g=f(".%L"),d=f(":%S"),v=f("%I:%M"),M=f("%I %p"),y=f("%a %d"),k=f("%b %d"),x=f("%B"),b=f("%Y"),q=[[o,1,C],[o,5,5*C],[o,15,15*C],[o,30,30*C],[a,1,H],[a,5,5*H],[a,15,15*H],[a,30,30*H],[i,1,W],[i,3,3*W],[i,6,6*W],[i,12,12*W],[u,1,_],[u,2,2*_],[r,1,z],[e,1,G],[e,3,3*G],[n,1,J]];function D(t){return(o(t)<t?g:a(t)<t?d:i(t)<t?v:u(t)<t?M:e(t)<t?r(t)<t?y:k:n(t)<t?x:b)(t)}function I(e,r,u,i){if(null==e&&(e=10),"number"==typeof e){var a=Math.abs(u-r)/e,o=t.bisector(function(n){return n[2]}).right(q,a);o===q.length?(i=t.tickStep(r/J,u/J,e),e=n):o?(i=(o=q[a/q[o-1][2]<q[o][2]/a?o-1:o])[1],e=o[0]):(i=Math.max(t.tickStep(r,u,e),1),e=c)}return null==i?e:e.every(i)}return p.invert=function(n){return new Date(h(n))},p.domain=function(n){return arguments.length?s(l.call(n,V)):s().map(K)},p.ticks=function(n,t){var e,r=s(),u=r[0],i=r[r.length-1],a=i<u;return a&&(e=u,u=i,i=e),e=(e=I(n,u,i,t))?e.range(u,i+1):[],a?e.reverse():e},p.tickFormat=function(n,t){return null==t?D:f(t)},p.nice=function(n,t){var e=s();return(n=I(n,e[0],e[e.length-1],t))?s(S(e,n)):p},p.copy=function(){return w(p,X(n,e,r,u,i,a,o,c,f))},p}function Z(){var n,t,e,r,u,i=0,a=1,o=m,c=!1;function l(t){return isNaN(t=+t)?u:o(0===e?.5:(t=(r(t)-n)*e,c?Math.max(0,Math.min(1,t)):t))}return l.domain=function(u){return arguments.length?(n=r(i=+u[0]),t=r(a=+u[1]),e=n===t?0:1/(t-n),l):[i,a]},l.clamp=function(n){return arguments.length?(c=!!n,l):c},l.interpolator=function(n){return arguments.length?(o=n,l):o},l.unknown=function(n){return arguments.length?(u=n,l):u},function(u){return r=u,n=u(i),t=u(a),e=n===t?0:1/(t-n),l}}function $(n,t){return t.domain(n.domain()).interpolator(n.interpolator()).clamp(n.clamp()).unknown(n.unknown())}function nn(){var n=j(Z());return n.copy=function(){return $(n,nn()).exponent(n.exponent())},o.apply(n,arguments)}function tn(){var n,t,e,r,u,i,a,o=0,c=.5,l=1,f=m,p=!1;function h(n){return isNaN(n=+n)?a:(n=.5+((n=+i(n))-t)*(n<t?r:u),f(p?Math.max(0,Math.min(1,n)):n))}return h.domain=function(a){return arguments.length?(n=i(o=+a[0]),t=i(c=+a[1]),e=i(l=+a[2]),r=n===t?0:.5/(t-n),u=t===e?0:.5/(e-t),h):[o,c,l]},h.clamp=function(n){return arguments.length?(p=!!n,h):p},h.interpolator=function(n){return arguments.length?(f=n,h):f},h.unknown=function(n){return arguments.length?(a=n,h):a},function(a){return i=a,n=a(o),t=a(c),e=a(l),r=n===t?0:.5/(t-n),u=t===e?0:.5/(e-t),h}}function en(){var n=j(tn());return n.copy=function(){return $(n,en()).exponent(n.exponent())},o.apply(n,arguments)}n.scaleBand=s,n.scalePoint=function(){return function n(t){var e=t.copy;return t.padding=t.paddingOuter,delete t.paddingInner,delete t.paddingOuter,t.copy=function(){return n(e())},t}(s.apply(null,arguments).paddingInner(1))},n.scaleIdentity=function n(t){var e;function r(n){return isNaN(n=+n)?e:n}return r.invert=r,r.domain=r.range=function(n){return arguments.length?(t=l.call(n,g),r):t.slice()},r.unknown=function(n){return arguments.length?(e=n,r):e},r.copy=function(){return n(t).unknown(e)},t=arguments.length?l.call(t,g):[0,1],q(r)},n.scaleLinear=function n(){var t=N(m,m);return t.copy=function(){return w(t,n())},a.apply(t,arguments),q(t)},n.scaleLog=function n(){var t=E(x()).domain([1,10]);return t.copy=function(){return w(t,n()).base(t.base())},a.apply(t,arguments),t},n.scaleSymlog=function n(){var t=T(x());return t.copy=function(){return w(t,n()).constant(t.constant())},a.apply(t,arguments)},n.scaleOrdinal=h,n.scaleImplicit=p,n.scalePow=B,n.scaleSqrt=function(){return B.apply(null,arguments).exponent(.5)},n.scaleQuantile=function n(){var e,r=[],u=[],i=[];function o(){var n=0,e=Math.max(1,u.length);for(i=new Array(e-1);++n<e;)i[n-1]=t.quantile(r,n/e);return c}function c(n){return isNaN(n=+n)?e:u[t.bisect(i,n)]}return c.invertExtent=function(n){var t=u.indexOf(n);return t<0?[NaN,NaN]:[t>0?i[t-1]:r[0],t<i.length?i[t]:r[r.length-1]]},c.domain=function(n){if(!arguments.length)return r.slice();r=[];for(var e,u=0,i=n.length;u<i;++u)null==(e=n[u])||isNaN(e=+e)||r.push(e);return r.sort(t.ascending),o()},c.range=function(n){return arguments.length?(u=f.call(n),o()):u.slice()},c.unknown=function(n){return arguments.length?(e=n,c):e},c.quantiles=function(){return i.slice()},c.copy=function(){return n().domain(r).range(u).unknown(e)},a.apply(c,arguments)},n.scaleQuantize=function n(){var e,r=0,u=1,i=1,o=[.5],c=[0,1];function l(n){return n<=n?c[t.bisect(o,n,0,i)]:e}function p(){var n=-1;for(o=new Array(i);++n<i;)o[n]=((n+1)*u-(n-i)*r)/(i+1);return l}return l.domain=function(n){return arguments.length?(r=+n[0],u=+n[1],p()):[r,u]},l.range=function(n){return arguments.length?(i=(c=f.call(n)).length-1,p()):c.slice()},l.invertExtent=function(n){var t=c.indexOf(n);return t<0?[NaN,NaN]:t<1?[r,o[0]]:t>=i?[o[i-1],u]:[o[t-1],o[t]]},l.unknown=function(n){return arguments.length?(e=n,l):l},l.thresholds=function(){return o.slice()},l.copy=function(){return n().domain([r,u]).range(c).unknown(e)},a.apply(q(l),arguments)},n.scaleThreshold=function n(){var e,r=[.5],u=[0,1],i=1;function o(n){return n<=n?u[t.bisect(r,n,0,i)]:e}return o.domain=function(n){return arguments.length?(r=f.call(n),i=Math.min(r.length,u.length-1),o):r.slice()},o.range=function(n){return arguments.length?(u=f.call(n),i=Math.min(r.length,u.length-1),o):u.slice()},o.invertExtent=function(n){var t=u.indexOf(n);return[r[t-1],r[t]]},o.unknown=function(n){return arguments.length?(e=n,o):e},o.copy=function(){return n().domain(r).range(u).unknown(e)},a.apply(o,arguments)},n.scaleTime=function(){return a.apply(X(u.timeYear,u.timeMonth,u.timeWeek,u.timeDay,u.timeHour,u.timeMinute,u.timeSecond,u.timeMillisecond,i.timeFormat).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)},n.scaleUtc=function(){return a.apply(X(u.utcYear,u.utcMonth,u.utcWeek,u.utcDay,u.utcHour,u.utcMinute,u.utcSecond,u.utcMillisecond,i.utcFormat).domain([Date.UTC(2e3,0,1),Date.UTC(2e3,0,2)]),arguments)},n.scaleSequential=function n(){var t=q(Z()(m));return t.copy=function(){return $(t,n())},o.apply(t,arguments)},n.scaleSequentialLog=function n(){var t=E(Z()).domain([1,10]);return t.copy=function(){return $(t,n()).base(t.base())},o.apply(t,arguments)},n.scaleSequentialPow=nn,n.scaleSequentialSqrt=function(){return nn.apply(null,arguments).exponent(.5)},n.scaleSequentialSymlog=function n(){var t=T(Z());return t.copy=function(){return $(t,n()).constant(t.constant())},o.apply(t,arguments)},n.scaleSequentialQuantile=function n(){var e=[],r=m;function u(n){if(!isNaN(n=+n))return r((t.bisect(e,n)-1)/(e.length-1))}return u.domain=function(n){if(!arguments.length)return e.slice();e=[];for(var r,i=0,a=n.length;i<a;++i)null==(r=n[i])||isNaN(r=+r)||e.push(r);return e.sort(t.ascending),u},u.interpolator=function(n){return arguments.length?(r=n,u):r},u.copy=function(){return n(r).domain(e)},o.apply(u,arguments)},n.scaleDiverging=function n(){var t=q(tn()(m));return t.copy=function(){return $(t,n())},o.apply(t,arguments)},n.scaleDivergingLog=function n(){var t=E(tn()).domain([.1,1,10]);return t.copy=function(){return $(t,n()).base(t.base())},o.apply(t,arguments)},n.scaleDivergingPow=en,n.scaleDivergingSqrt=function(){return en.apply(null,arguments).exponent(.5)},n.tickFormat=b,Object.defineProperty(n,"__esModule",{value:!0})}); |
{ | ||
"name": "d3-scale", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "Encodings that map abstract data to visual representation.", | ||
@@ -33,3 +33,2 @@ "keywords": [ | ||
"d3-array": "^1.2.0", | ||
"d3-collection": "1", | ||
"d3-format": "1", | ||
@@ -36,0 +35,0 @@ "d3-interpolate": "1", |
import {range as sequence} from "d3-array"; | ||
import {initRange} from "./init"; | ||
import ordinal from "./ordinal"; | ||
@@ -57,11 +58,11 @@ | ||
scale.padding = function(_) { | ||
return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner; | ||
return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner; | ||
}; | ||
scale.paddingInner = function(_) { | ||
return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner; | ||
return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner; | ||
}; | ||
scale.paddingOuter = function(_) { | ||
return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter; | ||
return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter; | ||
}; | ||
@@ -74,5 +75,3 @@ | ||
scale.copy = function() { | ||
return band() | ||
.domain(domain()) | ||
.range(range) | ||
return band(domain(), range) | ||
.round(round) | ||
@@ -84,3 +83,3 @@ .paddingInner(paddingInner) | ||
return rescale(); | ||
return initRange.apply(rescale(), arguments); | ||
} | ||
@@ -103,3 +102,3 @@ | ||
export function point() { | ||
return pointish(band().paddingInner(1)); | ||
return pointish(band.apply(null, arguments).paddingInner(1)); | ||
} |
import {bisect} from "d3-array"; | ||
import {interpolate as interpolateValue, interpolateRound} from "d3-interpolate"; | ||
import {interpolate as interpolateValue, interpolateNumber, interpolateRound} from "d3-interpolate"; | ||
import {map, slice} from "./array"; | ||
@@ -9,30 +9,28 @@ import constant from "./constant"; | ||
export function deinterpolateLinear(a, b) { | ||
export function identity(x) { | ||
return x; | ||
} | ||
function normalize(a, b) { | ||
return (b -= (a = +a)) | ||
? function(x) { return (x - a) / b; } | ||
: constant(b); | ||
: constant(isNaN(b) ? NaN : 0.5); | ||
} | ||
function deinterpolateClamp(deinterpolate) { | ||
return function(a, b) { | ||
var d = deinterpolate(a = +a, b = +b); | ||
return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); }; | ||
}; | ||
function clamper(domain) { | ||
var a = domain[0], b = domain[domain.length - 1], t; | ||
if (a > b) t = a, a = b, b = t; | ||
return function(x) { return Math.max(a, Math.min(b, x)); }; | ||
} | ||
function reinterpolateClamp(reinterpolate) { | ||
return function(a, b) { | ||
var r = reinterpolate(a = +a, b = +b); | ||
return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); }; | ||
}; | ||
} | ||
function bimap(domain, range, deinterpolate, reinterpolate) { | ||
// normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1]. | ||
// interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b]. | ||
function bimap(domain, range, interpolate) { | ||
var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1]; | ||
if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0); | ||
else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1); | ||
if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0); | ||
else d0 = normalize(d0, d1), r0 = interpolate(r0, r1); | ||
return function(x) { return r0(d0(x)); }; | ||
} | ||
function polymap(domain, range, deinterpolate, reinterpolate) { | ||
function polymap(domain, range, interpolate) { | ||
var j = Math.min(domain.length, range.length) - 1, | ||
@@ -50,4 +48,4 @@ d = new Array(j), | ||
while (++i < j) { | ||
d[i] = deinterpolate(domain[i], domain[i + 1]); | ||
r[i] = reinterpolate(range[i], range[i + 1]); | ||
d[i] = normalize(domain[i], domain[i + 1]); | ||
r[i] = interpolate(range[i], range[i + 1]); | ||
} | ||
@@ -66,12 +64,14 @@ | ||
.interpolate(source.interpolate()) | ||
.clamp(source.clamp()); | ||
.clamp(source.clamp()) | ||
.unknown(source.unknown()); | ||
} | ||
// deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1]. | ||
// reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b]. | ||
export default function continuous(deinterpolate, reinterpolate) { | ||
export function transformer() { | ||
var domain = unit, | ||
range = unit, | ||
interpolate = interpolateValue, | ||
clamp = false, | ||
transform, | ||
untransform, | ||
unknown, | ||
clamp = identity, | ||
piecewise, | ||
@@ -88,11 +88,11 @@ output, | ||
function scale(x) { | ||
return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate)))(+x); | ||
return isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x))); | ||
} | ||
scale.invert = function(y) { | ||
return (input || (input = piecewise(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y); | ||
return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y))); | ||
}; | ||
scale.domain = function(_) { | ||
return arguments.length ? (domain = map.call(_, number), rescale()) : domain.slice(); | ||
return arguments.length ? (domain = map.call(_, number), clamp === identity || (clamp = clamper(domain)), rescale()) : domain.slice(); | ||
}; | ||
@@ -109,3 +109,3 @@ | ||
scale.clamp = function(_) { | ||
return arguments.length ? (clamp = !!_, rescale()) : clamp; | ||
return arguments.length ? (clamp = _ ? clamper(domain) : identity, scale) : clamp !== identity; | ||
}; | ||
@@ -117,3 +117,14 @@ | ||
return rescale(); | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
return function(t, u) { | ||
transform = t, untransform = u; | ||
return rescale(); | ||
}; | ||
} | ||
export default function continuous(transform, untransform) { | ||
return transformer()(transform, untransform); | ||
} |
@@ -0,18 +1,29 @@ | ||
import {identity} from "./continuous"; | ||
import {initInterpolator} from "./init"; | ||
import {linearish} from "./linear"; | ||
import {loggish} from "./log"; | ||
import {copy} from "./sequential"; | ||
import {symlogish} from "./symlog"; | ||
import {powish} from "./pow"; | ||
export default function diverging(interpolator) { | ||
function transformer() { | ||
var x0 = 0, | ||
x1 = 0.5, | ||
x2 = 1, | ||
k10 = 1, | ||
k21 = 1, | ||
clamp = false; | ||
t0, | ||
t1, | ||
t2, | ||
k10, | ||
k21, | ||
interpolator = identity, | ||
transform, | ||
clamp = false, | ||
unknown; | ||
function scale(x) { | ||
var t = 0.5 + ((x = +x) - x1) * (x < x1 ? k10 : k21); | ||
return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t); | ||
return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (x < t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x)); | ||
} | ||
scale.domain = function(_) { | ||
return arguments.length ? (x0 = +_[0], x1 = +_[1], x2 = +_[2], k10 = x0 === x1 ? 0 : 0.5 / (x1 - x0), k21 = x1 === x2 ? 0 : 0.5 / (x2 - x1), scale) : [x0, x1, x2]; | ||
return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), t2 = transform(x2 = +_[2]), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), scale) : [x0, x1, x2]; | ||
}; | ||
@@ -28,7 +39,54 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
return function(t) { | ||
transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1); | ||
return scale; | ||
}; | ||
} | ||
export default function diverging() { | ||
var scale = linearish(transformer()(identity)); | ||
scale.copy = function() { | ||
return diverging(interpolator).domain([x0, x1, x2]).clamp(clamp); | ||
return copy(scale, diverging()); | ||
}; | ||
return linearish(scale); | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
export function divergingLog() { | ||
var scale = loggish(transformer()).domain([0.1, 1, 10]); | ||
scale.copy = function() { | ||
return copy(scale, divergingLog()).base(scale.base()); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
export function divergingSymlog() { | ||
var scale = symlogish(transformer()); | ||
scale.copy = function() { | ||
return copy(scale, divergingSymlog()).constant(scale.constant()); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
export function divergingPow() { | ||
var scale = powish(transformer()); | ||
scale.copy = function() { | ||
return copy(scale, divergingPow()).exponent(scale.exponent()); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
export function divergingSqrt() { | ||
return divergingPow.apply(null, arguments).exponent(0.5); | ||
} |
@@ -5,7 +5,7 @@ import {map} from "./array"; | ||
export default function identity() { | ||
var domain = [0, 1]; | ||
export default function identity(domain) { | ||
var unknown; | ||
function scale(x) { | ||
return +x; | ||
return isNaN(x = +x) ? unknown : x; | ||
} | ||
@@ -19,7 +19,13 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
scale.copy = function() { | ||
return identity().domain(domain); | ||
return identity(domain).unknown(unknown); | ||
}; | ||
domain = arguments.length ? map.call(domain, number) : [0, 1]; | ||
return linearish(scale); | ||
} |
@@ -19,2 +19,6 @@ export { | ||
export { | ||
default as scaleSymlog | ||
} from "./symlog"; | ||
export { | ||
default as scaleOrdinal, | ||
@@ -50,7 +54,22 @@ implicit as scaleImplicit | ||
export { | ||
default as scaleSequential | ||
default as scaleSequential, | ||
sequentialLog as scaleSequentialLog, | ||
sequentialPow as scaleSequentialPow, | ||
sequentialSqrt as scaleSequentialSqrt, | ||
sequentialSymlog as scaleSequentialSymlog | ||
} from "./sequential"; | ||
export { | ||
default as scaleDiverging | ||
default as scaleSequentialQuantile | ||
} from "./sequentialQuantile"; | ||
export { | ||
default as scaleDiverging, | ||
divergingLog as scaleDivergingLog, | ||
divergingPow as scaleDivergingPow, | ||
divergingSqrt as scaleDivergingSqrt | ||
} from "./diverging"; | ||
export { | ||
default as tickFormat | ||
} from "./tickFormat"; |
import {ticks, tickIncrement} from "d3-array"; | ||
import {interpolateNumber as reinterpolate} from "d3-interpolate"; | ||
import {default as continuous, copy, deinterpolateLinear as deinterpolate} from "./continuous"; | ||
import continuous, {copy, identity} from "./continuous"; | ||
import {initRange} from "./init"; | ||
import tickFormat from "./tickFormat"; | ||
@@ -15,3 +15,4 @@ | ||
scale.tickFormat = function(count, specifier) { | ||
return tickFormat(domain(), count, specifier); | ||
var d = domain(); | ||
return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier); | ||
}; | ||
@@ -63,3 +64,3 @@ | ||
export default function linear() { | ||
var scale = continuous(deinterpolate, reinterpolate); | ||
var scale = continuous(identity, identity); | ||
@@ -70,3 +71,5 @@ scale.copy = function() { | ||
initRange.apply(scale, arguments); | ||
return linearish(scale); | ||
} |
import {ticks} from "d3-array"; | ||
import {format} from "d3-format"; | ||
import constant from "./constant"; | ||
import nice from "./nice"; | ||
import {default as continuous, copy} from "./continuous"; | ||
import {copy, transformer} from "./continuous"; | ||
import {initRange} from "./init"; | ||
function deinterpolate(a, b) { | ||
return (b = Math.log(b / a)) | ||
? function(x) { return Math.log(x / a) / b; } | ||
: constant(b); | ||
function transformLog(x) { | ||
return Math.log(x); | ||
} | ||
function reinterpolate(a, b) { | ||
return a < 0 | ||
? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); } | ||
: function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); }; | ||
function transformExp(x) { | ||
return Math.exp(x); | ||
} | ||
function transformLogn(x) { | ||
return -Math.log(-x); | ||
} | ||
function transformExpn(x) { | ||
return -Math.exp(-x); | ||
} | ||
function pow10(x) { | ||
@@ -42,12 +46,17 @@ return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x; | ||
export default function log() { | ||
var scale = continuous(deinterpolate, reinterpolate).domain([1, 10]), | ||
export function loggish(transform) { | ||
var scale = transform(transformLog, transformExp), | ||
domain = scale.domain, | ||
base = 10, | ||
logs = logp(10), | ||
pows = powp(10); | ||
logs, | ||
pows; | ||
function rescale() { | ||
logs = logp(base), pows = powp(base); | ||
if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows); | ||
if (domain()[0] < 0) { | ||
logs = reflect(logs), pows = reflect(pows); | ||
transform(transformLogn, transformExpn); | ||
} else { | ||
transform(transformLog, transformExp); | ||
} | ||
return scale; | ||
@@ -124,7 +133,15 @@ } | ||
return scale; | ||
} | ||
export default function log() { | ||
var scale = loggish(transformer()).domain([1, 10]); | ||
scale.copy = function() { | ||
return copy(scale, log().base(base)); | ||
return copy(scale, log()).base(scale.base()); | ||
}; | ||
initRange.apply(scale, arguments); | ||
return scale; | ||
} |
@@ -1,13 +0,12 @@ | ||
import {map} from "d3-collection"; | ||
import {slice} from "./array"; | ||
import {initRange} from "./init"; | ||
export var implicit = {name: "implicit"}; | ||
export default function ordinal(range) { | ||
var index = map(), | ||
export default function ordinal() { | ||
var index = new Map, | ||
domain = [], | ||
range = [], | ||
unknown = implicit; | ||
range = range == null ? [] : slice.call(range); | ||
function scale(d) { | ||
@@ -24,3 +23,3 @@ var key = d + "", i = index.get(key); | ||
if (!arguments.length) return domain.slice(); | ||
domain = [], index = map(); | ||
domain = [], index = new Map(); | ||
var i = -1, n = _.length, d, key; | ||
@@ -40,9 +39,8 @@ while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d)); | ||
scale.copy = function() { | ||
return ordinal() | ||
.domain(domain) | ||
.range(range) | ||
.unknown(unknown); | ||
return ordinal(domain, range).unknown(unknown); | ||
}; | ||
initRange.apply(scale, arguments); | ||
return scale; | ||
} |
@@ -1,38 +0,50 @@ | ||
import constant from "./constant"; | ||
import {linearish} from "./linear"; | ||
import {default as continuous, copy} from "./continuous"; | ||
import {copy, identity, transformer} from "./continuous"; | ||
import {initRange} from "./init"; | ||
function raise(x, exponent) { | ||
return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent); | ||
function transformPow(exponent) { | ||
return function(x) { | ||
return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent); | ||
}; | ||
} | ||
export default function pow() { | ||
var exponent = 1, | ||
scale = continuous(deinterpolate, reinterpolate), | ||
domain = scale.domain; | ||
function transformSqrt(x) { | ||
return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x); | ||
} | ||
function deinterpolate(a, b) { | ||
return (b = raise(b, exponent) - (a = raise(a, exponent))) | ||
? function(x) { return (raise(x, exponent) - a) / b; } | ||
: constant(b); | ||
} | ||
function transformSquare(x) { | ||
return x < 0 ? -x * x : x * x; | ||
} | ||
function reinterpolate(a, b) { | ||
b = raise(b, exponent) - (a = raise(a, exponent)); | ||
return function(t) { return raise(a + b * t, 1 / exponent); }; | ||
export function powish(transform) { | ||
var scale = transform(identity, identity), | ||
exponent = 1; | ||
function rescale() { | ||
return exponent === 1 ? transform(identity, identity) | ||
: exponent === 0.5 ? transform(transformSqrt, transformSquare) | ||
: transform(transformPow(exponent), transformPow(1 / exponent)); | ||
} | ||
scale.exponent = function(_) { | ||
return arguments.length ? (exponent = +_, domain(domain())) : exponent; | ||
return arguments.length ? (exponent = +_, rescale()) : exponent; | ||
}; | ||
return linearish(scale); | ||
} | ||
export default function pow() { | ||
var scale = powish(transformer()); | ||
scale.copy = function() { | ||
return copy(scale, pow().exponent(exponent)); | ||
return copy(scale, pow()).exponent(scale.exponent()); | ||
}; | ||
return linearish(scale); | ||
initRange.apply(scale, arguments); | ||
return scale; | ||
} | ||
export function sqrt() { | ||
return pow().exponent(0.5); | ||
return pow.apply(null, arguments).exponent(0.5); | ||
} |
import {ascending, bisect, quantile as threshold} from "d3-array"; | ||
import {slice} from "./array"; | ||
import {initRange} from "./init"; | ||
@@ -7,3 +8,4 @@ export default function quantile() { | ||
range = [], | ||
thresholds = []; | ||
thresholds = [], | ||
unknown; | ||
@@ -18,3 +20,3 @@ function rescale() { | ||
function scale(x) { | ||
if (!isNaN(x = +x)) return range[bisect(thresholds, x)]; | ||
return isNaN(x = +x) ? unknown : range[bisect(thresholds, x)]; | ||
} | ||
@@ -42,2 +44,6 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
scale.quantiles = function() { | ||
@@ -50,6 +56,7 @@ return thresholds.slice(); | ||
.domain(domain) | ||
.range(range); | ||
.range(range) | ||
.unknown(unknown); | ||
}; | ||
return scale; | ||
return initRange.apply(scale, arguments); | ||
} |
import {bisect} from "d3-array"; | ||
import {slice} from "./array"; | ||
import {linearish} from "./linear"; | ||
import {initRange} from "./init"; | ||
@@ -10,6 +11,7 @@ export default function quantize() { | ||
domain = [0.5], | ||
range = [0, 1]; | ||
range = [0, 1], | ||
unknown; | ||
function scale(x) { | ||
if (x <= x) return range[bisect(domain, x, 0, n)]; | ||
return x <= x ? range[bisect(domain, x, 0, n)] : unknown; | ||
} | ||
@@ -40,9 +42,18 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : scale; | ||
}; | ||
scale.thresholds = function() { | ||
return domain.slice(); | ||
}; | ||
scale.copy = function() { | ||
return quantize() | ||
.domain([x0, x1]) | ||
.range(range); | ||
.range(range) | ||
.unknown(unknown); | ||
}; | ||
return linearish(scale); | ||
return initRange.apply(linearish(scale), arguments); | ||
} |
@@ -0,16 +1,25 @@ | ||
import {identity} from "./continuous"; | ||
import {initInterpolator} from "./init"; | ||
import {linearish} from "./linear"; | ||
import {loggish} from "./log"; | ||
import {symlogish} from "./symlog"; | ||
import {powish} from "./pow"; | ||
export default function sequential(interpolator) { | ||
function transformer() { | ||
var x0 = 0, | ||
x1 = 1, | ||
k10 = 1, | ||
clamp = false; | ||
t0, | ||
t1, | ||
k10, | ||
transform, | ||
interpolator = identity, | ||
clamp = false, | ||
unknown; | ||
function scale(x) { | ||
var t = (x - x0) * k10; | ||
return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t); | ||
return isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x)); | ||
} | ||
scale.domain = function(_) { | ||
return arguments.length ? (x0 = +_[0], x1 = +_[1], k10 = x0 === x1 ? 0 : 1 / (x1 - x0), scale) : [x0, x1]; | ||
return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1]; | ||
}; | ||
@@ -26,7 +35,62 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
return function(t) { | ||
transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0); | ||
return scale; | ||
}; | ||
} | ||
export function copy(source, target) { | ||
return target | ||
.domain(source.domain()) | ||
.interpolator(source.interpolator()) | ||
.clamp(source.clamp()) | ||
.unknown(source.unknown()); | ||
} | ||
export default function sequential() { | ||
var scale = linearish(transformer()(identity)); | ||
scale.copy = function() { | ||
return sequential(interpolator).domain([x0, x1]).clamp(clamp); | ||
return copy(scale, sequential()); | ||
}; | ||
return linearish(scale); | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
export function sequentialLog() { | ||
var scale = loggish(transformer()).domain([1, 10]); | ||
scale.copy = function() { | ||
return copy(scale, sequentialLog()).base(scale.base()); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
export function sequentialSymlog() { | ||
var scale = symlogish(transformer()); | ||
scale.copy = function() { | ||
return copy(scale, sequentialSymlog()).constant(scale.constant()); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
export function sequentialPow() { | ||
var scale = powish(transformer()); | ||
scale.copy = function() { | ||
return copy(scale, sequentialPow()).exponent(scale.exponent()); | ||
}; | ||
return initInterpolator.apply(scale, arguments); | ||
} | ||
export function sequentialSqrt() { | ||
return sequentialPow.apply(null, arguments).exponent(0.5); | ||
} |
import {bisect} from "d3-array"; | ||
import {slice} from "./array"; | ||
import {initRange} from "./init"; | ||
@@ -7,6 +8,7 @@ export default function threshold() { | ||
range = [0, 1], | ||
unknown, | ||
n = 1; | ||
function scale(x) { | ||
if (x <= x) return range[bisect(domain, x, 0, n)]; | ||
return x <= x ? range[bisect(domain, x, 0, n)] : unknown; | ||
} | ||
@@ -27,9 +29,14 @@ | ||
scale.unknown = function(_) { | ||
return arguments.length ? (unknown = _, scale) : unknown; | ||
}; | ||
scale.copy = function() { | ||
return threshold() | ||
.domain(domain) | ||
.range(range); | ||
.range(range) | ||
.unknown(unknown); | ||
}; | ||
return scale; | ||
return initRange.apply(scale, arguments); | ||
} |
import {tickStep} from "d3-array"; | ||
import {format, formatPrefix, formatSpecifier, precisionFixed, precisionPrefix, precisionRound} from "d3-format"; | ||
export default function(domain, count, specifier) { | ||
var start = domain[0], | ||
stop = domain[domain.length - 1], | ||
step = tickStep(start, stop, count == null ? 10 : count), | ||
export default function(start, stop, count, specifier) { | ||
var step = tickStep(start, stop, count), | ||
precision; | ||
@@ -9,0 +7,0 @@ specifier = formatSpecifier(specifier == null ? ",f" : specifier); |
import {bisector, tickStep} from "d3-array"; | ||
import {interpolateNumber as reinterpolate} from "d3-interpolate"; | ||
import {timeYear, timeMonth, timeWeek, timeDay, timeHour, timeMinute, timeSecond, timeMillisecond} from "d3-time"; | ||
import {timeFormat} from "d3-time-format"; | ||
import {map} from "./array"; | ||
import {default as continuous, copy, deinterpolateLinear as deinterpolate} from "./continuous"; | ||
import continuous, {copy, identity} from "./continuous"; | ||
import {initRange} from "./init"; | ||
import nice from "./nice"; | ||
@@ -26,3 +26,3 @@ | ||
export function calendar(year, month, week, day, hour, minute, second, millisecond, format) { | ||
var scale = continuous(deinterpolate, reinterpolate), | ||
var scale = continuous(identity, identity), | ||
invert = scale.invert, | ||
@@ -135,3 +135,3 @@ domain = scale.domain; | ||
export default function() { | ||
return calendar(timeYear, timeMonth, timeWeek, timeDay, timeHour, timeMinute, timeSecond, timeMillisecond, timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]); | ||
return initRange.apply(calendar(timeYear, timeMonth, timeWeek, timeDay, timeHour, timeMinute, timeSecond, timeMillisecond, timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments); | ||
} |
import {calendar} from "./time"; | ||
import {utcFormat} from "d3-time-format"; | ||
import {utcYear, utcMonth, utcWeek, utcDay, utcHour, utcMinute, utcSecond, utcMillisecond} from "d3-time"; | ||
import {initRange} from "./init"; | ||
export default function() { | ||
return calendar(utcYear, utcMonth, utcWeek, utcDay, utcHour, utcMinute, utcSecond, utcMillisecond, utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]); | ||
return initRange.apply(calendar(utcYear, utcMonth, utcWeek, utcDay, utcHour, utcMinute, utcSecond, utcMillisecond, utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments); | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
191872
5
32
2072
944
- Removedd3-collection@1
- Removedd3-collection@1.0.7(transitive)