1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var util_1 = require("@antv/util");
|
4 | var base_1 = require("../base");
|
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 | var split_points_1 = require("../util/split-points");
|
9 | var util_2 = require("./util");
|
10 | function getShapeAttrs(cfg, smooth, constraint) {
|
11 | var isStack = cfg.isStack, connectNulls = cfg.connectNulls, isInCircle = cfg.isInCircle, showSinglePoint = cfg.showSinglePoint;
|
12 | var shapeAttrs = get_style_1.getStyle(cfg, true, false, 'lineWidth');
|
13 | var points = get_path_points_1.getPathPoints(cfg.points, connectNulls, showSinglePoint);
|
14 | var path = [];
|
15 | for (var i = 0, len = points.length; i < len; i++) {
|
16 | var eachLinePoints = points[i];
|
17 | path = path.concat(getPath(eachLinePoints, isInCircle, isStack, smooth, constraint, shapeAttrs));
|
18 | }
|
19 | shapeAttrs.path = path;
|
20 | return shapeAttrs;
|
21 | }
|
22 |
|
23 | function getSinglePath(points, isInCircle, smooth, constraint, style) {
|
24 | if (points.length === 1) {
|
25 |
|
26 | return [
|
27 | ['M', points[0].x, points[0].y - style.lineWidth / 2],
|
28 | ['L', points[0].x, points[0].y],
|
29 | ['L', points[0].x, points[0].y + style.lineWidth / 2],
|
30 | ];
|
31 | }
|
32 | var path;
|
33 | if (!smooth) {
|
34 | path = path_1.getLinePath(points, false);
|
35 | if (isInCircle) {
|
36 | path.push(['Z']);
|
37 | }
|
38 | }
|
39 | else {
|
40 |
|
41 | if (isInCircle && points.length) {
|
42 | points.push({ x: points[0].x, y: points[0].y });
|
43 | }
|
44 | path = path_1.getSplinePath(points, false, constraint);
|
45 | }
|
46 | return path;
|
47 | }
|
48 | function getRangePath(points, isInCircle, isStack, smooth, constraint, style) {
|
49 | var topPoints = [];
|
50 | var bottomPoints = [];
|
51 | util_1.each(points, function (point) {
|
52 | var result = split_points_1.splitPoints(point);
|
53 | topPoints.push(result[1]);
|
54 | bottomPoints.push(result[0]);
|
55 | });
|
56 | var topPath = getSinglePath(topPoints, isInCircle, smooth, constraint, style);
|
57 | var bottomPath = getSinglePath(bottomPoints, isInCircle, smooth, constraint, style);
|
58 | if (isStack) {
|
59 | return topPath;
|
60 | }
|
61 | return topPath.concat(bottomPath);
|
62 | }
|
63 | function getPath(points, isInCircle, isStack, smooth, constraint, style) {
|
64 | if (points.length) {
|
65 | var first = points[0];
|
66 | return util_1.isArray(first.y)
|
67 | ? getRangePath(points, isInCircle, isStack, smooth, constraint, style)
|
68 | : getSinglePath(points, isInCircle, smooth, constraint, style);
|
69 | }
|
70 | return [];
|
71 | }
|
72 | var LineShapeFactory = base_1.registerShapeFactory('line', {
|
73 | defaultShapeType: 'line',
|
74 | });
|
75 |
|
76 |
|
77 | util_1.each(['line', 'dot', 'dash', 'smooth'], function (shapeType) {
|
78 | base_1.registerShape('line', shapeType, {
|
79 | draw: function (cfg, container) {
|
80 | var smooth = shapeType === 'smooth';
|
81 | var constraint;
|
82 | if (smooth) {
|
83 | var _a = this.coordinate, start = _a.start, end = _a.end;
|
84 | constraint = [
|
85 | [start.x, end.y],
|
86 | [end.x, start.y],
|
87 | ];
|
88 | }
|
89 | var attrs = getShapeAttrs(cfg, smooth, constraint);
|
90 | var shape = container.addShape({
|
91 | type: 'path',
|
92 | attrs: attrs,
|
93 | name: 'line',
|
94 | capture: !smooth,
|
95 | });
|
96 | return shape;
|
97 | },
|
98 | getMarker: function (markerCfg) {
|
99 | return util_2.getLineMarker(markerCfg, shapeType);
|
100 | },
|
101 | });
|
102 | });
|
103 | exports.default = LineShapeFactory;
|
104 |
|
\ | No newline at end of file |