Skip to content

Commit

Permalink
exposes "sort" as a prop on pie-chart
Browse files Browse the repository at this point in the history
  • Loading branch information
JesperLekland committed Nov 21, 2017
1 parent a474fb3 commit 649894a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ class PieChartExample extends React.PureComponent {
| labelRadius | undefined | The radius of the circle that will help you layout your labels. Takes either percentages or absolute numbers (pixels) |
| padAngle | | The angle between the slices |
| renderDecorator | `() => {}` | PropTypes.func |
| 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 |


### ProgressCircle
![Progress circle](https://raw.githubusercontent.com/jesperlekland/react-native-svg-charts/master/screenshots/progress-circle.png)
Expand Down
4 changes: 4 additions & 0 deletions src/pie-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PieChart extends PureComponent {
animationDuration,
style,
renderDecorator,
sort,
} = this.props

const { height, width } = this.state
Expand Down Expand Up @@ -83,6 +84,7 @@ class PieChart extends PureComponent {

const pieSlices = shape.pie()
.value(d => d.value)
.sort(sort)
(dataPoints)

return (
Expand Down Expand Up @@ -135,13 +137,15 @@ PieChart.propTypes = {
animationDuration: PropTypes.number,
style: PropTypes.any,
renderDecorator: PropTypes.func,
sort: PropTypes.func,
}

PieChart.defaultProps = {
width: 100,
height: 100,
padAngle: 0.05,
innerRadius: '50%',
sort: (a, b) => b.value - a.value,
renderDecorator: () => {
},
}
Expand Down

0 comments on commit 649894a

Please sign in to comment.