Skip to content

Commit

Permalink
add renderLineGradient for area-chart (#25)
Browse files Browse the repository at this point in the history
* add `renderLineGradient` for area-chart
  • Loading branch information
JesperLekland authored Jan 24, 2018
1 parent 0cea679 commit bd6f30a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class AreaChartExample extends React.PureComponent {
#### Props

See [Common Props](#common-props)
| Property | Default | Description |
| --- | --- | --- |
| renderLineGradient | undefined | The same as `renderGradient` but for the line in the chart |

### StackedAreaChart

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.2.0",
"version": "2.2.1",
"private": false,
"description": "Customizable charts (Line, Bar, Area, Pie, Circle, Waterfall, Progress) for React Native",
"main": "src/index.js",
Expand Down
4 changes: 4 additions & 0 deletions src/area-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AreaChart extends PureComponent {
animationDuration,
style,
renderGradient,
renderLineGradient,
curve,
showGrid,
numberOfTicks,
Expand Down Expand Up @@ -102,6 +103,7 @@ class AreaChart extends PureComponent {
{ showGrid && renderGrid({ x, y, ticks, dataPoints, gridProps }) }
<Defs>
{ renderGradient && renderGradient({ id: 'gradient', width, height, x, y }) }
{ renderLineGradient && renderLineGradient({ id: 'line-gradient', width, height, x, y }) }
</Defs>
<Path
{ ...svg }
Expand All @@ -113,6 +115,7 @@ class AreaChart extends PureComponent {
/>
<Path
{ ...svg }
stroke={ renderLineGradient ? 'url(#line-gradient)' : svg.stroke }
animate={animate}
animationDuration={animationDuration}
d={ line }
Expand Down Expand Up @@ -150,6 +153,7 @@ AreaChart.propTypes = {
gridMax: PropTypes.number,
// see https://github.com/react-native-community/react-native-svg#lineargradient for more info
renderGradient: PropTypes.func,
renderLineGradient: PropTypes.func,
curve: PropTypes.func,
renderGrid: PropTypes.func,
}
Expand Down
6 changes: 6 additions & 0 deletions storybook/stories/gradient.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class GradientExample extends React.PureComponent {
<Stop offset={ '100%' } stopColor={ 'rgb(134, 65, 244)' } stopOpacity={ 0.2 }/>
</LinearGradient>
) }
renderLineGradient={ ({ id }) => (
<LinearGradient id={ id } x1={ '0%' } y={ '0%' } x2={ '0%' } y2={ '100%' }>
<Stop offset={ '0%' } stopColor={ 'rgb(134, 65, 244)' } stopOpacity={ 0.8 }/>
<Stop offset={ '100%' } stopColor={ 'rgb(134, 65, 244)' } stopOpacity={ 0.2 }/>
</LinearGradient>
) }
/>
)
}
Expand Down

0 comments on commit bd6f30a

Please sign in to comment.