UNPKG

3.7 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var util_1 = require("@antv/util");
5var scale_transform_1 = tslib_1.__importDefault(require("./scale-transform"));
6/**
7 * 拖拽 Scale 的 Action
8 * @ignore
9 */
10var ScaleTranslate = /** @class */ (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 // private translateCategory(dim, scale, normalPoint) {
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 // else { // 暂时仅处理连续字段
74 // this.translateCategory(dim, scale, normalPoint);
75 // }
76 }
77 };
78 // linear 度量平移
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 // @ts-ignore
88 nice: scale.nice,
89 min: min,
90 max: max,
91 };
92 }
93 view.scale(scale.field, {
94 // @ts-ignore
95 nice: false,
96 min: min + d,
97 max: max + d,
98 });
99 };
100 // 平移分类的度量
101 // private translateCategory(dim, scale, normalPoint) {
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));
113exports.default = ScaleTranslate;
114//# sourceMappingURL=scale-translate.js.map
\No newline at end of file