Skip to content

Commit

Permalink
Fix/grid min max (#31)
Browse files Browse the repository at this point in the history
* gridMin/Max should not have default values. YAxis now supports min/max prop to sync with chart

* 2.2.0
  • Loading branch information
JesperLekland authored Jan 24, 2018
1 parent 1906b7c commit 0cea679
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 14 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ class YAxisExample extends React.PureComponent {
| labelStyle | undefined | Supports all [TextStyleProps](https://facebook.github.io/react-native/docs/textstyleproptypes.html) |
| formatLabel | `value => {}` | A utility function to format the text before it is displayed, e.g `value => "$" + value |
| contentInset | { top: 0, bottom: 0 } | Used to sync layout with chart (if same prop used there) |
| min | undefined | Used to sync layout with chart (if gridMin is used there) |
| max | undefined | Used to sync layout with chart (if gridMax is used there) |


### XAxis

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-svg-charts",
"version": "2.1.0",
"version": "2.2.0",
"private": false,
"description": "Customizable charts (Line, Bar, Area, Pie, Circle, Waterfall, Progress) for React Native",
"main": "src/index.js",
Expand Down
2 changes: 0 additions & 2 deletions src/area-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ AreaChart.defaultProps = {
contentInset: {},
numberOfTicks: 10,
showGrid: true,
gridMin: 0,
gridMax: 0,
extras: [],
renderDecorator: () => {
},
Expand Down
2 changes: 0 additions & 2 deletions src/bar-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ BarChart.defaultProps = {
contentInset: {},
numberOfTicks: 10,
showGrid: true,
gridMin: 0,
gridMax: 0,
extras: [],
renderDecorator: () => {
},
Expand Down
5 changes: 1 addition & 4 deletions src/line-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class LineChart extends PureComponent {
return <View style={ style }/>
}

const extent = array.extent([ ...dataPoints, gridMax, gridMin, -shadowOffset ])
const extent = array.extent([ ...dataPoints, gridMax, gridMin ])
const ticks = array.ticks(extent[ 0 ], extent[ 1 ], numberOfTicks)

//invert range to support svg coordinate system
Expand Down Expand Up @@ -128,7 +128,6 @@ LineChart.propTypes = {
dataPoints: PropTypes.arrayOf(PropTypes.number).isRequired,
svg: PropTypes.object,
shadowSvg: PropTypes.object,
shadowWidth: PropTypes.number,
shadowOffset: PropTypes.number,

style: PropTypes.any,
Expand Down Expand Up @@ -167,8 +166,6 @@ LineChart.defaultProps = {
contentInset: {},
numberOfTicks: 10,
showGrid: true,
gridMin: 0,
gridMax: 0,
extras: [],
renderDecorator: () => {
},
Expand Down
2 changes: 0 additions & 2 deletions src/stacked-area-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ AreaStack.defaultProps = {
contentInset: {},
numberOfTicks: 10,
showGrid: true,
gridMin: 0,
gridMax: 0,
extras: [],
renderDecorator: () => {
},
Expand Down
2 changes: 0 additions & 2 deletions src/stacked-bar-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ BarChart.defaultProps = {
contentInset: {},
numberOfTicks: 10,
showGrid: true,
gridMin: 0,
gridMax: 0,
extras: [],
renderDecorator: () => {
},
Expand Down
6 changes: 5 additions & 1 deletion src/y-axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ class YAxis extends PureComponent {
top = 0,
bottom = 0,
},
min,
max,
} = this.props
const { height, textHeight } = this.state

if (dataPoints.length === 0) {
return <View style={ style }/>
}

const extent = array.extent([ ...dataPoints, 0 ])
const extent = array.extent([ ...dataPoints, min, max ])
const ticks = array.ticks(extent[ 0 ], extent[ 1 ], numberOfTicks)

const y = scale.scaleLinear()
Expand Down Expand Up @@ -101,6 +103,8 @@ YAxis.propTypes = {
top: PropTypes.number,
bottom: PropTypes.number,
}),
min: PropTypes.number,
max: PropTypes.number,
}

YAxis.defaultProps = {
Expand Down

0 comments on commit 0cea679

Please sign in to comment.