1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getConstraint = exports.getShapeAttrs = void 0;
|
4 | var util_1 = require("@antv/util");
|
5 | var get_path_points_1 = require("../util/get-path-points");
|
6 | var get_style_1 = require("../util/get-style");
|
7 | var path_1 = require("../util/path");
|
8 | function getPath(points, isInCircle, smooth, registeredShape, constraint) {
|
9 | var path = [];
|
10 | if (points.length) {
|
11 | var topLinePoints_1 = [];
|
12 | var bottomLinePoints_1 = [];
|
13 | for (var i = 0, len = points.length; i < len; i++) {
|
14 | var point = points[i];
|
15 | topLinePoints_1.push(point[1]);
|
16 | bottomLinePoints_1.push(point[0]);
|
17 | }
|
18 | bottomLinePoints_1 = bottomLinePoints_1.reverse();
|
19 | (0, util_1.each)([topLinePoints_1, bottomLinePoints_1], function (pointsData, index) {
|
20 | var subPath = [];
|
21 | var parsedPoints = registeredShape.parsePoints(pointsData);
|
22 | var p1 = parsedPoints[0];
|
23 | if (topLinePoints_1.length === 1 && bottomLinePoints_1.length === 1) {
|
24 |
|
25 | subPath =
|
26 | index === 0
|
27 | ? [
|
28 | ['M', p1.x - 0.5, p1.y],
|
29 | ['L', p1.x + 0.5, p1.y],
|
30 | ]
|
31 | : [
|
32 | ['L', p1.x + 0.5, p1.y],
|
33 | ['L', p1.x - 0.5, p1.y],
|
34 | ];
|
35 | }
|
36 | else {
|
37 | if (isInCircle) {
|
38 | parsedPoints.push({ x: p1.x, y: p1.y });
|
39 | }
|
40 | if (smooth) {
|
41 | subPath = (0, path_1.getSplinePath)(parsedPoints, false, constraint);
|
42 | }
|
43 | else {
|
44 | subPath = (0, path_1.getLinePath)(parsedPoints, false);
|
45 | }
|
46 | if (index > 0) {
|
47 | subPath[0][0] = 'L';
|
48 | }
|
49 | }
|
50 | path = path.concat(subPath);
|
51 | });
|
52 | path.push(['Z']);
|
53 | }
|
54 | return path;
|
55 | }
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | function getShapeAttrs(cfg, isStroke, smooth, registeredShape, constraint) {
|
67 | var attrs = (0, get_style_1.getStyle)(cfg, isStroke, !isStroke, 'lineWidth');
|
68 | var connectNulls = cfg.connectNulls, isInCircle = cfg.isInCircle, points = cfg.points, showSinglePoint = cfg.showSinglePoint;
|
69 | var pathPoints = (0, get_path_points_1.getPathPoints)(points, connectNulls, showSinglePoint);
|
70 | var path = [];
|
71 | for (var i = 0, len = pathPoints.length; i < len; i++) {
|
72 | var eachPoints = pathPoints[i];
|
73 | path = path.concat(getPath(eachPoints, isInCircle, smooth, registeredShape, constraint));
|
74 | }
|
75 | attrs.path = path;
|
76 | return attrs;
|
77 | }
|
78 | exports.getShapeAttrs = getShapeAttrs;
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | function getConstraint(coordinate) {
|
86 | var start = coordinate.start, end = coordinate.end;
|
87 | return [
|
88 | [start.x, end.y],
|
89 | [end.x, start.y],
|
90 | ];
|
91 | }
|
92 | exports.getConstraint = getConstraint;
|
93 |
|
\ | No newline at end of file |