1 | import { __assign } from "tslib";
|
2 | import { isEmpty, clamp } from '@antv/util';
|
3 | import { registerShape } from '../base';
|
4 | import { getStyle } from '../util/get-style';
|
5 | function getRectAttrs(points, size) {
|
6 | var width = Math.abs(points[0].x - points[2].x);
|
7 | var height = Math.abs(points[0].y - points[2].y);
|
8 | var len = Math.min(width, height);
|
9 | if (size) {
|
10 | len = clamp(size, 0, Math.min(width, height));
|
11 | }
|
12 | len = len / 2;
|
13 | var centerX = (points[0].x + points[2].x) / 2;
|
14 | var centerY = (points[0].y + points[2].y) / 2;
|
15 | return {
|
16 | x: centerX - len,
|
17 | y: centerY - len,
|
18 | width: len * 2,
|
19 | height: len * 2,
|
20 | };
|
21 | }
|
22 | registerShape('polygon', 'square', {
|
23 | draw: function (cfg, container) {
|
24 | if (!isEmpty(cfg.points)) {
|
25 | var shapeAttrs = getStyle(cfg, true, true);
|
26 | var points = this.parsePoints(cfg.points);
|
27 | return container.addShape('rect', {
|
28 | attrs: __assign(__assign({}, shapeAttrs), getRectAttrs(points, cfg.size)),
|
29 | name: 'polygon',
|
30 | });
|
31 | }
|
32 | },
|
33 | getMarker: function (markerCfg) {
|
34 | var color = markerCfg.color;
|
35 | return {
|
36 | symbol: 'square',
|
37 | style: {
|
38 | r: 4,
|
39 | fill: color,
|
40 | },
|
41 | };
|
42 | },
|
43 | });
|
44 |
|
\ | No newline at end of file |