1ca4b7d5b19ba8655d0a661c6e9728fc.json 16.2 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 _toConsumableArray2=_interopRequireDefault(require(\"@babel/runtime/helpers/toConsumableArray\"));var _defineProperty2=_interopRequireDefault(require(\"@babel/runtime/helpers/defineProperty\"));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 _getPrototypeOf2=_interopRequireDefault(require(\"@babel/runtime/helpers/getPrototypeOf\"));var _inherits2=_interopRequireDefault(require(\"@babel/runtime/helpers/inherits\"));var _propTypes=_interopRequireDefault(require(\"prop-types\"));var array=_interopRequireWildcard(require(\"d3-array\"));var scale=_interopRequireWildcard(require(\"d3-scale\"));var shape=_interopRequireWildcard(require(\"d3-shape\"));var _barChart=_interopRequireDefault(require(\"./bar-chart\"));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 GroupedBarChart=function(_BarChart){(0,_inherits2.default)(GroupedBarChart,_BarChart);function GroupedBarChart(){(0,_classCallCheck2.default)(this,GroupedBarChart);return(0,_possibleConstructorReturn2.default)(this,(0,_getPrototypeOf2.default)(GroupedBarChart).apply(this,arguments));}(0,_createClass2.default)(GroupedBarChart,[{key:\"calcXScale\",value:function calcXScale(domain){var _this$props=this.props,horizontal=_this$props.horizontal,_this$props$contentIn=_this$props.contentInset,_this$props$contentIn2=_this$props$contentIn.left,left=_this$props$contentIn2===void 0?0:_this$props$contentIn2,_this$props$contentIn3=_this$props$contentIn.right,right=_this$props$contentIn3===void 0?0:_this$props$contentIn3,spacingInner=_this$props.spacingInner,spacingOuter=_this$props.spacingOuter,clamp=_this$props.clamp;var width=this.state.width;if(horizontal){return scale.scaleLinear().domain(domain).range([left,width-right]).clamp(clamp);}return scale.scaleBand().domain(domain).range([left,width-right]).paddingInner([spacingInner]).paddingOuter([spacingOuter]);}},{key:\"calcYScale\",value:function calcYScale(domain){var _this$props2=this.props,horizontal=_this$props2.horizontal,spacingInner=_this$props2.spacingInner,spacingOuter=_this$props2.spacingOuter,_this$props2$contentI=_this$props2.contentInset,_this$props2$contentI2=_this$props2$contentI.top,top=_this$props2$contentI2===void 0?0:_this$props2$contentI2,_this$props2$contentI3=_this$props2$contentI.bottom,bottom=_this$props2$contentI3===void 0?0:_this$props2$contentI3,clamp=_this$props2.clamp;var height=this.state.height;if(horizontal){return scale.scaleBand().domain(domain).range([top,height-bottom]).paddingInner([spacingInner]).paddingOuter([spacingOuter]);}return scale.scaleLinear().domain(domain).range([height-bottom,top]).clamp(clamp);}},{key:\"calcAreas\",value:function calcAreas(x,y){var _this$props3=this.props,horizontal=_this$props3.horizontal,data=_this$props3.data,yAccessor=_this$props3.yAccessor;var _data=data.map(function(obj){var _obj$svg=obj.svg,svg=_obj$svg===void 0?{}:_obj$svg;return _objectSpread({},obj,{data:obj.data.map(function(item){if(typeof item==='number'){return{value:item,svg:svg};}return _objectSpread({},item,{svg:_objectSpread({},svg,{},item.svg),value:yAccessor({item:item})});})});});var areas=[];if(horizontal){var barWidth=y.bandwidth()/data.length;_data.forEach(function(obj,collectionIndex){obj.data.forEach(function(item,valueIndex){areas.push({bar:item,path:shape.area().y(function(value,_index){return _index===0?y(valueIndex)+barWidth*collectionIndex:y(valueIndex)+barWidth+barWidth*collectionIndex;}).x0(x(0)).x1(function(value){return x(value);}).defined(function(value){return typeof value==='number';})([item.value,item.value])});});});}else{var _barWidth=x.bandwidth()/data.length;_data.forEach(function(obj,collectionIndex){obj.data.forEach(function(item,valueIndex){areas.push({bar:item,path:shape.area().x(function(value,_index){return _index===0?x(valueIndex)+_barWidth*collectionIndex:x(valueIndex)+_barWidth+_barWidth*collectionIndex;}).y0(y(0)).y1(function(value){return y(value);}).defined(function(value){return typeof value==='number';})([item.value,item.value])});});});}return areas;}},{key:\"calcExtent\",value:function calcExtent(){var _this$props4=this.props,data=_this$props4.data,yAccessor=_this$props4.yAccessor,gridMin=_this$props4.gridMin,gridMax=_this$props4.gridMax;var dataExtent=array.merge(data.map(function(obj){return obj.data.map(function(item){return yAccessor({item:item});});}));var extent=array.extent([].concat((0,_toConsumableArray2.default)(dataExtent),[gridMax,gridMin]));var _this$props5=this.props,_this$props5$yMin=_this$props5.yMin,yMin=_this$props5$yMin===void 0?extent[0]:_this$props5$yMin,_this$props5$yMax=_this$props5.yMax,yMax=_this$props5$yMax===void 0?extent[1]:_this$props5$yMax;return[yMin,yMax];}},{key:\"calcIndexes\",value:function calcIndexes(){var data=this.props.data;return data[0].data.map(function(_,index){return index;});}}]);return GroupedBarChart;}(_barChart.default);GroupedBarChart.propTypes=_objectSpread({},_barChart.default.propTypes,{data:_propTypes.default.arrayOf(_propTypes.default.shape({data:_propTypes.default.array.isRequired,svg:_propTypes.default.object})).isRequired});var _default=GroupedBarChart;exports.default=_default;","map":{"version":3,"sources":["C:/Users/bluej/Desktop/2_2/searchGuide/searchGuide/node_modules/react-native-svg-charts/src/bar-chart/bar-chart-grouped.js"],"names":["GroupedBarChart","domain","props","horizontal","contentInset","left","right","spacingInner","spacingOuter","clamp","width","state","scale","scaleLinear","range","scaleBand","paddingInner","paddingOuter","top","bottom","height","x","y","data","yAccessor","_data","map","obj","svg","item","value","areas","barWidth","bandwidth","length","forEach","collectionIndex","valueIndex","push","bar","path","shape","area","_index","x0","x1","defined","y0","y1","gridMin","gridMax","dataExtent","array","merge","extent","yMin","yMax","_","index","BarChart","propTypes","PropTypes","arrayOf","isRequired","object"],"mappings":"o5BAAA,6DACA,uDACA,uDACA,uDACA,6D,4xBAEMA,CAAAA,e,qWACSC,M,CAAQ,iBAOX,KAAKC,KAPM,CAEXC,UAFW,aAEXA,UAFW,mCAGXC,YAHW,8CAGKC,IAHL,CAGKA,IAHL,iCAGY,CAHZ,qEAGeC,KAHf,CAGeA,KAHf,iCAGuB,CAHvB,wBAIXC,YAJW,aAIXA,YAJW,CAKXC,YALW,aAKXA,YALW,CAMXC,KANW,aAMXA,KANW,IASPC,CAAAA,KATO,CASG,KAAKC,KATR,CASPD,KATO,CAWf,GAAIP,UAAJ,CAAgB,CACZ,MAAOS,CAAAA,KAAK,CACPC,WADE,GAEFZ,MAFE,CAEKA,MAFL,EAGFa,KAHE,CAGI,CAACT,IAAD,CAAOK,KAAK,CAAGJ,KAAf,CAHJ,EAIFG,KAJE,CAIIA,KAJJ,CAAP,CAKH,CAED,MAAOG,CAAAA,KAAK,CACPG,SADE,GAEFd,MAFE,CAEKA,MAFL,EAGFa,KAHE,CAGI,CAACT,IAAD,CAAOK,KAAK,CAAGJ,KAAf,CAHJ,EAIFU,YAJE,CAIW,CAACT,YAAD,CAJX,EAKFU,YALE,CAKW,CAACT,YAAD,CALX,CAAP,CAMH,C,8CAEUP,M,CAAQ,kBAOX,KAAKC,KAPM,CAEXC,UAFW,cAEXA,UAFW,CAGXI,YAHW,cAGXA,YAHW,CAIXC,YAJW,cAIXA,YAJW,oCAKXJ,YALW,8CAKKc,GALL,CAKKA,GALL,iCAKW,CALX,qEAKcC,MALd,CAKcA,MALd,iCAKuB,CALvB,wBAMXV,KANW,cAMXA,K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AAI,CAAC,CAAD,CAAJ,CAAQA,IAAR,CAAaG,GAAb,CAAiB,SAAC+B,CAAD,CAAIC,KAAJ,QAAcA,CAAAA,KAAd,EAAjB,CAAP,CACH,C,6BA/IyBC,iB,EAkJ9B3D,eAAe,CAAC4D,SAAhB,kBACOD,kBAASC,SADhB,EAEIrC,IAAI,CAAEsC,mBAAUC,OAAV,CACFD,mBAAUpB,KAAV,CAAgB,CACZlB,IAAI,CAAEsC,mBAAUT,KAAV,CAAgBW,UADV,CAEZnC,GAAG,CAAEiC,mBAAUG,MAFH,CAAhB,CADE,EAKJD,UAPN,G,aAUe/D,e","sourcesContent":["import PropTypes from 'prop-types'\nimport * as array from 'd3-array'\nimport * as scale from 'd3-scale'\nimport * as shape from 'd3-shape'\nimport BarChart from './bar-chart'\n\nclass GroupedBarChart extends BarChart {\n    calcXScale(domain) {\n        const {\n            horizontal,\n            contentInset: { left = 0, right = 0 },\n            spacingInner,\n            spacingOuter,\n            clamp,\n        } = this.props\n\n        const { width } = this.state\n\n        if (horizontal) {\n            return scale\n                .scaleLinear()\n                .domain(domain)\n                .range([left, width - right])\n                .clamp(clamp)\n        }\n\n        return scale\n            .scaleBand()\n            .domain(domain)\n            .range([left, width - right])\n            .paddingInner([spacingInner])\n            .paddingOuter([spacingOuter])\n    }\n\n    calcYScale(domain) {\n        const {\n            horizontal,\n            spacingInner,\n            spacingOuter,\n            contentInset: { top = 0, bottom = 0 },\n            clamp,\n        } = this.props\n\n        const { height } = this.state\n\n        if (horizontal) {\n            return scale\n                .scaleBand()\n                .domain(domain)\n                .range([top, height - bottom])\n                .paddingInner([spacingInner])\n                .paddingOuter([spacingOuter])\n        }\n\n        return scale\n            .scaleLinear()\n            .domain(domain)\n            .range([height - bottom, top])\n            .clamp(clamp)\n    }\n\n    calcAreas(x, y) {\n        const { horizontal, data, yAccessor } = this.props\n\n        const _data = data.map((obj) => {\n            const { svg = {} } = obj\n            return {\n                ...obj,\n                data: obj.data.map((item) => {\n                    if (typeof item === 'number') {\n                        return {\n                            value: item,\n                            svg,\n                        }\n                    }\n\n                    return {\n                        ...item,\n                        svg: {\n                            ...svg,\n                            ...item.svg,\n                        },\n                        value: yAccessor({ item }),\n                    }\n                }),\n            }\n        })\n\n        const areas = []\n\n        if (horizontal) {\n            const barWidth = y.bandwidth() / data.length\n\n            _data.forEach((obj, collectionIndex) => {\n                obj.data.forEach((item, valueIndex) => {\n                    areas.push({\n                        bar: item,\n                        path: shape\n                            .area()\n                            .y((value, _index) =>\n                                _index === 0\n                                    ? y(valueIndex) + barWidth * collectionIndex\n                                    : y(valueIndex) + barWidth + barWidth * collectionIndex\n                            )\n                            .x0(x(0))\n                            .x1((value) => x(value))\n                            .defined((value) => typeof value === 'number')([item.value, item.value]),\n                    })\n                })\n            })\n        } else {\n            const barWidth = x.bandwidth() / data.length\n\n            _data.forEach((obj, collectionIndex) => {\n                obj.data.forEach((item, valueIndex) => {\n                    areas.push({\n                        bar: item,\n                        path: shape\n                            .area()\n                            .x((value, _index) =>\n                                _index === 0\n                                    ? x(valueIndex) + barWidth * collectionIndex\n                                    : x(valueIndex) + barWidth + barWidth * collectionIndex\n                            )\n                            .y0(y(0))\n                            .y1((value) => y(value))\n                            .defined((value) => typeof value === 'number')([item.value, item.value]),\n                    })\n                })\n            })\n        }\n\n        return areas\n    }\n\n    calcExtent() {\n        const { data, yAccessor, gridMin, gridMax } = this.props\n        const dataExtent = array.merge(data.map((obj) => obj.data.map((item) => yAccessor({ item }))))\n\n        const extent = array.extent([...dataExtent, gridMax, gridMin])\n\n        const { yMin = extent[0], yMax = extent[1] } = this.props\n\n        return [yMin, yMax]\n    }\n\n    calcIndexes() {\n        const { data } = this.props\n        return data[0].data.map((_, index) => index)\n    }\n}\n\nGroupedBarChart.propTypes = {\n    ...BarChart.propTypes,\n    data: PropTypes.arrayOf(\n        PropTypes.shape({\n            data: PropTypes.array.isRequired,\n            svg: PropTypes.object,\n        })\n    ).isRequired,\n}\n\nexport default GroupedBarChart\n"]},"metadata":{},"sourceType":"script"}