Skip to content

Commit 006e633

Browse files
Merge pull request #238 from krzysztof-miemiec/fix-for-axis
XAxis/YAxis crash fix
2 parents c9f5c39 + d12d1f1 commit 006e633

File tree

3 files changed

+51
-47
lines changed

3 files changed

+51
-47
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"peerDependencies": {
5555
"react": ">=16.0.0-alpha.12",
5656
"react-native": ">=0.46.0",
57-
"react-native-svg": "^6.2.1"
57+
"react-native-svg": "^6.2.1||^7.0.3"
5858
},
5959
"devDependencies": {
6060
"date-fns": "^1.28.5",

src/x-axis.js

+26-24
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
33
import { Text, View } from 'react-native'
44
import * as d3Scale from 'd3-scale'
55
import * as array from 'd3-array'
6-
import Svg, { Text as SVGText } from 'react-native-svg'
6+
import Svg, { G, Text as SVGText } from 'react-native-svg'
77

88
class XAxis extends PureComponent {
99

@@ -99,29 +99,31 @@ class XAxis extends PureComponent {
9999
height,
100100
width,
101101
}}>
102-
{children}
103-
{
104-
// don't render labels if width isn't measured yet,
105-
// causes rendering issues
106-
width > 0 &&
107-
ticks.map((value, index) => {
108-
const { svg: valueSvg = {} } = data[ index ] || {}
109-
110-
return (
111-
<SVGText
112-
textAnchor={ 'middle' }
113-
originX={ x(value) }
114-
alignmentBaseline={ 'hanging' }
115-
{ ...svg }
116-
{ ...valueSvg }
117-
key={ index }
118-
x={ x(value) }
119-
>
120-
{formatLabel(value, index)}
121-
</SVGText>
122-
)
123-
})
124-
}
102+
<G>
103+
{children}
104+
{
105+
// don't render labels if width isn't measured yet,
106+
// causes rendering issues
107+
width > 0 &&
108+
ticks.map((value, index) => {
109+
const { svg: valueSvg = {} } = data[ index ] || {}
110+
111+
return (
112+
<SVGText
113+
textAnchor={ 'middle' }
114+
originX={ x(value) }
115+
alignmentBaseline={ 'hanging' }
116+
{ ...svg }
117+
{ ...valueSvg }
118+
key={ index }
119+
x={ x(value) }
120+
>
121+
{formatLabel(value, index)}
122+
</SVGText>
123+
)
124+
})
125+
}
126+
</G>
125127
</Svg>
126128
}
127129
</View>

src/y-axis.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PureComponent } from 'react'
22
import PropTypes from 'prop-types'
33
import { Text, View } from 'react-native'
4-
import { Svg, Text as SVGText } from 'react-native-svg'
4+
import { Svg, G, Text as SVGText } from 'react-native-svg'
55
import * as d3Scale from 'd3-scale'
66
import * as array from 'd3-array'
77

@@ -113,27 +113,29 @@ class YAxis extends PureComponent {
113113
height,
114114
width,
115115
}}>
116-
{children}
117-
{
118-
// don't render labels if width isn't measured yet,
119-
// causes rendering issues
120-
height > 0 &&
121-
ticks.map((value, index) => {
122-
return (
123-
<SVGText
124-
originY={ y(value) }
125-
textAnchor={ 'middle' }
126-
x={ '50%' }
127-
alignmentBaseline={ 'middle' }
128-
{ ...svg }
129-
key={ index }
130-
y={ y(value) }
131-
>
132-
{formatLabel(value, index)}
133-
</SVGText>
134-
)
135-
})
136-
}
116+
<G>
117+
{children}
118+
{
119+
// don't render labels if width isn't measured yet,
120+
// causes rendering issues
121+
height > 0 &&
122+
ticks.map((value, index) => {
123+
return (
124+
<SVGText
125+
originY={ y(value) }
126+
textAnchor={ 'middle' }
127+
x={ '50%' }
128+
alignmentBaseline={ 'middle' }
129+
{ ...svg }
130+
key={ index }
131+
y={ y(value) }
132+
>
133+
{formatLabel(value, index)}
134+
</SVGText>
135+
)
136+
})
137+
}
138+
</G>
137139
</Svg>
138140
}
139141
</View>

0 commit comments

Comments
 (0)