1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var util_1 = require("@antv/util");
|
5 | var scale_transform_1 = tslib_1.__importDefault(require("./scale-transform"));
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var ScaleTranslate = (function (_super) {
|
11 | tslib_1.__extends(ScaleTranslate, _super);
|
12 | function ScaleTranslate() {
|
13 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
14 | _this.startPoint = null;
|
15 | _this.starting = false;
|
16 | _this.startCache = {};
|
17 | return _this;
|
18 | }
|
19 | |
20 |
|
21 |
|
22 | ScaleTranslate.prototype.start = function () {
|
23 | var _this = this;
|
24 | this.startPoint = this.context.getCurrentPoint();
|
25 | this.starting = true;
|
26 | var dims = this.dims;
|
27 | util_1.each(dims, function (dim) {
|
28 | var scale = _this.getScale(dim);
|
29 | var min = scale.min, max = scale.max, values = scale.values;
|
30 | _this.startCache[dim] = { min: min, max: max, values: values };
|
31 | });
|
32 | };
|
33 |
|
34 |
|
35 |
|
36 | |
37 |
|
38 |
|
39 | ScaleTranslate.prototype.end = function () {
|
40 | this.startPoint = null;
|
41 | this.starting = false;
|
42 | this.startCache = {};
|
43 | };
|
44 | |
45 |
|
46 |
|
47 | ScaleTranslate.prototype.translate = function () {
|
48 | var _this = this;
|
49 | if (!this.starting) {
|
50 | return;
|
51 | }
|
52 | var startPoint = this.startPoint;
|
53 | var coord = this.context.view.getCoordinate();
|
54 | var currentPoint = this.context.getCurrentPoint();
|
55 | var normalStart = coord.invert(startPoint);
|
56 | var noramlCurrent = coord.invert(currentPoint);
|
57 | var dx = noramlCurrent.x - normalStart.x;
|
58 | var dy = noramlCurrent.y - normalStart.y;
|
59 | var view = this.context.view;
|
60 | var dims = this.dims;
|
61 | util_1.each(dims, function (dim) {
|
62 | _this.translateDim(dim, { x: dx * -1, y: dy * -1 });
|
63 | });
|
64 | view.render(true);
|
65 | };
|
66 |
|
67 | ScaleTranslate.prototype.translateDim = function (dim, normalPoint) {
|
68 | if (this.hasDim(dim)) {
|
69 | var scale = this.getScale(dim);
|
70 | if (scale.isLinear) {
|
71 | this.translateLinear(dim, scale, normalPoint);
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 | }
|
77 | };
|
78 |
|
79 | ScaleTranslate.prototype.translateLinear = function (dim, scale, normalPoint) {
|
80 | var view = this.context.view;
|
81 | var _a = this.startCache[dim], min = _a.min, max = _a.max;
|
82 | var range = max - min;
|
83 | var d = normalPoint[dim] * range;
|
84 |
|
85 | if (!this.cacheScaleDefs[dim]) {
|
86 | this.cacheScaleDefs[dim] = {
|
87 |
|
88 | nice: scale.nice,
|
89 | min: min,
|
90 | max: max,
|
91 | };
|
92 | }
|
93 | view.scale(scale.field, {
|
94 |
|
95 | nice: false,
|
96 | min: min + d,
|
97 | max: max + d,
|
98 | });
|
99 | };
|
100 |
|
101 |
|
102 |
|
103 | |
104 |
|
105 |
|
106 | ScaleTranslate.prototype.reset = function () {
|
107 | _super.prototype.reset.call(this);
|
108 | this.startPoint = null;
|
109 | this.starting = false;
|
110 | };
|
111 | return ScaleTranslate;
|
112 | }(scale_transform_1.default));
|
113 | exports.default = ScaleTranslate;
|
114 |
|
\ | No newline at end of file |