35be6f7355b13b4525a52f18809cbee8.json 26.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 _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 array=_interopRequireWildcard(require(\"d3-array\"));var scale=_interopRequireWildcard(require(\"d3-scale\"));var shape=_interopRequireWildcard(require(\"d3-shape\"));var _propTypes=_interopRequireDefault(require(\"prop-types\"));var _react=_interopRequireWildcard(require(\"react\"));var _View=_interopRequireDefault(require(\"react-native-web/dist/exports/View\"));var _reactNativeSvg=_interopRequireDefault(require(\"react-native-svg\"));var _animatedPath=_interopRequireDefault(require(\"../animated-path\"));var BarChart=function(_PureComponent){(0,_inherits2.default)(BarChart,_PureComponent);function BarChart(){var _getPrototypeOf2;var _this;(0,_classCallCheck2.default)(this,BarChart);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)(BarChart)).call.apply(_getPrototypeOf2,[this].concat(args)));_this.state={width:0,height:0};return _this;}(0,_createClass2.default)(BarChart,[{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:\"calcXScale\",value:function calcXScale(domain){var data=this.props.data;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;var width=this.state.width;if(horizontal){return scale.scaleLinear().domain(domain).range([left,width-right]);}return scale.scaleBand().domain(data.map(function(_,index){return index;})).range([left,width-right]).paddingInner([spacingInner]).paddingOuter([spacingOuter]);}},{key:\"calcYScale\",value:function calcYScale(domain){var data=this.props.data;var _this$props2=this.props,horizontal=_this$props2.horizontal,_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,spacingInner=_this$props2.spacingInner,spacingOuter=_this$props2.spacingOuter;var height=this.state.height;if(horizontal){return scale.scaleBand().domain(data.map(function(_,index){return index;})).range([top,height-bottom]).paddingInner([spacingInner]).paddingOuter([spacingOuter]);}return scale.scaleLinear().domain(domain).range([height-bottom,top]);}},{key:\"calcAreas\",value:function calcAreas(x,y,series){var _this$props3=this.props,horizontal=_this$props3.horizontal,colors=_this$props3.colors,keys=_this$props3.keys;if(horizontal){return array.merge(series.map(function(serie,keyIndex){return serie.map(function(entry,entryIndex){var path=shape.area().x0(function(d){return x(d[0]);}).x1(function(d){return x(d[1]);}).y(function(d,_index){return _index===0?y(entryIndex):y(entryIndex)+y.bandwidth();}).defined(function(d){return!isNaN(d[0])&&!isNaN(d[1]);})([entry,entry]);return{path:path,color:colors[keyIndex],key:keys[keyIndex]};});}));}return array.merge(series.map(function(serie,keyIndex){return serie.map(function(entry,entryIndex){var path=shape.area().y0(function(d){return y(d[0]);}).y1(function(d){return y(d[1]);}).x(function(d,_index){return _index===0?x(entryIndex):x(entryIndex)+x.bandwidth();}).defined(function(d){return!isNaN(d[0])&&!isNaN(d[1]);})([entry,entry]);return{path:path,color:colors[keyIndex],key:keys[keyIndex]};});}));}},{key:\"calcExtent\",value:function calcExtent(values){var _this$props4=this.props,gridMax=_this$props4.gridMax,gridMin=_this$props4.gridMin;return array.extent([].concat((0,_toConsumableArray2.default)(values),[gridMin,gridMax]));}},{key:\"calcIndexes\",value:function calcIndexes(values){return values.map(function(_,index){return index;});}},{key:\"getSeries\",value:function getSeries(){var _this$props5=this.props,data=_this$props5.data,keys=_this$props5.keys,offset=_this$props5.offset,order=_this$props5.order,valueAccessor=_this$props5.valueAccessor;return shape.stack().keys(keys).value(function(item,key){return valueAccessor({item:item,key:key});}).order(order).offset(offset)(data);}},{key:\"render\",value:function render(){var _this2=this;var _this$props6=this.props,data=_this$props6.data,animate=_this$props6.animate,animationDuration=_this$props6.animationDuration,style=_this$props6.style,numberOfTicks=_this$props6.numberOfTicks,children=_this$props6.children,horizontal=_this$props6.horizontal;var _this$state=this.state,height=_this$state.height,width=_this$state.width;if(data.length===0){return _react.default.createElement(_View.default,{style:style});}var series=this.getSeries();var values=array.merge(array.merge(series));var indexes=this.calcIndexes(values);var extent=this.calcExtent(values);var ticks=array.ticks(extent[0],extent[1],numberOfTicks);var xDomain=horizontal?extent:indexes;var yDomain=horizontal?indexes:extent;var x=this.calcXScale(xDomain);var y=this.calcYScale(yDomain);var bandwidth=horizontal?y.bandwidth():x.bandwidth();var areas=this.calcAreas(x,y,series);var extraProps={x:x,y:y,width:width,height:height,ticks:ticks,data:data,bandwidth:bandwidth};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.Children.map(children,function(child){if(child&&child.props.belowChart){return _react.default.cloneElement(child,extraProps);}return null;}),areas.map(function(bar,index){var keyIndex=index%data.length;var key=keyIndex+\"-\"+bar.key;var svg=data[keyIndex][bar.key].svg;return _react.default.createElement(_animatedPath.default,(0,_extends2.default)({key:key,fill:bar.color},svg,{d:bar.path,animate:animate,animationDuration:animationDuration}));}),_react.default.Children.map(children,function(child){if(child&&!child.props.belowChart){return _react.default.cloneElement(child,extraProps);}return null;}))));}}],[{key:\"extractDataPoints\",value:function extractDataPoints(data,keys){var order=arguments.length>2&&arguments[2]!==undefined?arguments[2]:shape.stackOrderNone;var offset=arguments.length>3&&arguments[3]!==undefined?arguments[3]:shape.stackOffsetNone;var series=shape.stack().keys(keys).order(order).offset(offset)(data);return array.merge(array.merge(series));}}]);return BarChart;}(_react.PureComponent);BarChart.propTypes={data:_propTypes.default.arrayOf(_propTypes.default.object),keys:_propTypes.default.arrayOf(_propTypes.default.string).isRequired,colors:_propTypes.default.arrayOf(_propTypes.default.string).isRequired,offset:_propTypes.default.func,order:_propTypes.default.func,style:_propTypes.default.any,spacingInner:_propTypes.default.number,spacingOuter:_propTypes.default.number,animate:_propTypes.default.bool,animationDuration:_propTypes.default.number,contentInset:_propTypes.default.shape({top:_propTypes.default.number,left:_propTypes.default.number,right:_propTypes.default.number,bottom:_propTypes.default.number}),gridMin:_propTypes.default.number,gridMax:_propTypes.default.number,valueAccessor:_propTypes.default.func};BarChart.defaultProps={spacingInner:0.05,spacingOuter:0.05,offset:shape.stackOffsetNone,order:shape.stackOrderNone,width:100,height:100,showZeroAxis:true,contentInset:{},numberOfTicks:10,showGrid:true,valueAccessor:function valueAccessor(_ref){var item=_ref.item,key=_ref.key;return item[key];}};var _default=BarChart;exports.default=_default;","map":{"version":3,"sources":["C:/Users/bluej/Desktop/2_2/searchGuide/searchGuide/node_modules/react-native-svg-charts/src/stacked-bar-chart/stacked-bar-chart.js"],"names":["BarChart","state","width","height","event","nativeEvent","layout","setState","domain","data","props","horizontal","contentInset","left","right","spacingInner","spacingOuter","scale","scaleLinear","range","scaleBand","map","_","index","paddingInner","paddingOuter","top","bottom","x","y","series","colors","keys","array","merge","serie","keyIndex","entry","entryIndex","path","shape","area","x0","d","x1","_index","bandwidth","defined","isNaN","color","key","y0","y1","values","gridMax","gridMin","extent","offset","order","valueAccessor","stack","value","item","animate","animationDuration","style","numberOfTicks","children","length","getSeries","indexes","calcIndexes","calcExtent","ticks","xDomain","yDomain","calcXScale","calcYScale","areas","calcAreas","extraProps","flex","_onLayout","React","Children","child","belowChart","cloneElement","bar","svg","stackOrderNone","stackOffsetNone","PureComponent","propTypes","PropTypes","arrayOf","object","string","isRequired","func","any","number","bool","defaultProps","showZeroAxis","showGrid"],"mappings":"s4BAAA,uDACA,uDACA,uDACA,6DACA,qD,gFAEA,wEACA,sE,GAEMA,CAAAA,Q,sbAYFC,K,CAAQ,CACJC,KAAK,CAAE,CADH,CAEJC,MAAM,CAAE,CAFJ,C,6FAKEC,K,CAAO,2BAKTA,KALS,CAETC,WAFS,CAGLC,MAHK,CAGKH,MAHL,uBAGKA,MAHL,CAGaD,KAHb,uBAGaA,KAHb,CAMb,KAAKK,QAAL,CAAc,CAAEJ,MAAM,CAANA,MAAF,CAAUD,KAAK,CAALA,KAAV,CAAd,EACH,C,8CAEUM,M,CAAQ,IACPC,CAAAA,IADO,CACE,KAAKC,KADP,CACPD,IADO,iBAQX,KAAKC,KARM,CAIXC,UAJW,aAIXA,UAJW,mCAKXC,YALW,8CAKKC,IALL,CAKKA,IALL,iCAKY,CALZ,qEAKeC,KALf,CAKeA,KALf,iCAKuB,CALvB,wBAMXC,YANW,aAMXA,YANW,CAOXC,YAPW,aAOXA,YAPW,IAUPd,CAAAA,KAVO,CAUG,KAAKD,KAVR,CAUPC,KAVO,CAYf,GAAIS,UAAJ,CAAgB,CACZ,MAAOM,CAAAA,KAAK,CACPC,WADE,GAEFV,MAFE,CAEKA,MAFL,EAGFW,KAHE,CAGI,CAACN,IAAD,CAAOX,KAAK,CAAGY,KAAf,CAHJ,CAAP,CAIH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AAH,CAASZ,GAAT,MAASA,GAAT,OAAmBY,CAAAA,IAAI,CAACZ,GAAD,CAAvB,EAXK,CAAxB,C,aAcelD,Q","sourcesContent":["import * as array from 'd3-array'\nimport * as scale from 'd3-scale'\nimport * as shape from 'd3-shape'\nimport PropTypes from 'prop-types'\nimport React, { PureComponent } from 'react'\nimport { View } from 'react-native'\nimport Svg from 'react-native-svg'\nimport Path from '../animated-path'\n\nclass BarChart extends PureComponent {\n    static extractDataPoints(data, keys, order = shape.stackOrderNone, offset = shape.stackOffsetNone) {\n        const series = shape\n            .stack()\n            .keys(keys)\n            .order(order)\n            .offset(offset)(data)\n\n        //double merge arrays to extract just the values\n        return array.merge(array.merge(series))\n    }\n\n    state = {\n        width: 0,\n        height: 0,\n    }\n\n    _onLayout(event) {\n        const {\n            nativeEvent: {\n                layout: { height, width },\n            },\n        } = event\n        this.setState({ height, width })\n    }\n\n    calcXScale(domain) {\n        const { data } = this.props\n\n        const {\n            horizontal,\n            contentInset: { left = 0, right = 0 },\n            spacingInner,\n            spacingOuter,\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        }\n\n        // use index as domain identifier instead of value since\n        // domain must be same length as number of bars\n        // same value can occur at several places in data\n        return scale\n            .scaleBand()\n            .domain(data.map((_, index) => index))\n            .range([left, width - right])\n            .paddingInner([spacingInner])\n            .paddingOuter([spacingOuter])\n    }\n\n    calcYScale(domain) {\n        const { data } = this.props\n\n        const {\n            horizontal,\n            contentInset: { top = 0, bottom = 0 },\n            spacingInner,\n            spacingOuter,\n        } = this.props\n\n        const { height } = this.state\n\n        if (horizontal) {\n            return scale\n                .scaleBand()\n                .domain(data.map((_, index) => index))\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    }\n\n    calcAreas(x, y, series) {\n        const { horizontal, colors, keys } = this.props\n\n        if (horizontal) {\n            return array.merge(\n                series.map((serie, keyIndex) => {\n                    return serie.map((entry, entryIndex) => {\n                        const path = shape\n                            .area()\n                            .x0((d) => x(d[0]))\n                            .x1((d) => x(d[1]))\n                            .y((d, _index) => (_index === 0 ? y(entryIndex) : y(entryIndex) + y.bandwidth()))\n                            .defined((d) => !isNaN(d[0]) && !isNaN(d[1]))([entry, entry])\n\n                        return {\n                            path,\n                            color: colors[keyIndex],\n                            key: keys[keyIndex],\n                        }\n                    })\n                })\n            )\n        }\n\n        return array.merge(\n            series.map((serie, keyIndex) => {\n                return serie.map((entry, entryIndex) => {\n                    const path = shape\n                        .area()\n                        .y0((d) => y(d[0]))\n                        .y1((d) => y(d[1]))\n                        .x((d, _index) => (_index === 0 ? x(entryIndex) : x(entryIndex) + x.bandwidth()))\n                        .defined((d) => !isNaN(d[0]) && !isNaN(d[1]))([entry, entry])\n\n                    return {\n                        path,\n                        color: colors[keyIndex],\n                        key: keys[keyIndex],\n                    }\n                })\n            })\n        )\n    }\n\n    calcExtent(values) {\n        const { gridMax, gridMin } = this.props\n\n        return array.extent([...values, gridMin, gridMax])\n    }\n\n    calcIndexes(values) {\n        return values.map((_, index) => index)\n    }\n\n    getSeries() {\n        const { data, keys, offset, order, valueAccessor } = this.props\n\n        return shape\n            .stack()\n            .keys(keys)\n            .value((item, key) => valueAccessor({ item, key }))\n            .order(order)\n            .offset(offset)(data)\n    }\n\n    render() {\n        const { data, animate, animationDuration, style, numberOfTicks, children, horizontal } = this.props\n\n        const { height, width } = this.state\n\n        if (data.length === 0) {\n            return <View style={style} />\n        }\n\n        const series = this.getSeries()\n\n        //double merge arrays to extract just the values\n        const values = array.merge(array.merge(series))\n        const indexes = this.calcIndexes(values)\n\n        const extent = this.calcExtent(values)\n        const ticks = array.ticks(extent[0], extent[1], numberOfTicks)\n\n        const xDomain = horizontal ? extent : indexes\n        const yDomain = horizontal ? indexes : extent\n\n        const x = this.calcXScale(xDomain)\n        const y = this.calcYScale(yDomain)\n\n        const bandwidth = horizontal ? y.bandwidth() : x.bandwidth()\n\n        const areas = this.calcAreas(x, y, series)\n\n        const extraProps = {\n            x,\n            y,\n            width,\n            height,\n            ticks,\n            data,\n            bandwidth,\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                            {React.Children.map(children, (child) => {\n                                if (child && child.props.belowChart) {\n                                    return React.cloneElement(child, extraProps)\n                                }\n                                return null\n                            })}\n                            {areas.map((bar, index) => {\n                                const keyIndex = index % data.length\n                                const key = `${keyIndex}-${bar.key}`\n                                const { svg } = data[keyIndex][bar.key]\n\n                                return (\n                                    <Path\n                                        key={key}\n                                        fill={bar.color}\n                                        {...svg}\n                                        d={bar.path}\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                        </Svg>\n                    )}\n                </View>\n            </View>\n        )\n    }\n}\n\nBarChart.propTypes = {\n    data: PropTypes.arrayOf(PropTypes.object),\n    keys: PropTypes.arrayOf(PropTypes.string).isRequired,\n    colors: PropTypes.arrayOf(PropTypes.string).isRequired,\n    offset: PropTypes.func,\n    order: PropTypes.func,\n    style: PropTypes.any,\n    spacingInner: PropTypes.number,\n    spacingOuter: PropTypes.number,\n    animate: PropTypes.bool,\n    animationDuration: PropTypes.number,\n    contentInset: PropTypes.shape({\n        top: PropTypes.number,\n        left: PropTypes.number,\n        right: PropTypes.number,\n        bottom: PropTypes.number,\n    }),\n    gridMin: PropTypes.number,\n    gridMax: PropTypes.number,\n    valueAccessor: PropTypes.func,\n}\n\nBarChart.defaultProps = {\n    spacingInner: 0.05,\n    spacingOuter: 0.05,\n    offset: shape.stackOffsetNone,\n    order: shape.stackOrderNone,\n    width: 100,\n    height: 100,\n    showZeroAxis: true,\n    contentInset: {},\n    numberOfTicks: 10,\n    showGrid: true,\n    valueAccessor: ({ item, key }) => item[key],\n}\n\nexport default BarChart\n"]},"metadata":{},"sourceType":"script"}