import { jsx } from '@antv/f-engine'; import { getMiddlePoint } from '../../../util/coord'; import { convertToPoints } from '../util'; // 金字塔图和漏斗图的View export default (props) => { const { records, shape, showLabel, labelCfg, LabelView } = props; // 是否倒置 let overturn = false; return ( {records.map((record, index) => { const { key, children } = record; const isLastRecord = index === records.length - 1; const nextRecord = isLastRecord ? record : records[index + 1]; const { children: nextChildren } = nextRecord; const nextFirstPoint = convertToPoints(nextChildren[0]); const nextLastPoints = convertToPoints(nextChildren[nextChildren.length - 1]); if (!overturn) { overturn = nextChildren[0].yMax > children[0].yMax; } if (overturn) { nextFirstPoint.reverse(); nextLastPoints.reverse(); } const polygonPoints = children.map((child, childIndex) => { let points = convertToPoints(child); if (overturn) { points.reverse(); } if (isLastRecord) { if (shape === 'pyramid') { points = [getMiddlePoint(points[0], points[1]), points[2], points[3]]; } } else { if (childIndex === 0) { points[0] = nextFirstPoint[3]; } if (childIndex === children.length - 1) { points[1] = nextLastPoints[2]; } } return { ...child, points, }; }); return ( {polygonPoints.map((child) => { const { points, color, shape } = child; return ( [d.x, d.y]), fill: color, ...shape, }} /> {showLabel && LabelView ? ( ) : null} ); })} ); })} ); };