UNPKG

2.46 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var Diverging_1;
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.Diverging = void 0;
11const util_1 = require("@antv/util");
12const d3_ticks_1 = require("../tick-methods/d3-ticks");
13const utils_1 = require("../utils");
14const linear_1 = require("./linear");
15function rangeOf(interpolator) {
16 return [interpolator(0), interpolator(0.5), interpolator(1)];
17}
18const normalizeDomain = (domain) => {
19 const [d0, d1, d2] = domain;
20 // [d0, d1] => [0, 0.5]
21 const normalizeLeft = (0, utils_1.compose)((0, utils_1.createInterpolateNumber)(0, 0.5), (0, utils_1.createNormalize)(d0, d1));
22 // [d1, d2] => [0.5, 1]
23 const normalizeRight = (0, utils_1.compose)((0, utils_1.createInterpolateNumber)(0.5, 1), (0, utils_1.createNormalize)(d1, d2));
24 return (x) => {
25 // Find x belongs to the range of [d0, d1] or [d1, d2].
26 if (d0 > d2) {
27 return x < d1 ? normalizeRight(x) : normalizeLeft(x);
28 }
29 else {
30 return x < d1 ? normalizeLeft(x) : normalizeRight(x);
31 }
32 };
33};
34/**
35 * Diverging 比例尺
36 *
37 * 构造可创建一个在输入和输出之间通过插值函数进行转换的比例尺
38 */
39let Diverging = Diverging_1 = class Diverging extends linear_1.Linear {
40 getDefaultOptions() {
41 return {
42 domain: [0, 0.5, 1],
43 unknown: undefined,
44 nice: false,
45 clamp: false,
46 round: false,
47 interpolator: util_1.identity,
48 tickMethod: d3_ticks_1.d3Ticks,
49 tickCount: 5,
50 };
51 }
52 constructor(options) {
53 super(options);
54 }
55 clone() {
56 return new Diverging_1(this.options);
57 }
58};
59Diverging = Diverging_1 = __decorate([
60 (0, utils_1.interpolatize)(rangeOf, normalizeDomain)
61], Diverging);
62exports.Diverging = Diverging;
63//# sourceMappingURL=diverging.js.map
\No newline at end of file