| 1 | // https://d3js.org/d3-scale/ v4.0.2 Copyright 2010-2021 Mike Bostock
|
|---|
| 2 | (function (global, factory) {
|
|---|
| 3 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('d3-interpolate'), require('d3-format'), require('d3-time'), require('d3-time-format')) :
|
|---|
| 4 | typeof define === 'function' && define.amd ? define(['exports', 'd3-array', 'd3-interpolate', 'd3-format', 'd3-time', 'd3-time-format'], factory) :
|
|---|
| 5 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}, global.d3, global.d3, global.d3, global.d3, global.d3));
|
|---|
| 6 | })(this, (function (exports, d3Array, d3Interpolate, d3Format, d3Time, d3TimeFormat) { 'use strict';
|
|---|
| 7 |
|
|---|
| 8 | function initRange(domain, range) {
|
|---|
| 9 | switch (arguments.length) {
|
|---|
| 10 | case 0: break;
|
|---|
| 11 | case 1: this.range(domain); break;
|
|---|
| 12 | default: this.range(range).domain(domain); break;
|
|---|
| 13 | }
|
|---|
| 14 | return this;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | function initInterpolator(domain, interpolator) {
|
|---|
| 18 | switch (arguments.length) {
|
|---|
| 19 | case 0: break;
|
|---|
| 20 | case 1: {
|
|---|
| 21 | if (typeof domain === "function") this.interpolator(domain);
|
|---|
| 22 | else this.range(domain);
|
|---|
| 23 | break;
|
|---|
| 24 | }
|
|---|
| 25 | default: {
|
|---|
| 26 | this.domain(domain);
|
|---|
| 27 | if (typeof interpolator === "function") this.interpolator(interpolator);
|
|---|
| 28 | else this.range(interpolator);
|
|---|
| 29 | break;
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | return this;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | const implicit = Symbol("implicit");
|
|---|
| 36 |
|
|---|
| 37 | function ordinal() {
|
|---|
| 38 | var index = new d3Array.InternMap(),
|
|---|
| 39 | domain = [],
|
|---|
| 40 | range = [],
|
|---|
| 41 | unknown = implicit;
|
|---|
| 42 |
|
|---|
| 43 | function scale(d) {
|
|---|
| 44 | let i = index.get(d);
|
|---|
| 45 | if (i === undefined) {
|
|---|
| 46 | if (unknown !== implicit) return unknown;
|
|---|
| 47 | index.set(d, i = domain.push(d) - 1);
|
|---|
| 48 | }
|
|---|
| 49 | return range[i % range.length];
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | scale.domain = function(_) {
|
|---|
| 53 | if (!arguments.length) return domain.slice();
|
|---|
| 54 | domain = [], index = new d3Array.InternMap();
|
|---|
| 55 | for (const value of _) {
|
|---|
| 56 | if (index.has(value)) continue;
|
|---|
| 57 | index.set(value, domain.push(value) - 1);
|
|---|
| 58 | }
|
|---|
| 59 | return scale;
|
|---|
| 60 | };
|
|---|
| 61 |
|
|---|
| 62 | scale.range = function(_) {
|
|---|
| 63 | return arguments.length ? (range = Array.from(_), scale) : range.slice();
|
|---|
| 64 | };
|
|---|
| 65 |
|
|---|
| 66 | scale.unknown = function(_) {
|
|---|
| 67 | return arguments.length ? (unknown = _, scale) : unknown;
|
|---|
| 68 | };
|
|---|
| 69 |
|
|---|
| 70 | scale.copy = function() {
|
|---|
| 71 | return ordinal(domain, range).unknown(unknown);
|
|---|
| 72 | };
|
|---|
| 73 |
|
|---|
| 74 | initRange.apply(scale, arguments);
|
|---|
| 75 |
|
|---|
| 76 | return scale;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | function band() {
|
|---|
| 80 | var scale = ordinal().unknown(undefined),
|
|---|
| 81 | domain = scale.domain,
|
|---|
| 82 | ordinalRange = scale.range,
|
|---|
| 83 | r0 = 0,
|
|---|
| 84 | r1 = 1,
|
|---|
| 85 | step,
|
|---|
| 86 | bandwidth,
|
|---|
| 87 | round = false,
|
|---|
| 88 | paddingInner = 0,
|
|---|
| 89 | paddingOuter = 0,
|
|---|
| 90 | align = 0.5;
|
|---|
| 91 |
|
|---|
| 92 | delete scale.unknown;
|
|---|
| 93 |
|
|---|
| 94 | function rescale() {
|
|---|
| 95 | var n = domain().length,
|
|---|
| 96 | reverse = r1 < r0,
|
|---|
| 97 | start = reverse ? r1 : r0,
|
|---|
| 98 | stop = reverse ? r0 : r1;
|
|---|
| 99 | step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
|
|---|
| 100 | if (round) step = Math.floor(step);
|
|---|
| 101 | start += (stop - start - step * (n - paddingInner)) * align;
|
|---|
| 102 | bandwidth = step * (1 - paddingInner);
|
|---|
| 103 | if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
|
|---|
| 104 | var values = d3Array.range(n).map(function(i) { return start + step * i; });
|
|---|
| 105 | return ordinalRange(reverse ? values.reverse() : values);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | scale.domain = function(_) {
|
|---|
| 109 | return arguments.length ? (domain(_), rescale()) : domain();
|
|---|
| 110 | };
|
|---|
| 111 |
|
|---|
| 112 | scale.range = function(_) {
|
|---|
| 113 | return arguments.length ? ([r0, r1] = _, r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
|
|---|
| 114 | };
|
|---|
| 115 |
|
|---|
| 116 | scale.rangeRound = function(_) {
|
|---|
| 117 | return [r0, r1] = _, r0 = +r0, r1 = +r1, round = true, rescale();
|
|---|
| 118 | };
|
|---|
| 119 |
|
|---|
| 120 | scale.bandwidth = function() {
|
|---|
| 121 | return bandwidth;
|
|---|
| 122 | };
|
|---|
| 123 |
|
|---|
| 124 | scale.step = function() {
|
|---|
| 125 | return step;
|
|---|
| 126 | };
|
|---|
| 127 |
|
|---|
| 128 | scale.round = function(_) {
|
|---|
| 129 | return arguments.length ? (round = !!_, rescale()) : round;
|
|---|
| 130 | };
|
|---|
| 131 |
|
|---|
| 132 | scale.padding = function(_) {
|
|---|
| 133 | return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
|
|---|
| 134 | };
|
|---|
| 135 |
|
|---|
| 136 | scale.paddingInner = function(_) {
|
|---|
| 137 | return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
|
|---|
| 138 | };
|
|---|
| 139 |
|
|---|
| 140 | scale.paddingOuter = function(_) {
|
|---|
| 141 | return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
|
|---|
| 142 | };
|
|---|
| 143 |
|
|---|
| 144 | scale.align = function(_) {
|
|---|
| 145 | return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
|
|---|
| 146 | };
|
|---|
| 147 |
|
|---|
| 148 | scale.copy = function() {
|
|---|
| 149 | return band(domain(), [r0, r1])
|
|---|
| 150 | .round(round)
|
|---|
| 151 | .paddingInner(paddingInner)
|
|---|
| 152 | .paddingOuter(paddingOuter)
|
|---|
| 153 | .align(align);
|
|---|
| 154 | };
|
|---|
| 155 |
|
|---|
| 156 | return initRange.apply(rescale(), arguments);
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | function pointish(scale) {
|
|---|
| 160 | var copy = scale.copy;
|
|---|
| 161 |
|
|---|
| 162 | scale.padding = scale.paddingOuter;
|
|---|
| 163 | delete scale.paddingInner;
|
|---|
| 164 | delete scale.paddingOuter;
|
|---|
| 165 |
|
|---|
| 166 | scale.copy = function() {
|
|---|
| 167 | return pointish(copy());
|
|---|
| 168 | };
|
|---|
| 169 |
|
|---|
| 170 | return scale;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | function point() {
|
|---|
| 174 | return pointish(band.apply(null, arguments).paddingInner(1));
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | function constants(x) {
|
|---|
| 178 | return function() {
|
|---|
| 179 | return x;
|
|---|
| 180 | };
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | function number$1(x) {
|
|---|
| 184 | return +x;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | var unit = [0, 1];
|
|---|
| 188 |
|
|---|
| 189 | function identity$1(x) {
|
|---|
| 190 | return x;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | function normalize(a, b) {
|
|---|
| 194 | return (b -= (a = +a))
|
|---|
| 195 | ? function(x) { return (x - a) / b; }
|
|---|
| 196 | : constants(isNaN(b) ? NaN : 0.5);
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | function clamper(a, b) {
|
|---|
| 200 | var t;
|
|---|
| 201 | if (a > b) t = a, a = b, b = t;
|
|---|
| 202 | return function(x) { return Math.max(a, Math.min(b, x)); };
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
|
|---|
| 206 | // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
|
|---|
| 207 | function bimap(domain, range, interpolate) {
|
|---|
| 208 | var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
|
|---|
| 209 | if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
|
|---|
| 210 | else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
|
|---|
| 211 | return function(x) { return r0(d0(x)); };
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | function polymap(domain, range, interpolate) {
|
|---|
| 215 | var j = Math.min(domain.length, range.length) - 1,
|
|---|
| 216 | d = new Array(j),
|
|---|
| 217 | r = new Array(j),
|
|---|
| 218 | i = -1;
|
|---|
| 219 |
|
|---|
| 220 | // Reverse descending domains.
|
|---|
| 221 | if (domain[j] < domain[0]) {
|
|---|
| 222 | domain = domain.slice().reverse();
|
|---|
| 223 | range = range.slice().reverse();
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | while (++i < j) {
|
|---|
| 227 | d[i] = normalize(domain[i], domain[i + 1]);
|
|---|
| 228 | r[i] = interpolate(range[i], range[i + 1]);
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | return function(x) {
|
|---|
| 232 | var i = d3Array.bisect(domain, x, 1, j) - 1;
|
|---|
| 233 | return r[i](d[i](x));
|
|---|
| 234 | };
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | function copy$1(source, target) {
|
|---|
| 238 | return target
|
|---|
| 239 | .domain(source.domain())
|
|---|
| 240 | .range(source.range())
|
|---|
| 241 | .interpolate(source.interpolate())
|
|---|
| 242 | .clamp(source.clamp())
|
|---|
| 243 | .unknown(source.unknown());
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | function transformer$2() {
|
|---|
| 247 | var domain = unit,
|
|---|
| 248 | range = unit,
|
|---|
| 249 | interpolate = d3Interpolate.interpolate,
|
|---|
| 250 | transform,
|
|---|
| 251 | untransform,
|
|---|
| 252 | unknown,
|
|---|
| 253 | clamp = identity$1,
|
|---|
| 254 | piecewise,
|
|---|
| 255 | output,
|
|---|
| 256 | input;
|
|---|
| 257 |
|
|---|
| 258 | function rescale() {
|
|---|
| 259 | var n = Math.min(domain.length, range.length);
|
|---|
| 260 | if (clamp !== identity$1) clamp = clamper(domain[0], domain[n - 1]);
|
|---|
| 261 | piecewise = n > 2 ? polymap : bimap;
|
|---|
| 262 | output = input = null;
|
|---|
| 263 | return scale;
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | function scale(x) {
|
|---|
| 267 | return x == null || isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | scale.invert = function(y) {
|
|---|
| 271 | return clamp(untransform((input || (input = piecewise(range, domain.map(transform), d3Interpolate.interpolateNumber)))(y)));
|
|---|
| 272 | };
|
|---|
| 273 |
|
|---|
| 274 | scale.domain = function(_) {
|
|---|
| 275 | return arguments.length ? (domain = Array.from(_, number$1), rescale()) : domain.slice();
|
|---|
| 276 | };
|
|---|
| 277 |
|
|---|
| 278 | scale.range = function(_) {
|
|---|
| 279 | return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
|
|---|
| 280 | };
|
|---|
| 281 |
|
|---|
| 282 | scale.rangeRound = function(_) {
|
|---|
| 283 | return range = Array.from(_), interpolate = d3Interpolate.interpolateRound, rescale();
|
|---|
| 284 | };
|
|---|
| 285 |
|
|---|
| 286 | scale.clamp = function(_) {
|
|---|
| 287 | return arguments.length ? (clamp = _ ? true : identity$1, rescale()) : clamp !== identity$1;
|
|---|
| 288 | };
|
|---|
| 289 |
|
|---|
| 290 | scale.interpolate = function(_) {
|
|---|
| 291 | return arguments.length ? (interpolate = _, rescale()) : interpolate;
|
|---|
| 292 | };
|
|---|
| 293 |
|
|---|
| 294 | scale.unknown = function(_) {
|
|---|
| 295 | return arguments.length ? (unknown = _, scale) : unknown;
|
|---|
| 296 | };
|
|---|
| 297 |
|
|---|
| 298 | return function(t, u) {
|
|---|
| 299 | transform = t, untransform = u;
|
|---|
| 300 | return rescale();
|
|---|
| 301 | };
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | function continuous() {
|
|---|
| 305 | return transformer$2()(identity$1, identity$1);
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | function tickFormat(start, stop, count, specifier) {
|
|---|
| 309 | var step = d3Array.tickStep(start, stop, count),
|
|---|
| 310 | precision;
|
|---|
| 311 | specifier = d3Format.formatSpecifier(specifier == null ? ",f" : specifier);
|
|---|
| 312 | switch (specifier.type) {
|
|---|
| 313 | case "s": {
|
|---|
| 314 | var value = Math.max(Math.abs(start), Math.abs(stop));
|
|---|
| 315 | if (specifier.precision == null && !isNaN(precision = d3Format.precisionPrefix(step, value))) specifier.precision = precision;
|
|---|
| 316 | return d3Format.formatPrefix(specifier, value);
|
|---|
| 317 | }
|
|---|
| 318 | case "":
|
|---|
| 319 | case "e":
|
|---|
| 320 | case "g":
|
|---|
| 321 | case "p":
|
|---|
| 322 | case "r": {
|
|---|
| 323 | if (specifier.precision == null && !isNaN(precision = d3Format.precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
|
|---|
| 324 | break;
|
|---|
| 325 | }
|
|---|
| 326 | case "f":
|
|---|
| 327 | case "%": {
|
|---|
| 328 | if (specifier.precision == null && !isNaN(precision = d3Format.precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
|
|---|
| 329 | break;
|
|---|
| 330 | }
|
|---|
| 331 | }
|
|---|
| 332 | return d3Format.format(specifier);
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | function linearish(scale) {
|
|---|
| 336 | var domain = scale.domain;
|
|---|
| 337 |
|
|---|
| 338 | scale.ticks = function(count) {
|
|---|
| 339 | var d = domain();
|
|---|
| 340 | return d3Array.ticks(d[0], d[d.length - 1], count == null ? 10 : count);
|
|---|
| 341 | };
|
|---|
| 342 |
|
|---|
| 343 | scale.tickFormat = function(count, specifier) {
|
|---|
| 344 | var d = domain();
|
|---|
| 345 | return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
|
|---|
| 346 | };
|
|---|
| 347 |
|
|---|
| 348 | scale.nice = function(count) {
|
|---|
| 349 | if (count == null) count = 10;
|
|---|
| 350 |
|
|---|
| 351 | var d = domain();
|
|---|
| 352 | var i0 = 0;
|
|---|
| 353 | var i1 = d.length - 1;
|
|---|
| 354 | var start = d[i0];
|
|---|
| 355 | var stop = d[i1];
|
|---|
| 356 | var prestep;
|
|---|
| 357 | var step;
|
|---|
| 358 | var maxIter = 10;
|
|---|
| 359 |
|
|---|
| 360 | if (stop < start) {
|
|---|
| 361 | step = start, start = stop, stop = step;
|
|---|
| 362 | step = i0, i0 = i1, i1 = step;
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 | while (maxIter-- > 0) {
|
|---|
| 366 | step = d3Array.tickIncrement(start, stop, count);
|
|---|
| 367 | if (step === prestep) {
|
|---|
| 368 | d[i0] = start;
|
|---|
| 369 | d[i1] = stop;
|
|---|
| 370 | return domain(d);
|
|---|
| 371 | } else if (step > 0) {
|
|---|
| 372 | start = Math.floor(start / step) * step;
|
|---|
| 373 | stop = Math.ceil(stop / step) * step;
|
|---|
| 374 | } else if (step < 0) {
|
|---|
| 375 | start = Math.ceil(start * step) / step;
|
|---|
| 376 | stop = Math.floor(stop * step) / step;
|
|---|
| 377 | } else {
|
|---|
| 378 | break;
|
|---|
| 379 | }
|
|---|
| 380 | prestep = step;
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | return scale;
|
|---|
| 384 | };
|
|---|
| 385 |
|
|---|
| 386 | return scale;
|
|---|
| 387 | }
|
|---|
| 388 |
|
|---|
| 389 | function linear() {
|
|---|
| 390 | var scale = continuous();
|
|---|
| 391 |
|
|---|
| 392 | scale.copy = function() {
|
|---|
| 393 | return copy$1(scale, linear());
|
|---|
| 394 | };
|
|---|
| 395 |
|
|---|
| 396 | initRange.apply(scale, arguments);
|
|---|
| 397 |
|
|---|
| 398 | return linearish(scale);
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | function identity(domain) {
|
|---|
| 402 | var unknown;
|
|---|
| 403 |
|
|---|
| 404 | function scale(x) {
|
|---|
| 405 | return x == null || isNaN(x = +x) ? unknown : x;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | scale.invert = scale;
|
|---|
| 409 |
|
|---|
| 410 | scale.domain = scale.range = function(_) {
|
|---|
| 411 | return arguments.length ? (domain = Array.from(_, number$1), scale) : domain.slice();
|
|---|
| 412 | };
|
|---|
| 413 |
|
|---|
| 414 | scale.unknown = function(_) {
|
|---|
| 415 | return arguments.length ? (unknown = _, scale) : unknown;
|
|---|
| 416 | };
|
|---|
| 417 |
|
|---|
| 418 | scale.copy = function() {
|
|---|
| 419 | return identity(domain).unknown(unknown);
|
|---|
| 420 | };
|
|---|
| 421 |
|
|---|
| 422 | domain = arguments.length ? Array.from(domain, number$1) : [0, 1];
|
|---|
| 423 |
|
|---|
| 424 | return linearish(scale);
|
|---|
| 425 | }
|
|---|
| 426 |
|
|---|
| 427 | function nice(domain, interval) {
|
|---|
| 428 | domain = domain.slice();
|
|---|
| 429 |
|
|---|
| 430 | var i0 = 0,
|
|---|
| 431 | i1 = domain.length - 1,
|
|---|
| 432 | x0 = domain[i0],
|
|---|
| 433 | x1 = domain[i1],
|
|---|
| 434 | t;
|
|---|
| 435 |
|
|---|
| 436 | if (x1 < x0) {
|
|---|
| 437 | t = i0, i0 = i1, i1 = t;
|
|---|
| 438 | t = x0, x0 = x1, x1 = t;
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | domain[i0] = interval.floor(x0);
|
|---|
| 442 | domain[i1] = interval.ceil(x1);
|
|---|
| 443 | return domain;
|
|---|
| 444 | }
|
|---|
| 445 |
|
|---|
| 446 | function transformLog(x) {
|
|---|
| 447 | return Math.log(x);
|
|---|
| 448 | }
|
|---|
| 449 |
|
|---|
| 450 | function transformExp(x) {
|
|---|
| 451 | return Math.exp(x);
|
|---|
| 452 | }
|
|---|
| 453 |
|
|---|
| 454 | function transformLogn(x) {
|
|---|
| 455 | return -Math.log(-x);
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | function transformExpn(x) {
|
|---|
| 459 | return -Math.exp(-x);
|
|---|
| 460 | }
|
|---|
| 461 |
|
|---|
| 462 | function pow10(x) {
|
|---|
| 463 | return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
|
|---|
| 464 | }
|
|---|
| 465 |
|
|---|
| 466 | function powp(base) {
|
|---|
| 467 | return base === 10 ? pow10
|
|---|
| 468 | : base === Math.E ? Math.exp
|
|---|
| 469 | : x => Math.pow(base, x);
|
|---|
| 470 | }
|
|---|
| 471 |
|
|---|
| 472 | function logp(base) {
|
|---|
| 473 | return base === Math.E ? Math.log
|
|---|
| 474 | : base === 10 && Math.log10
|
|---|
| 475 | || base === 2 && Math.log2
|
|---|
| 476 | || (base = Math.log(base), x => Math.log(x) / base);
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | function reflect(f) {
|
|---|
| 480 | return (x, k) => -f(-x, k);
|
|---|
| 481 | }
|
|---|
| 482 |
|
|---|
| 483 | function loggish(transform) {
|
|---|
| 484 | const scale = transform(transformLog, transformExp);
|
|---|
| 485 | const domain = scale.domain;
|
|---|
| 486 | let base = 10;
|
|---|
| 487 | let logs;
|
|---|
| 488 | let pows;
|
|---|
| 489 |
|
|---|
| 490 | function rescale() {
|
|---|
| 491 | logs = logp(base), pows = powp(base);
|
|---|
| 492 | if (domain()[0] < 0) {
|
|---|
| 493 | logs = reflect(logs), pows = reflect(pows);
|
|---|
| 494 | transform(transformLogn, transformExpn);
|
|---|
| 495 | } else {
|
|---|
| 496 | transform(transformLog, transformExp);
|
|---|
| 497 | }
|
|---|
| 498 | return scale;
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 | scale.base = function(_) {
|
|---|
| 502 | return arguments.length ? (base = +_, rescale()) : base;
|
|---|
| 503 | };
|
|---|
| 504 |
|
|---|
| 505 | scale.domain = function(_) {
|
|---|
| 506 | return arguments.length ? (domain(_), rescale()) : domain();
|
|---|
| 507 | };
|
|---|
| 508 |
|
|---|
| 509 | scale.ticks = count => {
|
|---|
| 510 | const d = domain();
|
|---|
| 511 | let u = d[0];
|
|---|
| 512 | let v = d[d.length - 1];
|
|---|
| 513 | const r = v < u;
|
|---|
| 514 |
|
|---|
| 515 | if (r) ([u, v] = [v, u]);
|
|---|
| 516 |
|
|---|
| 517 | let i = logs(u);
|
|---|
| 518 | let j = logs(v);
|
|---|
| 519 | let k;
|
|---|
| 520 | let t;
|
|---|
| 521 | const n = count == null ? 10 : +count;
|
|---|
| 522 | let z = [];
|
|---|
| 523 |
|
|---|
| 524 | if (!(base % 1) && j - i < n) {
|
|---|
| 525 | i = Math.floor(i), j = Math.ceil(j);
|
|---|
| 526 | if (u > 0) for (; i <= j; ++i) {
|
|---|
| 527 | for (k = 1; k < base; ++k) {
|
|---|
| 528 | t = i < 0 ? k / pows(-i) : k * pows(i);
|
|---|
| 529 | if (t < u) continue;
|
|---|
| 530 | if (t > v) break;
|
|---|
| 531 | z.push(t);
|
|---|
| 532 | }
|
|---|
| 533 | } else for (; i <= j; ++i) {
|
|---|
| 534 | for (k = base - 1; k >= 1; --k) {
|
|---|
| 535 | t = i > 0 ? k / pows(-i) : k * pows(i);
|
|---|
| 536 | if (t < u) continue;
|
|---|
| 537 | if (t > v) break;
|
|---|
| 538 | z.push(t);
|
|---|
| 539 | }
|
|---|
| 540 | }
|
|---|
| 541 | if (z.length * 2 < n) z = d3Array.ticks(u, v, n);
|
|---|
| 542 | } else {
|
|---|
| 543 | z = d3Array.ticks(i, j, Math.min(j - i, n)).map(pows);
|
|---|
| 544 | }
|
|---|
| 545 | return r ? z.reverse() : z;
|
|---|
| 546 | };
|
|---|
| 547 |
|
|---|
| 548 | scale.tickFormat = (count, specifier) => {
|
|---|
| 549 | if (count == null) count = 10;
|
|---|
| 550 | if (specifier == null) specifier = base === 10 ? "s" : ",";
|
|---|
| 551 | if (typeof specifier !== "function") {
|
|---|
| 552 | if (!(base % 1) && (specifier = d3Format.formatSpecifier(specifier)).precision == null) specifier.trim = true;
|
|---|
| 553 | specifier = d3Format.format(specifier);
|
|---|
| 554 | }
|
|---|
| 555 | if (count === Infinity) return specifier;
|
|---|
| 556 | const k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
|
|---|
| 557 | return d => {
|
|---|
| 558 | let i = d / pows(Math.round(logs(d)));
|
|---|
| 559 | if (i * base < base - 0.5) i *= base;
|
|---|
| 560 | return i <= k ? specifier(d) : "";
|
|---|
| 561 | };
|
|---|
| 562 | };
|
|---|
| 563 |
|
|---|
| 564 | scale.nice = () => {
|
|---|
| 565 | return domain(nice(domain(), {
|
|---|
| 566 | floor: x => pows(Math.floor(logs(x))),
|
|---|
| 567 | ceil: x => pows(Math.ceil(logs(x)))
|
|---|
| 568 | }));
|
|---|
| 569 | };
|
|---|
| 570 |
|
|---|
| 571 | return scale;
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | function log() {
|
|---|
| 575 | const scale = loggish(transformer$2()).domain([1, 10]);
|
|---|
| 576 | scale.copy = () => copy$1(scale, log()).base(scale.base());
|
|---|
| 577 | initRange.apply(scale, arguments);
|
|---|
| 578 | return scale;
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | function transformSymlog(c) {
|
|---|
| 582 | return function(x) {
|
|---|
| 583 | return Math.sign(x) * Math.log1p(Math.abs(x / c));
|
|---|
| 584 | };
|
|---|
| 585 | }
|
|---|
| 586 |
|
|---|
| 587 | function transformSymexp(c) {
|
|---|
| 588 | return function(x) {
|
|---|
| 589 | return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
|
|---|
| 590 | };
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | function symlogish(transform) {
|
|---|
| 594 | var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
|
|---|
| 595 |
|
|---|
| 596 | scale.constant = function(_) {
|
|---|
| 597 | return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
|
|---|
| 598 | };
|
|---|
| 599 |
|
|---|
| 600 | return linearish(scale);
|
|---|
| 601 | }
|
|---|
| 602 |
|
|---|
| 603 | function symlog() {
|
|---|
| 604 | var scale = symlogish(transformer$2());
|
|---|
| 605 |
|
|---|
| 606 | scale.copy = function() {
|
|---|
| 607 | return copy$1(scale, symlog()).constant(scale.constant());
|
|---|
| 608 | };
|
|---|
| 609 |
|
|---|
| 610 | return initRange.apply(scale, arguments);
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | function transformPow(exponent) {
|
|---|
| 614 | return function(x) {
|
|---|
| 615 | return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
|
|---|
| 616 | };
|
|---|
| 617 | }
|
|---|
| 618 |
|
|---|
| 619 | function transformSqrt(x) {
|
|---|
| 620 | return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
|
|---|
| 621 | }
|
|---|
| 622 |
|
|---|
| 623 | function transformSquare(x) {
|
|---|
| 624 | return x < 0 ? -x * x : x * x;
|
|---|
| 625 | }
|
|---|
| 626 |
|
|---|
| 627 | function powish(transform) {
|
|---|
| 628 | var scale = transform(identity$1, identity$1),
|
|---|
| 629 | exponent = 1;
|
|---|
| 630 |
|
|---|
| 631 | function rescale() {
|
|---|
| 632 | return exponent === 1 ? transform(identity$1, identity$1)
|
|---|
| 633 | : exponent === 0.5 ? transform(transformSqrt, transformSquare)
|
|---|
| 634 | : transform(transformPow(exponent), transformPow(1 / exponent));
|
|---|
| 635 | }
|
|---|
| 636 |
|
|---|
| 637 | scale.exponent = function(_) {
|
|---|
| 638 | return arguments.length ? (exponent = +_, rescale()) : exponent;
|
|---|
| 639 | };
|
|---|
| 640 |
|
|---|
| 641 | return linearish(scale);
|
|---|
| 642 | }
|
|---|
| 643 |
|
|---|
| 644 | function pow() {
|
|---|
| 645 | var scale = powish(transformer$2());
|
|---|
| 646 |
|
|---|
| 647 | scale.copy = function() {
|
|---|
| 648 | return copy$1(scale, pow()).exponent(scale.exponent());
|
|---|
| 649 | };
|
|---|
| 650 |
|
|---|
| 651 | initRange.apply(scale, arguments);
|
|---|
| 652 |
|
|---|
| 653 | return scale;
|
|---|
| 654 | }
|
|---|
| 655 |
|
|---|
| 656 | function sqrt() {
|
|---|
| 657 | return pow.apply(null, arguments).exponent(0.5);
|
|---|
| 658 | }
|
|---|
| 659 |
|
|---|
| 660 | function square(x) {
|
|---|
| 661 | return Math.sign(x) * x * x;
|
|---|
| 662 | }
|
|---|
| 663 |
|
|---|
| 664 | function unsquare(x) {
|
|---|
| 665 | return Math.sign(x) * Math.sqrt(Math.abs(x));
|
|---|
| 666 | }
|
|---|
| 667 |
|
|---|
| 668 | function radial() {
|
|---|
| 669 | var squared = continuous(),
|
|---|
| 670 | range = [0, 1],
|
|---|
| 671 | round = false,
|
|---|
| 672 | unknown;
|
|---|
| 673 |
|
|---|
| 674 | function scale(x) {
|
|---|
| 675 | var y = unsquare(squared(x));
|
|---|
| 676 | return isNaN(y) ? unknown : round ? Math.round(y) : y;
|
|---|
| 677 | }
|
|---|
| 678 |
|
|---|
| 679 | scale.invert = function(y) {
|
|---|
| 680 | return squared.invert(square(y));
|
|---|
| 681 | };
|
|---|
| 682 |
|
|---|
| 683 | scale.domain = function(_) {
|
|---|
| 684 | return arguments.length ? (squared.domain(_), scale) : squared.domain();
|
|---|
| 685 | };
|
|---|
| 686 |
|
|---|
| 687 | scale.range = function(_) {
|
|---|
| 688 | return arguments.length ? (squared.range((range = Array.from(_, number$1)).map(square)), scale) : range.slice();
|
|---|
| 689 | };
|
|---|
| 690 |
|
|---|
| 691 | scale.rangeRound = function(_) {
|
|---|
| 692 | return scale.range(_).round(true);
|
|---|
| 693 | };
|
|---|
| 694 |
|
|---|
| 695 | scale.round = function(_) {
|
|---|
| 696 | return arguments.length ? (round = !!_, scale) : round;
|
|---|
| 697 | };
|
|---|
| 698 |
|
|---|
| 699 | scale.clamp = function(_) {
|
|---|
| 700 | return arguments.length ? (squared.clamp(_), scale) : squared.clamp();
|
|---|
| 701 | };
|
|---|
| 702 |
|
|---|
| 703 | scale.unknown = function(_) {
|
|---|
| 704 | return arguments.length ? (unknown = _, scale) : unknown;
|
|---|
| 705 | };
|
|---|
| 706 |
|
|---|
| 707 | scale.copy = function() {
|
|---|
| 708 | return radial(squared.domain(), range)
|
|---|
| 709 | .round(round)
|
|---|
| 710 | .clamp(squared.clamp())
|
|---|
| 711 | .unknown(unknown);
|
|---|
| 712 | };
|
|---|
| 713 |
|
|---|
| 714 | initRange.apply(scale, arguments);
|
|---|
| 715 |
|
|---|
| 716 | return linearish(scale);
|
|---|
| 717 | }
|
|---|
| 718 |
|
|---|
| 719 | function quantile() {
|
|---|
| 720 | var domain = [],
|
|---|
| 721 | range = [],
|
|---|
| 722 | thresholds = [],
|
|---|
| 723 | unknown;
|
|---|
| 724 |
|
|---|
| 725 | function rescale() {
|
|---|
| 726 | var i = 0, n = Math.max(1, range.length);
|
|---|
| 727 | thresholds = new Array(n - 1);
|
|---|
| 728 | while (++i < n) thresholds[i - 1] = d3Array.quantileSorted(domain, i / n);
|
|---|
| 729 | return scale;
|
|---|
| 730 | }
|
|---|
| 731 |
|
|---|
| 732 | function scale(x) {
|
|---|
| 733 | return x == null || isNaN(x = +x) ? unknown : range[d3Array.bisect(thresholds, x)];
|
|---|
| 734 | }
|
|---|
| 735 |
|
|---|
| 736 | scale.invertExtent = function(y) {
|
|---|
| 737 | var i = range.indexOf(y);
|
|---|
| 738 | return i < 0 ? [NaN, NaN] : [
|
|---|
| 739 | i > 0 ? thresholds[i - 1] : domain[0],
|
|---|
| 740 | i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
|
|---|
| 741 | ];
|
|---|
| 742 | };
|
|---|
| 743 |
|
|---|
| 744 | scale.domain = function(_) {
|
|---|
| 745 | if (!arguments.length) return domain.slice();
|
|---|
| 746 | domain = [];
|
|---|
| 747 | for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
|
|---|
| 748 | domain.sort(d3Array.ascending);
|
|---|
| 749 | return rescale();
|
|---|
| 750 | };
|
|---|
| 751 |
|
|---|
| 752 | scale.range = function(_) {
|
|---|
| 753 | return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
|
|---|
| 754 | };
|
|---|
| 755 |
|
|---|
| 756 | scale.unknown = function(_) {
|
|---|
| 757 | return arguments.length ? (unknown = _, scale) : unknown;
|
|---|
| 758 | };
|
|---|
| 759 |
|
|---|
| 760 | scale.quantiles = function() {
|
|---|
| 761 | return thresholds.slice();
|
|---|
| 762 | };
|
|---|
| 763 |
|
|---|
| 764 | scale.copy = function() {
|
|---|
| 765 | return quantile()
|
|---|
| 766 | .domain(domain)
|
|---|
| 767 | .range(range)
|
|---|
| 768 | .unknown(unknown);
|
|---|
| 769 | };
|
|---|
| 770 |
|
|---|
| 771 | return initRange.apply(scale, arguments);
|
|---|
| 772 | }
|
|---|
| 773 |
|
|---|
| 774 | function quantize() {
|
|---|
| 775 | var x0 = 0,
|
|---|
| 776 | x1 = 1,
|
|---|
| 777 | n = 1,
|
|---|
| 778 | domain = [0.5],
|
|---|
| 779 | range = [0, 1],
|
|---|
| 780 | unknown;
|
|---|
| 781 |
|
|---|
| 782 | function scale(x) {
|
|---|
| 783 | return x != null && x <= x ? range[d3Array.bisect(domain, x, 0, n)] : unknown;
|
|---|
| 784 | }
|
|---|
| 785 |
|
|---|
| 786 | function rescale() {
|
|---|
| 787 | var i = -1;
|
|---|
| 788 | domain = new Array(n);
|
|---|
| 789 | while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
|
|---|
| 790 | return scale;
|
|---|
| 791 | }
|
|---|
| 792 |
|
|---|
| 793 | scale.domain = function(_) {
|
|---|
| 794 | return arguments.length ? ([x0, x1] = _, x0 = +x0, x1 = +x1, rescale()) : [x0, x1];
|
|---|
| 795 | };
|
|---|
| 796 |
|
|---|
| 797 | scale.range = function(_) {
|
|---|
| 798 | return arguments.length ? (n = (range = Array.from(_)).length - 1, rescale()) : range.slice();
|
|---|
| 799 | };
|
|---|
| 800 |
|
|---|
| 801 | scale.invertExtent = function(y) {
|
|---|
| 802 | var i = range.indexOf(y);
|
|---|
| 803 | return i < 0 ? [NaN, NaN]
|
|---|
| 804 | : i < 1 ? [x0, domain[0]]
|
|---|
| 805 | : i >= n ? [domain[n - 1], x1]
|
|---|
| 806 | : [domain[i - 1], domain[i]];
|
|---|
| 807 | };
|
|---|
| 808 |
|
|---|
| 809 | scale.unknown = function(_) {
|
|---|
| 810 | return arguments.length ? (unknown = _, scale) : scale;
|
|---|
| 811 | };
|
|---|
| 812 |
|
|---|
| 813 | scale.thresholds = function() {
|
|---|
| 814 | return domain.slice();
|
|---|
| 815 | };
|
|---|
| 816 |
|
|---|
| 817 | scale.copy = function() {
|
|---|
| 818 | return quantize()
|
|---|
| 819 | .domain([x0, x1])
|
|---|
| 820 | .range(range)
|
|---|
| 821 | .unknown(unknown);
|
|---|
| 822 | };
|
|---|
| 823 |
|
|---|
| 824 | return initRange.apply(linearish(scale), arguments);
|
|---|
| 825 | }
|
|---|
| 826 |
|
|---|
| 827 | function threshold() {
|
|---|
| 828 | var domain = [0.5],
|
|---|
| 829 | range = [0, 1],
|
|---|
| 830 | unknown,
|
|---|
| 831 | n = 1;
|
|---|
| 832 |
|
|---|
| 833 | function scale(x) {
|
|---|
| 834 | return x != null && x <= x ? range[d3Array.bisect(domain, x, 0, n)] : unknown;
|
|---|
| 835 | }
|
|---|
| 836 |
|
|---|
| 837 | scale.domain = function(_) {
|
|---|
| 838 | return arguments.length ? (domain = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
|
|---|
| 839 | };
|
|---|
| 840 |
|
|---|
| 841 | scale.range = function(_) {
|
|---|
| 842 | return arguments.length ? (range = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
|
|---|
| 843 | };
|
|---|
| 844 |
|
|---|
| 845 | scale.invertExtent = function(y) {
|
|---|
| 846 | var i = range.indexOf(y);
|
|---|
| 847 | return [domain[i - 1], domain[i]];
|
|---|
| 848 | };
|
|---|
| 849 |
|
|---|
| 850 | scale.unknown = function(_) {
|
|---|
| 851 | return arguments.length ? (unknown = _, scale) : unknown;
|
|---|
| 852 | };
|
|---|
| 853 |
|
|---|
| 854 | scale.copy = function() {
|
|---|
| 855 | return threshold()
|
|---|
| 856 | .domain(domain)
|
|---|
| 857 | .range(range)
|
|---|
| 858 | .unknown(unknown);
|
|---|
| 859 | };
|
|---|
| 860 |
|
|---|
| 861 | return initRange.apply(scale, arguments);
|
|---|
| 862 | }
|
|---|
| 863 |
|
|---|
| 864 | function date(t) {
|
|---|
| 865 | return new Date(t);
|
|---|
| 866 | }
|
|---|
| 867 |
|
|---|
| 868 | function number(t) {
|
|---|
| 869 | return t instanceof Date ? +t : +new Date(+t);
|
|---|
| 870 | }
|
|---|
| 871 |
|
|---|
| 872 | function calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format) {
|
|---|
| 873 | var scale = continuous(),
|
|---|
| 874 | invert = scale.invert,
|
|---|
| 875 | domain = scale.domain;
|
|---|
| 876 |
|
|---|
| 877 | var formatMillisecond = format(".%L"),
|
|---|
| 878 | formatSecond = format(":%S"),
|
|---|
| 879 | formatMinute = format("%I:%M"),
|
|---|
| 880 | formatHour = format("%I %p"),
|
|---|
| 881 | formatDay = format("%a %d"),
|
|---|
| 882 | formatWeek = format("%b %d"),
|
|---|
| 883 | formatMonth = format("%B"),
|
|---|
| 884 | formatYear = format("%Y");
|
|---|
| 885 |
|
|---|
| 886 | function tickFormat(date) {
|
|---|
| 887 | return (second(date) < date ? formatMillisecond
|
|---|
| 888 | : minute(date) < date ? formatSecond
|
|---|
| 889 | : hour(date) < date ? formatMinute
|
|---|
| 890 | : day(date) < date ? formatHour
|
|---|
| 891 | : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
|
|---|
| 892 | : year(date) < date ? formatMonth
|
|---|
| 893 | : formatYear)(date);
|
|---|
| 894 | }
|
|---|
| 895 |
|
|---|
| 896 | scale.invert = function(y) {
|
|---|
| 897 | return new Date(invert(y));
|
|---|
| 898 | };
|
|---|
| 899 |
|
|---|
| 900 | scale.domain = function(_) {
|
|---|
| 901 | return arguments.length ? domain(Array.from(_, number)) : domain().map(date);
|
|---|
| 902 | };
|
|---|
| 903 |
|
|---|
| 904 | scale.ticks = function(interval) {
|
|---|
| 905 | var d = domain();
|
|---|
| 906 | return ticks(d[0], d[d.length - 1], interval == null ? 10 : interval);
|
|---|
| 907 | };
|
|---|
| 908 |
|
|---|
| 909 | scale.tickFormat = function(count, specifier) {
|
|---|
| 910 | return specifier == null ? tickFormat : format(specifier);
|
|---|
| 911 | };
|
|---|
| 912 |
|
|---|
| 913 | scale.nice = function(interval) {
|
|---|
| 914 | var d = domain();
|
|---|
| 915 | if (!interval || typeof interval.range !== "function") interval = tickInterval(d[0], d[d.length - 1], interval == null ? 10 : interval);
|
|---|
| 916 | return interval ? domain(nice(d, interval)) : scale;
|
|---|
| 917 | };
|
|---|
| 918 |
|
|---|
| 919 | scale.copy = function() {
|
|---|
| 920 | return copy$1(scale, calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format));
|
|---|
| 921 | };
|
|---|
| 922 |
|
|---|
| 923 | return scale;
|
|---|
| 924 | }
|
|---|
| 925 |
|
|---|
| 926 | function time() {
|
|---|
| 927 | return initRange.apply(calendar(d3Time.timeTicks, d3Time.timeTickInterval, d3Time.timeYear, d3Time.timeMonth, d3Time.timeWeek, d3Time.timeDay, d3Time.timeHour, d3Time.timeMinute, d3Time.timeSecond, d3TimeFormat.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
|
|---|
| 928 | }
|
|---|
| 929 |
|
|---|
| 930 | function utcTime() {
|
|---|
| 931 | return initRange.apply(calendar(d3Time.utcTicks, d3Time.utcTickInterval, d3Time.utcYear, d3Time.utcMonth, d3Time.utcWeek, d3Time.utcDay, d3Time.utcHour, d3Time.utcMinute, d3Time.utcSecond, d3TimeFormat.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 | function transformer$1() {
|
|---|
| 935 | var x0 = 0,
|
|---|
| 936 | x1 = 1,
|
|---|
| 937 | t0,
|
|---|
| 938 | t1,
|
|---|
| 939 | k10,
|
|---|
| 940 | transform,
|
|---|
| 941 | interpolator = identity$1,
|
|---|
| 942 | clamp = false,
|
|---|
| 943 | unknown;
|
|---|
| 944 |
|
|---|
| 945 | function scale(x) {
|
|---|
| 946 | return x == null || isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
|
|---|
| 947 | }
|
|---|
| 948 |
|
|---|
| 949 | scale.domain = function(_) {
|
|---|
| 950 | return arguments.length ? ([x0, x1] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
|
|---|
| 951 | };
|
|---|
| 952 |
|
|---|
| 953 | scale.clamp = function(_) {
|
|---|
| 954 | return arguments.length ? (clamp = !!_, scale) : clamp;
|
|---|
| 955 | };
|
|---|
| 956 |
|
|---|
| 957 | scale.interpolator = function(_) {
|
|---|
| 958 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
|---|
| 959 | };
|
|---|
| 960 |
|
|---|
| 961 | function range(interpolate) {
|
|---|
| 962 | return function(_) {
|
|---|
| 963 | var r0, r1;
|
|---|
| 964 | return arguments.length ? ([r0, r1] = _, interpolator = interpolate(r0, r1), scale) : [interpolator(0), interpolator(1)];
|
|---|
| 965 | };
|
|---|
| 966 | }
|
|---|
| 967 |
|
|---|
| 968 | scale.range = range(d3Interpolate.interpolate);
|
|---|
| 969 |
|
|---|
| 970 | scale.rangeRound = range(d3Interpolate.interpolateRound);
|
|---|
| 971 |
|
|---|
| 972 | scale.unknown = function(_) {
|
|---|
| 973 | return arguments.length ? (unknown = _, scale) : unknown;
|
|---|
| 974 | };
|
|---|
| 975 |
|
|---|
| 976 | return function(t) {
|
|---|
| 977 | transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
|
|---|
| 978 | return scale;
|
|---|
| 979 | };
|
|---|
| 980 | }
|
|---|
| 981 |
|
|---|
| 982 | function copy(source, target) {
|
|---|
| 983 | return target
|
|---|
| 984 | .domain(source.domain())
|
|---|
| 985 | .interpolator(source.interpolator())
|
|---|
| 986 | .clamp(source.clamp())
|
|---|
| 987 | .unknown(source.unknown());
|
|---|
| 988 | }
|
|---|
| 989 |
|
|---|
| 990 | function sequential() {
|
|---|
| 991 | var scale = linearish(transformer$1()(identity$1));
|
|---|
| 992 |
|
|---|
| 993 | scale.copy = function() {
|
|---|
| 994 | return copy(scale, sequential());
|
|---|
| 995 | };
|
|---|
| 996 |
|
|---|
| 997 | return initInterpolator.apply(scale, arguments);
|
|---|
| 998 | }
|
|---|
| 999 |
|
|---|
| 1000 | function sequentialLog() {
|
|---|
| 1001 | var scale = loggish(transformer$1()).domain([1, 10]);
|
|---|
| 1002 |
|
|---|
| 1003 | scale.copy = function() {
|
|---|
| 1004 | return copy(scale, sequentialLog()).base(scale.base());
|
|---|
| 1005 | };
|
|---|
| 1006 |
|
|---|
| 1007 | return initInterpolator.apply(scale, arguments);
|
|---|
| 1008 | }
|
|---|
| 1009 |
|
|---|
| 1010 | function sequentialSymlog() {
|
|---|
| 1011 | var scale = symlogish(transformer$1());
|
|---|
| 1012 |
|
|---|
| 1013 | scale.copy = function() {
|
|---|
| 1014 | return copy(scale, sequentialSymlog()).constant(scale.constant());
|
|---|
| 1015 | };
|
|---|
| 1016 |
|
|---|
| 1017 | return initInterpolator.apply(scale, arguments);
|
|---|
| 1018 | }
|
|---|
| 1019 |
|
|---|
| 1020 | function sequentialPow() {
|
|---|
| 1021 | var scale = powish(transformer$1());
|
|---|
| 1022 |
|
|---|
| 1023 | scale.copy = function() {
|
|---|
| 1024 | return copy(scale, sequentialPow()).exponent(scale.exponent());
|
|---|
| 1025 | };
|
|---|
| 1026 |
|
|---|
| 1027 | return initInterpolator.apply(scale, arguments);
|
|---|
| 1028 | }
|
|---|
| 1029 |
|
|---|
| 1030 | function sequentialSqrt() {
|
|---|
| 1031 | return sequentialPow.apply(null, arguments).exponent(0.5);
|
|---|
| 1032 | }
|
|---|
| 1033 |
|
|---|
| 1034 | function sequentialQuantile() {
|
|---|
| 1035 | var domain = [],
|
|---|
| 1036 | interpolator = identity$1;
|
|---|
| 1037 |
|
|---|
| 1038 | function scale(x) {
|
|---|
| 1039 | if (x != null && !isNaN(x = +x)) return interpolator((d3Array.bisect(domain, x, 1) - 1) / (domain.length - 1));
|
|---|
| 1040 | }
|
|---|
| 1041 |
|
|---|
| 1042 | scale.domain = function(_) {
|
|---|
| 1043 | if (!arguments.length) return domain.slice();
|
|---|
| 1044 | domain = [];
|
|---|
| 1045 | for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
|
|---|
| 1046 | domain.sort(d3Array.ascending);
|
|---|
| 1047 | return scale;
|
|---|
| 1048 | };
|
|---|
| 1049 |
|
|---|
| 1050 | scale.interpolator = function(_) {
|
|---|
| 1051 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
|---|
| 1052 | };
|
|---|
| 1053 |
|
|---|
| 1054 | scale.range = function() {
|
|---|
| 1055 | return domain.map((d, i) => interpolator(i / (domain.length - 1)));
|
|---|
| 1056 | };
|
|---|
| 1057 |
|
|---|
| 1058 | scale.quantiles = function(n) {
|
|---|
| 1059 | return Array.from({length: n + 1}, (_, i) => d3Array.quantile(domain, i / n));
|
|---|
| 1060 | };
|
|---|
| 1061 |
|
|---|
| 1062 | scale.copy = function() {
|
|---|
| 1063 | return sequentialQuantile(interpolator).domain(domain);
|
|---|
| 1064 | };
|
|---|
| 1065 |
|
|---|
| 1066 | return initInterpolator.apply(scale, arguments);
|
|---|
| 1067 | }
|
|---|
| 1068 |
|
|---|
| 1069 | function transformer() {
|
|---|
| 1070 | var x0 = 0,
|
|---|
| 1071 | x1 = 0.5,
|
|---|
| 1072 | x2 = 1,
|
|---|
| 1073 | s = 1,
|
|---|
| 1074 | t0,
|
|---|
| 1075 | t1,
|
|---|
| 1076 | t2,
|
|---|
| 1077 | k10,
|
|---|
| 1078 | k21,
|
|---|
| 1079 | interpolator = identity$1,
|
|---|
| 1080 | transform,
|
|---|
| 1081 | clamp = false,
|
|---|
| 1082 | unknown;
|
|---|
| 1083 |
|
|---|
| 1084 | function scale(x) {
|
|---|
| 1085 | return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (s * x < s * t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x));
|
|---|
| 1086 | }
|
|---|
| 1087 |
|
|---|
| 1088 | scale.domain = function(_) {
|
|---|
| 1089 | return arguments.length ? ([x0, x1, x2] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), t2 = transform(x2 = +x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1, scale) : [x0, x1, x2];
|
|---|
| 1090 | };
|
|---|
| 1091 |
|
|---|
| 1092 | scale.clamp = function(_) {
|
|---|
| 1093 | return arguments.length ? (clamp = !!_, scale) : clamp;
|
|---|
| 1094 | };
|
|---|
| 1095 |
|
|---|
| 1096 | scale.interpolator = function(_) {
|
|---|
| 1097 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
|---|
| 1098 | };
|
|---|
| 1099 |
|
|---|
| 1100 | function range(interpolate) {
|
|---|
| 1101 | return function(_) {
|
|---|
| 1102 | var r0, r1, r2;
|
|---|
| 1103 | return arguments.length ? ([r0, r1, r2] = _, interpolator = d3Interpolate.piecewise(interpolate, [r0, r1, r2]), scale) : [interpolator(0), interpolator(0.5), interpolator(1)];
|
|---|
| 1104 | };
|
|---|
| 1105 | }
|
|---|
| 1106 |
|
|---|
| 1107 | scale.range = range(d3Interpolate.interpolate);
|
|---|
| 1108 |
|
|---|
| 1109 | scale.rangeRound = range(d3Interpolate.interpolateRound);
|
|---|
| 1110 |
|
|---|
| 1111 | scale.unknown = function(_) {
|
|---|
| 1112 | return arguments.length ? (unknown = _, scale) : unknown;
|
|---|
| 1113 | };
|
|---|
| 1114 |
|
|---|
| 1115 | return function(t) {
|
|---|
| 1116 | 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), s = t1 < t0 ? -1 : 1;
|
|---|
| 1117 | return scale;
|
|---|
| 1118 | };
|
|---|
| 1119 | }
|
|---|
| 1120 |
|
|---|
| 1121 | function diverging() {
|
|---|
| 1122 | var scale = linearish(transformer()(identity$1));
|
|---|
| 1123 |
|
|---|
| 1124 | scale.copy = function() {
|
|---|
| 1125 | return copy(scale, diverging());
|
|---|
| 1126 | };
|
|---|
| 1127 |
|
|---|
| 1128 | return initInterpolator.apply(scale, arguments);
|
|---|
| 1129 | }
|
|---|
| 1130 |
|
|---|
| 1131 | function divergingLog() {
|
|---|
| 1132 | var scale = loggish(transformer()).domain([0.1, 1, 10]);
|
|---|
| 1133 |
|
|---|
| 1134 | scale.copy = function() {
|
|---|
| 1135 | return copy(scale, divergingLog()).base(scale.base());
|
|---|
| 1136 | };
|
|---|
| 1137 |
|
|---|
| 1138 | return initInterpolator.apply(scale, arguments);
|
|---|
| 1139 | }
|
|---|
| 1140 |
|
|---|
| 1141 | function divergingSymlog() {
|
|---|
| 1142 | var scale = symlogish(transformer());
|
|---|
| 1143 |
|
|---|
| 1144 | scale.copy = function() {
|
|---|
| 1145 | return copy(scale, divergingSymlog()).constant(scale.constant());
|
|---|
| 1146 | };
|
|---|
| 1147 |
|
|---|
| 1148 | return initInterpolator.apply(scale, arguments);
|
|---|
| 1149 | }
|
|---|
| 1150 |
|
|---|
| 1151 | function divergingPow() {
|
|---|
| 1152 | var scale = powish(transformer());
|
|---|
| 1153 |
|
|---|
| 1154 | scale.copy = function() {
|
|---|
| 1155 | return copy(scale, divergingPow()).exponent(scale.exponent());
|
|---|
| 1156 | };
|
|---|
| 1157 |
|
|---|
| 1158 | return initInterpolator.apply(scale, arguments);
|
|---|
| 1159 | }
|
|---|
| 1160 |
|
|---|
| 1161 | function divergingSqrt() {
|
|---|
| 1162 | return divergingPow.apply(null, arguments).exponent(0.5);
|
|---|
| 1163 | }
|
|---|
| 1164 |
|
|---|
| 1165 | exports.scaleBand = band;
|
|---|
| 1166 | exports.scaleDiverging = diverging;
|
|---|
| 1167 | exports.scaleDivergingLog = divergingLog;
|
|---|
| 1168 | exports.scaleDivergingPow = divergingPow;
|
|---|
| 1169 | exports.scaleDivergingSqrt = divergingSqrt;
|
|---|
| 1170 | exports.scaleDivergingSymlog = divergingSymlog;
|
|---|
| 1171 | exports.scaleIdentity = identity;
|
|---|
| 1172 | exports.scaleImplicit = implicit;
|
|---|
| 1173 | exports.scaleLinear = linear;
|
|---|
| 1174 | exports.scaleLog = log;
|
|---|
| 1175 | exports.scaleOrdinal = ordinal;
|
|---|
| 1176 | exports.scalePoint = point;
|
|---|
| 1177 | exports.scalePow = pow;
|
|---|
| 1178 | exports.scaleQuantile = quantile;
|
|---|
| 1179 | exports.scaleQuantize = quantize;
|
|---|
| 1180 | exports.scaleRadial = radial;
|
|---|
| 1181 | exports.scaleSequential = sequential;
|
|---|
| 1182 | exports.scaleSequentialLog = sequentialLog;
|
|---|
| 1183 | exports.scaleSequentialPow = sequentialPow;
|
|---|
| 1184 | exports.scaleSequentialQuantile = sequentialQuantile;
|
|---|
| 1185 | exports.scaleSequentialSqrt = sequentialSqrt;
|
|---|
| 1186 | exports.scaleSequentialSymlog = sequentialSymlog;
|
|---|
| 1187 | exports.scaleSqrt = sqrt;
|
|---|
| 1188 | exports.scaleSymlog = symlog;
|
|---|
| 1189 | exports.scaleThreshold = threshold;
|
|---|
| 1190 | exports.scaleTime = time;
|
|---|
| 1191 | exports.scaleUtc = utcTime;
|
|---|
| 1192 | exports.tickFormat = tickFormat;
|
|---|
| 1193 |
|
|---|
| 1194 | Object.defineProperty(exports, '__esModule', { value: true });
|
|---|
| 1195 |
|
|---|
| 1196 | }));
|
|---|