UNPKG

2.33 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var util_1 = require("@antv/util");
5var base_1 = tslib_1.__importDefault(require("./base"));
6/** 引入 Path 对应的 ShapeFactory */
7require("./shape/polygon");
8/**
9 * Polygon 几何标记。
10 * 常用于绘制色块图、日历图等。
11 */
12var Polygon = /** @class */ (function (_super) {
13 tslib_1.__extends(Polygon, _super);
14 function Polygon() {
15 var _this = _super !== null && _super.apply(this, arguments) || this;
16 _this.type = 'polygon';
17 _this.shapeType = 'polygon';
18 _this.generatePoints = true;
19 return _this;
20 }
21 /**
22 * 获取 Shape 的关键点数据。
23 * @param obj
24 * @returns
25 */
26 Polygon.prototype.createShapePointsCfg = function (obj) {
27 var cfg = _super.prototype.createShapePointsCfg.call(this, obj);
28 var x = cfg.x;
29 var y = cfg.y;
30 var temp;
31 // x y 都是数组时,不做处理
32 if (!((0, util_1.isArray)(x) && (0, util_1.isArray)(y))) {
33 var xScale = this.getXScale();
34 var yScale = this.getYScale();
35 var xCount = xScale.values.length;
36 var yCount = yScale.values.length;
37 var xOffset = (0.5 * 1) / xCount;
38 var yOffset = (0.5 * 1) / yCount;
39 if (xScale.isCategory && yScale.isCategory) {
40 // 如果x,y都是分类
41 x = [x - xOffset, x - xOffset, x + xOffset, x + xOffset];
42 y = [y - yOffset, y + yOffset, y + yOffset, y - yOffset];
43 }
44 else if ((0, util_1.isArray)(x)) {
45 // x 是数组
46 temp = x;
47 x = [temp[0], temp[0], temp[1], temp[1]];
48 y = [y - yOffset / 2, y + yOffset / 2, y + yOffset / 2, y - yOffset / 2];
49 }
50 else if ((0, util_1.isArray)(y)) {
51 // y 是数组
52 temp = y;
53 y = [temp[0], temp[1], temp[1], temp[0]];
54 x = [x - xOffset / 2, x - xOffset / 2, x + xOffset / 2, x + xOffset / 2];
55 }
56 cfg.x = x;
57 cfg.y = y;
58 }
59 return cfg;
60 };
61 return Polygon;
62}(base_1.default));
63exports.default = Polygon;
64//# sourceMappingURL=polygon.js.map
\No newline at end of file