@@ -62,24 +62,24 @@ import { merge, debounce, throwErr } from "../../utils";
6262 * window.alert('Clicked the graph background');
6363 * };
6464 *
65- * const onClickNode = function(nodeId) {
66- * window.alert('Clicked node ${nodeId}');
65+ * const onClickNode = function(nodeId, node ) {
66+ * window.alert('Clicked node ${nodeId} in position (${node.x}, ${node.y}) ');
6767 * };
6868 *
69- * const onDoubleClickNode = function(nodeId) {
70- * window.alert('Double clicked node ${nodeId}');
69+ * const onDoubleClickNode = function(nodeId, node ) {
70+ * window.alert('Double clicked node ${nodeId} in position (${node.x}, ${node.y}) ');
7171 * };
7272 *
73- * const onRightClickNode = function(event, nodeId) {
74- * window.alert('Right clicked node ${nodeId}');
73+ * const onRightClickNode = function(event, nodeId, node ) {
74+ * window.alert('Right clicked node ${nodeId} in position (${node.x}, ${node.y}) ');
7575 * };
7676 *
77- * const onMouseOverNode = function(nodeId) {
78- * window.alert(`Mouse over node ${nodeId}`);
77+ * const onMouseOverNode = function(nodeId, node ) {
78+ * window.alert(`Mouse over node ${nodeId} in position (${node.x}, ${node.y}) `);
7979 * };
8080 *
81- * const onMouseOutNode = function(nodeId) {
82- * window.alert(`Mouse out node ${nodeId}`);
81+ * const onMouseOutNode = function(nodeId, node ) {
82+ * window.alert(`Mouse out node ${nodeId} in position (${node.x}, ${node.y}) `);
8383 * };
8484 *
8585 * const onClickLink = function(source, target) {
@@ -347,6 +347,8 @@ export default class Graph extends React.Component {
347347 * @returns {undefined }
348348 */
349349 onClickNode = clickedNodeId => {
350+ const clickedNode = this . state . nodes [ clickedNodeId ] ;
351+
350352 if ( this . state . config . collapsible ) {
351353 const leafConnections = getTargetLeafConnections ( clickedNodeId , this . state . links , this . state . config ) ;
352354 const links = toggleLinksMatrixConnections ( this . state . links , leafConnections , this . state . config ) ;
@@ -367,7 +369,7 @@ export default class Graph extends React.Component {
367369 d3Links,
368370 } ,
369371 ( ) => {
370- this . props . onClickNode && this . props . onClickNode ( clickedNodeId ) ;
372+ this . props . onClickNode && this . props . onClickNode ( clickedNodeId , clickedNode ) ;
371373
372374 if ( isExpanding ) {
373375 this . _graphNodeDragConfig ( ) ;
@@ -377,16 +379,27 @@ export default class Graph extends React.Component {
377379 } else {
378380 if ( ! this . nodeClickTimer ) {
379381 this . nodeClickTimer = setTimeout ( ( ) => {
380- this . props . onClickNode && this . props . onClickNode ( clickedNodeId ) ;
382+ this . props . onClickNode && this . props . onClickNode ( clickedNodeId , clickedNode ) ;
381383 this . nodeClickTimer = null ;
382384 } , CONST . TTL_DOUBLE_CLICK_IN_MS ) ;
383385 } else {
384- this . props . onDoubleClickNode && this . props . onDoubleClickNode ( clickedNodeId ) ;
386+ this . props . onDoubleClickNode && this . props . onDoubleClickNode ( clickedNodeId , clickedNode ) ;
385387 this . nodeClickTimer = clearTimeout ( this . nodeClickTimer ) ;
386388 }
387389 }
388390 } ;
389391
392+ /**
393+ * Handles right click event on a node.
394+ * @param {Object } event - Right click event.
395+ * @param {string } id - id of the node that participates in the event.
396+ * @returns {undefined }
397+ */
398+ onRightClickNode = ( event , id ) => {
399+ const clickedNode = this . state . nodes [ id ] ;
400+ this . props . onRightClickNode && this . props . onRightClickNode ( event , id , clickedNode ) ;
401+ } ;
402+
390403 /**
391404 * Handles mouse over node event.
392405 * @param {string } id - id of the node that participates in the event.
@@ -397,7 +410,8 @@ export default class Graph extends React.Component {
397410 return ;
398411 }
399412
400- this . props . onMouseOverNode && this . props . onMouseOverNode ( id ) ;
413+ const clickedNode = this . state . nodes [ id ] ;
414+ this . props . onMouseOverNode && this . props . onMouseOverNode ( id , clickedNode ) ;
401415
402416 this . state . config . nodeHighlightBehavior && this . _setNodeHighlightedValue ( id , true ) ;
403417 } ;
@@ -412,7 +426,8 @@ export default class Graph extends React.Component {
412426 return ;
413427 }
414428
415- this . props . onMouseOutNode && this . props . onMouseOutNode ( id ) ;
429+ const clickedNode = this . state . nodes [ id ] ;
430+ this . props . onMouseOutNode && this . props . onMouseOutNode ( id , clickedNode ) ;
416431
417432 this . state . config . nodeHighlightBehavior && this . _setNodeHighlightedValue ( id , false ) ;
418433 } ;
@@ -623,7 +638,7 @@ export default class Graph extends React.Component {
623638 {
624639 onClickNode : this . onClickNode ,
625640 onDoubleClickNode : this . onDoubleClickNode ,
626- onRightClickNode : this . props . onRightClickNode ,
641+ onRightClickNode : this . onRightClickNode ,
627642 onMouseOverNode : this . onMouseOverNode ,
628643 onMouseOut : this . onMouseOutNode ,
629644 } ,
0 commit comments