@@ -94,27 +94,24 @@ function _getScaleFns(props) {
94
94
/**
95
95
* Adds padding in desired directions to treemapingFunction.
96
96
* @param {Function } treemapingFunction function to update.
97
- * @param {Number } padding value in pixels.
98
- * @param {Array } paddingDirections .
99
- * @returns {Function } treemapingFunction, updated with padding.
97
+ * @param {Object } sidePadding .
98
+ * @returns {Function } treemapingFunction, updated with side padding.
100
99
* @private
101
100
*/
102
- function _applyPadding ( treemapingFunction , padding , paddingDirections ) {
103
- if ( ! paddingDirections ) {
104
- return treemapingFunction . padding ( padding ) ;
101
+ function _applySidePadding ( treemapingFunction , sidePadding ) {
102
+ if ( ! sidePadding ) {
103
+ return treemapingFunction ;
105
104
}
106
105
const directionToProperty = {
107
106
'left' : 'paddingLeft' ,
108
107
'right' : 'paddingRight' ,
109
108
'bottom' : 'paddingBottom' ,
110
109
'top' : 'paddingTop' ,
111
110
} ;
112
- let i = 0 ;
113
- paddingDirections . forEach ( direction => {
114
- const property = directionToProperty [ direction ] ;
115
- const paddingForDirection = Array . isArray ( padding ) ? padding [ i ] : padding ;
116
- i += 1 ;
117
- treemapingFunction = treemapingFunction [ property ] ( paddingForDirection ) ;
111
+ Object . entries ( sidePadding ) . forEach ( entry => {
112
+ const [ direction , padding ] = entry ;
113
+ const functionProperty = directionToProperty [ direction ] ;
114
+ treemapingFunction = treemapingFunction [ functionProperty ] ( padding ) ;
118
115
} ) ;
119
116
return treemapingFunction ;
120
117
}
@@ -142,7 +139,7 @@ class Treemap extends React.Component {
142
139
*/
143
140
_getNodesToRender ( ) {
144
141
const { innerWidth, innerHeight} = this . state ;
145
- const { data, mode, padding, sortFunction, getSize, paddingDirections } = this . props ;
142
+ const { data, mode, padding, sortFunction, getSize, sidePadding } = this . props ;
146
143
if ( ! data ) {
147
144
return [ ] ;
148
145
}
@@ -181,9 +178,10 @@ class Treemap extends React.Component {
181
178
}
182
179
183
180
const tileFn = TREEMAP_TILE_MODES [ mode ] ;
184
- const treemapingFunction = _applyPadding ( treemap ( tileFn )
181
+ const treemapingFunction = _applySidePadding ( treemap ( tileFn )
185
182
. tile ( tileFn )
186
- . size ( [ innerWidth , innerHeight ] ) , padding , paddingDirections ) ;
183
+ . size ( [ innerWidth , innerHeight ] )
184
+ . padding ( padding ) , sidePadding ) ;
187
185
const structuredInput = hierarchy ( data )
188
186
. sum ( getSize )
189
187
. sort ( ( a , b ) => sortFunction ( a , b , getSize ) ) ;
@@ -214,8 +212,13 @@ Treemap.propTypes = {
214
212
onLeafMouseOver : PropTypes . func ,
215
213
onLeafMouseOut : PropTypes . func ,
216
214
useCirclePacking : PropTypes . bool ,
217
- padding : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . arrayOf ( PropTypes . number ) ] ) . isRequired ,
218
- paddingDirections : PropTypes . arrayOf ( PropTypes . oneOf ( [ 'left' , 'right' , 'top' , 'bottom' ] ) ) ,
215
+ padding : PropTypes . number . isRequired ,
216
+ sidePadding : PropTypes . shape ( {
217
+ 'left' : PropTypes . number ,
218
+ 'right' : PropTypes . number ,
219
+ 'top' : PropTypes . number ,
220
+ 'bottom' : PropTypes . number ,
221
+ } ) ,
219
222
sortFunction : PropTypes . func ,
220
223
width : PropTypes . number . isRequired ,
221
224
getSize : PropTypes . func ,
@@ -238,7 +241,7 @@ Treemap.defaultProps = {
238
241
opacityType : OPACITY_TYPE ,
239
242
_opacityValue : DEFAULT_OPACITY ,
240
243
padding : 1 ,
241
- paddingDirections : null ,
244
+ sidePadding : null ,
242
245
sortFunction : ( a , b , accessor ) => {
243
246
if ( ! accessor ) {
244
247
return 0 ;
0 commit comments