@@ -21,6 +21,8 @@ export default class Tree extends React.Component {
2121 this . collapseNode = this . collapseNode . bind ( this ) ;
2222 this . handleNodeToggle = this . handleNodeToggle . bind ( this ) ;
2323 this . handleOnClickCb = this . handleOnClickCb . bind ( this ) ;
24+ this . handleOnMouseOverCb = this . handleOnMouseOverCb . bind ( this ) ;
25+ this . handleOnMouseOutCb = this . handleOnMouseOutCb . bind ( this ) ;
2426 }
2527
2628 componentDidMount ( ) {
@@ -203,6 +205,40 @@ export default class Tree extends React.Component {
203205 }
204206 }
205207
208+ /**
209+ * handleOnMouseOverCb - Handles the user-defined `onMouseOver` function
210+ *
211+ * @param {string } nodeId
212+ *
213+ * @return {void }
214+ */
215+ handleOnMouseOverCb ( nodeId ) {
216+ const { onMouseOver } = this . props ;
217+ if ( onMouseOver && typeof onMouseOver === 'function' ) {
218+ const data = clone ( this . state . data ) ;
219+ const matches = this . findNodesById ( nodeId , data , [ ] ) ;
220+ const targetNode = matches [ 0 ] ;
221+ onMouseOver ( clone ( targetNode ) ) ;
222+ }
223+ }
224+
225+ /**
226+ * handleOnMouseOutCb - Handles the user-defined `onMouseOut` function
227+ *
228+ * @param {string } nodeId
229+ *
230+ * @return {void }
231+ */
232+ handleOnMouseOutCb ( nodeId ) {
233+ const { onMouseOut } = this . props ;
234+ if ( onMouseOut && typeof onMouseOut === 'function' ) {
235+ const data = clone ( this . state . data ) ;
236+ const matches = this . findNodesById ( nodeId , data , [ ] ) ;
237+ const targetNode = matches [ 0 ] ;
238+ onMouseOut ( clone ( targetNode ) ) ;
239+ }
240+ }
241+
206242 /**
207243 * generateTree - Generates tree elements (`nodes` and `links`) by
208244 * grabbing the rootNode from `this.state.data[0]`.
@@ -218,7 +254,7 @@ export default class Tree extends React.Component {
218254 . tree ( )
219255 . nodeSize ( orientation === 'horizontal' ? [ nodeSize . y , nodeSize . x ] : [ nodeSize . x , nodeSize . y ] )
220256 . separation (
221- ( a , b ) => ( deepEqual ( a . parent , b . parent ) ? separation . siblings : separation . nonSiblings ) ,
257+ ( a , b ) => ( a . parent . id === b . parent . id ? separation . siblings : separation . nonSiblings ) ,
222258 )
223259 . children ( d => ( d . _collapsed ? null : d . _children ) ) ;
224260
@@ -289,6 +325,8 @@ export default class Tree extends React.Component {
289325 name = { nodeData . name }
290326 attributes = { nodeData . attributes }
291327 onClick = { this . handleNodeToggle }
328+ onMouseOver = { this . handleOnMouseOverCb }
329+ onMouseOut = { this . handleOnMouseOutCb }
292330 textLayout = { textLayout }
293331 circleRadius = { circleRadius }
294332 subscriptions = { subscriptions }
@@ -310,6 +348,8 @@ Tree.defaultProps = {
310348 } ,
311349 } ,
312350 onClick : undefined ,
351+ onMouseOver : undefined ,
352+ onMouseOut : undefined ,
313353 orientation : 'horizontal' ,
314354 translate : { x : 0 , y : 0 } ,
315355 pathFunc : 'diagonal' ,
@@ -338,6 +378,8 @@ Tree.propTypes = {
338378 shapeProps : PropTypes . object ,
339379 } ) ,
340380 onClick : PropTypes . func ,
381+ onMouseOver : PropTypes . func ,
382+ onMouseOut : PropTypes . func ,
341383 orientation : PropTypes . oneOf ( [ 'horizontal' , 'vertical' ] ) ,
342384 translate : PropTypes . shape ( {
343385 x : PropTypes . number ,
0 commit comments