@@ -91,6 +91,31 @@ function _getScaleFns(props) {
91
91
} ;
92
92
}
93
93
94
+ /**
95
+ * Adds padding in desired directions to treemapingFunction.
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.
100
+ * @private
101
+ */
102
+ function _applyPadding ( treemapingFunction , padding , paddingDirections ) {
103
+ if ( ! paddingDirections ) {
104
+ return treemapingFunction . padding ( padding ) ;
105
+ }
106
+ const directionToProperty = {
107
+ 'left' : 'paddingLeft' ,
108
+ 'right' : 'paddingRight' ,
109
+ 'bottom' : 'paddingBottom' ,
110
+ 'top' : 'paddingTop' ,
111
+ } ;
112
+ paddingDirections . forEach ( direction => {
113
+ const property = directionToProperty [ direction ] ;
114
+ treemapingFunction = treemapingFunction [ property ] ( padding ) ;
115
+ } ) ;
116
+ return treemapingFunction ;
117
+ }
118
+
94
119
class Treemap extends React . Component {
95
120
constructor ( props ) {
96
121
super ( props ) ;
@@ -114,7 +139,7 @@ class Treemap extends React.Component {
114
139
*/
115
140
_getNodesToRender ( ) {
116
141
const { innerWidth, innerHeight} = this . state ;
117
- const { data, mode, padding, sortFunction, getSize} = this . props ;
142
+ const { data, mode, padding, sortFunction, getSize, paddingDirections } = this . props ;
118
143
if ( ! data ) {
119
144
return [ ] ;
120
145
}
@@ -153,10 +178,9 @@ class Treemap extends React.Component {
153
178
}
154
179
155
180
const tileFn = TREEMAP_TILE_MODES [ mode ] ;
156
- const treemapingFunction = treemap ( tileFn )
181
+ const treemapingFunction = _applyPadding ( treemap ( tileFn )
157
182
. tile ( tileFn )
158
- . size ( [ innerWidth , innerHeight ] )
159
- . padding ( padding ) ;
183
+ . size ( [ innerWidth , innerHeight ] ) , padding , paddingDirections ) ;
160
184
const structuredInput = hierarchy ( data )
161
185
. sum ( getSize )
162
186
. sort ( ( a , b ) => sortFunction ( a , b , getSize ) ) ;
@@ -188,6 +212,7 @@ Treemap.propTypes = {
188
212
onLeafMouseOut : PropTypes . func ,
189
213
useCirclePacking : PropTypes . bool ,
190
214
padding : PropTypes . number . isRequired ,
215
+ paddingDirections : PropTypes . arrayOf ( PropTypes . oneOf ( [ 'left' , 'right' , 'top' , 'bottom' ] ) ) ,
191
216
sortFunction : PropTypes . func ,
192
217
width : PropTypes . number . isRequired ,
193
218
getSize : PropTypes . func ,
@@ -210,6 +235,7 @@ Treemap.defaultProps = {
210
235
opacityType : OPACITY_TYPE ,
211
236
_opacityValue : DEFAULT_OPACITY ,
212
237
padding : 1 ,
238
+ paddingDirections : null ,
213
239
sortFunction : ( a , b , accessor ) => {
214
240
if ( ! accessor ) {
215
241
return 0 ;
0 commit comments