-
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
Node Collapse #83
Node Collapse #83
Conversation
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.
- Should we toggle also connections from the parent node -> leaf node? I think we could leave this to a next iteration, still, I'm curious whether we could make this work with your current approach since you are preserving the matrix maybe we could apply something like the command pattern to undo/redo collapse interactions.
Nice job @svipatov! Thanks for putting your effort on this!
sandbox/data/default.js
Outdated
@@ -90,7 +90,19 @@ module.exports = { | |||
}, | |||
{ | |||
source: 'VUX', | |||
target: 'Intruder' | |||
target: 'Intruder 1' |
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.
It might be useful to have a specific data set (for instance collapsible) for this feature, this can be done by doing the following:
- Create a folder under
sandbox/data/collapsible
- Add a config and a data file where you can tweak the data and configs in a more convenient way (collapsible.config.js and collapsible.data.js)
- Load the dataset in the sandbox by adding a query parameter to the url:
?data=collapsible
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.
Sounds like an excelent idea! I can create another PR with this feature included without a doubt.
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.
Maybe this could be useful for this PR in order for us to do some functional tests on top of the dataset.
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.
You are correct, haven't thought about the functional tests in this context.
src/components/graph/Graph.jsx
Outdated
@@ -358,11 +358,74 @@ export default class Graph extends React.Component { | |||
this.pauseSimulation(); | |||
} | |||
|
|||
_toggleNodeConnection(targetNodeId, allConnections) { |
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.
_toggleNodeConnection
and _getLeafNodeConnections
could be moved into graph.helper.js
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.
Agree completely, at the time of the submission I decided to wait for your input where would be the best place for these functions :)
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.
These have been moved! :)
src/components/graph/Graph.jsx
Outdated
} | ||
|
||
onClickNode = clickedNodeId => { | ||
const currentConnections = this.state.links; |
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.
We could move all logic from line 387
to 411
in a separate function (maybe collapseNodes
) the ouputs would be toggledLeafNodes
and a new d3Links
structure
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.
We could, and we should.
I also attempted this separation, so in the future this could be done to any node.
But it may need a few tweaks to be a bit more resilient for other nodes (not just leaves).
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.
I've moved this function for now into graph.helper.js
. The discussion above could be a future concern :)
return Object.keys(nodes) | ||
.filter( | ||
nodeId => | ||
!!Object.values(linksMatrix[nodeId]).reduce( |
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.
Maybe move this to a function countActiveNeighbours
?
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.
Sounds good!
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.
I've created a getNodeCardinality
in graph.helper.js
.
Tell me what you think about the name. I felt that this way the name doesn't bind it directly to the concept of being active
, but rather knowing how many nodes it has attached.
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.
But aren't we hiding the purpose of the function by detaching the name from knowing how many nodes it has attached
?
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.
We discussed this and the conclusion was that the name does make sense as being getNodeCardinality
:)
Mostly so that it can be used in other contexts, and still making its responsibility transparent
A config should be added, to
|
…links to the graph.helper.js
…links to the graph.helper.js
7ce030e
to
93238fc
Compare
Thanks for approving! I have not been able to add some functional tests yet. I'll try to find some time soon to do those! |
…e of numeric ID's usage.
…eact-d3-graph into feature/node-collapse
@danielcaldas I've added a small functional test to verify the functionality :) However I've had to change Solutions:
Tell me which one you think best? (The culprit is in https://github.com/danielcaldas/react-d3-graph/pull/83/files#diff-f1693f8128c0a5fd1fd1ac84b9fd38cbR427) |
The ids from This has affected the component in the past, for instance here #73. Nice job with the testing tough!! |
I assumed it had a purpose correctly then. I'll implement your suggestion! Thank you :) |
@danielcaldas I've corrected it! :) https://media.giphy.com/media/xT5LMQK2y8LCyb5mP6/giphy.gif |
@danielcaldas
When possible give it a look please.
_toggleNodeConnection
for toggling a node connection inthis.state.links
._getLeafNodeConnections
for finding leaf node connections based on a starting node id.links
matrix.isHidden
is added to thethis.state.d3links
.Possible improvements:
parent node
->leaf node
?isHidden
being added as a default.After a review I'll get started on testing and validating.