@@ -91,6 +91,31 @@ function _getScaleFns(props) {
9191 } ;
9292}
9393
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+
94119class Treemap extends React . Component {
95120 constructor ( props ) {
96121 super ( props ) ;
@@ -114,7 +139,7 @@ class Treemap extends React.Component {
114139 */
115140 _getNodesToRender ( ) {
116141 const { innerWidth, innerHeight} = this . state ;
117- const { data, mode, padding, sortFunction, getSize} = this . props ;
142+ const { data, mode, padding, sortFunction, getSize, paddingDirections } = this . props ;
118143 if ( ! data ) {
119144 return [ ] ;
120145 }
@@ -153,10 +178,9 @@ class Treemap extends React.Component {
153178 }
154179
155180 const tileFn = TREEMAP_TILE_MODES [ mode ] ;
156- const treemapingFunction = treemap ( tileFn )
181+ const treemapingFunction = _applyPadding ( treemap ( tileFn )
157182 . tile ( tileFn )
158- . size ( [ innerWidth , innerHeight ] )
159- . padding ( padding ) ;
183+ . size ( [ innerWidth , innerHeight ] ) , padding , paddingDirections ) ;
160184 const structuredInput = hierarchy ( data )
161185 . sum ( getSize )
162186 . sort ( ( a , b ) => sortFunction ( a , b , getSize ) ) ;
@@ -188,6 +212,7 @@ Treemap.propTypes = {
188212 onLeafMouseOut : PropTypes . func ,
189213 useCirclePacking : PropTypes . bool ,
190214 padding : PropTypes . number . isRequired ,
215+ paddingDirections : PropTypes . arrayOf ( PropTypes . oneOf ( [ 'left' , 'right' , 'top' , 'bottom' ] ) ) ,
191216 sortFunction : PropTypes . func ,
192217 width : PropTypes . number . isRequired ,
193218 getSize : PropTypes . func ,
@@ -210,6 +235,7 @@ Treemap.defaultProps = {
210235 opacityType : OPACITY_TYPE ,
211236 _opacityValue : DEFAULT_OPACITY ,
212237 padding : 1 ,
238+ paddingDirections : null ,
213239 sortFunction : ( a , b , accessor ) => {
214240 if ( ! accessor ) {
215241 return 0 ;
0 commit comments