From 0cea67904f7907721b099bd9ce31ca544bfd9031 Mon Sep 17 00:00:00 2001 From: Jesper Lekland Date: Wed, 24 Jan 2018 12:01:04 +0100 Subject: [PATCH] Fix/grid min max (#31) * gridMin/Max should not have default values. YAxis now supports min/max prop to sync with chart * 2.2.0 --- README.md | 3 +++ package.json | 2 +- src/area-chart.js | 2 -- src/bar-chart.js | 2 -- src/line-chart.js | 5 +---- src/stacked-area-chart.js | 2 -- src/stacked-bar-chart.js | 2 -- src/y-axis.js | 6 +++++- 8 files changed, 10 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3133f46f..94fd8455 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index 1c4754f5..2b8c1699 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/area-chart.js b/src/area-chart.js index 9b6e8af3..e6fbab4e 100644 --- a/src/area-chart.js +++ b/src/area-chart.js @@ -160,8 +160,6 @@ AreaChart.defaultProps = { contentInset: {}, numberOfTicks: 10, showGrid: true, - gridMin: 0, - gridMax: 0, extras: [], renderDecorator: () => { }, diff --git a/src/bar-chart.js b/src/bar-chart.js index b8b26259..ed888921 100644 --- a/src/bar-chart.js +++ b/src/bar-chart.js @@ -220,8 +220,6 @@ BarChart.defaultProps = { contentInset: {}, numberOfTicks: 10, showGrid: true, - gridMin: 0, - gridMax: 0, extras: [], renderDecorator: () => { }, diff --git a/src/line-chart.js b/src/line-chart.js index 422c3fa5..c059ec1f 100644 --- a/src/line-chart.js +++ b/src/line-chart.js @@ -65,7 +65,7 @@ class LineChart extends PureComponent { return } - 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 @@ -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, @@ -167,8 +166,6 @@ LineChart.defaultProps = { contentInset: {}, numberOfTicks: 10, showGrid: true, - gridMin: 0, - gridMax: 0, extras: [], renderDecorator: () => { }, diff --git a/src/stacked-area-chart.js b/src/stacked-area-chart.js index f0f3068e..0d3839ef 100644 --- a/src/stacked-area-chart.js +++ b/src/stacked-area-chart.js @@ -183,8 +183,6 @@ AreaStack.defaultProps = { contentInset: {}, numberOfTicks: 10, showGrid: true, - gridMin: 0, - gridMax: 0, extras: [], renderDecorator: () => { }, diff --git a/src/stacked-bar-chart.js b/src/stacked-bar-chart.js index ad3ca2d8..1ebc3f55 100644 --- a/src/stacked-bar-chart.js +++ b/src/stacked-bar-chart.js @@ -188,8 +188,6 @@ BarChart.defaultProps = { contentInset: {}, numberOfTicks: 10, showGrid: true, - gridMin: 0, - gridMax: 0, extras: [], renderDecorator: () => { }, diff --git a/src/y-axis.js b/src/y-axis.js index b885bf4e..25ac410b 100644 --- a/src/y-axis.js +++ b/src/y-axis.js @@ -36,6 +36,8 @@ class YAxis extends PureComponent { top = 0, bottom = 0, }, + min, + max, } = this.props const { height, textHeight } = this.state @@ -43,7 +45,7 @@ class YAxis extends PureComponent { return } - 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() @@ -101,6 +103,8 @@ YAxis.propTypes = { top: PropTypes.number, bottom: PropTypes.number, }), + min: PropTypes.number, + max: PropTypes.number, } YAxis.defaultProps = {