1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Pow = void 0;
|
4 | const util_1 = require("@antv/util");
|
5 | const continuous_1 = require("./continuous");
|
6 | const utils_1 = require("../utils");
|
7 | const d3_ticks_1 = require("../tick-methods/d3-ticks");
|
8 | const transformPow = (exponent) => {
|
9 | return (x) => {
|
10 | return x < 0 ? -((-x) ** exponent) : x ** exponent;
|
11 | };
|
12 | };
|
13 | const transformPowInvert = (exponent) => {
|
14 | return (x) => {
|
15 | return x < 0 ? -((-x) ** (1 / exponent)) : x ** (1 / exponent);
|
16 | };
|
17 | };
|
18 | const transformSqrt = (x) => {
|
19 | return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
|
20 | };
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | class Pow extends continuous_1.Continuous {
|
28 | getDefaultOptions() {
|
29 | return {
|
30 | domain: [0, 1],
|
31 | range: [0, 1],
|
32 | nice: false,
|
33 | clamp: false,
|
34 | round: false,
|
35 | exponent: 2,
|
36 | interpolate: utils_1.createInterpolateValue,
|
37 | tickMethod: d3_ticks_1.d3Ticks,
|
38 | tickCount: 5,
|
39 | };
|
40 | }
|
41 |
|
42 | constructor(options) {
|
43 | super(options);
|
44 | }
|
45 | chooseTransforms() {
|
46 | const { exponent } = this.options;
|
47 | if (exponent === 1)
|
48 | return [util_1.identity, util_1.identity];
|
49 | const transform = exponent === 0.5 ? transformSqrt : transformPow(exponent);
|
50 | const untransform = transformPowInvert(exponent);
|
51 | return [transform, untransform];
|
52 | }
|
53 | clone() {
|
54 | return new Pow(this.options);
|
55 | }
|
56 | }
|
57 | exports.Pow = Pow;
|
58 |
|
\ | No newline at end of file |