Skip to content

Commit

Permalink
update to 5.0.0 (#7)
Browse files Browse the repository at this point in the history
* update to 5.0.0
  • Loading branch information
JesperLekland authored Apr 15, 2018
1 parent 1833d8d commit 62d5d1a
Show file tree
Hide file tree
Showing 34 changed files with 291 additions and 239 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Click an example to see the code! 💪
[<img src="./screenshots/custom-grid.png" width=33% />](./storybook/stories/custom-grid.js)
[<img src="./screenshots/extras.png" width=33% />](./storybook/stories/extras.js)
[<img src="./screenshots/both-axes.png" width=33% />](./storybook/stories/both-axes.js)
[<img src="./screenshots/decorators.png" width=33% />](./storybook/stories/decorators.js)

## StackedAreaChart

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "16.2.0",
"react-native": "0.53.3",
"react-native-svg": "^6.2.2",
"react-native-svg-charts": "^4.0.0"
"react-native-svg-charts": "^5.0.0"
},
"devDependencies": {
"@storybook/addon-actions": "^3.3.14",
Expand Down
Binary file modified screenshots/decorators.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions storybook/stories/area-chart/with-gradient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AreaChart } from 'react-native-svg-charts'
import { AreaChart, Grid } from 'react-native-svg-charts'
import { Defs, LinearGradient, Stop } from 'react-native-svg'

class GradientExample extends React.PureComponent {
Expand All @@ -22,9 +22,11 @@ class GradientExample extends React.PureComponent {
style={{ height: 200 }}
data={data}
contentInset={{ top: 20, bottom: 20 }}
extras={[ Gradient ]}
svg={{ fill: 'url(#gradient)' }}
/>
>
<Grid/>
<Gradient/>
</AreaChart>
)
}

Expand Down
8 changes: 5 additions & 3 deletions storybook/stories/area-chart/with-line.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { Path } from 'react-native-svg'
import { AreaChart } from 'react-native-svg-charts'
import { AreaChart, Grid } from 'react-native-svg-charts'
import * as shape from 'd3-shape'

class AreaChartExample extends React.PureComponent {
Expand All @@ -25,8 +25,10 @@ class AreaChartExample extends React.PureComponent {
contentInset={{ top: 30, bottom: 30 }}
curve={shape.curveNatural}
svg={{ fill: 'rgba(134, 65, 244, 0.2)' }}
extras={[ Line ]}
/>
>
<Grid/>
<Line/>
</AreaChart>
)
}
}
Expand Down
2 changes: 0 additions & 2 deletions storybook/stories/area-stack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class AreaStackChartExample extends React.PureComponent {
keys={ keys }
colors={ colors }
curve={ shape.curveNatural }
showGrid={ false }
{ ...this.props }
/>
)
}
Expand Down
7 changes: 4 additions & 3 deletions storybook/stories/area-stack/with-y-axis.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { StackedAreaChart, YAxis } from 'react-native-svg-charts'
import { StackedAreaChart, YAxis, Grid } from 'react-native-svg-charts'
import * as shape from 'd3-shape'
import { View } from 'react-native'

Expand Down Expand Up @@ -50,8 +50,9 @@ class AreaStackWithAxisExample extends React.PureComponent {
keys={ keys }
colors={ colors }
curve={ shape.curveNatural }
{ ...this.props }
/>
>
<Grid/>
</StackedAreaChart>
<YAxis
style={ { position: 'absolute', top: 0, bottom: 0 }}
data={ StackedAreaChart.extractDataPoints(data, keys) }
Expand Down
7 changes: 4 additions & 3 deletions storybook/stories/bar-chart/horizontal-grouped.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ class BarChartExample extends React.PureComponent {
fill: 'blue',
}}
horizontal={true}
extras={[ Gradient ]}
contentInset={{ top: 10, bottom: 10 }}
spacing={0.2}
gridMin={0}
renderGrid={Grid.Vertical}
/>
>
<Grid direction={Grid.Direction.VERTICAL}/>
<Gradient/>
</BarChart>
</View>
)
}
Expand Down
5 changes: 3 additions & 2 deletions storybook/stories/bar-chart/horizontal-with-axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ class HorizontaBarChartWithYAxis extends React.PureComponent {
contentInset={{ top: 10, bottom: 10 }}
spacing={0.2}
gridMin={0}
renderGrid={Grid.Vertical}
/>
>
<Grid direction={Grid.Direction.VERTICAL}/>
</BarChart>
</View>
)
}
Expand Down
32 changes: 17 additions & 15 deletions storybook/stories/bar-chart/horizontal-with-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ class BarChartHorizontalWithLabels extends React.PureComponent {
const data = [ 50, 10, 40, 95, 85 ]

const CUT_OFF = 50
const Label = ({ item: value, x, y, index, bandwidth }) => (
<Text
key={index}
x={value > CUT_OFF ? x(value) - 10 : x(value) + 10}
y={y(index) + (bandwidth / 2)}
fontSize={14}
fill={value > CUT_OFF ? 'white' : 'black'}
alignmentBaseline={'middle'}
textAnchor={value > CUT_OFF ? 'end' : 'start'}
>
{value}
</Text>
const Labels = ({ x, y, bandwidth, data }) => (
data.map((value, index) => (
<Text
key={ index }
x={ value > CUT_OFF ? x(0) + 10 : x(value) + 10 }
y={ y(index) + (bandwidth / 2) }
fontSize={ 14 }
fill={ value > CUT_OFF ? 'white' : 'black' }
alignmentBaseline={ 'middle' }
>
{value}
</Text>
))
)

return (
Expand All @@ -34,9 +35,10 @@ class BarChartHorizontalWithLabels extends React.PureComponent {
contentInset={{ top: 10, bottom: 10 }}
spacing={0.2}
gridMin={0}
renderDecorator={Label}
renderGrid={Grid.Vertical}
/>
>
<Grid direction={Grid.Direction.VERTICAL}/>
<Labels/>
</BarChart>
</View>
)
}
Expand Down
7 changes: 4 additions & 3 deletions storybook/stories/bar-chart/horizontal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { View } from 'react-native'
import { BarChart } from 'react-native-svg-charts'
import { BarChart, Grid } from 'react-native-svg-charts'

class BarChartExample extends React.PureComponent {

Expand All @@ -18,8 +18,9 @@ class BarChartExample extends React.PureComponent {
contentInset={{ top: 10, bottom: 10 }}
spacing={0.2}
gridMin={0}
showGrid={false}
/>
>
<Grid direction={Grid.Direction.VERTICAL}/>
</BarChart>
</View>
)
}
Expand Down
8 changes: 5 additions & 3 deletions storybook/stories/bar-chart/with-different-bars.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { BarChart } from 'react-native-svg-charts'
import { BarChart, Grid } from 'react-native-svg-charts'
import { Defs, LinearGradient, Stop } from "react-native-svg";

class ColorBarExample extends React.PureComponent {
Expand Down Expand Up @@ -55,9 +55,11 @@ class ColorBarExample extends React.PureComponent {
gridMin={0}
svg={{ fill: 'rgba(134, 65, 244, 0.8)' }}
yAccessor={({ item }) => item.value}
extras={[ Gradient ]}
contentInset={{ top: 20, bottom: 20 }}
/>
>
<Grid/>
<Gradient/>
</BarChart>
)
}

Expand Down
8 changes: 5 additions & 3 deletions storybook/stories/bar-chart/with-gradient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { LinearGradient, Stop, Defs } from 'react-native-svg'
import { BarChart } from 'react-native-svg-charts'
import { BarChart, Grid } from 'react-native-svg-charts'

class GradientBarExample extends React.PureComponent {

Expand All @@ -22,12 +22,14 @@ class GradientBarExample extends React.PureComponent {
style={ { height: 200 } }
data={ data }
contentInset={ { top: 20, bottom: 20 } }
extras={[ Gradient ]}
svg={ {
strokeWidth: 2,
fill: 'url(#gradient)',
} }
/>
>
<Grid/>
<Gradient/>
</BarChart>
)
}

Expand Down
6 changes: 4 additions & 2 deletions storybook/stories/bar-chart/with-multiple-data-sets.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { BarChart } from 'react-native-svg-charts'
import { BarChart, Grid } from 'react-native-svg-charts'

class GroupedBarChartExample extends React.PureComponent {

Expand Down Expand Up @@ -32,7 +32,9 @@ class GroupedBarChartExample extends React.PureComponent {
}}
contentInset={ { top: 30, bottom: 30 } }
{ ...this.props }
/>
>
<Grid/>
</BarChart>
)
}

Expand Down
6 changes: 4 additions & 2 deletions storybook/stories/both-axes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { LineChart, XAxis, YAxis } from 'react-native-svg-charts'
import { Grid, LineChart, XAxis, YAxis } from 'react-native-svg-charts'
import { View } from 'react-native'

class AxesExample extends React.PureComponent {
Expand Down Expand Up @@ -32,7 +32,9 @@ class AxesExample extends React.PureComponent {
data={data}
contentInset={verticalContentInset}
svg={{ stroke: 'rgb(134, 65, 244)' }}
/>
>
<Grid/>
</LineChart>
<XAxis
style={{ marginHorizontal: -10, height: xAxisHeight }}
data={data}
Expand Down
5 changes: 3 additions & 2 deletions storybook/stories/custom-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class CustomGridExample extends React.PureComponent {
svg={ {
stroke: 'rgb(134, 65, 244)',
} }
renderGrid={ CustomGrid }
/>
>
<CustomGrid belowChart={true}/>
</LineChart>
</View>
)
}
Expand Down
47 changes: 31 additions & 16 deletions storybook/stories/decorator.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
import React from 'react'
import { AreaChart } from 'react-native-svg-charts'
import { Circle } from 'react-native-svg'
import { AreaChart, Grid } from 'react-native-svg-charts'
import { Circle, Path } from 'react-native-svg'

class DecoratorExample extends React.PureComponent {

render() {

const data = [ 50, 10, 40, 95, -4, -24, 85, 91, 35, 53, -53, 24, 50, -20, -80 ]

const Decorator = ({ x, y, data }) => {
return data.map((value, index) => (
<Circle
key={ index }
cx={ x(index) }
cy={ y(value) }
r={ 4 }
stroke={ 'rgb(134, 65, 244)' }
fill={ 'white' }
/>
))
}

const Line = ({ line }) => (
<Path
d={ line }
stroke={ 'rgba(134, 65, 244)' }
fill={ 'none' }
/>
)

return (
<AreaChart
style={ { height: 200 } }
style={{ height: 200 }}
data={ data }
svg={ { fill: 'rgba(134, 65, 244, 0.2)' } }
contentInset={ { top: 20, bottom: 30 } }
renderDecorator={ ({ x, y, index, value }) => (
<Circle
key={ index }
cx={ x(index) }
cy={ y(value) }
r={ 4 }
stroke={ 'rgb(134, 65, 244)' }
fill={ 'white' }
/>
) }
/>
svg={{ fill: 'rgba(134, 65, 244, 0.2)' }}
contentInset={{ top: 20, bottom: 30 }}
>
<Grid/>
<Line/>
<Decorator/>
</AreaChart>
)
}

Expand Down
19 changes: 11 additions & 8 deletions storybook/stories/extras.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { LineChart } from 'react-native-svg-charts'
import { LineChart, Grid } from 'react-native-svg-charts'
import * as shape from 'd3-shape'
import { Circle, G, Line, Rect, Text } from 'react-native-svg'

Expand Down Expand Up @@ -43,8 +43,8 @@ class ExtrasExample extends React.PureComponent {
/>
<Text
x={ 75 / 2 }
dy={20}
alignmentBaseline={'middle'}
dy={ 20 }
alignmentBaseline={ 'middle' }
textAnchor={ 'middle' }
stroke={ 'rgb(134, 65, 244)' }
>
Expand All @@ -62,7 +62,7 @@ class ExtrasExample extends React.PureComponent {
cy={ y(data[ 5 ]) }
r={ 6 }
stroke={ 'rgb(134, 65, 244)' }
strokeWidth={2}
strokeWidth={ 2 }
fill={ 'white' }
/>
</G>
Expand All @@ -71,16 +71,19 @@ class ExtrasExample extends React.PureComponent {

return (
<LineChart
style={ { height: 200 } }
style={{ height: 200 }}
data={ data }
svg={{
stroke: 'rgb(134, 65, 244)',
strokeWidth: 2,
}}
contentInset={ { top: 20, bottom: 20 } }
contentInset={{ top: 20, bottom: 20 }}
curve={ shape.curveLinear }
extras={ [ HorizontalLine, Tooltip ] }
/>
>
<Grid/>
<HorizontalLine/>
<Tooltip/>
</LineChart>
)
}

Expand Down
Loading

0 comments on commit 62d5d1a

Please sign in to comment.