UNPKG

@semcore/chart

Version:
123 lines (121 loc) 4.3 kB
import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["outerRadius"]; import React from 'react'; import Animate from 'react-smooth'; import isFunction from 'lodash/isFunction'; import isPlainObject from 'lodash/isPlainObject'; import { Pie, Sector } from 'recharts'; import Layer from "recharts/es6/container/Layer"; import { filterEventsOfChild } from "recharts/es6/util/ReactUtils"; import { colors } from '../../utils/colors'; import copyComponent from '../../copy'; var activeIndex = []; function renderSectorItem(option, props, PieProps) { var outerRadius = props.outerRadius, other = _objectWithoutProperties(props, _excluded); var isAnimationActive = PieProps.isAnimationActive, shapeAnimationBegin = PieProps.shapeAnimationBegin, shapeAnimationDuration = PieProps.shapeAnimationDuration, shapeAnimationEasing = PieProps.shapeAnimationEasing, _PieProps$shapeOuterR = PieProps.shapeOuterRadius, shapeOuterRadius = _PieProps$shapeOuterR === void 0 ? outerRadius + 8 : _PieProps$shapeOuterR; var fromOuterRadius = shapeOuterRadius; var toOuterRadius = outerRadius; var children = function children(outerRadius) { return /*#__PURE__*/React.createElement(Sector, _extends({}, other, { outerRadius: outerRadius })); }; if ( /*#__PURE__*/React.isValidElement(option)) { children = function children(outerRadius) { return /*#__PURE__*/React.cloneElement(option, _objectSpread(_objectSpread({}, other), {}, { outerRadius: outerRadius })); }; } if (isFunction(option)) { children = function children(outerRadius) { return option(_objectSpread(_objectSpread({}, other), {}, { outerRadius: outerRadius })); }; } if (isPlainObject(option)) { children = function children(outerRadius) { return /*#__PURE__*/React.createElement(Sector, _extends({}, option, other, { outerRadius: outerRadius })); }; } if (option || activeIndex.includes(other.id)) { activeIndex = activeIndex.filter(function (index) { return index !== other.id; }); if (option) { activeIndex.push(other.id); var _ref = [toOuterRadius, fromOuterRadius]; fromOuterRadius = _ref[0]; toOuterRadius = _ref[1]; } return /*#__PURE__*/React.createElement(Animate, { begin: shapeAnimationBegin, duration: shapeAnimationDuration, easing: shapeAnimationEasing, isActive: isAnimationActive //@ts-ignore , onAnimationStart: Pie.prototype.handleAnimationStart //@ts-ignore , onAnimationEnd: Pie.prototype.handleAnimationEnd, from: { outerRadius: fromOuterRadius }, to: { outerRadius: toOuterRadius } }, function (_ref2) { var outerRadius = _ref2.outerRadius; return children(outerRadius); }); } return children(outerRadius); } //@ts-ignore Pie.prototype.renderSectorsStatically = function (sectors) { var _this = this; var _this$props = this.props, activeShape = _this$props.activeShape, blendStroke = _this$props.blendStroke; return sectors.map(function (entry, i) { var sectorOptions = _this.isActiveIndex(i) ? activeShape : null; var sectorProps = _objectSpread(_objectSpread({}, entry), {}, { stroke: blendStroke ? entry.fill : entry.stroke }); return /*#__PURE__*/React.createElement(Layer, _extends({ className: "recharts-pie-sector" }, filterEventsOfChild(_this.props, entry, i), { key: "sector-".concat(i) }), renderSectorItem(sectorOptions, sectorProps, _this.props)); }); }; /** * @deprecated Please, use package `@semcore/ui/d3-chart` instead. Package `@semcore/chart` is deprecated. */ export default copyComponent(Pie, { defaultProps: { fill: colors['blue-01'], animationDuration: 350, animationEasing: 'ease-in-out', paddingAngle: 1, animationShapeBegin: 0, animationShapeDuration: 300, animationShapeEasing: 'ease-in' }, render: function render() { return /*#__PURE__*/React.createElement(Pie, this.props); } }); //# sourceMappingURL=Pie.js.map