Added onPress as a prop to Bar Chart and passed item and index as parameters
This commit is contained in:
parent
493c0cf8bf
commit
33818b9783
|
@ -9,6 +9,7 @@
|
|||
| data | Array of items | An item object represents a bar in the bar chart. It is described in the next table. | \_ |
|
||||
| width | number | Width of the Bar chart | width of the parent |
|
||||
| height | number | Height of the Bar chart (excluding the bottom label) | 200 |
|
||||
| onPress | Function | Callback function called on press of a Bar (takes item and index as parameter) | null |
|
||||
| maxValue | number | Maximum value shown in the Y axis | 200 |
|
||||
| minValue | number | Minimum negative value shown in the Y axis (to be used only if the data set has negative values too) | \_ |
|
||||
| noOfSections | number | Number of sections in the Y axis | 10 |
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "react-native-gifted-charts",
|
||||
"version": "1.2.6",
|
||||
"version": "1.2.7",
|
||||
"description": "The most complete library for Bar, Line, Area, Pie, Donut and Stacked Bar charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
||||
"main": "src/index.tsx",
|
||||
"files": [
|
||||
|
|
|
@ -63,6 +63,7 @@ type Props = {
|
|||
barBackgroundPattern?: Function;
|
||||
patternId?: String;
|
||||
barMarginBottom?: number;
|
||||
onPress?: Function;
|
||||
};
|
||||
type itemType = {
|
||||
value?: number;
|
||||
|
@ -319,7 +320,13 @@ const RenderBars = (props: Props) => {
|
|||
<TouchableOpacity
|
||||
disabled={item.disablePress || props.disablePress}
|
||||
activeOpacity={props.activeOpacity || 0.2}
|
||||
onPress={item.onPress}
|
||||
onPress={() => {
|
||||
item.onPress
|
||||
? item.onPress()
|
||||
: props.onPress
|
||||
? props.onPress(item, index)
|
||||
: null;
|
||||
}}
|
||||
style={[
|
||||
{
|
||||
// overflow: 'visible',
|
||||
|
|
|
@ -130,6 +130,7 @@ type PropTypes = {
|
|||
barBackgroundPattern?: Function;
|
||||
patternId?: String;
|
||||
barMarginBottom?: number;
|
||||
onPress?: Function;
|
||||
};
|
||||
type lineConfigType = {
|
||||
initialSpacing?: number;
|
||||
|
@ -1458,6 +1459,7 @@ export const BarChart = (props: PropTypes) => {
|
|||
labelTextStyle={
|
||||
item.labelTextStyle || props.xAxisLabelTextStyle
|
||||
}
|
||||
onPress={props.onPress}
|
||||
/>
|
||||
))}
|
||||
</Fragment>
|
||||
|
|
|
@ -230,7 +230,7 @@ export const PieChart = (props: propTypes) => {
|
|||
})}
|
||||
</Defs>
|
||||
{data.map((item, index) => {
|
||||
console.log('index', index);
|
||||
// console.log('index', index);
|
||||
let nextItem;
|
||||
if (index === pData.length - 1) nextItem = pData[0];
|
||||
else nextItem = pData[index + 1];
|
||||
|
|
Loading…
Reference in New Issue