Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XAxis/YAxis crash fix #238

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"peerDependencies": {
"react": ">=16.0.0-alpha.12",
"react-native": ">=0.46.0",
"react-native-svg": "^6.2.1"
"react-native-svg": "^6.2.1||^7.0.3"
},
"devDependencies": {
"date-fns": "^1.28.5",
Expand Down
50 changes: 26 additions & 24 deletions src/x-axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import { Text, View } from 'react-native'
import * as d3Scale from 'd3-scale'
import * as array from 'd3-array'
import Svg, { Text as SVGText } from 'react-native-svg'
import Svg, { G, Text as SVGText } from 'react-native-svg'

class XAxis extends PureComponent {

Expand Down Expand Up @@ -99,29 +99,31 @@ class XAxis extends PureComponent {
height,
width,
}}>
{children}
{
// don't render labels if width isn't measured yet,
// causes rendering issues
width > 0 &&
ticks.map((value, index) => {
const { svg: valueSvg = {} } = data[ index ] || {}

return (
<SVGText
textAnchor={ 'middle' }
originX={ x(value) }
alignmentBaseline={ 'hanging' }
{ ...svg }
{ ...valueSvg }
key={ index }
x={ x(value) }
>
{formatLabel(value, index)}
</SVGText>
)
})
}
<G>
JesperLekland marked this conversation as resolved.
Show resolved Hide resolved
{children}
{
// don't render labels if width isn't measured yet,
// causes rendering issues
width > 0 &&
ticks.map((value, index) => {
const { svg: valueSvg = {} } = data[ index ] || {}

return (
<SVGText
textAnchor={ 'middle' }
originX={ x(value) }
alignmentBaseline={ 'hanging' }
{ ...svg }
{ ...valueSvg }
key={ index }
x={ x(value) }
>
{formatLabel(value, index)}
</SVGText>
)
})
}
</G>
</Svg>
}
</View>
Expand Down
46 changes: 24 additions & 22 deletions src/y-axis.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { Text, View } from 'react-native'
import { Svg, Text as SVGText } from 'react-native-svg'
import { Svg, G, Text as SVGText } from 'react-native-svg'
import * as d3Scale from 'd3-scale'
import * as array from 'd3-array'

Expand Down Expand Up @@ -113,27 +113,29 @@ class YAxis extends PureComponent {
height,
width,
}}>
{children}
{
// don't render labels if width isn't measured yet,
// causes rendering issues
height > 0 &&
ticks.map((value, index) => {
return (
<SVGText
originY={ y(value) }
textAnchor={ 'middle' }
x={ '50%' }
alignmentBaseline={ 'middle' }
{ ...svg }
key={ index }
y={ y(value) }
>
{formatLabel(value, index)}
</SVGText>
)
})
}
<G>
{children}
{
// don't render labels if width isn't measured yet,
// causes rendering issues
height > 0 &&
ticks.map((value, index) => {
return (
<SVGText
originY={ y(value) }
textAnchor={ 'middle' }
x={ '50%' }
alignmentBaseline={ 'middle' }
{ ...svg }
key={ index }
y={ y(value) }
>
{formatLabel(value, index)}
</SVGText>
)
})
}
</G>
</Svg>
}
</View>
Expand Down