UNPKG

2.19 kBJavaScriptView Raw
1import { __assign } from "tslib";
2import { jsx } from '@antv/f-engine';
3import { getMiddlePoint } from '../../../util/coord';
4import { convertToPoints } from '../util';
5// 金字塔图和漏斗图的View
6export default (function (props) {
7 var records = props.records,
8 shape = props.shape,
9 showLabel = props.showLabel,
10 labelCfg = props.labelCfg,
11 LabelView = props.LabelView;
12 // 是否倒置
13 var overturn = false;
14 return jsx("group", null, records.map(function (record, index) {
15 var key = record.key,
16 children = record.children;
17 var isLastRecord = index === records.length - 1;
18 var nextRecord = isLastRecord ? record : records[index + 1];
19 var nextChildren = nextRecord.children;
20 var nextFirstPoint = convertToPoints(nextChildren[0]);
21 var nextLastPoints = convertToPoints(nextChildren[nextChildren.length - 1]);
22 if (!overturn) {
23 overturn = nextChildren[0].yMax > children[0].yMax;
24 }
25 if (overturn) {
26 nextFirstPoint.reverse();
27 nextLastPoints.reverse();
28 }
29 var polygonPoints = children.map(function (child, childIndex) {
30 var points = convertToPoints(child);
31 if (overturn) {
32 points.reverse();
33 }
34 if (isLastRecord) {
35 if (shape === 'pyramid') {
36 points = [getMiddlePoint(points[0], points[1]), points[2], points[3]];
37 }
38 } else {
39 if (childIndex === 0) {
40 points[0] = nextFirstPoint[3];
41 }
42 if (childIndex === children.length - 1) {
43 points[1] = nextLastPoints[2];
44 }
45 }
46 return __assign(__assign({}, child), {
47 points: points
48 });
49 });
50 return jsx("group", {
51 key: key
52 }, polygonPoints.map(function (child) {
53 var points = child.points,
54 color = child.color,
55 shape = child.shape;
56 return jsx("group", null, jsx("polygon", {
57 attrs: __assign({
58 points: points.map(function (d) {
59 return [d.x, d.y];
60 }),
61 fill: color
62 }, shape)
63 }), showLabel && LabelView ? jsx(LabelView, __assign({
64 record: child,
65 points: points
66 }, labelCfg)) : null);
67 }));
68 }));
69});
\No newline at end of file