-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add onClick handler to the canvas, for use in eg. unselecting nodes #113
Changes from 3 commits
5d2b58c
7a14c3d
456b2ae
1bc050e
b062fa6
819ea1e
095f44c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -372,6 +372,23 @@ export default class Graph extends React.Component { | |
this.props.onClickNode && this.props.onClickNode(clickedNodeId); | ||
}; | ||
|
||
/** | ||
* Calls the callback passed to the component. | ||
* @param {string} e - The event of onClick handler. | ||
* @returns {undefined} | ||
*/ | ||
onClickGraph = e => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add this method to the component documentation, just follow the example of one of the functions there like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added it to Readme docs. Is there anywhere else you would like me to add it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please add it as well to the |
||
// Only trigger the graph onClickHandler, if not clicked a node or link. | ||
// toUpperCase() is added as a precaution, as the documentation says tagName should always | ||
// return in UPPERCASE, but chrome returns lowercase | ||
if ( | ||
e.target.tagName.toUpperCase() === 'SVG' && | ||
e.target.attributes.name.value === `svg-container-${this.state.id}` | ||
) { | ||
this.props.onClickGraph && this.props.onClickGraph(); | ||
} | ||
}; | ||
|
||
render() { | ||
const { nodes, links } = graphRenderer.buildGraph( | ||
this.state.nodes, | ||
|
@@ -400,7 +417,7 @@ export default class Graph extends React.Component { | |
|
||
return ( | ||
<div id={`${this.state.id}-${CONST.GRAPH_WRAPPER_ID}`}> | ||
<svg style={svgStyle}> | ||
<svg name={`svg-container-${this.state.id}`} style={svgStyle} onClick={this.onClickGraph}> | ||
<g id={`${this.state.id}-${CONST.GRAPH_CONTAINER_ID}`}> | ||
{links} | ||
{nodes} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@param {Object}
e
is an Object not a string