@@ -36,6 +36,40 @@ function getAxisProps(child, props, calculatedProps) {
36
36
} ;
37
37
}
38
38
39
+ function getBackgroundWithProps ( props , calculatedProps ) {
40
+ const backgroundElement = props . backgroundComponent ;
41
+
42
+ const height = props . polar
43
+ ? calculatedProps . range . y [ 1 ]
44
+ : calculatedProps . range . y [ 0 ] - calculatedProps . range . y [ 1 ] ;
45
+ const width = calculatedProps . range . x [ 1 ] - calculatedProps . range . x [ 0 ] ;
46
+
47
+ const xScale = props . horizontal
48
+ ? calculatedProps . scale . y . range ( ) [ 0 ]
49
+ : calculatedProps . scale . x . range ( ) [ 0 ] ;
50
+ const yScale = props . horizontal
51
+ ? calculatedProps . scale . x . range ( ) [ 1 ]
52
+ : calculatedProps . scale . y . range ( ) [ 1 ] ;
53
+
54
+ const xCoordinate = props . polar ? calculatedProps . origin . x : xScale ;
55
+ const yCoordinate = props . polar ? calculatedProps . origin . y : yScale ;
56
+
57
+ const backgroundProps = {
58
+ height,
59
+ polar : props . polar ,
60
+ scale : calculatedProps . scale ,
61
+ style : props . style . background ,
62
+ x : xCoordinate ,
63
+ y : yCoordinate ,
64
+ width
65
+ } ;
66
+
67
+ return React . cloneElement (
68
+ backgroundElement ,
69
+ defaults ( { } , backgroundElement . props , backgroundProps )
70
+ ) ;
71
+ }
72
+
39
73
function getChildProps ( child , props , calculatedProps ) {
40
74
const axisChild = Axis . findAxisComponents ( [ child ] ) ;
41
75
if ( axisChild . length > 0 ) {
@@ -47,6 +81,7 @@ function getChildProps(child, props, calculatedProps) {
47
81
48
82
function getStyles ( props ) {
49
83
const styleProps = props . style && props . style . parent ;
84
+
50
85
return {
51
86
parent : defaults ( { } , styleProps , {
52
87
height : "100%" ,
@@ -129,6 +164,7 @@ function getChildren(props, childComponents, calculatedProps) {
129
164
const { height, polar, theme, width } = props ;
130
165
const { origin, horizontal } = calculatedProps ;
131
166
const parentName = props . name || "chart" ;
167
+
132
168
return childComponents . map ( ( child , index ) => {
133
169
const role = child . type && child . type . role ;
134
170
const style = Array . isArray ( child . props . style )
@@ -158,21 +194,24 @@ function getChildren(props, childComponents, calculatedProps) {
158
194
159
195
const getChildComponents = ( props , defaultAxes ) => {
160
196
const childComponents = React . Children . toArray ( props . children ) ;
161
- if ( childComponents . length === 0 ) {
162
- return [ defaultAxes . independent , defaultAxes . dependent ] ;
163
- }
197
+ let newChildComponents = [ ...childComponents ] ;
164
198
165
- const axisComponents = {
166
- dependent : Axis . getAxisComponentsWithParent ( childComponents , "dependent" ) ,
167
- independent : Axis . getAxisComponentsWithParent ( childComponents , "independent" )
168
- } ;
199
+ if ( childComponents . length === 0 ) {
200
+ newChildComponents . push ( defaultAxes . independent , defaultAxes . dependent ) ;
201
+ } else {
202
+ const axisComponents = {
203
+ dependent : Axis . getAxisComponentsWithParent ( childComponents , "dependent" ) ,
204
+ independent : Axis . getAxisComponentsWithParent ( childComponents , "independent" )
205
+ } ;
169
206
170
- if ( axisComponents . dependent . length === 0 && axisComponents . independent . length === 0 ) {
171
- return props . prependDefaultAxes
172
- ? [ defaultAxes . independent , defaultAxes . dependent ] . concat ( childComponents )
173
- : childComponents . concat ( [ defaultAxes . independent , defaultAxes . dependent ] ) ;
207
+ if ( axisComponents . dependent . length === 0 && axisComponents . independent . length === 0 ) {
208
+ newChildComponents = props . prependDefaultAxes
209
+ ? [ defaultAxes . independent , defaultAxes . dependent ] . concat ( newChildComponents )
210
+ : newChildComponents . concat ( [ defaultAxes . independent , defaultAxes . dependent ] ) ;
211
+ }
174
212
}
175
- return childComponents ;
213
+
214
+ return newChildComponents ;
176
215
} ;
177
216
178
217
const getDomain = ( props , axis , childComponents ) => {
@@ -252,4 +291,4 @@ const createStringMap = (props, childComponents) => {
252
291
return { x, y } ;
253
292
} ;
254
293
255
- export { getChildren , getCalculatedProps , getChildComponents } ;
294
+ export { getBackgroundWithProps , getChildren , getCalculatedProps , getChildComponents } ;
0 commit comments