interpolateCool = function (t) { start.h = h(t); start.s = s(t); start.l = l(Math.pow(t, y)); start.opacity = opacity(t); return start + ""; }
n/a
interpolateCubehelixDefault = function (t) { start.h = h(t); start.s = s(t); start.l = l(Math.pow(t, y)); start.opacity = opacity(t); return start + ""; }
n/a
interpolateInferno = function (t) { return range$$1[Math.max(0, Math.min(n - 1, Math.floor(t * n)))]; }
n/a
interpolateMagma = function (t) { return range$$1[Math.max(0, Math.min(n - 1, Math.floor(t * n)))]; }
n/a
interpolatePlasma = function (t) { return range$$1[Math.max(0, Math.min(n - 1, Math.floor(t * n)))]; }
n/a
interpolateRainbow = function (t) { if (t < 0 || t > 1) t -= Math.floor(t); var ts = Math.abs(t - 0.5); rainbow.h = 360 * t - 100; rainbow.s = 1.5 - 1.5 * ts; rainbow.l = 0.8 - 0.9 * ts; return rainbow + ""; }
n/a
interpolateViridis = function (t) { return range$$1[Math.max(0, Math.min(n - 1, Math.floor(t * n)))]; }
n/a
interpolateWarm = function (t) { start.h = h(t); start.s = s(t); start.l = l(Math.pow(t, y)); start.opacity = opacity(t); return start + ""; }
n/a
function band() { var scale = ordinal().unknown(undefined), domain = scale.domain, ordinalRange = scale.range, range$$1 = [0, 1], step, bandwidth, round = false, paddingInner = 0, paddingOuter = 0, align = 0.5; delete scale.unknown; function rescale() { var n = domain().length, reverse = range$$1[1] < range$$1[0], start = range$$1[reverse - 0], stop = range$$1[1 - reverse]; step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2); if (round) step = Math.floor(step); start += (stop - start - step * (n - paddingInner)) * align; bandwidth = step * (1 - paddingInner); if (round) start = Math.round(start), bandwidth = Math.round(bandwidth); var values = d3Array.range(n).map(function(i) { return start + step * i; }); return ordinalRange(reverse ? values.reverse() : values); } scale.domain = function(_) { return arguments.length ? (domain(_), rescale()) : domain(); }; scale.range = function(_) { return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice(); }; scale.rangeRound = function(_) { return range$$1 = [+_[0], +_[1]], round = true, rescale(); }; scale.bandwidth = function() { return bandwidth; }; scale.step = function() { return step; }; scale.round = function(_) { return arguments.length ? (round = !!_, rescale()) : round; }; scale.padding = function(_) { return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner; }; scale.paddingInner = function(_) { return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner; }; scale.paddingOuter = function(_) { return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter; }; scale.align = function(_) { return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align; }; scale.copy = function() { return band() .domain(domain()) .range(range$$1) .round(round) .paddingInner(paddingInner) .paddingOuter(paddingOuter) .align(align); }; return rescale(); }
n/a
function identity() { var domain = [0, 1]; function scale(x) { return +x; } scale.invert = scale; scale.domain = scale.range = function(_) { return arguments.length ? (domain = map$1.call(_, number), scale) : domain.slice(); }; scale.copy = function() { return identity().domain(domain); }; return linearish(scale); }
n/a
function linear() { var scale = continuous(deinterpolateLinear, d3Interpolate.interpolateNumber); scale.copy = function() { return copy(scale, linear()); }; return linearish(scale); }
...
<script src="https://d3js.org/d3-format.v1.min.js"></script>
<script src="https://d3js.org/d3-interpolate.v1.min.js"></script>
<script src="https://d3js.org/d3-time.v1.min.js"></script>
<script src="https://d3js.org/d3-time-format.v2.min.js"></script>
<script src="https://d3js.org/d3-scale.v1.min.js"></script>
<script>
var x = d3.scaleLinear();
</script>
```
(You can omit d3-time and d3-time-format if you’re not using [d3.scaleTime](#scaleTime) or [d3.scaleUtc](#scaleUtc).)
[Try d3-scale in your browser.](https://tonicdev.com/npm/d3-scale)
...
function log() { var scale = continuous(deinterpolate, reinterpolate).domain([1, 10]), domain = scale.domain, base = 10, logs = logp(10), pows = powp(10); function rescale() { logs = logp(base), pows = powp(base); if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows); return scale; } scale.base = function(_) { return arguments.length ? (base = +_, rescale()) : base; }; scale.domain = function(_) { return arguments.length ? (domain(_), rescale()) : domain(); }; scale.ticks = function(count) { var d = domain(), u = d[0], v = d[d.length - 1], r; if (r = v < u) i = u, u = v, v = i; var i = logs(u), j = logs(v), p, k, t, n = count == null ? 10 : +count, z = []; if (!(base % 1) && j - i < n) { i = Math.round(i) - 1, j = Math.round(j) + 1; if (u > 0) for (; i < j; ++i) { for (k = 1, p = pows(i); k < base; ++k) { t = p * k; if (t < u) continue; if (t > v) break; z.push(t); } } else for (; i < j; ++i) { for (k = base - 1, p = pows(i); k >= 1; --k) { t = p * k; if (t < u) continue; if (t > v) break; z.push(t); } } } else { z = d3Array.ticks(i, j, Math.min(j - i, n)).map(pows); } return r ? z.reverse() : z; }; scale.tickFormat = function(count, specifier) { if (specifier == null) specifier = base === 10 ? ".0e" : ","; if (typeof specifier !== "function") specifier = d3Format.format(specifier); if (count === Infinity) return specifier; if (count == null) count = 10; var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate? return function(d) { var i = d / pows(Math.round(logs(d))); if (i * base < base - 0.5) i *= base; return i <= k ? specifier(d) : ""; }; }; scale.nice = function() { return domain(nice(domain(), { floor: function(x) { return pows(Math.floor(logs(x))); }, ceil: function(x) { return pows(Math.ceil(logs(x))); } })); }; scale.copy = function() { return copy(scale, log().base(base)); }; return scale; }
n/a
function ordinal(range$$1) { var index = d3Collection.map(), domain = [], unknown = implicit; range$$1 = range$$1 == null ? [] : slice.call(range$$1); function scale(d) { var key = d + "", i = index.get(key); if (!i) { if (unknown !== implicit) return unknown; index.set(key, i = domain.push(d)); } return range$$1[(i - 1) % range$$1.length]; } scale.domain = function(_) { if (!arguments.length) return domain.slice(); domain = [], index = d3Collection.map(); var i = -1, n = _.length, d, key; while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d)); return scale; }; scale.range = function(_) { return arguments.length ? (range$$1 = slice.call(_), scale) : range$$1.slice(); }; scale.unknown = function(_) { return arguments.length ? (unknown = _, scale) : unknown; }; scale.copy = function() { return ordinal() .domain(domain) .range(range$$1) .unknown(unknown); }; return scale; }
...
Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
#### Category Scales
These color schemes are designed to work with [d3.scaleOrdinal](#scaleOrdinal). For example:
```js
var color = d3.scaleOrdinal(d3.schemeCategory10);
```
For even more category scales, see [d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic).
<a name="schemeCategory10" href="#schemeCategory10">#</a> d3.<b>schemeCategory10
</b> [<>](https://github.com/d3/d3-scale/blob/master/src/category10.js "Source")
<img src="https://raw.githubusercontent.com/d3/d3-scale/master/img/category10.png" width="100%" height=
x22;40" alt="category10">
...
function point() { return pointish(band().paddingInner(1)); }
n/a
function pow() { var exponent = 1, scale = continuous(deinterpolate, reinterpolate), domain = scale.domain; function deinterpolate(a, b) { return (b = raise(b, exponent) - (a = raise(a, exponent))) ? function(x) { return (raise(x, exponent) - a) / b; } : constant(b); } function reinterpolate(a, b) { b = raise(b, exponent) - (a = raise(a, exponent)); return function(t) { return raise(a + b * t, 1 / exponent); }; } scale.exponent = function(_) { return arguments.length ? (exponent = +_, domain(domain())) : exponent; }; scale.copy = function() { return copy(scale, pow().exponent(exponent)); }; return linearish(scale); }
...
<a name="pow_copy" href="#pow_copy">#</a> <i>pow</i>.<b>copy
</b>() [<>](https://github.com/d3/d3-scale/blob/master/src/pow.js#L29 "Source")
See [*continuous*.copy](#continuous_copy).
<a name="scaleSqrt" href="#scaleSqrt">#</a> d3.<b>scaleSqrt</b>() [
x3c;>](https://github.com/d3/d3-scale/blob/master/src/pow.js#L36 "Source")
Constructs a new [continuous](#continuous-scales) [power scale](#power-scales) with the unit [domain](#continuous_domain) [0, 1],
the unit [range](#continuous_range) [0, 1], the [exponent](#pow_exponent) 0.5, the [default](https://github.com/d3/d3-interpolate
#interpolate) [interpolator](#continuous_interpolate) and [clamping](#continuous_clamp) disabled. This is a convenience method equivalent
to `d3.scalePow().exponent(0.5)`.
#### Log Scales
Log scales are similar to [linear scales](#linear-scales), except a logarithmic transform is applied to the input domain value before
the output range value is computed. The mapping to the range value *y* can be expressed as a function of the domain value *x*: *
y* = *m* log(<i>x</i>) + *b*.
As log(0) = -∞, a log scale domain must be **strictly-positive or strictly-negative**; the domain must not include or cross zero
. A log scale with a positive domain has a well-defined behavior for positive values, and a log scale with a negative domain has
a well-defined behavior for negative values. (For a negative domain, input and output values are implicitly multiplied by -1.)
The behavior of the scale is undefined if you pass a negative value to a log scale with a positive domain or vice versa.
...
function quantile$1() { var domain = [], range$$1 = [], thresholds = []; function rescale() { var i = 0, n = Math.max(1, range$$1.length); thresholds = new Array(n - 1); while (++i < n) thresholds[i - 1] = d3Array.quantile(domain, i / n); return scale; } function scale(x) { if (!isNaN(x = +x)) return range$$1[d3Array.bisect(thresholds, x)]; } scale.invertExtent = function(y) { var i = range$$1.indexOf(y); return i < 0 ? [NaN, NaN] : [ i > 0 ? thresholds[i - 1] : domain[0], i < thresholds.length ? thresholds[i] : domain[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 rescale(); }; scale.range = function(_) { return arguments.length ? (range$$1 = slice.call(_), rescale()) : range$$1.slice(); }; scale.quantiles = function() { return thresholds.slice(); }; scale.copy = function() { return quantile$1() .domain(domain) .range(range$$1); }; return scale; }
n/a
function quantize() { var x0 = 0, x1 = 1, n = 1, domain = [0.5], range$$1 = [0, 1]; function scale(x) { if (x <= x) return range$$1[d3Array.bisect(domain, x, 0, n)]; } function rescale() { var i = -1; domain = new Array(n); while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1); return scale; } scale.domain = function(_) { return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1]; }; scale.range = function(_) { return arguments.length ? (n = (range$$1 = slice.call(_)).length - 1, rescale()) : range$$1.slice(); }; scale.invertExtent = function(y) { var i = range$$1.indexOf(y); return i < 0 ? [NaN, NaN] : i < 1 ? [x0, domain[0]] : i >= n ? [domain[n - 1], x1] : [domain[i - 1], domain[i]]; }; scale.copy = function() { return quantize() .domain([x0, x1]) .range(range$$1); }; return linearish(scale); }
...
Constructs a new quantize scale with the unit [domain](#quantize_domain) [0, 1] and the unit [range](#quantize_range) [0, 1]. Thus
, the default quantize scale is equivalent to the [Math.round](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects
/Math/round) function.
<a name="_quantize" href="#_quantize">#</a> <i>quantize</i>(<i
x3e;value</i>) [<>](https://github.com/d3/d3-scale/blob/master/src/quantize.js#L5 "Source")
Given a *value* in the input [domain](#quantize_domain), returns the corresponding value in the output [range](#quantize_range).
For example, to apply a color encoding:
```js
var color = d3.scaleQuantize()
.domain([0, 1])
.range(["brown", "steelblue"]);
color(0.49); // "brown"
color(0.51); // "steelblue"
```
...
function sequential(interpolator) { var x0 = 0, x1 = 1, clamp = false; function scale(x) { var t = (x - x0) / (x1 - x0); return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t); } scale.domain = function(_) { return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1]; }; scale.clamp = function(_) { return arguments.length ? (clamp = !!_, scale) : clamp; }; scale.interpolator = function(_) { return arguments.length ? (interpolator = _, scale) : interpolator; }; scale.copy = function() { return sequential(interpolator).domain([x0, x1]).clamp(clamp); }; return linearish(scale); }
...
Sequential scales are similar to [continuous scales](#continuous-scales) in that they map a continuous, numeric input domain to
a continuous output range. However, unlike continuous scales, the output range of a sequential scale is fixed by its interpolator
and not configurable. These scales do not expose [invert](#continuous_invert), [range](#continuous_range), [rangeRound](#continuous_rangeRound
) and [interpolate](#continuous_interpolate) methods.
<a name="scaleSequential" href="#scaleSequential">#</a> d3.<b>scaleSequential
x3c;/b>(<i>interpolator</i>) [<>](https://github.com/d3/d3-scale/blob/master/src/sequential.js
"Source")
Constructs a new sequential scale with the given [*interpolator*](#sequential_interpolator) function. When the scale is [applied
](#_sequential), the interpolator will be invoked with a value typically in the range [0, 1], where 0 represents the start of the
domain, and 1 represents the end of the domain. For example, to implement the ill-advised [HSL](https://github.com/d3/d3-color#
hsl) rainbow scale:
```js
var rainbow = d3.scaleSequential(function(t) {
return d3.hsl(t * 360, 1, 0.5) + "";
});
```
A more aesthetically-pleasing and perceptually-effective cyclical hue encoding is to use [d3.interpolateRainbow](#interpolateRainbow
):
```js
...
function sqrt() { return pow().exponent(0.5); }
n/a
function threshold() { var domain = [0.5], range$$1 = [0, 1], n = 1; function scale(x) { if (x <= x) return range$$1[d3Array.bisect(domain, x, 0, n)]; } scale.domain = function(_) { return arguments.length ? (domain = slice.call(_), n = Math.min(domain.length, range$$1.length - 1), scale) : domain.slice(); }; scale.range = function(_) { return arguments.length ? (range$$1 = slice.call(_), n = Math.min(domain.length, range$$1.length - 1), scale) : range$$1.slice (); }; scale.invertExtent = function(y) { var i = range$$1.indexOf(y); return [domain[i - 1], domain[i]]; }; scale.copy = function() { return threshold() .domain(domain) .range(range$$1); }; return scale; }
...
Constructs a new threshold scale with the default [domain](#threshold_domain) [0.5] and the default [range](#threshold_range) [0
, 1]. Thus, the default threshold scale is equivalent to the [Math.round](https://developer.mozilla.org/en/JavaScript/Reference/
Global_Objects/Math/round) function for numbers; for example threshold(0.49) returns 0, and threshold(0.51) returns 1.
<a name="_threshold" href="#_threshold">#</a> <i>threshold</i>(<
;i>value</i>) [<>](https://github.com/d3/d3-scale/blob/master/src/threshold.js#L4 "Source")
Given a *value* in the input [domain](#threshold_domain), returns the corresponding value in the output [range](#threshold_range
). For example:
```js
var color = d3.scaleThreshold()
.domain([0, 1])
.range(["red", "white", "green"]);
color(-1); // "red"
color(0); // "white"
color(0.5); // "white"
color(1); // "green"
...
scaleTime = function () { 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)]); }
...
#### Time Scales
Time scales are a variant of [linear scales](#linear-scales) that have a temporal domain: domain values are coerced to [dates](https
://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) rather than numbers, and [invert](#continuous_invert) likewise
returns a date. Time scales implement [ticks](#time_ticks) based on [calendar intervals](https://github.com/d3/d3-time), taking
the pain out of generating axes for temporal domains.
For example, to create a position encoding:
```js
var x = d3.scaleTime()
.domain([new Date(2000, 0, 1), new Date(2000, 0, 2)])
.range([0, 960]);
x(new Date(2000, 0, 1, 5)); // 200
x(new Date(2000, 0, 1, 16)); // 640
x.invert(200); // Sat Jan 01 2000 05:00:00 GMT-0800 (PST)
x.invert(640); // Sat Jan 01 2000 16:00:00 GMT-0800 (PST)
...
scaleUtc = function () { 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)]); }
n/a