| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = pow;
|
|---|
| 7 | exports.powish = powish;
|
|---|
| 8 | exports.sqrt = sqrt;
|
|---|
| 9 | var _linear = require("./linear.js");
|
|---|
| 10 | var _continuous = require("./continuous.js");
|
|---|
| 11 | var _init = require("./init.js");
|
|---|
| 12 | function transformPow(exponent) {
|
|---|
| 13 | return function (x) {
|
|---|
| 14 | return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
|
|---|
| 15 | };
|
|---|
| 16 | }
|
|---|
| 17 | function transformSqrt(x) {
|
|---|
| 18 | return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
|
|---|
| 19 | }
|
|---|
| 20 | function transformSquare(x) {
|
|---|
| 21 | return x < 0 ? -x * x : x * x;
|
|---|
| 22 | }
|
|---|
| 23 | function powish(transform) {
|
|---|
| 24 | var scale = transform(_continuous.identity, _continuous.identity),
|
|---|
| 25 | exponent = 1;
|
|---|
| 26 | function rescale() {
|
|---|
| 27 | return exponent === 1 ? transform(_continuous.identity, _continuous.identity) : exponent === 0.5 ? transform(transformSqrt, transformSquare) : transform(transformPow(exponent), transformPow(1 / exponent));
|
|---|
| 28 | }
|
|---|
| 29 | scale.exponent = function (_) {
|
|---|
| 30 | return arguments.length ? (exponent = +_, rescale()) : exponent;
|
|---|
| 31 | };
|
|---|
| 32 | return (0, _linear.linearish)(scale);
|
|---|
| 33 | }
|
|---|
| 34 | function pow() {
|
|---|
| 35 | var scale = powish((0, _continuous.transformer)());
|
|---|
| 36 | scale.copy = function () {
|
|---|
| 37 | return (0, _continuous.copy)(scale, pow()).exponent(scale.exponent());
|
|---|
| 38 | };
|
|---|
| 39 | _init.initRange.apply(scale, arguments);
|
|---|
| 40 | return scale;
|
|---|
| 41 | }
|
|---|
| 42 | function sqrt() {
|
|---|
| 43 | return pow.apply(null, arguments).exponent(0.5);
|
|---|
| 44 | } |
|---|