36be07001e315b4fb360f8ee03ebf5cd.json
20.4 KB
{"ast":null,"code":"var _interopRequireWildcard=require(\"@babel/runtime/helpers/interopRequireWildcard\");var _interopRequireDefault=require(\"@babel/runtime/helpers/interopRequireDefault\");Object.defineProperty(exports,\"__esModule\",{value:true});exports.default=void 0;var _extends2=_interopRequireDefault(require(\"@babel/runtime/helpers/extends\"));var _defineProperty2=_interopRequireDefault(require(\"@babel/runtime/helpers/defineProperty\"));var _slicedToArray2=_interopRequireDefault(require(\"@babel/runtime/helpers/slicedToArray\"));var _toConsumableArray2=_interopRequireDefault(require(\"@babel/runtime/helpers/toConsumableArray\"));var _classCallCheck2=_interopRequireDefault(require(\"@babel/runtime/helpers/classCallCheck\"));var _createClass2=_interopRequireDefault(require(\"@babel/runtime/helpers/createClass\"));var _possibleConstructorReturn2=_interopRequireDefault(require(\"@babel/runtime/helpers/possibleConstructorReturn\"));var _getPrototypeOf3=_interopRequireDefault(require(\"@babel/runtime/helpers/getPrototypeOf\"));var _inherits2=_interopRequireDefault(require(\"@babel/runtime/helpers/inherits\"));var _react=_interopRequireWildcard(require(\"react\"));var _View=_interopRequireDefault(require(\"react-native-web/dist/exports/View\"));var _propTypes=_interopRequireDefault(require(\"prop-types\"));var shape=_interopRequireWildcard(require(\"d3-shape\"));var _reactNativeSvg=_interopRequireWildcard(require(\"react-native-svg\"));function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(source,true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(source).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}var PieChart=function(_PureComponent){(0,_inherits2.default)(PieChart,_PureComponent);function PieChart(){var _getPrototypeOf2;var _this;(0,_classCallCheck2.default)(this,PieChart);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=(0,_possibleConstructorReturn2.default)(this,(_getPrototypeOf2=(0,_getPrototypeOf3.default)(PieChart)).call.apply(_getPrototypeOf2,[this].concat(args)));_this.state={height:0,width:0};return _this;}(0,_createClass2.default)(PieChart,[{key:\"_onLayout\",value:function _onLayout(event){var _event$nativeEvent$la=event.nativeEvent.layout,height=_event$nativeEvent$la.height,width=_event$nativeEvent$la.width;this.setState({height:height,width:width});}},{key:\"_calculateRadius\",value:function _calculateRadius(arg,max,defaultVal){if(typeof arg==='string'){return arg.split('%')[0]/100*max;}else if(arg){return arg;}else{return defaultVal;}}},{key:\"render\",value:function render(){var _this2=this;var _this$props=this.props,data=_this$props.data,dataPoints=_this$props.dataPoints,innerRadius=_this$props.innerRadius,outerRadius=_this$props.outerRadius,labelRadius=_this$props.labelRadius,padAngle=_this$props.padAngle,animate=_this$props.animate,animationDuration=_this$props.animationDuration,style=_this$props.style,sort=_this$props.sort,valueAccessor=_this$props.valueAccessor,children=_this$props.children,startAngle=_this$props.startAngle,endAngle=_this$props.endAngle;var _this$state=this.state,height=_this$state.height,width=_this$state.width;if(!data&&dataPoints){throw\"\\\"dataPoints\\\" have been renamed to \\\"data\\\" to better reflect the fact that it's an array of objects\";}if(data.length===0){return _react.default.createElement(_View.default,{style:style});}var maxRadius=Math.min(width,height)/2;if(Math.min.apply(Math,(0,_toConsumableArray2.default)(data.map(function(obj){return valueAccessor({item:obj});})))<0){console.error(\"don't pass negative numbers to pie-chart, it makes no sense!\");}var _outerRadius=this._calculateRadius(outerRadius,maxRadius,maxRadius);var _innerRadius=this._calculateRadius(innerRadius,maxRadius,0);var _labelRadius=this._calculateRadius(labelRadius,maxRadius,_outerRadius);if(outerRadius>0&&_innerRadius>=outerRadius){console.warn('innerRadius is equal to or greater than outerRadius');}var arcs=data.map(function(item){var arc=shape.arc().outerRadius(_outerRadius).innerRadius(_innerRadius).padAngle(padAngle);item.arc&&Object.entries(item.arc).forEach(function(_ref){var _ref2=(0,_slicedToArray2.default)(_ref,2),key=_ref2[0],value=_ref2[1];if(typeof arc[key]==='function'){if(typeof value==='string'){arc[key](value.split('%')[0]/100*_outerRadius);}else{arc[key](value);}}});return arc;});var labelArcs=data.map(function(item,index){if(labelRadius){return shape.arc().outerRadius(_labelRadius).innerRadius(_labelRadius).padAngle(padAngle);}return arcs[index];});var pieSlices=shape.pie().value(function(d){return valueAccessor({item:d});}).sort(sort).startAngle(startAngle).endAngle(endAngle)(data);var slices=pieSlices.map(function(slice,index){return _objectSpread({},slice,{pieCentroid:arcs[index].centroid(slice),labelCentroid:labelArcs[index].centroid(slice)});});var extraProps={width:width,height:height,data:data,slices:slices};return _react.default.createElement(_View.default,{style:style},_react.default.createElement(_View.default,{style:{flex:1},onLayout:function onLayout(event){return _this2._onLayout(event);}},height>0&&width>0&&_react.default.createElement(_reactNativeSvg.default,{style:{height:height,width:width}},_react.default.createElement(_reactNativeSvg.G,{x:width/2,y:height/2},_react.default.Children.map(children,function(child){if(child&&child.props.belowChart){return _react.default.cloneElement(child,extraProps);}return null;}),pieSlices.map(function(slice,index){var _data$index=data[index],key=_data$index.key,onPress=_data$index.onPress,svg=_data$index.svg;return _react.default.createElement(_reactNativeSvg.Path,(0,_extends2.default)({key:key,onPress:onPress},svg,{d:arcs[index](slice),animate:animate,animationDuration:animationDuration}));}),_react.default.Children.map(children,function(child){if(child&&!child.props.belowChart){return _react.default.cloneElement(child,extraProps);}return null;})))));}}]);return PieChart;}(_react.PureComponent);PieChart.propTypes={data:_propTypes.default.arrayOf(_propTypes.default.shape({svg:_propTypes.default.object,key:_propTypes.default.any.isRequired,value:_propTypes.default.number,arc:_propTypes.default.object})).isRequired,innerRadius:_propTypes.default.oneOfType([_propTypes.default.number,_propTypes.default.string]),outerRadius:_propTypes.default.oneOfType([_propTypes.default.number,_propTypes.default.string]),labelRadius:_propTypes.default.oneOfType([_propTypes.default.number,_propTypes.default.string]),padAngle:_propTypes.default.number,animate:_propTypes.default.bool,animationDuration:_propTypes.default.number,style:_propTypes.default.any,sort:_propTypes.default.func,valueAccessor:_propTypes.default.func};PieChart.defaultProps={width:100,height:100,padAngle:0.05,startAngle:0,endAngle:Math.PI*2,valueAccessor:function valueAccessor(_ref3){var item=_ref3.item;return item.value;},innerRadius:'50%',sort:function sort(a,b){return b.value-a.value;}};var _default=PieChart;exports.default=_default;","map":{"version":3,"sources":["C:/Users/bluej/Desktop/2_2/searchGuide/searchGuide/node_modules/react-native-svg-charts/src/pie-chart.js"],"names":["PieChart","state","height","width","event","nativeEvent","layout","setState","arg","max","defaultVal","split","props","data","dataPoints","innerRadius","outerRadius","labelRadius","padAngle","animate","animationDuration","style","sort","valueAccessor","children","startAngle","endAngle","length","maxRadius","Math","min","map","obj","item","console","error","_outerRadius","_calculateRadius","_innerRadius","_labelRadius","warn","arcs","arc","shape","Object","entries","forEach","key","value","labelArcs","index","pieSlices","pie","d","slices","slice","pieCentroid","centroid","labelCentroid","extraProps","flex","_onLayout","React","Children","child","belowChart","cloneElement","onPress","svg","PureComponent","propTypes","PropTypes","arrayOf","object","any","isRequired","number","oneOfType","string","bool","func","defaultProps","PI","a","b"],"mappings":"gkCAAA,qD,gFAEA,6DACA,uDACA,yE,4xBAEMA,CAAAA,Q,sbACFC,K,CAAQ,CACJC,MAAM,CAAE,CADJ,CAEJC,KAAK,CAAE,CAFH,C,6FAKEC,K,CAAO,2BAKTA,KALS,CAETC,WAFS,CAGLC,MAHK,CAGKJ,MAHL,uBAGKA,MAHL,CAGaC,KAHb,uBAGaA,KAHb,CAOb,KAAKI,QAAL,CAAc,CAAEL,MAAM,CAANA,MAAF,CAAUC,KAAK,CAALA,KAAV,CAAd,EACH,C,0DAEgBK,G,CAAKC,G,CAAK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 'prop-types'\nimport * as shape from 'd3-shape'\nimport Svg, { G, Path } from 'react-native-svg'\n\nclass PieChart extends PureComponent {\n state = {\n height: 0,\n width: 0,\n }\n\n _onLayout(event) {\n const {\n nativeEvent: {\n layout: { height, width },\n },\n } = event\n\n this.setState({ height, width })\n }\n\n _calculateRadius(arg, max, defaultVal) {\n if (typeof arg === 'string') {\n return (arg.split('%')[0] / 100) * max\n } else if (arg) {\n return arg\n } else {\n return defaultVal\n }\n }\n\n render() {\n const {\n data,\n dataPoints,\n innerRadius,\n outerRadius,\n labelRadius,\n padAngle,\n animate,\n animationDuration,\n style,\n sort,\n valueAccessor,\n children,\n startAngle,\n endAngle,\n } = this.props\n\n const { height, width } = this.state\n\n if (!data && dataPoints) {\n throw `\"dataPoints\" have been renamed to \"data\" to better reflect the fact that it's an array of objects`\n }\n\n if (data.length === 0) {\n return <View style={style} />\n }\n\n const maxRadius = Math.min(width, height) / 2\n\n if (Math.min(...data.map((obj) => valueAccessor({ item: obj }))) < 0) {\n console.error(\"don't pass negative numbers to pie-chart, it makes no sense!\")\n }\n\n const _outerRadius = this._calculateRadius(outerRadius, maxRadius, maxRadius)\n const _innerRadius = this._calculateRadius(innerRadius, maxRadius, 0)\n const _labelRadius = this._calculateRadius(labelRadius, maxRadius, _outerRadius)\n\n if (outerRadius > 0 && _innerRadius >= outerRadius) {\n console.warn('innerRadius is equal to or greater than outerRadius')\n }\n\n const arcs = data.map((item) => {\n const arc = shape\n .arc()\n .outerRadius(_outerRadius)\n .innerRadius(_innerRadius)\n .padAngle(padAngle) // Angle between sections\n\n item.arc &&\n Object.entries(item.arc).forEach(([key, value]) => {\n if (typeof arc[key] === 'function') {\n if (typeof value === 'string') {\n arc[key]((value.split('%')[0] / 100) * _outerRadius)\n } else {\n arc[key](value)\n }\n }\n })\n\n return arc\n })\n\n const labelArcs = data.map((item, index) => {\n if (labelRadius) {\n return shape\n .arc()\n .outerRadius(_labelRadius)\n .innerRadius(_labelRadius)\n .padAngle(padAngle)\n }\n return arcs[index]\n })\n\n const pieSlices = shape\n .pie()\n .value((d) => valueAccessor({ item: d }))\n .sort(sort)\n .startAngle(startAngle)\n .endAngle(endAngle)(data)\n\n const slices = pieSlices.map((slice, index) => ({\n ...slice,\n pieCentroid: arcs[index].centroid(slice),\n labelCentroid: labelArcs[index].centroid(slice),\n }))\n\n const extraProps = {\n width,\n height,\n data,\n slices,\n }\n\n return (\n <View style={style}>\n <View style={{ flex: 1 }} onLayout={(event) => this._onLayout(event)}>\n {height > 0 && width > 0 && (\n <Svg style={{ height, width }}>\n {/* center the progress circle*/}\n <G x={width / 2} y={height / 2}>\n {React.Children.map(children, (child) => {\n if (child && child.props.belowChart) {\n return React.cloneElement(child, extraProps)\n }\n return null\n })}\n {pieSlices.map((slice, index) => {\n const { key, onPress, svg } = data[index]\n return (\n <Path\n key={key}\n onPress={onPress}\n {...svg}\n d={arcs[index](slice)}\n animate={animate}\n animationDuration={animationDuration}\n />\n )\n })}\n {React.Children.map(children, (child) => {\n if (child && !child.props.belowChart) {\n return React.cloneElement(child, extraProps)\n }\n return null\n })}\n </G>\n </Svg>\n )}\n </View>\n </View>\n )\n }\n}\n\nPieChart.propTypes = {\n data: PropTypes.arrayOf(\n PropTypes.shape({\n svg: PropTypes.object,\n key: PropTypes.any.isRequired,\n value: PropTypes.number,\n arc: PropTypes.object,\n })\n ).isRequired,\n innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),\n outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),\n labelRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),\n padAngle: PropTypes.number,\n animate: PropTypes.bool,\n animationDuration: PropTypes.number,\n style: PropTypes.any,\n sort: PropTypes.func,\n valueAccessor: PropTypes.func,\n}\n\nPieChart.defaultProps = {\n width: 100,\n height: 100,\n padAngle: 0.05,\n startAngle: 0,\n endAngle: Math.PI * 2,\n valueAccessor: ({ item }) => item.value,\n innerRadius: '50%',\n sort: (a, b) => b.value - a.value,\n}\n\nexport default PieChart\n"]},"metadata":{},"sourceType":"script"}