Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/chart.js
#	src/pie-chart.js
#	src/progress-circle.js
#	src/x-axis.js
#	src/y-axis.js
  • Loading branch information
JesperLekland committed Apr 15, 2018
2 parents 79799c8 + abf0f44 commit fb29199
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 36 deletions.
21 changes: 6 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@

* **Support for styles xAxis labels**
* **Support for horizontal StackedBarChart**

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.
Thanks to @fqueiruga for this ❤️
StackedBarChart now supports the prop `horizontal`
just as a regular BarChart


* **Support for backgroundColor in ProgressCircle**

You can now customize the progress "background" color

* **Support for strokeWidth in ProgressCircle**

Customize the width of the ProgressCircle

* **Prettier transition in ProgressCircle from progress to background**

Old implementation used to have a small cutoff between the progress and the background.
Now the progress seems to be "inside" the circle instead.
* **StackedBar/AreaChart adheres to new `extras` api**

StackedBarChart and StackedAreaChart was still on the legacy `renderExtras`
pattern. It has now been migrated to the single `extras` prop api.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ yarn storybook
| renderGrid | `Grid.Horizontal` | A function that returns the component to be rendered as the grid |
| extras | undefined | An array of whatever data you want to render. Each item in the array will call `renderExtra`. [See example](#extras) |
| renderDecorator | `() => {}`| Called once for each entry in `dataPoints` and expects a component. Use this prop to render e.g points (circles) on each data point. [See example](#decorator) |
| renderOrder | `[ 'grid', 'chart', 'decorators', 'extras' ]` | A function, returning an array of strings, defining the order in which components should be rendered. First item from array gets rendered first.

## Components

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": "4.1.0",
"version": "4.2.0",
"private": false,
"description": "Customizable charts (Line, Bar, Area, Pie, Circle, Progress) for React Native",
"main": "src/index.js",
Expand Down
32 changes: 13 additions & 19 deletions src/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as shape from 'd3-shape'
import PropTypes from 'prop-types'
import React, { PureComponent } from 'react'
import { View } from 'react-native'
import Svg, { G } from 'react-native-svg'
import Svg from 'react-native-svg'
import Path from './animated-path'
import Grid from './grid'

Expand All @@ -15,10 +15,6 @@ class Chart extends PureComponent {
height: 0,
}

_getComponentOrder(key) {
return this.props.renderOrder().findIndex(o => o === key)
}

_onLayout(event) {
const { nativeEvent: { layout: { height, width } } } = event
this.setState({ height, width })
Expand Down Expand Up @@ -98,20 +94,20 @@ class Chart extends PureComponent {
...paths,
}

const components = [
{ key: 'grid', render: () => showGrid && renderGrid({ x, y, ticks, data, gridProps }) },
{ key: 'chart', render: () => <Path fill={ 'none' } { ...svg } d={ paths.path } animate={ animate } animationDuration={ animationDuration }/> },
{ key: 'decorators', render: () => data.map((value, index) => renderDecorator({ x, y, value, index })) },
{ key: 'extras', render: () => extras.map((item, index) => item({ ...extraData, index })) },
]
.filter(it => this._getComponentOrder(it.key) > -1)
.sort((a,b) => this._getComponentOrder(a.key) > this._getComponentOrder(b.key) ? 1 : -1)

return (
<View style={ style }>
<View style={{ flex: 1 }} onLayout={ event => this._onLayout(event) }>
<Svg style={{ flex: 1 }}>
{ components.map((it, i) => <G key={ i }>{it.render(i)}</G>) }
{showGrid && renderGrid({ x, y, ticks, data, gridProps })}
<Path
fill={ 'none' }
{ ...svg }
d={ paths.path }
animate={ animate }
animationDuration={ animationDuration }
/>
{data.map((value, index) => renderDecorator({ x, y, value, index }))}
{extras.map((item, index) => item({ ...extraData, index }))}
</Svg>
</View>
</View>
Expand Down Expand Up @@ -154,8 +150,6 @@ Chart.propTypes = {

xAccessor: PropTypes.func,
yAccessor: PropTypes.func,

renderOrder: PropTypes.func,
}

Chart.defaultProps = {
Expand All @@ -171,8 +165,8 @@ Chart.defaultProps = {
yScale: scale.scaleLinear,
xAccessor: ({ index }) => index,
yAccessor: ({ item }) => item,
renderDecorator: () => {},
renderOrder: () => [ 'grid', 'chart', 'decorators', 'extras' ],
renderDecorator: () => {
},
}

export default Chart
2 changes: 2 additions & 0 deletions src/x-axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class XAxis extends PureComponent {
formatLabel,
numberOfTicks,
svg,
children,
} = this.props

const { width } = this.state
Expand All @@ -86,6 +87,7 @@ class XAxis extends PureComponent {
{ formatLabel(ticks[0], 0) }
</Text>
<Svg style={ StyleSheet.absoluteFill }>
{children}
{
// don't render labels if width isn't measured yet,
// causes rendering issues
Expand Down
2 changes: 2 additions & 0 deletions src/y-axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class YAxis extends PureComponent {
min,
max,
svg,
children,
} = this.props

const { height } = this.state
Expand Down Expand Up @@ -99,6 +100,7 @@ class YAxis extends PureComponent {
{longestValue}
</Text>
<Svg style={ StyleSheet.absoluteFill }>
{children}
{
// don't render labels if width isn't measured yet,
// causes rendering issues
Expand Down

0 comments on commit fb29199

Please sign in to comment.