@@ -94,27 +94,24 @@ function _getScaleFns(props) {
9494/**
9595 * Adds padding in desired directions to treemapingFunction.
9696 * @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.
10099 * @private
101100 */
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 ;
105104 }
106105 const directionToProperty = {
107106 'left' : 'paddingLeft' ,
108107 'right' : 'paddingRight' ,
109108 'bottom' : 'paddingBottom' ,
110109 'top' : 'paddingTop' ,
111110 } ;
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 ) ;
118115 } ) ;
119116 return treemapingFunction ;
120117}
@@ -142,7 +139,7 @@ class Treemap extends React.Component {
142139 */
143140 _getNodesToRender ( ) {
144141 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 ;
146143 if ( ! data ) {
147144 return [ ] ;
148145 }
@@ -181,9 +178,10 @@ class Treemap extends React.Component {
181178 }
182179
183180 const tileFn = TREEMAP_TILE_MODES [ mode ] ;
184- const treemapingFunction = _applyPadding ( treemap ( tileFn )
181+ const treemapingFunction = _applySidePadding ( treemap ( tileFn )
185182 . tile ( tileFn )
186- . size ( [ innerWidth , innerHeight ] ) , padding , paddingDirections ) ;
183+ . size ( [ innerWidth , innerHeight ] )
184+ . padding ( padding ) , sidePadding ) ;
187185 const structuredInput = hierarchy ( data )
188186 . sum ( getSize )
189187 . sort ( ( a , b ) => sortFunction ( a , b , getSize ) ) ;
@@ -214,8 +212,13 @@ Treemap.propTypes = {
214212 onLeafMouseOver : PropTypes . func ,
215213 onLeafMouseOut : PropTypes . func ,
216214 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+ } ) ,
219222 sortFunction : PropTypes . func ,
220223 width : PropTypes . number . isRequired ,
221224 getSize : PropTypes . func ,
@@ -238,7 +241,7 @@ Treemap.defaultProps = {
238241 opacityType : OPACITY_TYPE ,
239242 _opacityValue : DEFAULT_OPACITY ,
240243 padding : 1 ,
241- paddingDirections : null ,
244+ sidePadding : null ,
242245 sortFunction : ( a , b , accessor ) => {
243246 if ( ! accessor ) {
244247 return 0 ;
0 commit comments