1 | import { __extends } from "tslib";
|
2 | import { filter, getRange, head, isNil, last } from '@antv/util';
|
3 | import Base from '../base';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var Continuous = (function (_super) {
|
9 | __extends(Continuous, _super);
|
10 | function Continuous() {
|
11 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
12 | _this.isContinuous = true;
|
13 | return _this;
|
14 | }
|
15 | Continuous.prototype.scale = function (value) {
|
16 | if (isNil(value)) {
|
17 | return NaN;
|
18 | }
|
19 | var rangeMin = this.rangeMin();
|
20 | var rangeMax = this.rangeMax();
|
21 | var max = this.max;
|
22 | var min = this.min;
|
23 | if (max === min) {
|
24 | return rangeMin;
|
25 | }
|
26 | var percent = this.getScalePercent(value);
|
27 | return rangeMin + percent * (rangeMax - rangeMin);
|
28 | };
|
29 | Continuous.prototype.init = function () {
|
30 | _super.prototype.init.call(this);
|
31 |
|
32 | var ticks = this.ticks;
|
33 | var firstTick = head(ticks);
|
34 | var lastTick = last(ticks);
|
35 | if (firstTick < this.min) {
|
36 | this.min = firstTick;
|
37 | }
|
38 | if (lastTick > this.max) {
|
39 | this.max = lastTick;
|
40 | }
|
41 |
|
42 | if (!isNil(this.minLimit)) {
|
43 | this.min = firstTick;
|
44 | }
|
45 | if (!isNil(this.maxLimit)) {
|
46 | this.max = lastTick;
|
47 | }
|
48 | };
|
49 | Continuous.prototype.setDomain = function () {
|
50 | var _a = getRange(this.values), min = _a.min, max = _a.max;
|
51 | if (isNil(this.min)) {
|
52 | this.min = min;
|
53 | }
|
54 | if (isNil(this.max)) {
|
55 | this.max = max;
|
56 | }
|
57 | if (this.min > this.max) {
|
58 | this.min = min;
|
59 | this.max = max;
|
60 | }
|
61 | };
|
62 | Continuous.prototype.calculateTicks = function () {
|
63 | var _this = this;
|
64 | var ticks = _super.prototype.calculateTicks.call(this);
|
65 | if (!this.nice) {
|
66 | ticks = filter(ticks, function (tick) {
|
67 | return tick >= _this.min && tick <= _this.max;
|
68 | });
|
69 | }
|
70 | return ticks;
|
71 | };
|
72 |
|
73 | Continuous.prototype.getScalePercent = function (value) {
|
74 | var max = this.max;
|
75 | var min = this.min;
|
76 | return (value - min) / (max - min);
|
77 | };
|
78 | Continuous.prototype.getInvertPercent = function (value) {
|
79 | return (value - this.rangeMin()) / (this.rangeMax() - this.rangeMin());
|
80 | };
|
81 | return Continuous;
|
82 | }(Base));
|
83 | export default Continuous;
|
84 |
|
\ | No newline at end of file |