Skip to content

Commit 6549fb6

Browse files
Release/4.1.0 (#82)
v4.1.0
1 parent 351d66d commit 6549fb6

File tree

11 files changed

+122
-110
lines changed

11 files changed

+122
-110
lines changed

CHANGELOG.md

+10-53
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,21 @@
1-
### Awesome new BarChart (breaking changes)
21

3-
The BarChart has been rewritten from the ground up. It works the same as before
4-
but have some nice new features. The expectation on the `data` props has changed to better align with the other charts APIs, see the README and [examples](https://github.com/JesperLekland/react-native-svg-charts-examples) for more info.
2+
* **Support for styles xAxis labels**
53

6-
* **Complex objects**
4+
XAxis now supports complex data argument with `svg` property to style each label individually. See [examples repo](https://github.com/JesperLekland/react-native-svg-charts-examples) for usage.
5+
Thanks to @fqueiruga for this ❤️
76

8-
As before you can still pass in an array of just numbers, but you can now also pass in an array of complex objects! These objects can contain any data you want but you must also
9-
pass in a `yAccessor` prop to tell the chart what the actual value for the item is (same as Line/AreaChart).
10-
The entire object will be returned to you as `item` in the `renderDecorator` callback, allowing for nice label rendering.
11-
The BarChart looks for a `svg` property on each entry, allowing you to set custom svg props for each bar (!!!).
12-
The BarChart itself also takes an svg prop that will be passed to all bars (item specific svg properties will not be overriden)
137

14-
All in all you should be able to do what you did before, and then some 😄 Check out the [examples repo](https://github.com/JesperLekland/react-native-svg-charts-examples) for some nice use examples
8+
* **Support for backgroundColor in ProgressCircle**
159

10+
You can now customize the progress "background" color
1611

17-
* **Horizontal support**
12+
* **Support for strokeWidth in ProgressCircle**
1813

19-
`horizontal={true}`, how nice is that!? 😄 Supports both the standard barChart and the grouped one (multiple data sets).
20-
21-
* **Extras support**
22-
23-
BarChart now has first class support for the extras prop.
24-
Render a clip path or a gradient in a specific bar, up to you!
25-
26-
* **Spacing is replaced**
27-
28-
We've replaced `spacing` with `spacingInner` and `spacingOuter` to give more control to the user. Same default as before - 0.05
29-
This is true for all places where `spacing` was being used.
30-
31-
### YAxis supports scaleBand and spacing
32-
33-
In order to have a nice YAxis along with the horizontal BarChart we have now added support for `scale=d3.scaleBand` to the yAxis.
34-
This in turn comes with added props `spacingInner` and `spacingOuter` to align nicely with your BarChart.
35-
36-
37-
### PieChart
38-
39-
* **data entry supports `svg` prop**
40-
41-
PieChart has been upgraded to take the `svg` prop on each data entry, allowing you to customise your PieChart even further
42-
We've also added the `valueAccessor` prop to allow you to use different dataStructures, not forcing you to name the value "value" and aligning with the other APIs.
43-
44-
* **data entry supports `arc` prop**
45-
46-
You can now customize your arcs on an individual level. Want one arc to be bigger than the reset? No problem!
47-
48-
Check out [examples repo](https://github.com/JesperLekland/react-native-svg-charts-examples) for examples
49-
50-
### WaterfallChart is removed
51-
52-
Due to low usage and high maintenance the WaterfallChart is removed.
53-
54-
### Cleaned up README
55-
56-
The README is now more focused on the basic usage of this library. Any cool custom behavior has been moved to the [examples repo](https://github.com/JesperLekland/react-native-svg-charts-examples).
57-
This is the go to place where you want inspiration on how to do cool things with your charts or if you've ever asked yourself "can I do this with react-native-svg-charts?"
58-
59-
We want to make sure that the README is concise and to the point. Here we want to explain the APIs and not much more.
60-
All charts and their APIs will still be documented here, but as an MVP.
14+
Customize the width of the ProgressCircle
6115

16+
* **Prettier transition in ProgressCircle from progress to background**
6217

18+
Old implementation used to have a small cutoff between the progress and the background.
19+
Now the progress seems to be "inside" the circle instead.
6320

6421

README.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ yarn storybook
7272
| data | **required** | An array of arbitrary data - use prop `xAccessor`/`yAccessor`to tell the chart about the data structure|
7373
| yAccessor | ({ item }) => item | A function that takes each entry of `data` (named "item") as well as the index and returns the y-value of that entry |
7474
| xAccessor | ({ index }) => index | Same as `yAccessor` but returns the x-value of that entry|
75-
| yScale | d3Scale.scaleLinear | A function that determines the scale of said axis (only tested with scaleLinear, scaleTime & scaleBand )|
75+
| yScale | d3Scale.scaleLinear | A function that determines the scale of said axis (only tested with scaleLinear, scaleTime & scaleBand )|
7676
| xScale | d3Scale.scaleLinear | Same as `yScale` but for the x axis |
7777
| svg | `{}` | an object containing all the props that should be passed down to the underlying `react-native-svg` component. [See available props](https://github.com/react-native-community/react-native-svg#common-props)|
7878
| animate | true | PropTypes.bool |
@@ -257,8 +257,9 @@ Also see [Common Props](#common-props)
257257

258258
| Property | Default | Description |
259259
| --- | --- | --- |
260-
| data | **required** | The data prop in a barChart can look exactly like in a Line- or AreaChart, i.e an array of just numbers or complex objects. It can however also be an array with several data sets. See [the examples repo](https://github.com/JesperLekland/react-native-svg-charts-examples)|
260+
| data | **required** | The data prop in a barChart can look exactly like in a Line- or AreaChart, i.e an array of just numbers or complex objects. It can however also be an array with several data sets. A data object can contain a `svg` property which allows you two override styles on that specific object. See [the examples repo](https://github.com/JesperLekland/react-native-svg-charts-examples)|
261261
| horizontal | false | Boolean whether or not the bars should be horizontal |
262+
| svg | `{}` | Default svg props **for all bars**. Supports all svg props an svg path normally supports. This styles will be overriden if there are specific styles for a given data object |
262263
| spacingInner | 0.05 | Spacing between the bars (or groups of bars) |
263264
| spacingOuter | 0.05 | Spacing outside of the bars (or groups of bars). Percentage of one bars width |
264265
| contentInset | `{ top: 0, left: 0, right: 0, bottom: 0 }` | PropTypes.shape |
@@ -466,8 +467,10 @@ class ProgressCircleExample extends React.PureComponent {
466467
| --- | --- | --- |
467468
| progress | **required** | PropTypes.number.isRequired |
468469
| progressColor | 'black' | PropTypes.any |
470+
| backgroundColor | '#ECECEC' | PropTypes.any |
469471
| startAngle | `0` | PropTypes.number |
470472
| endAngle | `Math.PI * 2` | PropTypes.number |
473+
| strokeWidth | 5 | PropTypes.number |
471474

472475
### YAxis
473476

@@ -524,6 +527,8 @@ class YAxisExample extends React.PureComponent {
524527
| --- | --- | --- |
525528
| scale | `d3Scale.scaleLinear`| Should be the same as passed into the charts `yScale`, *or* d3Scale.scaleBand if used in conjunction with a horizontal BarChart |
526529
| svg | `{}` | supports all svg props an svg text normally supports |
530+
| spacingInner | 0.05 | Spacing between the labels. Only applicable if `scale=d3Scale.scaleBand` and should then be equal to `spacingInner` prop on the actual BarChart |
531+
| spacingOuter | 0.05 | Spacing outside of the labels. Only applicable if `scale=d3Scale.scaleBand` and should then be equal to `spacingOuter` prop on the actual BarChart |
527532
| formatLabel | `value => {}` | A utility function to format the text before it is displayed, e.g `value => "$" + value |
528533
| contentInset | { top: 0, bottom: 0 } | Used to sync layout with chart (if same prop used there) |
529534
| min | undefined | Used to sync layout with chart (if gridMin is used there) |
@@ -580,11 +585,12 @@ class XAxisExample extends React.PureComponent {
580585

581586
| Property | Default | Description |
582587
| --- | --- | --- |
583-
| values | **required** | An array of values to render on the xAxis. Should preferably have the same length as the chart's dataPoints. |
588+
| data | **required** | An array of values or objects to render on the xAxis. Should preferably have the same length as the chart's dataPoints. If a complex object is used instead of a simple value, a `xAccessor` prop **is required** to calculate the axis' extent. A data object can contain a `svg` property which allows you to override styles on that specific object |
584589
| scale | `d3Scale.scaleLinear`| Should be the same as passed into the charts `xScale` |
585-
| spacing | 0.05 | Only applicable if `scale=d3Scale.scaleBand` and should then be equal to `spacing` prop on the actual BarChart. |
586-
| svg | `{}` | supports all svg props an svg text normally supports |
587-
| formatLabel | `value => value` | A utility function to format the text before it is displayed, e.g `value => "day" + value. Passes back the value provided by the `xAccessor` |
590+
| spacingInner | 0.05 | Spacing between the labels. Only applicable if `scale=d3Scale.scaleBand` and should then be equal to `spacingInner` prop on the actual BarChart |
591+
| spacingOuter | 0.05 | Spacing between the labels. Only applicable if `scale=d3Scale.scaleBand` and should then be equal to `spacingOuter` prop on the actual BarChart |
592+
| svg | `{}` | Default svg props **for all labels**. Supports all svg props an svg text normally supports. This styles will be overriden if there are specific styles for a given data object |
593+
| formatLabel | `value => value` | A utility function to format the text before it is displayed, e.g `value => "day" + value`. Passes back the value provided by the `xAccessor` |
588594
| contentInset | { left: 0, right: 0 } | Used to sync layout with chart (if same prop used there) |
589595

590596

@@ -630,8 +636,8 @@ There might be additional parameters sent to the `extras` functions as well, dep
630636

631637
The `LineChart` passes the svg path data that rendered the line. (argument name `line`)
632638

633-
The `AreaChart` passes both the area svg path as well as the
634-
svg path for the line following the upper bounds of the area.
639+
The `AreaChart` passes both the area svg path as well as the
640+
svg path for the line following the upper bounds of the area.
635641
(argument name `area` and `line` respectively)
636642

637643
Take a look in the source code for additional details.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-svg-charts",
3-
"version": "4.0.1",
3+
"version": "4.1.0",
44
"private": false,
55
"description": "Customizable charts (Line, Bar, Area, Pie, Circle, Progress) for React Native",
66
"main": "src/index.js",

src/area-chart.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import React from 'react'
21
import * as shape from 'd3-shape'
32
import PropTypes from 'prop-types'
43
import Chart from './chart'
54

6-
class AreaChart extends React.PureComponent {
5+
class AreaChart extends Chart {
76

8-
_createPaths = ({ data, x, y }) => {
7+
createPaths({ data, x, y }) {
98
const { curve, start } = this.props
109

1110
const area = shape.area()
@@ -29,15 +28,6 @@ class AreaChart extends React.PureComponent {
2928
line,
3029
}
3130
}
32-
33-
render() {
34-
return (
35-
<Chart
36-
createPaths={this._createPaths}
37-
{...this.props}
38-
/>
39-
)
40-
}
4131
}
4232

4333
AreaChart.propTypes = {

src/chart.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class Chart extends PureComponent {
2020
this.setState({ height, width })
2121
}
2222

23+
createPaths() {
24+
throw 'Extending "Chart" requires you to override "createPaths'
25+
}
26+
2327
render() {
2428

2529
const {
@@ -29,7 +33,6 @@ class Chart extends PureComponent {
2933
yScale,
3034
xScale,
3135
style,
32-
createPaths,
3336
animate,
3437
animationDuration,
3538
showGrid,
@@ -75,7 +78,7 @@ class Chart extends PureComponent {
7578
.domain(xExtent)
7679
.range([ left, width - right ])
7780

78-
const paths = createPaths({
81+
const paths = this.createPaths({
7982
data: mappedData,
8083
x,
8184
y,

src/line-chart.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import React from 'react'
21
import * as shape from 'd3-shape'
32
import Chart from './chart'
43

5-
class LineChart extends React.PureComponent {
4+
class LineChart extends Chart {
65

7-
_createPaths = ({ data, x, y }) => {
6+
createPaths({ data, x, y }) {
87
const { curve } = this.props
98

109
const line = shape.line()
@@ -19,16 +18,6 @@ class LineChart extends React.PureComponent {
1918
line,
2019
}
2120
}
22-
23-
render() {
24-
25-
return (
26-
<Chart
27-
createPaths={this._createPaths}
28-
{...this.props}
29-
/>
30-
)
31-
}
3221
}
3322

3423
LineChart.propTypes = {

src/progress-circle.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class ProgressCircle extends PureComponent {
2121
const {
2222
style,
2323
progressColor,
24+
backgroundColor,
25+
strokeWidth,
2426
startAngle,
2527
endAngle,
2628
animate,
@@ -38,21 +40,20 @@ class ProgressCircle extends PureComponent {
3840
}
3941

4042
const data = [
43+
{
44+
key: 'rest',
45+
value: 1 - progress,
46+
color: backgroundColor,
47+
},
4148
{
4249
key: 'progress',
4350
value: progress,
4451
color: progressColor,
4552
},
46-
{
47-
key: 'rest',
48-
value: 1 - progress,
49-
color: '#ECECEC',
50-
},
5153
]
5254

5355
const pieSlices = shape
5456
.pie()
55-
.sort(null)
5657
.startAngle(startAngle)
5758
.endAngle(endAngle)
5859
(data.map(d => d.value))
@@ -63,9 +64,9 @@ class ProgressCircle extends PureComponent {
6364
...slice,
6465
path: shape.arc()
6566
.outerRadius(outerDiameter / 2) // Radius of the pie
66-
.innerRadius((outerDiameter / 2) - 5) // Inner radius: to create a donut or pie
67-
.startAngle(slice.startAngle)
68-
.endAngle(slice.endAngle)
67+
.innerRadius((outerDiameter / 2) - strokeWidth) // Inner radius: to create a donut or pie
68+
.startAngle(index === 0 ? startAngle : slice.startAngle)
69+
.endAngle(index === 0 ? endAngle : slice.endAngle)
6970
.cornerRadius(45)
7071
(),
7172
}
@@ -103,14 +104,18 @@ ProgressCircle.propTypes = {
103104
progress: PropTypes.number.isRequired,
104105
style: PropTypes.any,
105106
progressColor: PropTypes.any,
107+
backgroundColor: PropTypes.any,
108+
strokeWidth: PropTypes.number,
106109
startAngle: PropTypes.number,
107110
endAngle: PropTypes.number,
108111
animate: PropTypes.bool,
109112
animateDuration: PropTypes.number,
110113
}
111114

112115
ProgressCircle.defaultProps = {
113-
progressColor: '#22B6B0',
116+
progressColor: 'black',
117+
backgroundColor: '#ECECEC',
118+
strokeWidth: 5,
114119
startAngle: 0,
115120
endAngle: Math.PI * 2,
116121
}

src/x-axis.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ class XAxis extends PureComponent {
3939

4040
if (scale === d3Scale.scaleBand) {
4141

42-
// use index as domain identifier instead of value since
43-
// same value can occur at several places in dataPoints
4442
x
4543
.paddingInner([ spacingInner ])
4644
.paddingOuter([ spacingOuter ])
@@ -93,12 +91,15 @@ class XAxis extends PureComponent {
9391
// causes rendering issues
9492
width > 0 &&
9593
ticks.map((value, index) => {
94+
const { svg: valueSvg = {} } = data[ index ] || {}
95+
9696
return (
9797
<SVGText
9898
textAnchor={'middle'}
9999
originX={x(value)}
100100
alignmentBaseline={'hanging'}
101101
{...svg}
102+
{...valueSvg}
102103
key={index}
103104
x={x(value)}
104105
>
@@ -115,7 +116,10 @@ class XAxis extends PureComponent {
115116
}
116117

117118
XAxis.propTypes = {
118-
data: PropTypes.array.isRequired,
119+
data: PropTypes.arrayOf(PropTypes.oneOfType([
120+
PropTypes.number,
121+
PropTypes.object,
122+
])).isRequired,
119123
labelStyle: PropTypes.any,
120124
spacingInner: PropTypes.number,
121125
spacingOuter: PropTypes.number,

storybook/stories/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Extras from './extras'
2424
import XAxisScaleBandExample from './x-axis/scale-band'
2525
import XAxisScaleTimeExample from './x-axis/scale-time'
2626
import XAxisScaleLinearExample from './x-axis/scale-linear'
27+
import XAxisDataObjectExample from './x-axis/data-object'
2728

2829
import YAxisExample from './y-axis'
2930

@@ -75,6 +76,7 @@ storiesOf('Axes', module)
7576
.add('XAxis - scaleLinear', () => <XAxisScaleLinearExample/>)
7677
.add('XAxis - scaleTime', () => <XAxisScaleTimeExample/>)
7778
.add('XAxis - scaleBand', () => <XAxisScaleBandExample/>)
79+
.add('XAxis - data object', () => <XAxisDataObjectExample />)
7880

7981
storiesOf('Others', module)
8082
.addDecorator(getStory => <ShowcaseCard>{ getStory() }</ShowcaseCard>)

storybook/stories/progress-gauge/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import React from 'react'
2-
import ProgressCircle from '../../../src/progress-circle'
2+
import { ProgressCircle } from 'react-native-svg-charts'
33

44
class ProgressCircleExample extends React.PureComponent {
55

66
render() {
77

88
return (
9-
<ProgressCircle
10-
style={ { height: 200 } }
11-
progress={ 0.7 }
12-
progressColor={'rgb(134, 65, 244)'}
13-
startAngle={ -Math.PI * 0.8 }
14-
endAngle={ Math.PI * 0.8 }
15-
/>
9+
<ProgressCircle
10+
style={{ height: 200, marginTop: 10 }}
11+
progress={0.7}
12+
progressColor={'rgb(134, 65, 244)'}
13+
startAngle={-Math.PI * 0.8}
14+
endAngle={Math.PI * 0.8}
15+
/>
1616
)
1717
}
1818

0 commit comments

Comments
 (0)