UNPKG

3.43 kBJavaScriptView Raw
1import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2import { jsx } from '../../jsx';
3import { deepMix } from '@antv/util';
4import { Smooth, BBox } from '@antv/f2-graphic';
5export default (function (props) {
6 var coord = props.coord,
7 records = props.records,
8 shape = props.shape,
9 animation = props.animation;
10 var isSmooth = shape === 'smooth';
11 var left = coord.left,
12 top = coord.top,
13 width = coord.width,
14 height = coord.height,
15 center = coord.center,
16 startAngle = coord.startAngle,
17 endAngle = coord.endAngle,
18 radius = coord.radius;
19 var appear = coord.isPolar ? {
20 easing: 'quadraticOut',
21 duration: 450,
22 clip: {
23 type: 'sector',
24 property: ['endAngle'],
25 attrs: {
26 x: center.x,
27 y: center.y,
28 startAngle: startAngle,
29 r: radius
30 },
31 start: {
32 endAngle: startAngle
33 },
34 end: {
35 endAngle: endAngle
36 }
37 }
38 } : {
39 easing: 'quadraticOut',
40 duration: 450,
41 clip: {
42 type: 'rect',
43 property: ['width'],
44 attrs: {
45 x: left,
46 y: top,
47 height: height
48 },
49 start: {
50 width: 0
51 },
52 end: {
53 width: width
54 }
55 }
56 };
57 return jsx("group", null, records.map(function (record) {
58 var key = record.key,
59 children = record.children;
60 return jsx("group", {
61 key: key
62 }, children.map(function (child) {
63 var points = child.points,
64 bottomPoints = child.bottomPoints,
65 color = child.color,
66 shape = child.shape;
67
68 if (isSmooth) {
69 return jsx("custom", {
70 attrs: _objectSpread({
71 points: points,
72 lineWidth: '2px',
73 fill: color
74 }, shape),
75 createPath: function createPath(context) {
76 var constaint = [[0, 0], [1, 1]];
77 var bottomPointsLen = (bottomPoints === null || bottomPoints === void 0 ? void 0 : bottomPoints.length) || 0;
78 var topPoints = points.slice(0, points.length - bottomPointsLen);
79 var topSps = Smooth.smooth(topPoints, false, constaint);
80 context.beginPath();
81 context.moveTo(topPoints[0].x, topPoints[0].y);
82
83 for (var i = 0, n = topSps.length; i < n; i++) {
84 var sp = topSps[i];
85 context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
86 }
87
88 if (bottomPointsLen) {
89 var bottomSps = Smooth.smooth(bottomPoints, false, constaint);
90 context.lineTo(bottomPoints[0].x, bottomPoints[0].y);
91
92 for (var _i = 0, _n = bottomSps.length; _i < _n; _i++) {
93 var _sp = bottomSps[_i];
94 context.bezierCurveTo(_sp[1], _sp[2], _sp[3], _sp[4], _sp[5], _sp[6]);
95 }
96 }
97
98 context.closePath();
99 },
100 calculateBox: function calculateBox() {
101 return BBox.getBBoxFromPoints(points);
102 }
103 });
104 }
105
106 return jsx("polygon", {
107 attrs: _objectSpread({
108 points: points,
109 lineWidth: '2px',
110 fill: color
111 }, shape),
112 animation: deepMix({
113 appear: appear,
114 update: {
115 easing: 'linear',
116 duration: 450,
117 property: ['points']
118 }
119 }, animation)
120 });
121 }));
122 }));
123});
\No newline at end of file