UNPKG

1.89 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var util_1 = require("@antv/util");
5var rect_1 = tslib_1.__importDefault(require("./rect"));
6function clampPoint(point) {
7 point.x = util_1.clamp(point.x, 0, 1);
8 point.y = util_1.clamp(point.y, 0, 1);
9}
10/**
11 * @ignore
12 */
13var DimRect = /** @class */ (function (_super) {
14 tslib_1.__extends(DimRect, _super);
15 function DimRect() {
16 var _this = _super !== null && _super.apply(this, arguments) || this;
17 _this.dim = 'x';
18 _this.inPlot = true;
19 return _this;
20 }
21 DimRect.prototype.getRegion = function () {
22 var start = null;
23 var end = null;
24 var points = this.points;
25 var dim = this.dim;
26 var coord = this.context.view.getCoordinate();
27 var normalStart = coord.invert(util_1.head(points));
28 var normalEnd = coord.invert(util_1.last(points));
29 if (this.inPlot) {
30 // 约束到 0 - 1 范围内
31 clampPoint(normalStart);
32 clampPoint(normalEnd);
33 }
34 if (dim === 'x') {
35 // x 轴方向扩展, y 轴方向占满全部
36 start = coord.convert({
37 x: normalStart.x,
38 y: 0,
39 });
40 end = coord.convert({
41 x: normalEnd.x,
42 y: 1,
43 });
44 }
45 else {
46 // y 轴方向扩展, x 轴方向占满全部
47 start = coord.convert({
48 x: 0,
49 y: normalStart.y,
50 });
51 end = coord.convert({
52 x: 1,
53 y: normalEnd.y,
54 });
55 }
56 return {
57 start: start,
58 end: end,
59 };
60 };
61 return DimRect;
62}(rect_1.default));
63exports.default = DimRect;
64//# sourceMappingURL=dim-rect.js.map
\No newline at end of file