@antv/f2
Version:
Charts for mobile visualization.
75 lines (74 loc) • 2.46 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _tslib = require("tslib");
var _fEngine = require("@antv/f-engine");
var _coord = require("../../../util/coord");
var _util = require("../util");
// 金字塔图和漏斗图的View
var _default = exports.default = function _default(props) {
var records = props.records,
shape = props.shape,
showLabel = props.showLabel,
labelCfg = props.labelCfg,
LabelView = props.LabelView;
// 是否倒置
var overturn = false;
return (0, _fEngine.jsx)("group", null, records.map(function (record, index) {
var key = record.key,
children = record.children;
var isLastRecord = index === records.length - 1;
var nextRecord = isLastRecord ? record : records[index + 1];
var nextChildren = nextRecord.children;
var nextFirstPoint = (0, _util.convertToPoints)(nextChildren[0]);
var nextLastPoints = (0, _util.convertToPoints)(nextChildren[nextChildren.length - 1]);
if (!overturn) {
overturn = nextChildren[0].yMax > children[0].yMax;
}
if (overturn) {
nextFirstPoint.reverse();
nextLastPoints.reverse();
}
var polygonPoints = children.map(function (child, childIndex) {
var points = (0, _util.convertToPoints)(child);
if (overturn) {
points.reverse();
}
if (isLastRecord) {
if (shape === 'pyramid') {
points = [(0, _coord.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 (0, _tslib.__assign)((0, _tslib.__assign)({}, child), {
points: points
});
});
return (0, _fEngine.jsx)("group", {
key: key
}, polygonPoints.map(function (child) {
var points = child.points,
color = child.color,
shape = child.shape;
return (0, _fEngine.jsx)("group", null, (0, _fEngine.jsx)("polygon", {
attrs: (0, _tslib.__assign)({
points: points.map(function (d) {
return [d.x, d.y];
}),
fill: color
}, shape)
}), showLabel && LabelView ? (0, _fEngine.jsx)(LabelView, (0, _tslib.__assign)({
record: child,
points: points
}, labelCfg)) : null);
}));
}));
};
;