Added yAxisTextNumberOfLines and xAxisTextNumberOfLines to Bar, Line and Area charts

This commit is contained in:
Abhinandan-Kushwaha 2022-05-07 08:19:10 +05:30
parent e8fa2adbd5
commit 42658e11de
7 changed files with 28 additions and 10 deletions

View File

@ -118,6 +118,7 @@ The properties of this line chart can be controlled using the `lineConfig` prop
| yAxisThickness | number | Y axis thickness | 1 | | yAxisThickness | number | Y axis thickness | 1 |
| yAxisLabelWidth | number | Width of the Y axis Label container | 35 | | yAxisLabelWidth | number | Width of the Y axis Label container | 35 |
| yAxisTextStyle | object | Style object for the Y axis text style | \_ | | yAxisTextStyle | object | Style object for the Y axis text style | \_ |
| yAxisTextNumberOfLines | number | Number of lines for y axis label text | 1 |
| yAxisLabelContainerStyle | object | Style object for the Y axis label container | \_ | | yAxisLabelContainerStyle | object | Style object for the Y axis label container | \_ |
| horizontalRulesStyle | object | Style object for the horizontal rules container | \_ | | horizontalRulesStyle | object | Style object for the horizontal rules container | \_ |
| showFractionalValues | Boolean | Allow fractional values for the Y axis label | false | | showFractionalValues | Boolean | Allow fractional values for the Y axis label | false |
@ -160,6 +161,7 @@ The properties of this line chart can be controlled using the `lineConfig` prop
| rotateLabel | Boolean | To rotate the X axis labels (by 60deg) | false | | rotateLabel | Boolean | To rotate the X axis labels (by 60deg) | false |
| hideOrigin | Boolean | To hide the y Axis label at origin (i.e. 0) | false | | hideOrigin | Boolean | To hide the y Axis label at origin (i.e. 0) | false |
| labelWidth | number | Width of the Label text appearing below the bar (under the X axis) | barWidth | | labelWidth | number | Width of the Label text appearing below the bar (under the X axis) | barWidth |
| xAxisTextNumberOfLines | number | Number of lines for x axis label text | 1 |
| labelsExtraHeight | number | used to display large labels on X-axis (often rotated to show vertically) | 0 | | labelsExtraHeight | number | used to display large labels on X-axis (often rotated to show vertically) | 0 |
**Note** If you are setting yAxisSide to 'right', make sure to specify the width of the chart, using the `width` prop **Note** If you are setting yAxisSide to 'right', make sure to specify the width of the chart, using the `width` prop

View File

@ -99,6 +99,7 @@ When you are using the `dataPointLabelComponent`, make sure to provide the `data
| yAxisThickness | number | Y axis thickness | 1 | | yAxisThickness | number | Y axis thickness | 1 |
| yAxisLabelWidth | number | Width of the Y axis Label container | 35 | | yAxisLabelWidth | number | Width of the Y axis Label container | 35 |
| yAxisTextStyle | object | Style object for the Y axis text style | \_ | | yAxisTextStyle | object | Style object for the Y axis text style | \_ |
| yAxisTextNumberOfLines | number | Number of lines for y axis label text | 1 |
| yAxisLabelContainerStyle | object | Style object for the Y axis label container | \_ | | yAxisLabelContainerStyle | object | Style object for the Y axis label container | \_ |
| yAxisOffset | number | Starting value on Y Axis | 0 | | yAxisOffset | number | Starting value on Y Axis | 0 |
| horizontalRulesStyle | object | Style object for the horizontal rules container | \_ | | horizontalRulesStyle | object | Style object for the horizontal rules container | \_ |
@ -146,6 +147,7 @@ When you are using the `dataPointLabelComponent`, make sure to provide the `data
| yAxisLabelTexts | Array<string> | Array of label texts to be displayed along y axis | null | | yAxisLabelTexts | Array<string> | Array of label texts to be displayed along y axis | null |
| xAxisLabelTexts | Array<string> | Array of label texts to be displayed below x axis | null | | xAxisLabelTexts | Array<string> | Array of label texts to be displayed below x axis | null |
| xAxisLabelTextStyle | object | Style of label texts to be displayed below x axis | null | | xAxisLabelTextStyle | object | Style of label texts to be displayed below x axis | null |
| xAxisTextNumberOfLines | number | Number of lines for x axis label text | 1 |
| rotateLabel | Boolean | To rotate the X axis labels (by 60deg) | false | | rotateLabel | Boolean | To rotate the X axis labels (by 60deg) | false |
| hideOrigin | Boolean | To hide the y Axis label at origin (i.e. 0) | false | | hideOrigin | Boolean | To hide the y Axis label at origin (i.e. 0) | false |

View File

@ -1,6 +1,6 @@
{ {
"name": "react-native-gifted-charts", "name": "react-native-gifted-charts",
"version": "1.2.16", "version": "1.2.17",
"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

@ -64,6 +64,7 @@ type Props = {
patternId?: String; patternId?: String;
barMarginBottom?: number; barMarginBottom?: number;
onPress?: Function; onPress?: Function;
xAxisTextNumberOfLines: number;
}; };
type itemType = { type itemType = {
value?: number; value?: number;
@ -112,6 +113,7 @@ const RenderBars = (props: Props) => {
autoShiftLabels, autoShiftLabels,
label, label,
labelTextStyle, labelTextStyle,
xAxisTextNumberOfLines,
} = props; } = props;
const barMarginBottom = const barMarginBottom =
@ -161,7 +163,7 @@ const RenderBars = (props: Props) => {
) : ( ) : (
<Text <Text
style={labelTextStyle || {textAlign: 'center'}} style={labelTextStyle || {textAlign: 'center'}}
numberOfLines={1}> numberOfLines={xAxisTextNumberOfLines}>
{label || ''} {label || ''}
</Text> </Text>
)} )}
@ -204,7 +206,7 @@ const RenderBars = (props: Props) => {
) : ( ) : (
<Text <Text
style={labelTextStyle || {textAlign: 'center'}} style={labelTextStyle || {textAlign: 'center'}}
numberOfLines={1}> numberOfLines={xAxisTextNumberOfLines}>
{label || ''} {label || ''}
</Text> </Text>
)} )}

View File

@ -38,6 +38,7 @@ type Props = {
xAxisThickness: number; xAxisThickness: number;
barBackgroundPattern?: Function; barBackgroundPattern?: Function;
patternId?: String; patternId?: String;
xAxisTextNumberOfLines: number;
}; };
type itemType = { type itemType = {
value?: number; value?: number;
@ -69,6 +70,7 @@ const RenderStackBars = (props: Props) => {
xAxisThickness, xAxisThickness,
label, label,
labelTextStyle, labelTextStyle,
xAxisTextNumberOfLines,
} = props; } = props;
const disablePress = props.disablePress || false; const disablePress = props.disablePress || false;
const renderLabel = (label: String, labelTextStyle: any) => { const renderLabel = (label: String, labelTextStyle: any) => {
@ -92,7 +94,7 @@ const RenderStackBars = (props: Props) => {
{item.labelComponent ? ( {item.labelComponent ? (
item.labelComponent() item.labelComponent()
) : ( ) : (
<Text style={[labelTextStyle]} numberOfLines={1}> <Text style={[labelTextStyle]} numberOfLines={xAxisTextNumberOfLines}>
{label || ''} {label || ''}
</Text> </Text>
)} )}

View File

@ -47,6 +47,8 @@ type PropTypes = {
yAxisLabelContainerStyle?: any; yAxisLabelContainerStyle?: any;
horizontalRulesStyle?: any; horizontalRulesStyle?: any;
yAxisTextStyle?: any; yAxisTextStyle?: any;
yAxisTextNumberOfLines?: number;
xAxisTextNumberOfLines?: number;
yAxisLabelWidth?: number; yAxisLabelWidth?: number;
hideYAxisText?: Boolean; hideYAxisText?: Boolean;
yAxisSide?: string; yAxisSide?: string;
@ -372,6 +374,8 @@ export const BarChart = (props: PropTypes) => {
: props.yAxisThickness || 1; : props.yAxisThickness || 1;
const yAxisColor = props.yAxisColor || 'black'; const yAxisColor = props.yAxisColor || 'black';
const yAxisTextStyle = props.yAxisTextStyle; const yAxisTextStyle = props.yAxisTextStyle;
const yAxisTextNumberOfLines = props.yAxisTextNumberOfLines || 1;
const xAxisTextNumberOfLines = props.xAxisTextNumberOfLines || 1;
const yAxisLabelContainerStyle = props.yAxisLabelContainerStyle; const yAxisLabelContainerStyle = props.yAxisLabelContainerStyle;
const horizontalRulesStyle = props.horizontalRulesStyle; const horizontalRulesStyle = props.horizontalRulesStyle;
const showFractionalValues = props.showFractionalValues || false; const showFractionalValues = props.showFractionalValues || false;
@ -768,7 +772,7 @@ export const BarChart = (props: PropTypes) => {
yAxisLabelContainerStyle, yAxisLabelContainerStyle,
]}> ]}>
<Text <Text
numberOfLines={1} numberOfLines={yAxisTextNumberOfLines}
ellipsizeMode={'clip'} ellipsizeMode={'clip'}
style={[ style={[
yAxisTextStyle, yAxisTextStyle,
@ -875,7 +879,7 @@ export const BarChart = (props: PropTypes) => {
yAxisLabelContainerStyle, yAxisLabelContainerStyle,
]}> ]}>
<Text <Text
numberOfLines={1} numberOfLines={yAxisTextNumberOfLines}
ellipsizeMode={'clip'} ellipsizeMode={'clip'}
style={[ style={[
yAxisTextStyle, yAxisTextStyle,
@ -1399,6 +1403,7 @@ export const BarChart = (props: PropTypes) => {
labelTextStyle={ labelTextStyle={
item.labelTextStyle || props.xAxisLabelTextStyle item.labelTextStyle || props.xAxisLabelTextStyle
} }
xAxisTextNumberOfLines={xAxisTextNumberOfLines}
/> />
); );
}) })
@ -1460,6 +1465,7 @@ export const BarChart = (props: PropTypes) => {
item.labelTextStyle || props.xAxisLabelTextStyle item.labelTextStyle || props.xAxisLabelTextStyle
} }
onPress={props.onPress} onPress={props.onPress}
xAxisTextNumberOfLines={xAxisTextNumberOfLines}
/> />
))} ))}
</Fragment> </Fragment>

View File

@ -154,6 +154,8 @@ type propTypes = {
yAxisLabelContainerStyle?: any; yAxisLabelContainerStyle?: any;
horizontalRulesStyle?: any; horizontalRulesStyle?: any;
yAxisTextStyle?: any; yAxisTextStyle?: any;
yAxisTextNumberOfLines?: number;
xAxisTextNumberOfLines?: number;
showFractionalValues?: Boolean; showFractionalValues?: Boolean;
roundToDigits?: number; roundToDigits?: number;
yAxisLabelWidth?: number; yAxisLabelWidth?: number;
@ -1386,6 +1388,8 @@ export const LineChart = (props: propTypes) => {
props.yAxisThickness === 0 ? 0 : props.yAxisThickness || 1; props.yAxisThickness === 0 ? 0 : props.yAxisThickness || 1;
const yAxisColor = props.yAxisColor || 'black'; const yAxisColor = props.yAxisColor || 'black';
const yAxisTextStyle = props.yAxisTextStyle; const yAxisTextStyle = props.yAxisTextStyle;
const yAxisTextNumberOfLines = props.yAxisTextNumberOfLines || 1;
const xAxisTextNumberOfLines = props.xAxisTextNumberOfLines || 1;
const yAxisLabelContainerStyle = props.yAxisLabelContainerStyle; const yAxisLabelContainerStyle = props.yAxisLabelContainerStyle;
const horizontalRulesStyle = props.horizontalRulesStyle; const horizontalRulesStyle = props.horizontalRulesStyle;
const showFractionalValues = props.showFractionalValues || false; const showFractionalValues = props.showFractionalValues || false;
@ -1681,7 +1685,7 @@ export const LineChart = (props: propTypes) => {
) : ( ) : (
<Text <Text
style={labelTextStyle || {textAlign: 'center'}} style={labelTextStyle || {textAlign: 'center'}}
numberOfLines={1}> numberOfLines={xAxisTextNumberOfLines}>
{label || ''} {label || ''}
</Text> </Text>
)} )}
@ -1719,7 +1723,7 @@ export const LineChart = (props: propTypes) => {
) : ( ) : (
<Text <Text
style={labelTextStyle || {textAlign: 'center'}} style={labelTextStyle || {textAlign: 'center'}}
numberOfLines={1}> numberOfLines={xAxisTextNumberOfLines}>
{label || ''} {label || ''}
</Text> </Text>
)} )}
@ -1899,7 +1903,7 @@ export const LineChart = (props: propTypes) => {
yAxisLabelContainerStyle, yAxisLabelContainerStyle,
]}> ]}>
<Text <Text
numberOfLines={1} numberOfLines={yAxisTextNumberOfLines}
ellipsizeMode={'clip'} ellipsizeMode={'clip'}
style={[ style={[
yAxisTextStyle, yAxisTextStyle,
@ -2001,7 +2005,7 @@ export const LineChart = (props: propTypes) => {
yAxisLabelContainerStyle, yAxisLabelContainerStyle,
]}> ]}>
<Text <Text
numberOfLines={1} numberOfLines={yAxisTextNumberOfLines}
ellipsizeMode={'clip'} ellipsizeMode={'clip'}
style={[ style={[
yAxisTextStyle, yAxisTextStyle,