Added barStyle to Bar and Stacked bar charts

This commit is contained in:
Abhinandan-Kushwaha 2022-07-01 22:18:43 +05:30
parent afd46531eb
commit 3b3ea63f0f
7 changed files with 65 additions and 28 deletions

View File

@ -93,6 +93,7 @@ The properties of this line chart can be controlled using the `lineConfig` prop
| sideColor | ColorValue | Color of the side view of the bar, only for 3 D | | sideColor | ColorValue | Color of the side view of the bar, only for 3 D |
| sideWidth | number | Width of the side view of the bar, only for 3 D | | sideWidth | number | Width of the side view of the bar, only for 3 D |
| topColor | ColorValue | Color of the top view of the bar, only for 3 D | | topColor | ColorValue | Color of the top view of the bar, only for 3 D |
| barStyle | object | style object for the Bars |
| showGradient | Boolean | Prop to enable linear gradient for the bar color, defaults to false | | showGradient | Boolean | Prop to enable linear gradient for the bar color, defaults to false |
| gradientColor | ColorValue | Along with frontColor, this prop constitutes the 2 colors for gradient | | gradientColor | ColorValue | Along with frontColor, this prop constitutes the 2 colors for gradient |
| label | string | Label text appearing below the bar (under the X axis) | | label | string | Label text appearing below the bar (under the X axis) |
@ -110,7 +111,7 @@ The properties of this line chart can be controlled using the `lineConfig` prop
| spacing | number | Distance of the next Bar from the currennt Bar | | spacing | number | Distance of the next Bar from the currennt Bar |
| barBackgroundPattern | Component | A svg component containing the background pattern for bars | | barBackgroundPattern | Component | A svg component containing the background pattern for bars |
| patternId | String | ID of the pattern component | | patternId | String | ID of the pattern component |
| leftShiftForTooltip | number | The distance by which the tooltip component should shift towards left | | leftShiftForTooltip | number | The distance by which the tooltip component should shift towards left |
--- ---
@ -200,6 +201,7 @@ type referenceConfigType = {
| Prop | Type | Description | Default value | | Prop | Type | Description | Default value |
| --------------- | ---------- | -------------------------------------------------------------------------- | ------------------------ | | --------------- | ---------- | -------------------------------------------------------------------------- | ------------------------ |
| barWidth | number | Width of the bar | 30 | | barWidth | number | Width of the bar | 30 |
| barStyle | object | style object for the Bars | \_ |
| isThreeD | Boolean | Prop to render 3 dimensional bars | false | | isThreeD | Boolean | Prop to render 3 dimensional bars | false |
| frontColor | ColorValue | Color of the bar | black for 2D, red for 3D | | frontColor | ColorValue | Color of the bar | black for 2D, red for 3D |
| sideColor | ColorValue | Color of the side view of the bar, only for 3 D | red | | sideColor | ColorValue | Color of the side view of the bar, only for 3 D | red |

View File

@ -1,6 +1,6 @@
{ {
"name": "react-native-gifted-charts", "name": "react-native-gifted-charts",
"version": "1.2.38", "version": "1.2.39",
"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.", "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", "main": "src/index.tsx",
"files": [ "files": [

View File

@ -39,6 +39,7 @@ type propTypes = {
barBackgroundPattern?: Function; barBackgroundPattern?: Function;
patternId?: String; patternId?: String;
barMarginBottom?: number; barMarginBottom?: number;
barStyle?: object;
}; };
type itemType = { type itemType = {
value?: number; value?: number;
@ -61,6 +62,7 @@ type itemType = {
barBackgroundPattern?: Function; barBackgroundPattern?: Function;
patternId?: String; patternId?: String;
barMarginBottom?: number; barMarginBottom?: number;
barStyle?: object;
}; };
const Animated2DWithGradient = (props: propTypes) => { const Animated2DWithGradient = (props: propTypes) => {
@ -68,6 +70,7 @@ const Animated2DWithGradient = (props: propTypes) => {
barBackgroundPattern, barBackgroundPattern,
patternId, patternId,
barWidth, barWidth,
barStyle,
item, item,
opacity, opacity,
animationDuration, animationDuration,
@ -128,17 +131,20 @@ const Animated2DWithGradient = (props: propTypes) => {
: height) - (barMarginBottom || 0), : height) - (barMarginBottom || 0),
}}> }}>
<View <View
style={{ style={[
width: '100%', {
height: width: '100%',
(noAnimation height:
? Math.max( (noAnimation
props.minHeight, ? Math.max(
(Math.abs(item.value) * (containerHeight || 200)) / props.minHeight,
(maxValue || 200), (Math.abs(item.value) * (containerHeight || 200)) /
) (maxValue || 200),
: height) - (barMarginBottom || 0), )
}}> : height) - (barMarginBottom || 0),
},
item.barStyle || barStyle,
]}>
{noGradient ? ( {noGradient ? (
<View <View
style={[ style={[

View File

@ -69,6 +69,7 @@ type Props = {
initialSpacing: number; initialSpacing: number;
selectedIndex: number; selectedIndex: number;
setSelectedIndex: Function; setSelectedIndex: Function;
barStyle?: object;
}; };
type itemType = { type itemType = {
value?: number; value?: number;
@ -97,6 +98,7 @@ type itemType = {
patternId?: String; patternId?: String;
barMarginBottom?: number; barMarginBottom?: number;
leftShiftForTooltip?: number; leftShiftForTooltip?: number;
barStyle?: object;
}; };
const RenderBars = (props: Props) => { const RenderBars = (props: Props) => {
const { const {
@ -109,6 +111,7 @@ const RenderBars = (props: Props) => {
propSpacing, propSpacing,
side, side,
data, data,
barStyle,
// oldValue, // oldValue,
isThreeD, isThreeD,
@ -419,6 +422,8 @@ const RenderBars = (props: Props) => {
patternId={item.patternId || props.patternId} patternId={item.patternId || props.patternId}
topLabelContainerStyle={item.topLabelContainerStyle} topLabelContainerStyle={item.topLabelContainerStyle}
width={item.barWidth || props.barWidth || 30} width={item.barWidth || props.barWidth || 30}
barStyle={barStyle}
item={item}
sideWidth={ sideWidth={
item.sideWidth || item.sideWidth ||
props.sideWidth || props.sideWidth ||
@ -457,6 +462,8 @@ const RenderBars = (props: Props) => {
props.sideWidth || props.sideWidth ||
(item.barWidth || props.barWidth || 30) / 2 (item.barWidth || props.barWidth || 30) / 2
} }
barStyle={barStyle}
item={item}
side={side || 'left'} side={side || 'left'}
frontColor={item.frontColor || props.frontColor || ''} frontColor={item.frontColor || props.frontColor || ''}
sideColor={item.sideColor || props.sideColor || ''} sideColor={item.sideColor || props.sideColor || ''}
@ -482,6 +489,7 @@ const RenderBars = (props: Props) => {
barBackgroundPattern={props.barBackgroundPattern} barBackgroundPattern={props.barBackgroundPattern}
patternId={props.patternId} patternId={props.patternId}
barWidth={props.barWidth} barWidth={props.barWidth}
barStyle={barStyle}
item={item} item={item}
opacity={opacity} opacity={opacity}
animationDuration={animationDuration || 800} animationDuration={animationDuration || 800}
@ -514,6 +522,7 @@ const RenderBars = (props: Props) => {
barBackgroundPattern={props.barBackgroundPattern} barBackgroundPattern={props.barBackgroundPattern}
patternId={props.patternId} patternId={props.patternId}
barWidth={props.barWidth} barWidth={props.barWidth}
barStyle={barStyle}
item={item} item={item}
opacity={opacity} opacity={opacity}
animationDuration={animationDuration || 800} animationDuration={animationDuration || 800}
@ -544,6 +553,7 @@ const RenderBars = (props: Props) => {
barBackgroundPattern={props.barBackgroundPattern} barBackgroundPattern={props.barBackgroundPattern}
patternId={props.patternId} patternId={props.patternId}
barWidth={props.barWidth} barWidth={props.barWidth}
barStyle={barStyle}
item={item} item={item}
opacity={opacity} opacity={opacity}
animationDuration={animationDuration || 800} animationDuration={animationDuration || 800}

View File

@ -146,6 +146,7 @@ type PropTypes = {
renderTooltip?: Function; renderTooltip?: Function;
leftShiftForTooltip?: number; leftShiftForTooltip?: number;
leftShiftForLastIndexTooltip?: number; leftShiftForLastIndexTooltip?: number;
barStyle?: object;
}; };
type lineConfigType = { type lineConfigType = {
initialSpacing?: number; initialSpacing?: number;
@ -200,6 +201,7 @@ type itemType = {
spacing?: number; spacing?: number;
barBackgroundPattern?: Function; barBackgroundPattern?: Function;
patternId?: String; patternId?: String;
barStyle?: object;
}; };
export const BarChart = (props: PropTypes) => { export const BarChart = (props: PropTypes) => {
@ -1619,6 +1621,7 @@ export const BarChart = (props: PropTypes) => {
initialSpacing={initialSpacing} initialSpacing={initialSpacing}
selectedIndex={selectedIndex} selectedIndex={selectedIndex}
setSelectedIndex={setSelectedIndex} setSelectedIndex={setSelectedIndex}
barStyle={props.barStyle}
/> />
))} ))}
</Fragment> </Fragment>

View File

@ -40,6 +40,8 @@ type animatedBarPropTypes = {
intactTopLabel: Boolean; intactTopLabel: Boolean;
barBackgroundPattern?: Function; barBackgroundPattern?: Function;
patternId?: String; patternId?: String;
barStyle?: object;
item: any;
}; };
const TriangleCorner = (props: trianglePropTypes) => { const TriangleCorner = (props: trianglePropTypes) => {
@ -105,8 +107,7 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
setTimeout(() => elevate(), Platform.OS == 'ios' ? 10 : 100); setTimeout(() => elevate(), Platform.OS == 'ios' ? 10 : 100);
}; };
const width = props.width; const {item, width, sideWidth, barStyle} = props;
const sideWidth = props.sideWidth;
const {barBackgroundPattern, patternId} = props; const {barBackgroundPattern, patternId} = props;
@ -193,7 +194,7 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
) : null} ) : null}
<View <View
style={{ style={[{
width: width, width: width,
height: height, //animatedHeight height: height, //animatedHeight
backgroundColor: frontColor, backgroundColor: frontColor,
@ -201,7 +202,9 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
borderTopWidth: StyleSheet.hairlineWidth, borderTopWidth: StyleSheet.hairlineWidth,
borderColor: 'white', borderColor: 'white',
opacity: opacity, opacity: opacity,
}}> },
item.barStyle || barStyle
]}>
{showGradient && ( {showGradient && (
<LinearGradient <LinearGradient
style={{position: 'absolute', width: '100%', height: '100%'}} style={{position: 'absolute', width: '100%', height: '100%'}}

View File

@ -24,6 +24,8 @@ type PropTypes = {
value: number; value: number;
barBackgroundPattern?: Function; barBackgroundPattern?: Function;
patternId?: String; patternId?: String;
barStyle?: object;
item?: any;
}; };
type TriangleProps = { type TriangleProps = {
@ -60,8 +62,16 @@ const aStyles = StyleSheet.create({
}); });
const ThreeDBar = (props: PropTypes) => { const ThreeDBar = (props: PropTypes) => {
const {width, sideWidth, height, value, barBackgroundPattern, patternId} = const {
props; width,
sideWidth,
height,
value,
barBackgroundPattern,
patternId,
barStyle,
item,
} = props;
const showGradient = props.showGradient || false; const showGradient = props.showGradient || false;
const gradientColor = props.gradientColor || 'white'; const gradientColor = props.gradientColor || 'white';
@ -135,15 +145,18 @@ const ThreeDBar = (props: PropTypes) => {
</View> </View>
<View <View
style={{ style={[
width: width, {
height: height, width: width,
backgroundColor: frontColor, height: height,
borderLeftWidth: StyleSheet.hairlineWidth, backgroundColor: frontColor,
borderTopWidth: StyleSheet.hairlineWidth, borderLeftWidth: StyleSheet.hairlineWidth,
borderColor: 'white', borderTopWidth: StyleSheet.hairlineWidth,
opacity: opacity, borderColor: 'white',
}}> opacity: opacity,
},
item.barStyle || barStyle,
]}>
{showGradient && ( {showGradient && (
<LinearGradient <LinearGradient
style={{position: 'absolute', width: '100%', height: '100%'}} style={{position: 'absolute', width: '100%', height: '100%'}}