From fd5208fe18ca8393341042d3d5df7041b399203c Mon Sep 17 00:00:00 2001 From: abeyuya Date: Fri, 23 Sep 2022 12:19:24 +0900 Subject: [PATCH 1/2] add StackBars type definition --- src/BarChart/RenderStackBars.tsx | 25 ++++++++++++++++++++++--- src/BarChart/index.tsx | 12 ++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/BarChart/RenderStackBars.tsx b/src/BarChart/RenderStackBars.tsx index 1aeffc1..98d05e2 100644 --- a/src/BarChart/RenderStackBars.tsx +++ b/src/BarChart/RenderStackBars.tsx @@ -1,5 +1,11 @@ import React, {Component} from 'react'; -import {View, TouchableOpacity, Text, ColorValue} from 'react-native'; +import { + View, + TouchableOpacity, + Text, + ColorValue, + GestureResponderEvent, +} from 'react-native'; import LinearGradient from 'react-native-linear-gradient'; import Svg, {Defs, Rect} from 'react-native-svg'; import {Style} from 'util'; @@ -49,7 +55,7 @@ type Props = { gradientColor?: any; stackData: Array; }; -type itemType = { +export type itemType = { value?: number; onPress?: any; label?: String; @@ -67,7 +73,20 @@ type itemType = { capRadius?: number; labelComponent?: Function; borderRadius?: number; - stacks?: Array; + stacks?: Array<{ + value: number; + color?: ColorValue; + onPress?: (event: GestureResponderEvent) => void; + marginBottom?: number; + barBorderRadius?: number; + borderTopLeftRadius?: number; + borderTopRightRadius?: number; + borderBottomLeftRadius?: number; + borderBottomRightRadius?: number; + showGradient?: boolean; + gradientColor?: ColorValue; + barWidth?: number; + }>; barBackgroundPattern?: Function; barBorderRadius?: Number; patternId?: String; diff --git a/src/BarChart/index.tsx b/src/BarChart/index.tsx index f9688b6..b2e1358 100644 --- a/src/BarChart/index.tsx +++ b/src/BarChart/index.tsx @@ -13,10 +13,12 @@ import { Text, ColorValue, ScrollView, + StyleProp, + TextStyle, } from 'react-native'; import {styles} from './styles'; import RenderBars from './RenderBars'; -import RenderStackBars from './RenderStackBars'; +import RenderStackBars, {itemType as StackItemType} from './RenderStackBars'; import Rule from '../Components/lineSvg'; import {bezierCommand, svgPath} from '../utils'; import Svg, {Circle, Path, Rect, Text as CanvasText} from 'react-native-svg'; @@ -33,7 +35,13 @@ type PropTypes = { stepValue?: number; spacing?: number; data?: any; - stackData?: any; + stackData?: Array<{ + stacks: Array; + label?: string; + labelTextStyle?: StyleProp; + barWidth?: number; + spacing?: number; + }>; side?: String; rotateLabel?: Boolean; isAnimated?: Boolean; From 2d8a7fe85cd83fe0f0fdbe174582fe8a3578caab Mon Sep 17 00:00:00 2001 From: abeyuya Date: Fri, 23 Sep 2022 12:35:49 +0900 Subject: [PATCH 2/2] update docs --- docs/BarChart/BarChartProps.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/BarChart/BarChartProps.md b/docs/BarChart/BarChartProps.md index c56fe31..5bcc844 100644 --- a/docs/BarChart/BarChartProps.md +++ b/docs/BarChart/BarChartProps.md @@ -387,6 +387,8 @@ The value corresponding to the stacks key is an array of objects, each object re | stacks array | Array of stack items | A stack is made of 1 or more objects of the type described in the next table | | label | string | Label text appearing below the stack (under the X axis) | | labelTextStyle | Style object for the label text appearing below the stack | +| barWidth | number | +| spacing | number | A single stack item can be depicted as- @@ -406,7 +408,8 @@ A single stack item can be depicted as- | borderBottomLeftRadius | number | borderBottomLeftRadius for a stack section | | borderBottomRightRadius | number | borderBottomRightRadius for a stack section | | 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 | +| barWidth | number | Width of the bar | ```