Skip to content

Commit 34ba552

Browse files
Merge pull request #159 from JesperLekland/release/5.1.0
Release/5.1.0
2 parents 2c417a8 + 6c2cb95 commit 34ba552

19 files changed

+1451
-377
lines changed

CHANGELOG.md

+8-42
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,12 @@
1+
5.x.0
12

2-
Version 5.0 is a major overhaul to the "decorator" and "extras" pattern.
3-
We've simplified the API, made it declarative and added support for
4-
rendering order.
3+
* Added `cornerRadius` to progressCircle
4+
* Adhere to `Svg` api with `height` and `width` instead of `flex: 1`
5+
* StackedBarChart now supports `svg` prop for each data entry! Allowing onPress among other things.
6+
* StackedAreaChart now supports `svg` prop for each area! Allowing onPress among other things
7+
* The two above changes does remove the other "svg" props from the charts, for example `renderGradient`
8+
that is now replaces with the same gradient API as the other charts (i.e children).
9+
* PieChart supports `(start|end)Angle`
510

6-
All charts and axes now support React children. Meaning that your decorators
7-
and extras should now be placed as direct children to the chart in question.
8-
This is a breaking change but a very easy one to migrate (I migrated all storybooks in a matter of minutes),
9-
see the [examples repo](https://github.com/JesperLekland/react-native-svg-charts-examples)
10-
and read the [docs](https://github.com/JesperLekland/react-native-svg-charts#react-native-svg-charts) for inspiration.
11-
12-
I want to thank everyone who is contributing by submitting issues and joining
13-
in on discussions. A special thanks to @narciero, @Sprit3Dan and @RoarRain for
14-
contributing with PRs.
15-
16-
## Breaking Changes
17-
* **Extras and Decorators have been removed**
18-
19-
Extras and decorators should now be passed in as children to the chart in question.
20-
Each child will be called with similar arguments as before. See
21-
[README](https://github.com/JesperLekland/react-native-svg-charts#react-native-svg-charts)
22-
for more info.
23-
24-
Migrating an extra is as simple as just moving it from the `extras` array to a child of the chart.
25-
The `decorators` are nearly as easy to migrate. Create a wrapper component around
26-
your decorator that accepts the `data` prop, now you yourself can map this array and return as many decorators as you want.
27-
28-
29-
* **renderGrid and gridProps have been removed**
30-
31-
A grid show now be rendered through as a child. We still expose a default `Grid`
32-
component as part of the API but this must no manually be added to all charts that want to display a grid.
33-
34-
As a result of this the following props are deprecated:
35-
* `showGrid`
36-
* `gridProps`
37-
* `renderGrid`
38-
39-
40-
* **Grids are consolidate into one**
41-
42-
Before we hade `Grid.Vertical`,`Grid.Horizontal` and `Grid.Both`,
43-
now we simply have `Grid` with a `direction` property. See [README](https://github.com/JesperLekland/react-native-svg-charts#react-native-svg-charts)
44-
for more info
4511

4612

README.md

+43-12
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Also see
122122

123123
#### Example
124124

125-
```javascript
125+
```jsx
126126
import React from 'react'
127127
import { AreaChart, Grid } from 'react-native-svg-charts'
128128
import * as shape from 'd3-shape'
@@ -162,15 +162,16 @@ Supports all [Common arguments to children](#common-arguments-to-children)
162162

163163
### StackedAreaChart
164164

165-
Very similar to an area chart but with multiple sets of data stacked together. Notice that the `dataPoints` prop has changed to `data` and have a different signature.
165+
Very similar to an area chart but with multiple sets of data stacked together.
166166
We suggest that you read up on [d3 stacks](https://github.com/d3/d3-shape#stacks) in order to better understand this chart and its props
167167
See [Area stack chart with Y axis](https://github.com/JesperLekland/react-native-svg-charts-examples/blob/master/storybook/stories/area-stack/with-y-axis.js) to see how to use a YAxis with this component
168+
Use the `svgs` prop to pass in `react-native-svg` compliant props to each area.
168169

169170
![Stacked area chart](https://raw.githubusercontent.com/jesperlekland/react-native-svg-charts/master/screenshots/area-stack.png)
170171

171172
#### Example
172173

173-
```javascript
174+
```jsx
174175
import React from 'react'
175176
import { StackedAreaChart } from 'react-native-svg-charts'
176177
import * as shape from 'd3-shape'
@@ -212,6 +213,12 @@ class StackedAreaExample extends React.PureComponent {
212213

213214
const colors = [ '#8800cc', '#aa00ff', '#cc66ff', '#eeccff' ]
214215
const keys = [ 'apples', 'bananas', 'cherries', 'dates' ]
216+
const svgs = [
217+
{ onPress: () => console.log('apples') },
218+
{ onPress: () => console.log('bananas') },
219+
{ onPress: () => console.log('cherries') },
220+
{ onPress: () => console.log('dates') },
221+
]
215222

216223
return (
217224
<StackedAreaChart
@@ -221,6 +228,7 @@ class StackedAreaExample extends React.PureComponent {
221228
colors={ colors }
222229
curve={ shape.curveNatural }
223230
showGrid={ false }
231+
svgs={ svgs }
224232
/>
225233
)
226234
}
@@ -259,7 +267,8 @@ when trying to layout decorators. It does however call with the rest of the [com
259267
![Bar chart](https://raw.githubusercontent.com/jesperlekland/react-native-svg-charts/master/screenshots/bar-chart.png)
260268

261269
#### Example
262-
```javascript
270+
271+
```jsx
263272
import React from 'react'
264273
import { BarChart, Grid } from 'react-native-svg-charts'
265274

@@ -307,15 +316,19 @@ Also supports all [Common arguments to children](#common-arguments-to-children)
307316

308317
### StackedBarChart
309318

310-
The same as the [StackedAreaChart](#stackedareachart) except with bars.
319+
The same as the [StackedAreaChart](#stackedareachart) except with bars (and different `svgs` prop).
311320
We suggest that you read up on [d3 stacks](https://github.com/d3/d3-shape#stacks) in order to better understand this chart and its props
312321

322+
The `svgs` prop here is not based on keys, but rather entries, as the user might want to specify different props
323+
for each entry in each bar. Therefore each key entry can contain a complex object that contains e.g an `svg` prop. See [this example](./storybook/stories/bar-stack/with-on-press.js) for inspiration
324+
325+
313326
![Stacked bar chart](https://raw.githubusercontent.com/jesperlekland/react-native-svg-charts/master/screenshots/bar-stack.png)
314327
![Stacked bar chart - horizontal](https://raw.githubusercontent.com/jesperlekland/react-native-svg-charts/master/screenshots/bar-stack-horizontal.png)
315328

316329
#### Example
317330

318-
```javascript
331+
```jsx
319332
import React from 'react'
320333
import { StackedBarChart } from 'react-native-svg-charts'
321334

@@ -378,9 +391,10 @@ class StackedBarChartExample extends React.PureComponent {
378391

379392
| Property | Default | Description |
380393
| --- | --- | --- |
381-
| data | **required** | An array of the data entries |
394+
| data | **required** | An array of the data entries: each value can be a number or a complex object with custom `svg` props for example |
382395
| keys | **required** | This array should contain the object keys of interest (see above example)
383396
| colors | **required** | An array of equal size as `keys` with the color for each key |
397+
| valueAccessor | ({ item, key }) => item[key] | Very similar to the `yAccessor` of the other charts, usually needed when using complex objects as values |
384398
| horizontal | false | Boolean whether or not the bars should be horizontal |
385399
| order | [d3.stackOrderNone](https://github.com/d3/d3-shape#stackOrderNone) | The order in which to sort the areas |
386400
| offset | [d3.stackOffsetNone](https://github.com/d3/d3-shape#stackOffsetNone) | A function to determine the offset of the areas |
@@ -407,7 +421,7 @@ when trying to layout decorators. It does however call with the rest of the [com
407421

408422
#### Example
409423

410-
```javascript
424+
```jsx
411425
import React from 'react'
412426
import { LineChart, Grid } from 'react-native-svg-charts'
413427

@@ -448,7 +462,8 @@ See more examples in the [examples repo](https://github.com/JesperLekland/react-
448462
![Pie chart](https://raw.githubusercontent.com/jesperlekland/react-native-svg-charts/master/screenshots/pie-chart.png)
449463

450464
#### Example
451-
```javascript
465+
466+
```jsx
452467
import React from 'react'
453468
import { PieChart } from 'react-native-svg-charts'
454469

@@ -493,6 +508,8 @@ class PieChartExample extends React.PureComponent {
493508
| innerRadius | "50%" | The inner radius, use this to create a donut. Takes either percentages or absolute numbers (pixels) |
494509
| labelRadius | undefined | The radius of the circle that will help you layout your labels. Takes either percentages or absolute numbers (pixels) |
495510
| padAngle | | The angle between the slices |
511+
| startAngle | 0 | The start angle in radians of the entire pie |
512+
| endAngle | Math.PI * 2 | The end angle in radians of the entire pie |
496513
| sort | `(a,b) => b.value - a.value` | Like any normal sort function it expects either 0, a positive or negative return value. The arguments are each an object from the `dataPoints` array |
497514

498515
#### Arguments to children
@@ -509,7 +526,8 @@ class PieChartExample extends React.PureComponent {
509526
![Progress circle](https://raw.githubusercontent.com/jesperlekland/react-native-svg-charts/master/screenshots/progress-circle.png)
510527

511528
#### Example
512-
```javascript
529+
530+
```jsx
513531
import React from 'react'
514532
import { ProgressCircle } from 'react-native-svg-charts'
515533

@@ -541,6 +559,17 @@ class ProgressCircleExample extends React.PureComponent {
541559
| startAngle | `0` | PropTypes.number |
542560
| endAngle | `Math.PI * 2` | PropTypes.number |
543561
| strokeWidth | 5 | PropTypes.number |
562+
| cornerRadius | 45 | PropTypes.number |
563+
564+
565+
#### Arguments to children
566+
567+
| Property | Description
568+
| --- | --- |
569+
| width | the width of the canvas in pixels |
570+
| height | the height of the canvas in pixels |
571+
| data | the same data array provided to the chart, use this to map over your data points if you want decorators on each point |
572+
544573

545574
#### Arguments to children
546575

@@ -560,7 +589,8 @@ It's very important that the component has the exact same view bounds (preferabl
560589
If the chart has property `contentInset` set it's very important that the YAxis has the same vertical contentInset.
561590

562591
#### Example
563-
```javascript
592+
593+
```jsx
564594
import React from 'react'
565595
import { LineChart, YAxis, Grid } from 'react-native-svg-charts'
566596
import { View } from 'react-native'
@@ -632,7 +662,8 @@ If the chart has property `contentInset` set it's very important that the XAxis
632662
The XAxis also supports the `xAccessor` prop, if it's not supplied it will assume that you're only interested in the index of the data set.
633663

634664
#### Example
635-
```javascript
665+
666+
```jsx
636667
import React from 'react'
637668
import { LineChart, XAxis, Grid } from 'react-native-svg-charts'
638669
import { View } from 'react-native'

package.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-svg-charts",
3-
"version": "5.0.0",
3+
"version": "5.1.0",
44
"private": false,
55
"description": "Customizable charts (Line, Bar, Area, Pie, Circle, Progress) for React Native",
66
"main": "src/index.js",
@@ -10,6 +10,14 @@
1010
"storybook": "storybook start -p 7008",
1111
"eslint": "./node_modules/.bin/eslint ."
1212
},
13+
"husky": {
14+
"hooks": {
15+
"pre-commit": "yarn lint-staged"
16+
}
17+
},
18+
"lint-staged": {
19+
"*.js": "eslint"
20+
},
1321
"keywords": [
1422
"react-native",
1523
"react-component",
@@ -65,7 +73,9 @@
6573
"eslint-plugin-react": "^7.7.0",
6674
"eslint-plugin-react-native": "^2.3.2",
6775
"eslint-plugin-standard": "^3.0.1",
76+
"husky": "^1.0.0-rc.8",
6877
"jest": "20.0.1",
78+
"lint-staged": "^7.1.3",
6979
"react": "16.2.0",
7080
"react-dom": ">=16.0.0-alpha.12",
7181
"react-native": "0.52.2",

src/animated-path.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class AnimatedPath extends Component {
1111
this.state = { d: props.d }
1212
}
1313

14-
componentWillReceiveProps(props) {
15-
const { d: newD, animate } = props
16-
const { d: oldD } = this.props
14+
componentDidUpdate(props) {
15+
const { d: newD, animate } = this.props
16+
const { d: oldD } = props
1717

1818
this.newD = newD
1919

src/bar-chart/bar-chart.js

+36-33
Original file line numberDiff line numberDiff line change
@@ -168,39 +168,42 @@ class BarChart extends PureComponent {
168168
style={{ flex: 1 }}
169169
onLayout={ event => this._onLayout(event) }
170170
>
171-
<Svg style={{ flex: 1 }}>
172-
{
173-
React.Children.map(children, child => {
174-
if(child.props.belowChart) {
175-
return React.cloneElement(child, extraProps)
176-
}
177-
})
178-
}
179-
{
180-
areas.map((area, index) => {
181-
182-
const { bar: { svg: barSvg = {} }, path } = area
183-
184-
return (
185-
<Path
186-
key={ index }
187-
{ ...svg }
188-
{ ...barSvg }
189-
d={ path }
190-
animate={ animate }
191-
animationDuration={ animationDuration }
192-
/>
193-
)
194-
})
195-
}
196-
{
197-
React.Children.map(children, child => {
198-
if(!child.props.belowChart) {
199-
return React.cloneElement(child, extraProps)
200-
}
201-
})
202-
}
203-
</Svg>
171+
{
172+
height > 0 && width > 0 &&
173+
<Svg style={{ height, width }}>
174+
{
175+
React.Children.map(children, child => {
176+
if(child && child.props.belowChart) {
177+
return React.cloneElement(child, extraProps)
178+
}
179+
})
180+
}
181+
{
182+
areas.map((area, index) => {
183+
184+
const { bar: { svg: barSvg = {} }, path } = area
185+
186+
return (
187+
<Path
188+
key={ index }
189+
{ ...svg }
190+
{ ...barSvg }
191+
d={ path }
192+
animate={ animate }
193+
animationDuration={ animationDuration }
194+
/>
195+
)
196+
})
197+
}
198+
{
199+
React.Children.map(children, child => {
200+
if(child && !child.props.belowChart) {
201+
return React.cloneElement(child, extraProps)
202+
}
203+
})
204+
}
205+
</Svg>
206+
}
204207
</View>
205208
</View>
206209
)

src/chart-decorators/tooltip.js

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Tooltip.propTypes = {
5858
height: PropTypes.number,
5959
stroke: PropTypes.string,
6060
pointStroke: PropTypes.string,
61+
text: PropTypes.string,
6162
}
6263

6364
export default Tooltip

0 commit comments

Comments
 (0)