react-native-gifted-charts 1.4.21 → 1.4.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BarChart/Animated2DWithGradient.d.ts +3 -0
- package/dist/BarChart/Animated2DWithGradient.js +113 -1
- package/dist/BarChart/RenderBars.d.ts +3 -0
- package/dist/BarChart/RenderBars.js +264 -1
- package/dist/BarChart/RenderStackBars.d.ts +3 -0
- package/dist/BarChart/RenderStackBars.js +174 -1
- package/dist/BarChart/index.d.ts +2 -0
- package/dist/BarChart/index.js +236 -1
- package/dist/BarChart/styles.d.ts +45 -0
- package/dist/BarChart/styles.js +46 -1
- package/dist/Components/AnimatedThreeDBar/index.d.ts +3 -0
- package/dist/Components/AnimatedThreeDBar/index.js +129 -1
- package/dist/Components/AnimatedThreeDBar/styles.d.ts +10 -0
- package/dist/Components/AnimatedThreeDBar/styles.js +13 -1
- package/dist/Components/BarAndLineChartsWrapper/index.d.ts +3 -0
- package/dist/Components/BarAndLineChartsWrapper/index.js +128 -1
- package/dist/Components/BarAndLineChartsWrapper/renderHorizSections.d.ts +2 -0
- package/dist/Components/BarAndLineChartsWrapper/renderHorizSections.js +322 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.d.ts +3 -0
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.js +76 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.d.ts +2 -0
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.js +50 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.d.ts +1 -0
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.js +25 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.d.ts +1 -0
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.js +20 -1
- package/dist/Components/BarAndLineChartsWrapper/renderVerticalLines.d.ts +2 -0
- package/dist/Components/BarAndLineChartsWrapper/renderVerticalLines.js +94 -1
- package/dist/Components/BarSpecificComponents/barBackgroundPattern.d.ts +2 -0
- package/dist/Components/BarSpecificComponents/barBackgroundPattern.js +9 -1
- package/dist/Components/BarSpecificComponents/cap.d.ts +2 -0
- package/dist/Components/BarSpecificComponents/cap.js +16 -1
- package/dist/Components/BarSpecificComponents/tooltip.d.ts +15 -0
- package/dist/Components/BarSpecificComponents/tooltip.js +40 -1
- package/dist/Components/common/LinearGradient.d.ts +16 -0
- package/dist/Components/common/LinearGradient.js +15 -1
- package/dist/Components/common/Pointer.d.ts +1 -0
- package/dist/Components/common/Pointer.js +16 -1
- package/dist/Components/common/StripAndLabel.d.ts +2 -0
- package/dist/Components/common/StripAndLabel.js +43 -1
- package/dist/Components/lineSvg.d.ts +14 -0
- package/dist/Components/lineSvg.js +22 -1
- package/dist/LineChart/LineChartBicolor.d.ts +2 -0
- package/dist/LineChart/LineChartBicolor.js +294 -1
- package/dist/LineChart/index.d.ts +2 -0
- package/dist/LineChart/index.js +1110 -1
- package/dist/LineChart/previous.d.ts +2 -0
- package/dist/LineChart/previous.js +9 -0
- package/dist/LineChart/styles.d.ts +43 -0
- package/dist/LineChart/styles.js +46 -1
- package/dist/PieChart/index.d.ts +2 -0
- package/dist/PieChart/index.js +99 -1
- package/dist/PieChart/main.d.ts +2 -0
- package/dist/PieChart/main.js +182 -1
- package/dist/PieChartPro/index.d.ts +2 -0
- package/dist/PieChartPro/index.js +124 -1
- package/dist/PopulationPyramid/index.d.ts +2 -0
- package/dist/PopulationPyramid/index.js +130 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -1
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +20 -1
- package/package.json +3 -3
|
@@ -1 +1,174 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _reactNativeSvg=_interopRequireWildcard(require("react-native-svg"));var _LinearGradient=_interopRequireDefault(require("../Components/common/LinearGradient"));var _giftedChartsCore=require("gifted-charts-core");var _tooltip=_interopRequireDefault(require("../Components/BarSpecificComponents/tooltip"));var _jsxRuntime=require("react/jsx-runtime");var _this=this,_jsxFileName="/Users/abhinandankushwaha/sites/projects/react-native-gifted-charts/src/BarChart/RenderStackBars.tsx";function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap(),t=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r;})(e);}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&{}.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,t&&t.set(e,n),n;}if(_reactNative.Platform.OS==='android'){_reactNative.UIManager.setLayoutAnimationEnabledExperimental&&_reactNative.UIManager.setLayoutAnimationEnabledExperimental(true);}var RenderStackBars=function RenderStackBars(props){var _props$pointerConfig$;var barBackgroundPattern=props.barBackgroundPattern,patternId=props.patternId,item=props.item,index=props.index,containerHeight=props.containerHeight,spacing=props.spacing,rotateLabel=props.rotateLabel,label=props.label,labelTextStyle=props.labelTextStyle,xAxisTextNumberOfLines=props.xAxisTextNumberOfLines,xAxisLabelsVerticalShift=props.xAxisLabelsVerticalShift,renderTooltip=props.renderTooltip,selectedIndex=props.selectedIndex,setSelectedIndex=props.setSelectedIndex,activeOpacity=props.activeOpacity,_props$animationDurat=props.animationDuration,animationDuration=_props$animationDurat===void 0?_giftedChartsCore.BarDefaults.animationDuration:_props$animationDurat,barBorderWidth=props.barBorderWidth,barBorderColor=props.barBorderColor,stackBorderRadius=props.stackBorderRadius,stackBorderTopLeftRadius=props.stackBorderTopLeftRadius,stackBorderTopRightRadius=props.stackBorderTopRightRadius,stackBorderBottomLeftRadius=props.stackBorderBottomLeftRadius,stackBorderBottomRightRadius=props.stackBorderBottomRightRadius,showValuesAsTopLabel=props.showValuesAsTopLabel,_props$autoShiftLabel=props.autoShiftLabelsForNegativeStacks,autoShiftLabelsForNegativeStacks=_props$autoShiftLabel===void 0?true:_props$autoShiftLabel,_props$labelsDistance=props.labelsDistanceFromXaxis,labelsDistanceFromXaxis=_props$labelsDistance===void 0?0:_props$labelsDistance,horizontal=props.horizontal;var _useRenderStackBars=(0,_giftedChartsCore.useRenderStackBars)(props),cotainsNegative=_useRenderStackBars.cotainsNegative,noAnimation=_useRenderStackBars.noAnimation,localBarInnerComponent=_useRenderStackBars.localBarInnerComponent,borderRadius=_useRenderStackBars.borderRadius,borderTopLeftRadius=_useRenderStackBars.borderTopLeftRadius,borderTopRightRadius=_useRenderStackBars.borderTopRightRadius,borderBottomLeftRadius=_useRenderStackBars.borderBottomLeftRadius,borderBottomRightRadius=_useRenderStackBars.borderBottomRightRadius,disablePress=_useRenderStackBars.disablePress,totalHeight=_useRenderStackBars.totalHeight,height=_useRenderStackBars.height,setHeight=_useRenderStackBars.setHeight,getBarHeight=_useRenderStackBars.getBarHeight,getPosition=_useRenderStackBars.getPosition,lowestBarPosition=_useRenderStackBars.lowestBarPosition,getStackBorderRadii=_useRenderStackBars.getStackBorderRadii,tooltipProps=_useRenderStackBars.tooltipProps;var renderLabel=function renderLabel(label,labelTextStyle){return(0,_jsxRuntime.jsx)(_reactNative.View,{style:[{width:(item.stacks[0].barWidth||props.barWidth||30)+spacing/2,position:'absolute',bottom:autoShiftLabelsForNegativeStacks?-6-xAxisTextNumberOfLines*18+lowestBarPosition:-labelsDistanceFromXaxis},rotateLabel?horizontal?{transform:[{rotate:'330deg'}]}:{transform:[{rotate:'60deg'}]}:horizontal?{transform:[{rotate:'-90deg'}]}:{}],children:item.labelComponent?item.labelComponent():(0,_jsxRuntime.jsx)(_reactNative.Text,{style:[labelTextStyle],numberOfLines:xAxisTextNumberOfLines,children:label||''})});};(0,_react.useEffect)(function(){if(!noAnimation){layoutAppear();}},[totalHeight]);var elevate=function elevate(){_reactNative.LayoutAnimation.configureNext({duration:animationDuration,update:{type:'linear',property:'scaleXY'}});setHeight(totalHeight);};var layoutAppear=function layoutAppear(){_reactNative.LayoutAnimation.configureNext({duration:_reactNative.Platform.OS=='ios'?animationDuration:20,create:{type:'linear',property:'opacity'},update:{type:'linear',property:'scaleXY'}});setTimeout(function(){return elevate();},_reactNative.Platform.OS=='ios'?10:100);};var static2DSimple=function static2DSimple(){var _ref,_ref2,_ref3,_ref4,_ref5,_ref6,_ref7,_ref8;return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsxs)(_reactNative.TouchableOpacity,{disabled:disablePress,activeOpacity:activeOpacity,onPress:function onPress(){setSelectedIndex(index);if(item.onPress){item.onPress();}else if(props.onPress){props.onPress(item,index);}},onLongPress:function onLongPress(){if(item.onLongPress){item.onLongPress();}else if(props.onLongPress){props.onLongPress(item,index);}},onPressOut:function onPressOut(){if(item.onPressOut){item.onPressOut();}else if(props.onPressOut){props.onPressOut(item,index);}},style:[{position:'absolute',width:item.stacks[0].barWidth||props.barWidth||30,height:'100%',borderTopLeftRadius:(_ref=(_ref2=borderTopLeftRadius!=null?borderTopLeftRadius:borderRadius)!=null?_ref2:stackBorderTopLeftRadius)!=null?_ref:stackBorderRadius,borderTopRightRadius:(_ref3=(_ref4=borderTopRightRadius!=null?borderTopRightRadius:borderRadius)!=null?_ref4:stackBorderTopRightRadius)!=null?_ref3:stackBorderRadius,borderBottomLeftRadius:(_ref5=(_ref6=borderBottomLeftRadius!=null?borderBottomLeftRadius:borderRadius)!=null?_ref6:stackBorderBottomLeftRadius)!=null?_ref5:stackBorderRadius,borderBottomRightRadius:(_ref7=(_ref8=borderBottomRightRadius!=null?borderBottomRightRadius:borderRadius)!=null?_ref8:stackBorderBottomRightRadius)!=null?_ref7:stackBorderRadius,overflow:lowestBarPosition?'visible':'hidden'}],children:[item.stacks.map(function(stackItem,index){var borderRadii=getStackBorderRadii(item,index);var barHeight=getBarHeight(stackItem.value,stackItem.marginBottom);return(0,_jsxRuntime.jsxs)(_reactNative.TouchableOpacity,{onPress:stackItem.onPress,activeOpacity:activeOpacity,disabled:disablePress||!stackItem.onPress,style:Object.assign({position:'absolute',bottom:getPosition(index)+(stackItem.marginBottom||0),width:'100%',height:barHeight,backgroundColor:stackItem.color||item.color||props.color||'black',borderWidth:barBorderWidth!=null?barBorderWidth:0,borderColor:barBorderColor},borderRadii),children:[stackItem.showGradient||item.showGradient||props.showGradient?(0,_jsxRuntime.jsx)(_LinearGradient.default,{style:Object.assign({position:'absolute',width:'100%',height:'100%'},borderRadii),start:{x:0,y:0},end:{x:0,y:1},colors:[stackItem.gradientColor||item.gradientColor||props.gradientColor||'white',stackItem.color||item.color||props.color||'black']}):null,stackItem.innerBarComponent&&stackItem.innerBarComponent()]},index);}),(item.barBackgroundPattern||barBackgroundPattern)&&(0,_jsxRuntime.jsxs)(_reactNativeSvg.default,{children:[(0,_jsxRuntime.jsx)(_reactNativeSvg.Defs,{children:item.barBackgroundPattern?item.barBackgroundPattern():barBackgroundPattern==null?void 0:barBackgroundPattern()}),(0,_jsxRuntime.jsx)(_reactNativeSvg.Rect,{stroke:"transparent",x:"1",y:"1",width:"100%",height:"100%",fill:`url(#${item.patternId||patternId})`})]})]}),localBarInnerComponent?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:'100%',width:'100%'},children:localBarInnerComponent(item,index)}):null,(item.topLabelComponent||showValuesAsTopLabel)&&(0,_jsxRuntime.jsx)(_reactNative.View,{style:[{position:'absolute',top:cotainsNegative?0:(item.barWidth||props.barWidth||30)*-1,height:item.barWidth||props.barWidth||30,width:item.barWidth||props.barWidth||30,justifyContent:'center',alignItems:'center'},cotainsNegative&&{transform:[{translateY:totalHeight*2}]},horizontal&&!props.intactTopLabel&&{transform:[{rotate:'270deg'}]},item.topLabelContainerStyle],children:showValuesAsTopLabel?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:item.topLabelTextStyle,children:item.stacks.reduce(function(acc,stack){return acc+stack.value;},0)}):item.topLabelComponent==null?void 0:item.topLabelComponent()})]});};var barWrapper=function barWrapper(){return noAnimation?static2DSimple():(0,_jsxRuntime.jsx)(_reactNative.View,{style:{position:'absolute',bottom:0,height:height,width:'100%',overflow:'hidden'},children:static2DSimple()});};return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{pointerEvents:props.pointerConfig?(_props$pointerConfig$=props.pointerConfig.pointerEvents)!=null?_props$pointerConfig$:'none':'auto',style:[{marginBottom:60+xAxisLabelsVerticalShift,width:item.stacks[0].barWidth||props.barWidth||30,height:totalHeight,marginRight:spacing},props.pointerConfig?{transform:[{translateY:(containerHeight||200)-(totalHeight-10+xAxisLabelsVerticalShift)}]}:null],children:[(props.showXAxisIndices||item.showXAxisIndex)&&(0,_jsxRuntime.jsx)(_reactNative.View,{style:{zIndex:2,position:'absolute',height:props.xAxisIndicesHeight,width:props.xAxisIndicesWidth,bottom:props.xAxisIndicesHeight/-2,left:((item.barWidth||props.barWidth||30)-props.xAxisIndicesWidth)/2,backgroundColor:props.xAxisIndicesColor}}),barWrapper(),renderLabel(label||'',labelTextStyle)]}),renderTooltip&&selectedIndex===index&&(0,_jsxRuntime.jsx)(_tooltip.default,Object.assign({},tooltipProps))]});};var _default=exports.default=RenderStackBars;
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import { useEffect } from 'react';
|
|
14
|
+
import { View, TouchableOpacity, Text, LayoutAnimation, Platform, UIManager, } from 'react-native';
|
|
15
|
+
import Svg, { Defs, Rect } from 'react-native-svg';
|
|
16
|
+
import LinearGradient from '../Components/common/LinearGradient';
|
|
17
|
+
import { useRenderStackBars, BarDefaults, } from 'gifted-charts-core';
|
|
18
|
+
import Tooltip from '../Components/BarSpecificComponents/tooltip';
|
|
19
|
+
if (Platform.OS === 'android') {
|
|
20
|
+
UIManager.setLayoutAnimationEnabledExperimental &&
|
|
21
|
+
UIManager.setLayoutAnimationEnabledExperimental(true);
|
|
22
|
+
}
|
|
23
|
+
var RenderStackBars = function (props) {
|
|
24
|
+
var _a;
|
|
25
|
+
var barBackgroundPattern = props.barBackgroundPattern, patternId = props.patternId, item = props.item, index = props.index, containerHeight = props.containerHeight, spacing = props.spacing, rotateLabel = props.rotateLabel, label = props.label, labelTextStyle = props.labelTextStyle, xAxisTextNumberOfLines = props.xAxisTextNumberOfLines, xAxisLabelsVerticalShift = props.xAxisLabelsVerticalShift, renderTooltip = props.renderTooltip, selectedIndex = props.selectedIndex, setSelectedIndex = props.setSelectedIndex, activeOpacity = props.activeOpacity, _b = props.animationDuration, animationDuration = _b === void 0 ? BarDefaults.animationDuration : _b, barBorderWidth = props.barBorderWidth, barBorderColor = props.barBorderColor, stackBorderRadius = props.stackBorderRadius, stackBorderTopLeftRadius = props.stackBorderTopLeftRadius, stackBorderTopRightRadius = props.stackBorderTopRightRadius, stackBorderBottomLeftRadius = props.stackBorderBottomLeftRadius, stackBorderBottomRightRadius = props.stackBorderBottomRightRadius, showValuesAsTopLabel = props.showValuesAsTopLabel, _c = props.autoShiftLabelsForNegativeStacks, autoShiftLabelsForNegativeStacks = _c === void 0 ? true : _c, _d = props.labelsDistanceFromXaxis, labelsDistanceFromXaxis = _d === void 0 ? 0 : _d, horizontal = props.horizontal;
|
|
26
|
+
var _e = useRenderStackBars(props), containsNegativeValue = _e.containsNegativeValue, noAnimation = _e.noAnimation, localBarInnerComponent = _e.localBarInnerComponent, borderRadius = _e.borderRadius, borderTopLeftRadius = _e.borderTopLeftRadius, borderTopRightRadius = _e.borderTopRightRadius, borderBottomLeftRadius = _e.borderBottomLeftRadius, borderBottomRightRadius = _e.borderBottomRightRadius, disablePress = _e.disablePress, totalHeight = _e.totalHeight, height = _e.height, setHeight = _e.setHeight, getBarHeight = _e.getBarHeight, getPosition = _e.getPosition, lowestBarPosition = _e.lowestBarPosition, getStackBorderRadii = _e.getStackBorderRadii, tooltipProps = _e.tooltipProps;
|
|
27
|
+
var renderLabel = function (label, labelTextStyle) {
|
|
28
|
+
return (_jsx(View, { style: [
|
|
29
|
+
{
|
|
30
|
+
width: (item.stacks[0].barWidth || props.barWidth || 30) + spacing / 2,
|
|
31
|
+
position: 'absolute',
|
|
32
|
+
bottom: autoShiftLabelsForNegativeStacks
|
|
33
|
+
? -6 - xAxisTextNumberOfLines * 18 + lowestBarPosition
|
|
34
|
+
: -labelsDistanceFromXaxis,
|
|
35
|
+
},
|
|
36
|
+
rotateLabel
|
|
37
|
+
? horizontal
|
|
38
|
+
? { transform: [{ rotate: '330deg' }] }
|
|
39
|
+
: { transform: [{ rotate: '60deg' }] }
|
|
40
|
+
: horizontal
|
|
41
|
+
? { transform: [{ rotate: '-90deg' }] }
|
|
42
|
+
: {},
|
|
43
|
+
], children: item.labelComponent ? (item.labelComponent()) : (_jsx(Text, { style: [labelTextStyle], numberOfLines: xAxisTextNumberOfLines, children: label || '' })) }));
|
|
44
|
+
};
|
|
45
|
+
useEffect(function () {
|
|
46
|
+
if (!noAnimation) {
|
|
47
|
+
layoutAppear();
|
|
48
|
+
}
|
|
49
|
+
}, [totalHeight]);
|
|
50
|
+
var elevate = function () {
|
|
51
|
+
LayoutAnimation.configureNext({
|
|
52
|
+
duration: animationDuration,
|
|
53
|
+
update: { type: 'linear', property: 'scaleXY' },
|
|
54
|
+
});
|
|
55
|
+
setHeight(totalHeight);
|
|
56
|
+
};
|
|
57
|
+
var layoutAppear = function () {
|
|
58
|
+
LayoutAnimation.configureNext({
|
|
59
|
+
duration: Platform.OS == 'ios' ? animationDuration : 20,
|
|
60
|
+
create: { type: 'linear', property: 'opacity' },
|
|
61
|
+
update: { type: 'linear', property: 'scaleXY' },
|
|
62
|
+
});
|
|
63
|
+
setTimeout(function () { return elevate(); }, Platform.OS == 'ios' ? 10 : 100);
|
|
64
|
+
};
|
|
65
|
+
var static2DSimple = function () {
|
|
66
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
67
|
+
return (_jsxs(_Fragment, { children: [_jsxs(TouchableOpacity, { disabled: disablePress, activeOpacity: activeOpacity, onPress: function () {
|
|
68
|
+
setSelectedIndex(index);
|
|
69
|
+
if (item.onPress) {
|
|
70
|
+
item.onPress();
|
|
71
|
+
}
|
|
72
|
+
else if (props.onPress) {
|
|
73
|
+
props.onPress(item, index);
|
|
74
|
+
}
|
|
75
|
+
}, onLongPress: function () {
|
|
76
|
+
if (item.onLongPress) {
|
|
77
|
+
item.onLongPress();
|
|
78
|
+
}
|
|
79
|
+
else if (props.onLongPress) {
|
|
80
|
+
props.onLongPress(item, index);
|
|
81
|
+
}
|
|
82
|
+
}, onPressOut: function () {
|
|
83
|
+
if (item.onPressOut) {
|
|
84
|
+
item.onPressOut();
|
|
85
|
+
}
|
|
86
|
+
else if (props.onPressOut) {
|
|
87
|
+
props.onPressOut(item, index);
|
|
88
|
+
}
|
|
89
|
+
}, style: [
|
|
90
|
+
{
|
|
91
|
+
position: 'absolute',
|
|
92
|
+
width: item.stacks[0].barWidth || props.barWidth || 30,
|
|
93
|
+
height: '100%',
|
|
94
|
+
borderTopLeftRadius: (_b = (_a = borderTopLeftRadius !== null && borderTopLeftRadius !== void 0 ? borderTopLeftRadius : borderRadius) !== null && _a !== void 0 ? _a : stackBorderTopLeftRadius) !== null && _b !== void 0 ? _b : stackBorderRadius,
|
|
95
|
+
borderTopRightRadius: (_d = (_c = borderTopRightRadius !== null && borderTopRightRadius !== void 0 ? borderTopRightRadius : borderRadius) !== null && _c !== void 0 ? _c : stackBorderTopRightRadius) !== null && _d !== void 0 ? _d : stackBorderRadius,
|
|
96
|
+
borderBottomLeftRadius: (_f = (_e = borderBottomLeftRadius !== null && borderBottomLeftRadius !== void 0 ? borderBottomLeftRadius : borderRadius) !== null && _e !== void 0 ? _e : stackBorderBottomLeftRadius) !== null && _f !== void 0 ? _f : stackBorderRadius,
|
|
97
|
+
borderBottomRightRadius: (_h = (_g = borderBottomRightRadius !== null && borderBottomRightRadius !== void 0 ? borderBottomRightRadius : borderRadius) !== null && _g !== void 0 ? _g : stackBorderBottomRightRadius) !== null && _h !== void 0 ? _h : stackBorderRadius,
|
|
98
|
+
overflow: lowestBarPosition ? 'visible' : 'hidden',
|
|
99
|
+
},
|
|
100
|
+
], children: [item.stacks.map(function (stackItem, index) {
|
|
101
|
+
var borderRadii = getStackBorderRadii(item, index);
|
|
102
|
+
var barHeight = getBarHeight(stackItem.value, stackItem.marginBottom);
|
|
103
|
+
return (_jsxs(TouchableOpacity, { onPress: stackItem.onPress, activeOpacity: activeOpacity, disabled: disablePress || !stackItem.onPress, style: __assign({ position: 'absolute', bottom: getPosition(index) + (stackItem.marginBottom || 0), width: '100%', height: barHeight, backgroundColor: stackItem.color || item.color || props.color || 'black', borderWidth: barBorderWidth !== null && barBorderWidth !== void 0 ? barBorderWidth : 0, borderColor: barBorderColor }, borderRadii), children: [stackItem.showGradient ||
|
|
104
|
+
item.showGradient ||
|
|
105
|
+
props.showGradient ? (_jsx(LinearGradient, { style: __assign({ position: 'absolute', width: '100%', height: '100%' }, borderRadii), start: { x: 0, y: 0 }, end: { x: 0, y: 1 }, colors: [
|
|
106
|
+
stackItem.gradientColor ||
|
|
107
|
+
item.gradientColor ||
|
|
108
|
+
props.gradientColor ||
|
|
109
|
+
'white',
|
|
110
|
+
stackItem.color || item.color || props.color || 'black',
|
|
111
|
+
] })) : null, stackItem.innerBarComponent && stackItem.innerBarComponent()] }, index));
|
|
112
|
+
}), (item.barBackgroundPattern || barBackgroundPattern) && (_jsxs(Svg, { children: [_jsx(Defs, { children: item.barBackgroundPattern
|
|
113
|
+
? item.barBackgroundPattern()
|
|
114
|
+
: barBackgroundPattern === null || barBackgroundPattern === void 0 ? void 0 : barBackgroundPattern() }), _jsx(Rect, { stroke: "transparent", x: "1", y: "1", width: "100%", height: "100%", fill: "url(#".concat(item.patternId || patternId, ")") })] }))] }), localBarInnerComponent ? (_jsx(View, { style: { height: '100%', width: '100%' }, children: localBarInnerComponent(item, index) })) : null, (item.topLabelComponent || showValuesAsTopLabel) && (_jsx(View, { style: [
|
|
115
|
+
{
|
|
116
|
+
position: 'absolute',
|
|
117
|
+
top: containsNegativeValue
|
|
118
|
+
? 0
|
|
119
|
+
: (item.barWidth || props.barWidth || 30) * -1,
|
|
120
|
+
height: item.barWidth || props.barWidth || 30,
|
|
121
|
+
width: item.barWidth || props.barWidth || 30,
|
|
122
|
+
justifyContent: 'center',
|
|
123
|
+
alignItems: 'center',
|
|
124
|
+
},
|
|
125
|
+
containsNegativeValue && {
|
|
126
|
+
transform: [{ translateY: totalHeight * 2 }],
|
|
127
|
+
},
|
|
128
|
+
horizontal &&
|
|
129
|
+
!props.intactTopLabel && { transform: [{ rotate: '270deg' }] },
|
|
130
|
+
item.topLabelContainerStyle,
|
|
131
|
+
], children: showValuesAsTopLabel ? (_jsx(Text, { style: item.topLabelTextStyle, children: item.stacks.reduce(function (acc, stack) { return acc + stack.value; }, 0) })) : ((_j = item.topLabelComponent) === null || _j === void 0 ? void 0 : _j.call(item)) }))] }));
|
|
132
|
+
};
|
|
133
|
+
var barWrapper = function () {
|
|
134
|
+
return noAnimation ? (static2DSimple()) : (_jsx(View, { style: {
|
|
135
|
+
position: 'absolute',
|
|
136
|
+
bottom: 0,
|
|
137
|
+
height: height,
|
|
138
|
+
width: '100%',
|
|
139
|
+
overflow: 'hidden',
|
|
140
|
+
}, children: static2DSimple() }));
|
|
141
|
+
};
|
|
142
|
+
return (_jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: props.pointerConfig
|
|
143
|
+
? ((_a = props.pointerConfig.pointerEvents) !== null && _a !== void 0 ? _a : 'none')
|
|
144
|
+
: 'auto', style: [
|
|
145
|
+
{
|
|
146
|
+
// overflow: 'visible',
|
|
147
|
+
marginBottom: 60 + xAxisLabelsVerticalShift,
|
|
148
|
+
width: item.stacks[0].barWidth || props.barWidth || 30,
|
|
149
|
+
height: totalHeight,
|
|
150
|
+
marginRight: spacing,
|
|
151
|
+
},
|
|
152
|
+
props.pointerConfig
|
|
153
|
+
? {
|
|
154
|
+
transform: [
|
|
155
|
+
{
|
|
156
|
+
translateY: (containerHeight || 200) -
|
|
157
|
+
(totalHeight - 10 + xAxisLabelsVerticalShift),
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
}
|
|
161
|
+
: null,
|
|
162
|
+
], children: [(props.showXAxisIndices || item.showXAxisIndex) && (_jsx(View, { style: {
|
|
163
|
+
zIndex: 2,
|
|
164
|
+
position: 'absolute',
|
|
165
|
+
height: props.xAxisIndicesHeight,
|
|
166
|
+
width: props.xAxisIndicesWidth,
|
|
167
|
+
bottom: props.xAxisIndicesHeight / -2,
|
|
168
|
+
left: ((item.barWidth || props.barWidth || 30) -
|
|
169
|
+
props.xAxisIndicesWidth) /
|
|
170
|
+
2,
|
|
171
|
+
backgroundColor: props.xAxisIndicesColor,
|
|
172
|
+
} })), barWrapper(), renderLabel(label || '', labelTextStyle)] }), renderTooltip && selectedIndex === index && (_jsx(Tooltip, __assign({}, tooltipProps)))] }));
|
|
173
|
+
};
|
|
174
|
+
export default RenderStackBars;
|
package/dist/BarChart/index.js
CHANGED
|
@@ -1 +1,236 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.BarChart=void 0;var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _RenderBars=_interopRequireDefault(require("./RenderBars"));var _RenderStackBars=_interopRequireDefault(require("./RenderStackBars"));var _BarAndLineChartsWrapper=_interopRequireDefault(require("../Components/BarAndLineChartsWrapper"));var _giftedChartsCore=require("gifted-charts-core");var _StripAndLabel=require("../Components/common/StripAndLabel");var _Pointer=require("../Components/common/Pointer");var _utils=require("../utils");var _jsxRuntime=require("react/jsx-runtime");var _this=this,_jsxFileName="/Users/abhinandankushwaha/sites/projects/react-native-gifted-charts/src/BarChart/index.tsx";function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap(),t=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r;})(e);}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&{}.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,t&&t.set(e,n),n;}var BarChart=exports.BarChart=function BarChart(props){var _props$scrollRef,_props$parentWidth;var heightValue=(0,_react.useMemo)(function(){return new _reactNative.Animated.Value(0);},[]);var opacValue=(0,_react.useMemo)(function(){return new _reactNative.Animated.Value(0);},[]);var widthValue=(0,_react.useMemo)(function(){return new _reactNative.Animated.Value(0);},[]);var scrollRef=(_props$scrollRef=props.scrollRef)!=null?_props$scrollRef:(0,_react.useRef)(null);var remainingScrollViewProps={onScroll:function onScroll(ev){return props.onScroll==null?void 0:props.onScroll(ev);},onTouchStart:function onTouchStart(evt){if(props.renderTooltip){setSelectedIndex(-1);}}};var _useBarChart=(0,_giftedChartsCore.useBarChart)(Object.assign({},props,{heightValue:heightValue,widthValue:widthValue,opacValue:opacValue,parentWidth:(_props$parentWidth=props.parentWidth)!=null?_props$parentWidth:_utils.screenWidth})),lineConfig=_useBarChart.lineConfig,hidePointer1=_useBarChart.hidePointer1,pointerItem=_useBarChart.pointerItem,pointerY=_useBarChart.pointerY,pointerConfig=_useBarChart.pointerConfig,pointerColor=_useBarChart.pointerColor,pointerX=_useBarChart.pointerX,pointerComponent=_useBarChart.pointerComponent,pointerHeight=_useBarChart.pointerHeight,pointerRadius=_useBarChart.pointerRadius,pointerWidth=_useBarChart.pointerWidth,autoAdjustPointerLabelPosition=_useBarChart.autoAdjustPointerLabelPosition,pointerLabelWidth=_useBarChart.pointerLabelWidth,activatePointersOnLongPress=_useBarChart.activatePointersOnLongPress,yAxisLabelWidth=_useBarChart.yAxisLabelWidth,shiftPointerLabelX=_useBarChart.shiftPointerLabelX,pointerLabelHeight=_useBarChart.pointerLabelHeight,pointerStripUptoDataPoint=_useBarChart.pointerStripUptoDataPoint,pointerStripHeight=_useBarChart.pointerStripHeight,shiftPointerLabelY=_useBarChart.shiftPointerLabelY,showPointerStrip=_useBarChart.showPointerStrip,pointerStripWidth=_useBarChart.pointerStripWidth,containerHeight=_useBarChart.containerHeight,xAxisThickness=_useBarChart.xAxisThickness,pointerStripColor=_useBarChart.pointerStripColor,pointerEvents=_useBarChart.pointerEvents,setResponderStartTime=_useBarChart.setResponderStartTime,setPointerY=_useBarChart.setPointerY,setPointerItem=_useBarChart.setPointerItem,initialSpacing=_useBarChart.initialSpacing,spacing=_useBarChart.spacing,data=_useBarChart.data,barWidth=_useBarChart.barWidth,setPointerX=_useBarChart.setPointerX,setPointerIndex=_useBarChart.setPointerIndex,maxValue=_useBarChart.maxValue,responderStartTime=_useBarChart.responderStartTime,setResponderActive=_useBarChart.setResponderActive,activatePointersDelay=_useBarChart.activatePointersDelay,persistPointer=_useBarChart.persistPointer,pointerVanishDelay=_useBarChart.pointerVanishDelay,containerHeightIncludingBelowXAxis=_useBarChart.containerHeightIncludingBelowXAxis,extendedContainerHeight=_useBarChart.extendedContainerHeight,totalWidth=_useBarChart.totalWidth,stripBehindBars=_useBarChart.stripBehindBars,noOfSectionsBelowXAxis=_useBarChart.noOfSectionsBelowXAxis,stepHeight=_useBarChart.stepHeight,xAxisLabelsVerticalShift=_useBarChart.xAxisLabelsVerticalShift,labelsExtraHeight=_useBarChart.labelsExtraHeight,stripOverPointer=_useBarChart.stripOverPointer,pointerLabelComponent=_useBarChart.pointerLabelComponent,setSelectedIndex=_useBarChart.setSelectedIndex,isAnimated=_useBarChart.isAnimated,animationDuration=_useBarChart.animationDuration,side=_useBarChart.side,labelWidth=_useBarChart.labelWidth,isThreeD=_useBarChart.isThreeD,animatedHeight=_useBarChart.animatedHeight,appearingOpacity=_useBarChart.appearingOpacity,autoShiftLabels=_useBarChart.autoShiftLabels,getPropsCommonForBarAndStack=_useBarChart.getPropsCommonForBarAndStack,barAndLineChartsWrapperProps=_useBarChart.barAndLineChartsWrapperProps,autoShiftLabelsForNegativeStacks=_useBarChart.autoShiftLabelsForNegativeStacks;var labelsAppear=(0,_react.useCallback)(function(){opacValue.setValue(0);_reactNative.Animated.timing(opacValue,{toValue:1,duration:500,easing:_reactNative.Easing.ease,useNativeDriver:false}).start();},[opacValue]);var decreaseWidth=(0,_react.useCallback)(function(){widthValue.setValue(0);_reactNative.Animated.timing(widthValue,{toValue:1,duration:lineConfig.animationDuration,easing:_reactNative.Easing.linear,useNativeDriver:false}).start();},[lineConfig.animationDuration,widthValue]);(0,_react.useEffect)(function(){if(lineConfig.isAnimated){setTimeout(function(){return decreaseWidth();},lineConfig.delay||0);}setTimeout(function(){return labelsAppear();},animationDuration);},[decreaseWidth,labelsAppear,animationDuration]);var renderPointer=function renderPointer(lineNumber){if(lineNumber===1&&hidePointer1)return;var pointerItemLocal=pointerItem;var pointerYLocal=pointerY;var pointerColorLocal=(pointerConfig==null?void 0:pointerConfig.pointer1Color)||pointerColor;return(0,_Pointer.Pointer)({pointerX:pointerX,pointerYLocal:pointerYLocal,pointerComponent:pointerComponent,pointerHeight:pointerHeight,pointerRadius:pointerRadius,pointerWidth:pointerWidth,pointerItemLocal:pointerItemLocal,pointerColorLocal:pointerColorLocal});};var renderStripAndLabel=function renderStripAndLabel(pointerLabelComponent){var pointerItemLocal,pointerYLocal=pointerY;pointerItemLocal=[pointerItem];return(0,_StripAndLabel.StripAndLabel)({autoAdjustPointerLabelPosition:autoAdjustPointerLabelPosition,pointerX:pointerX,pointerLabelWidth:pointerLabelWidth,activatePointersOnLongPress:activatePointersOnLongPress,yAxisLabelWidth:yAxisLabelWidth,pointerRadius:pointerRadius,pointerWidth:pointerWidth,shiftPointerLabelX:shiftPointerLabelX,pointerLabelHeight:pointerLabelHeight,pointerYLocal:pointerYLocal,pointerStripUptoDataPoint:pointerStripUptoDataPoint,pointerStripHeight:pointerStripHeight,shiftPointerLabelY:shiftPointerLabelY,pointerItemLocal:pointerItemLocal,showPointerStrip:showPointerStrip,pointerStripWidth:pointerStripWidth,containerHeight:containerHeight,xAxisThickness:xAxisThickness,pointerStripColor:pointerStripColor,pointerConfig:pointerConfig,pointerLabelComponent:pointerLabelComponent,scrollX:0,pointerEvents:pointerEvents,isBarChart:true});};var renderChartContent=function renderChartContent(){if(pointerConfig){return(0,_jsxRuntime.jsxs)(_reactNative.View,{onStartShouldSetResponder:function onStartShouldSetResponder(evt){return pointerConfig?true:false;},onMoveShouldSetResponder:function onMoveShouldSetResponder(evt){return pointerConfig?true:false;},onResponderGrant:function onResponderGrant(evt){var _props$stackData,_stackSum;if(!pointerConfig)return;setResponderStartTime(evt.timeStamp);if(activatePointersOnLongPress){return;}var x=evt.nativeEvent.locationX;if(!activatePointersOnLongPress&&x>(props.width||_utils.screenWidth))return;var factor=(x-initialSpacing-barWidth/2)/(spacing+barWidth);factor=Math.round(factor);factor=Math.min(factor,data.length-1);factor=Math.max(factor,0);var z=initialSpacing+(spacing+barWidth)*factor-(pointerRadius||pointerWidth/2)+barWidth/2;setPointerX(z);setPointerIndex(factor);var item,y;item=((_props$stackData=props.stackData)!=null?_props$stackData:data)[factor];var stackSum=0;if('stacks'in item){stackSum=item.stacks.reduce(function(acc,stack){var _stack$value;return acc+((_stack$value=stack.value)!=null?_stack$value:0);},0);}y=containerHeight-((_stackSum=stackSum)!=null?_stackSum:item.value)*containerHeight/maxValue-(pointerRadius||pointerHeight/2)+10;setPointerY(y);setPointerItem(item);},onResponderMove:function onResponderMove(evt){var _props$stackData2,_props$stackData3;if(!pointerConfig)return;if(activatePointersOnLongPress&&evt.timeStamp-responderStartTime<activatePointersDelay){return;}else{setResponderActive(true);}var x=evt.nativeEvent.locationX;if(!activatePointersOnLongPress&&x>(props.width||_utils.screenWidth))return;var factor=(x-initialSpacing-barWidth/2)/(spacing+barWidth);factor=Math.round(factor);factor=Math.min(factor,((_props$stackData2=props.stackData)!=null?_props$stackData2:data).length-1);factor=Math.max(factor,0);var z=initialSpacing+(spacing+barWidth)*factor-(pointerRadius||pointerWidth/2)+barWidth/2;var item,y;setPointerX(z);setPointerIndex(factor);item=((_props$stackData3=props.stackData)!=null?_props$stackData3:data)[factor];var stackSum=0;if('stacks'in item){var _item$stacks;(_item$stacks=item.stacks)==null?void 0:_item$stacks.reduce(function(acc,stack){var _stack$value2;return acc+((_stack$value2=stack.value)!=null?_stack$value2:0);},0);}y=containerHeight-(stackSum!=null?stackSum:item.value)*containerHeight/maxValue-(pointerRadius||pointerHeight/2)+10;setPointerY(y);setPointerItem(item);},onResponderEnd:function onResponderEnd(evt){setResponderStartTime(0);setPointerIndex(-1);setResponderActive(false);if(!persistPointer)setTimeout(function(){return setPointerX(0);},pointerVanishDelay);},onResponderTerminationRequest:function onResponderTerminationRequest(evt){return false;},style:{position:'absolute',height:containerHeightIncludingBelowXAxis,bottom:60,paddingLeft:initialSpacing,width:totalWidth,flexDirection:'row'},children:[pointerX>0&&stripBehindBars?(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:pointerEvents!=null?pointerEvents:'none',style:{position:'absolute',height:extendedContainerHeight+noOfSectionsBelowXAxis*stepHeight,bottom:xAxisLabelsVerticalShift+labelsExtraHeight,width:totalWidth},children:renderStripAndLabel(null)}):null,renderChart(),pointerX>0?(0,_jsxRuntime.jsxs)(_reactNative.View,{pointerEvents:pointerEvents!=null?pointerEvents:'none',style:{position:'absolute',height:extendedContainerHeight+noOfSectionsBelowXAxis*stepHeight,bottom:xAxisLabelsVerticalShift+labelsExtraHeight,width:totalWidth,zIndex:20},children:[!stripOverPointer&&!stripBehindBars&&renderStripAndLabel(null),renderPointer(1),stripOverPointer&&!stripBehindBars&&renderStripAndLabel(null),pointerLabelComponent&&renderStripAndLabel(pointerLabelComponent)]}):null]});}else{return renderChart();}};var renderChart=function renderChart(){if(props.stackData){return props.stackData.map(function(item,index){return(0,_jsxRuntime.jsx)(_RenderStackBars.default,Object.assign({stackData:props.stackData||[],isAnimated:isAnimated,animationDuration:animationDuration,stackBorderRadius:props.stackBorderRadius,stackBorderTopLeftRadius:props.stackBorderTopLeftRadius,stackBorderTopRightRadius:props.stackBorderTopRightRadius,stackBorderBottomLeftRadius:props.stackBorderBottomLeftRadius,stackBorderBottomRightRadius:props.stackBorderBottomRightRadius,autoShiftLabelsForNegativeStacks:autoShiftLabelsForNegativeStacks},getPropsCommonForBarAndStack(item,index)),index);});}else{return data.map(function(item,index){var _props$minHeight;return(0,_jsxRuntime.jsx)(_RenderBars.default,Object.assign({data:data,side:side,minHeight:(_props$minHeight=props.minHeight)!=null?_props$minHeight:isAnimated&&!isThreeD?0.1:0,sideWidth:props.sideWidth,labelWidth:labelWidth,isThreeD:isThreeD,isAnimated:isAnimated,animationDuration:animationDuration,animatedHeight:animatedHeight,appearingOpacity:appearingOpacity,roundedTop:props.roundedTop,roundedBottom:props.roundedBottom,frontColor:props.frontColor,sideColor:props.sideColor,topColor:props.topColor,cappedBars:props.cappedBars,capThickness:props.capThickness,capColor:props.capColor,capRadius:props.capRadius,autoShiftLabels:autoShiftLabels,barMarginBottom:props.barMarginBottom,barStyle:props.barStyle},getPropsCommonForBarAndStack(item,index)),index);});}};return(0,_jsxRuntime.jsx)(_BarAndLineChartsWrapper.default,Object.assign({},barAndLineChartsWrapperProps,{scrollRef:scrollRef,renderChartContent:renderChartContent,remainingScrollViewProps:remainingScrollViewProps,nestedScrollEnabled:props.nestedScrollEnabled}));};
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
14
|
+
import { Animated, Easing, View } from 'react-native';
|
|
15
|
+
import RenderBars from './RenderBars';
|
|
16
|
+
import RenderStackBars from './RenderStackBars';
|
|
17
|
+
import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
|
|
18
|
+
import { useBarChart } from 'gifted-charts-core';
|
|
19
|
+
import { StripAndLabel } from '../Components/common/StripAndLabel';
|
|
20
|
+
import { Pointer } from '../Components/common/Pointer';
|
|
21
|
+
import { screenWidth } from '../utils';
|
|
22
|
+
export var BarChart = function (props) {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
var heightValue = useMemo(function () { return new Animated.Value(0); }, []);
|
|
25
|
+
var opacityValue = useMemo(function () { return new Animated.Value(0); }, []);
|
|
26
|
+
var widthValue = useMemo(function () { return new Animated.Value(0); }, []);
|
|
27
|
+
var scrollRef = (_a = props.scrollRef) !== null && _a !== void 0 ? _a : useRef(null);
|
|
28
|
+
var remainingScrollViewProps = {
|
|
29
|
+
onScroll: function (ev) { var _a; return (_a = props.onScroll) === null || _a === void 0 ? void 0 : _a.call(props, ev); },
|
|
30
|
+
onTouchStart: function (evt) {
|
|
31
|
+
if (props.renderTooltip) {
|
|
32
|
+
setSelectedIndex(-1);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
var _c = useBarChart(__assign(__assign({}, props), { heightValue: heightValue, widthValue: widthValue, opacityValue: opacityValue, parentWidth: (_b = props.parentWidth) !== null && _b !== void 0 ? _b : screenWidth })), lineConfig = _c.lineConfig, hidePointer1 = _c.hidePointer1, pointerItem = _c.pointerItem, pointerY = _c.pointerY, pointerConfig = _c.pointerConfig, pointerColor = _c.pointerColor, pointerX = _c.pointerX, pointerComponent = _c.pointerComponent, pointerHeight = _c.pointerHeight, pointerRadius = _c.pointerRadius, pointerWidth = _c.pointerWidth, autoAdjustPointerLabelPosition = _c.autoAdjustPointerLabelPosition, pointerLabelWidth = _c.pointerLabelWidth, activatePointersOnLongPress = _c.activatePointersOnLongPress, yAxisLabelWidth = _c.yAxisLabelWidth, shiftPointerLabelX = _c.shiftPointerLabelX, pointerLabelHeight = _c.pointerLabelHeight, pointerStripUptoDataPoint = _c.pointerStripUptoDataPoint, pointerStripHeight = _c.pointerStripHeight, shiftPointerLabelY = _c.shiftPointerLabelY, showPointerStrip = _c.showPointerStrip, pointerStripWidth = _c.pointerStripWidth, containerHeight = _c.containerHeight, xAxisThickness = _c.xAxisThickness, pointerStripColor = _c.pointerStripColor, pointerEvents = _c.pointerEvents, setResponderStartTime = _c.setResponderStartTime, setPointerY = _c.setPointerY, setPointerItem = _c.setPointerItem, initialSpacing = _c.initialSpacing, spacing = _c.spacing, data = _c.data, barWidth = _c.barWidth, setPointerX = _c.setPointerX, pointerIndex = _c.pointerIndex, setPointerIndex = _c.setPointerIndex, maxValue = _c.maxValue, responderStartTime = _c.responderStartTime, setResponderActive = _c.setResponderActive, activatePointersDelay = _c.activatePointersDelay, persistPointer = _c.persistPointer, pointerVanishDelay = _c.pointerVanishDelay, containerHeightIncludingBelowXAxis = _c.containerHeightIncludingBelowXAxis, extendedContainerHeight = _c.extendedContainerHeight, totalWidth = _c.totalWidth, stripBehindBars = _c.stripBehindBars, noOfSectionsBelowXAxis = _c.noOfSectionsBelowXAxis, stepHeight = _c.stepHeight, xAxisLabelsVerticalShift = _c.xAxisLabelsVerticalShift, labelsExtraHeight = _c.labelsExtraHeight, stripOverPointer = _c.stripOverPointer, pointerLabelComponent = _c.pointerLabelComponent, setSelectedIndex = _c.setSelectedIndex, isAnimated = _c.isAnimated, animationDuration = _c.animationDuration, side = _c.side, labelWidth = _c.labelWidth, isThreeD = _c.isThreeD, animatedHeight = _c.animatedHeight, appearingOpacity = _c.appearingOpacity, autoShiftLabels = _c.autoShiftLabels, getPropsCommonForBarAndStack = _c.getPropsCommonForBarAndStack, barAndLineChartsWrapperProps = _c.barAndLineChartsWrapperProps, autoShiftLabelsForNegativeStacks = _c.autoShiftLabelsForNegativeStacks;
|
|
37
|
+
var labelsAppear = useCallback(function () {
|
|
38
|
+
opacityValue.setValue(0);
|
|
39
|
+
Animated.timing(opacityValue, {
|
|
40
|
+
toValue: 1,
|
|
41
|
+
duration: 500,
|
|
42
|
+
easing: Easing.ease,
|
|
43
|
+
useNativeDriver: false,
|
|
44
|
+
}).start();
|
|
45
|
+
}, [opacityValue]);
|
|
46
|
+
var decreaseWidth = useCallback(function () {
|
|
47
|
+
widthValue.setValue(0);
|
|
48
|
+
Animated.timing(widthValue, {
|
|
49
|
+
toValue: 1,
|
|
50
|
+
duration: lineConfig.animationDuration,
|
|
51
|
+
easing: Easing.linear,
|
|
52
|
+
useNativeDriver: false,
|
|
53
|
+
}).start();
|
|
54
|
+
}, [lineConfig.animationDuration, widthValue]);
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
if (lineConfig.isAnimated) {
|
|
57
|
+
setTimeout(function () { return decreaseWidth(); }, lineConfig.delay || 0);
|
|
58
|
+
}
|
|
59
|
+
setTimeout(function () { return labelsAppear(); }, animationDuration);
|
|
60
|
+
}, [decreaseWidth, labelsAppear, animationDuration]);
|
|
61
|
+
var renderPointer = function (lineNumber) {
|
|
62
|
+
if (lineNumber === 1 && hidePointer1)
|
|
63
|
+
return;
|
|
64
|
+
var pointerItemLocal = pointerItem;
|
|
65
|
+
var pointerYLocal = pointerY;
|
|
66
|
+
var pointerColorLocal = (pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.pointer1Color) || pointerColor;
|
|
67
|
+
return Pointer({
|
|
68
|
+
pointerX: pointerX,
|
|
69
|
+
pointerYLocal: pointerYLocal,
|
|
70
|
+
pointerComponent: pointerComponent,
|
|
71
|
+
pointerHeight: pointerHeight,
|
|
72
|
+
pointerRadius: pointerRadius,
|
|
73
|
+
pointerWidth: pointerWidth,
|
|
74
|
+
pointerItemLocal: pointerItemLocal,
|
|
75
|
+
pointerColorLocal: pointerColorLocal,
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
var renderStripAndLabel = function (pointerLabelComponent) {
|
|
79
|
+
var pointerItemLocal, pointerYLocal = pointerY;
|
|
80
|
+
pointerItemLocal = [pointerItem];
|
|
81
|
+
return StripAndLabel({
|
|
82
|
+
autoAdjustPointerLabelPosition: autoAdjustPointerLabelPosition,
|
|
83
|
+
pointerX: pointerX,
|
|
84
|
+
pointerLabelWidth: pointerLabelWidth,
|
|
85
|
+
activatePointersOnLongPress: activatePointersOnLongPress,
|
|
86
|
+
yAxisLabelWidth: yAxisLabelWidth,
|
|
87
|
+
pointerRadius: pointerRadius,
|
|
88
|
+
pointerWidth: pointerWidth,
|
|
89
|
+
shiftPointerLabelX: shiftPointerLabelX,
|
|
90
|
+
pointerLabelHeight: pointerLabelHeight,
|
|
91
|
+
pointerYLocal: pointerYLocal,
|
|
92
|
+
pointerStripUptoDataPoint: pointerStripUptoDataPoint,
|
|
93
|
+
pointerStripHeight: pointerStripHeight,
|
|
94
|
+
shiftPointerLabelY: shiftPointerLabelY,
|
|
95
|
+
pointerItemLocal: pointerItemLocal,
|
|
96
|
+
showPointerStrip: showPointerStrip,
|
|
97
|
+
pointerStripWidth: pointerStripWidth,
|
|
98
|
+
containerHeight: containerHeight,
|
|
99
|
+
xAxisThickness: xAxisThickness,
|
|
100
|
+
pointerStripColor: pointerStripColor,
|
|
101
|
+
pointerConfig: pointerConfig,
|
|
102
|
+
pointerLabelComponent: pointerLabelComponent,
|
|
103
|
+
scrollX: 0,
|
|
104
|
+
pointerEvents: pointerEvents,
|
|
105
|
+
isBarChart: true,
|
|
106
|
+
pointerIndex: pointerIndex,
|
|
107
|
+
width: totalWidth,
|
|
108
|
+
screenWidth: screenWidth,
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
var renderChartContent = function () {
|
|
112
|
+
if (pointerConfig) {
|
|
113
|
+
return (_jsxs(View, { onStartShouldSetResponder: function () { return !!pointerConfig; }, onMoveShouldSetResponder: function () { return !!pointerConfig; }, onResponderGrant: function (evt) {
|
|
114
|
+
var _a;
|
|
115
|
+
if (!pointerConfig)
|
|
116
|
+
return;
|
|
117
|
+
setResponderStartTime(evt.timeStamp);
|
|
118
|
+
if (activatePointersOnLongPress) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
var x = evt.nativeEvent.locationX;
|
|
122
|
+
if (!activatePointersOnLongPress &&
|
|
123
|
+
x > (props.width || screenWidth))
|
|
124
|
+
return;
|
|
125
|
+
var factor = (x - initialSpacing - barWidth / 2) / (spacing + barWidth);
|
|
126
|
+
factor = Math.round(factor);
|
|
127
|
+
factor = Math.min(factor, data.length - 1);
|
|
128
|
+
factor = Math.max(factor, 0);
|
|
129
|
+
var z = initialSpacing +
|
|
130
|
+
(spacing + barWidth) * factor -
|
|
131
|
+
(pointerRadius || pointerWidth / 2) +
|
|
132
|
+
barWidth / 2;
|
|
133
|
+
setPointerX(z);
|
|
134
|
+
setPointerIndex(factor);
|
|
135
|
+
var item, y;
|
|
136
|
+
item = ((_a = props.stackData) !== null && _a !== void 0 ? _a : data)[factor];
|
|
137
|
+
var stackSum = 0;
|
|
138
|
+
if ('stacks' in item) {
|
|
139
|
+
stackSum = item.stacks.reduce(function (acc, stack) { var _a; return acc + ((_a = stack.value) !== null && _a !== void 0 ? _a : 0); }, 0);
|
|
140
|
+
}
|
|
141
|
+
y =
|
|
142
|
+
containerHeight -
|
|
143
|
+
((stackSum !== null && stackSum !== void 0 ? stackSum : item.value) * containerHeight) / maxValue -
|
|
144
|
+
(pointerRadius || pointerHeight / 2) +
|
|
145
|
+
10;
|
|
146
|
+
setPointerY(y);
|
|
147
|
+
setPointerItem(item);
|
|
148
|
+
}, onResponderMove: function (evt) {
|
|
149
|
+
var _a, _b, _c;
|
|
150
|
+
if (!pointerConfig)
|
|
151
|
+
return;
|
|
152
|
+
if (activatePointersOnLongPress &&
|
|
153
|
+
evt.timeStamp - responderStartTime < activatePointersDelay) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
setResponderActive(true);
|
|
158
|
+
}
|
|
159
|
+
var x = evt.nativeEvent.locationX;
|
|
160
|
+
if (!activatePointersOnLongPress &&
|
|
161
|
+
x > (props.width || screenWidth))
|
|
162
|
+
return;
|
|
163
|
+
var factor = (x - initialSpacing - barWidth / 2) / (spacing + barWidth);
|
|
164
|
+
factor = Math.round(factor);
|
|
165
|
+
factor = Math.min(factor, ((_a = props.stackData) !== null && _a !== void 0 ? _a : data).length - 1);
|
|
166
|
+
factor = Math.max(factor, 0);
|
|
167
|
+
var z = initialSpacing +
|
|
168
|
+
(spacing + barWidth) * factor -
|
|
169
|
+
(pointerRadius || pointerWidth / 2) +
|
|
170
|
+
barWidth / 2;
|
|
171
|
+
var item, y;
|
|
172
|
+
setPointerX(z);
|
|
173
|
+
setPointerIndex(factor);
|
|
174
|
+
item = ((_b = props.stackData) !== null && _b !== void 0 ? _b : data)[factor];
|
|
175
|
+
var stackSum = 0;
|
|
176
|
+
if ('stacks' in item) {
|
|
177
|
+
(_c = item.stacks) === null || _c === void 0 ? void 0 : _c.reduce(function (acc, stack) { var _a; return acc + ((_a = stack.value) !== null && _a !== void 0 ? _a : 0); }, 0);
|
|
178
|
+
}
|
|
179
|
+
y =
|
|
180
|
+
containerHeight -
|
|
181
|
+
((stackSum !== null && stackSum !== void 0 ? stackSum : item.value) * containerHeight) / maxValue -
|
|
182
|
+
(pointerRadius || pointerHeight / 2) +
|
|
183
|
+
10;
|
|
184
|
+
setPointerY(y);
|
|
185
|
+
setPointerItem(item);
|
|
186
|
+
}, onResponderEnd: function (evt) {
|
|
187
|
+
setResponderStartTime(0);
|
|
188
|
+
setPointerIndex(-1);
|
|
189
|
+
setResponderActive(false);
|
|
190
|
+
if (!persistPointer)
|
|
191
|
+
setTimeout(function () { return setPointerX(0); }, pointerVanishDelay);
|
|
192
|
+
}, onResponderTerminationRequest: function (evt) { return false; }, style: {
|
|
193
|
+
position: 'absolute',
|
|
194
|
+
height: containerHeightIncludingBelowXAxis,
|
|
195
|
+
bottom: 60,
|
|
196
|
+
paddingLeft: initialSpacing,
|
|
197
|
+
width: totalWidth,
|
|
198
|
+
flexDirection: 'row',
|
|
199
|
+
}, children: [pointerX > 0 && stripBehindBars ? (_jsx(View, { pointerEvents: pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : 'none', style: {
|
|
200
|
+
position: 'absolute',
|
|
201
|
+
height: extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight,
|
|
202
|
+
bottom: xAxisLabelsVerticalShift + labelsExtraHeight,
|
|
203
|
+
width: totalWidth,
|
|
204
|
+
}, children: renderStripAndLabel(null) })) : null, renderChart(), pointerX > 0 ? (_jsxs(View, { pointerEvents: pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : 'none', style: {
|
|
205
|
+
position: 'absolute',
|
|
206
|
+
height: extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight,
|
|
207
|
+
bottom: xAxisLabelsVerticalShift + labelsExtraHeight,
|
|
208
|
+
width: totalWidth,
|
|
209
|
+
zIndex: 20,
|
|
210
|
+
}, children: [!stripOverPointer &&
|
|
211
|
+
!stripBehindBars &&
|
|
212
|
+
renderStripAndLabel(null), renderPointer(1), stripOverPointer &&
|
|
213
|
+
!stripBehindBars &&
|
|
214
|
+
renderStripAndLabel(null), pointerLabelComponent &&
|
|
215
|
+
renderStripAndLabel(pointerLabelComponent) // no matter what, pointerLabelComponent will be rendered at last -> over the chart content
|
|
216
|
+
] })) : null] }));
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
return renderChart();
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
var renderChart = function () {
|
|
223
|
+
if (props.stackData) {
|
|
224
|
+
return props.stackData.map(function (item, index) {
|
|
225
|
+
return (_jsx(RenderStackBars, __assign({ stackData: props.stackData || [], isAnimated: isAnimated, animationDuration: animationDuration, stackBorderRadius: props.stackBorderRadius, stackBorderTopLeftRadius: props.stackBorderTopLeftRadius, stackBorderTopRightRadius: props.stackBorderTopRightRadius, stackBorderBottomLeftRadius: props.stackBorderBottomLeftRadius, stackBorderBottomRightRadius: props.stackBorderBottomRightRadius, autoShiftLabelsForNegativeStacks: autoShiftLabelsForNegativeStacks }, getPropsCommonForBarAndStack(item, index)), index));
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
return data.map(function (item, index) {
|
|
230
|
+
var _a;
|
|
231
|
+
return (_jsx(RenderBars, __assign({ data: data, side: side, minHeight: (_a = props.minHeight) !== null && _a !== void 0 ? _a : (isAnimated && !isThreeD ? 0.1 : 0), sideWidth: props.sideWidth, labelWidth: labelWidth, isThreeD: isThreeD, isAnimated: isAnimated, animationDuration: animationDuration, animatedHeight: animatedHeight, appearingOpacity: appearingOpacity, roundedTop: props.roundedTop, roundedBottom: props.roundedBottom, frontColor: props.frontColor, sideColor: props.sideColor, topColor: props.topColor, cappedBars: props.cappedBars, capThickness: props.capThickness, capColor: props.capColor, capRadius: props.capRadius, autoShiftLabels: autoShiftLabels, barMarginBottom: props.barMarginBottom, barStyle: props.barStyle }, getPropsCommonForBarAndStack(item, index)), index));
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
return (_jsx(BarAndLineChartsWrapper, __assign({}, barAndLineChartsWrapperProps, { scrollRef: scrollRef, renderChartContent: renderChartContent, remainingScrollViewProps: remainingScrollViewProps, nestedScrollEnabled: props.nestedScrollEnabled })));
|
|
236
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare const styles: {
|
|
2
|
+
container: {
|
|
3
|
+
width: "100%";
|
|
4
|
+
marginBottom: number;
|
|
5
|
+
marginRight: number;
|
|
6
|
+
};
|
|
7
|
+
horizBar: {
|
|
8
|
+
flexDirection: "row";
|
|
9
|
+
};
|
|
10
|
+
leftLabel: {
|
|
11
|
+
justifyContent: "center";
|
|
12
|
+
alignItems: "center";
|
|
13
|
+
};
|
|
14
|
+
lastLeftLabel: {
|
|
15
|
+
justifyContent: "center";
|
|
16
|
+
alignItems: "center";
|
|
17
|
+
};
|
|
18
|
+
leftPart: {
|
|
19
|
+
justifyContent: "center";
|
|
20
|
+
width: "100%";
|
|
21
|
+
};
|
|
22
|
+
lastLeftPart: {
|
|
23
|
+
justifyContent: "flex-end";
|
|
24
|
+
width: "100%";
|
|
25
|
+
};
|
|
26
|
+
line: {
|
|
27
|
+
width: "100%";
|
|
28
|
+
height: number;
|
|
29
|
+
backgroundColor: string;
|
|
30
|
+
opacity: number;
|
|
31
|
+
};
|
|
32
|
+
lastLine: {
|
|
33
|
+
width: "100%";
|
|
34
|
+
height: number;
|
|
35
|
+
backgroundColor: string;
|
|
36
|
+
};
|
|
37
|
+
bottomLabel: {
|
|
38
|
+
width: "100%";
|
|
39
|
+
};
|
|
40
|
+
customDataPointContainer: {
|
|
41
|
+
position: "absolute";
|
|
42
|
+
justifyContent: "center";
|
|
43
|
+
alignItems: "center";
|
|
44
|
+
};
|
|
45
|
+
};
|
package/dist/BarChart/styles.js
CHANGED
|
@@ -1 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
export var styles = StyleSheet.create({
|
|
3
|
+
container: {
|
|
4
|
+
width: '100%',
|
|
5
|
+
marginBottom: 40,
|
|
6
|
+
marginRight: 40,
|
|
7
|
+
},
|
|
8
|
+
horizBar: {
|
|
9
|
+
flexDirection: 'row',
|
|
10
|
+
},
|
|
11
|
+
leftLabel: {
|
|
12
|
+
justifyContent: 'center',
|
|
13
|
+
alignItems: 'center',
|
|
14
|
+
},
|
|
15
|
+
lastLeftLabel: {
|
|
16
|
+
justifyContent: 'center',
|
|
17
|
+
alignItems: 'center',
|
|
18
|
+
},
|
|
19
|
+
leftPart: {
|
|
20
|
+
justifyContent: 'center',
|
|
21
|
+
width: '100%',
|
|
22
|
+
},
|
|
23
|
+
lastLeftPart: {
|
|
24
|
+
justifyContent: 'flex-end',
|
|
25
|
+
width: '100%',
|
|
26
|
+
},
|
|
27
|
+
line: {
|
|
28
|
+
width: '100%',
|
|
29
|
+
height: 1,
|
|
30
|
+
backgroundColor: 'gray',
|
|
31
|
+
opacity: 0.5,
|
|
32
|
+
},
|
|
33
|
+
lastLine: {
|
|
34
|
+
width: '100%',
|
|
35
|
+
height: 1,
|
|
36
|
+
backgroundColor: 'black',
|
|
37
|
+
},
|
|
38
|
+
bottomLabel: {
|
|
39
|
+
width: '100%',
|
|
40
|
+
},
|
|
41
|
+
customDataPointContainer: {
|
|
42
|
+
position: 'absolute',
|
|
43
|
+
justifyContent: 'center',
|
|
44
|
+
alignItems: 'center',
|
|
45
|
+
},
|
|
46
|
+
});
|