-
Notifications
You must be signed in to change notification settings - Fork 18
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
Any way to select only node/edge which is clicked #68
Comments
If you are checking the Orb from const orb = new OrbView(container, {
strategy: {
isDefaultSelectEnabled: false,
},
});
let selectedNodeId = null;
orb.events.on(OrbEventType.MOUSE_CLICK, (event) => {
// Clear the previously selected node
if (selectedNodeId !== null) {
const selectedNode = orb.data.getNodeById(selectedNodeId);
selectedNode?.clearState();
selectedNodeId = null;
}
// isNode can be imported from Orb namespace
if (isNode(event.subject)) {
event.subject.state = GraphObjectState.SELECTED;
selectedNodeId = event.subject.id;
}
orb.render();
}); Btw I've used orb.data.getSelectedNodes().forEach(node => node.clearState()); Where you don't need to remember the last selected node. The iteration to slower though because it needs to go through all the nodes to find the selected ones. Just FYI, we plan to change the API a bit to add RxJS so all these setters (like state on the node) will be |
Based on the provided approach, it seems that the code snippet effectively addresses the requirement to select only the clicked node or edge. However, it could be beneficial to have a more flexible solution that allows for passing an argument to control which nodes and edges are selected upon clicking. This could provide greater customization options based on specific use cases. For example, introducing a parameter like By introducing this parameter, users of the Orb library could easily tailor the selection behavior to suit their specific requirements without having to modify the event handling logic each time. It would enhance the flexibility and usability of the library in different scenarios. |
I totally agree about providing greater customization based on specific use cases. I think the
There are so many cases and we can't cover them all with flags, so my thinking is in this direction:
With just these above two changes, the
Additionally, regardless of the two paths (event listener or callback implementation), an update on the // Select the node
node.setState({ state: SELECTED });
// Select the node if not selected, otherwise unselect it
node.setState({ state: SELECTED, options: { isToggle: true }});
// Select the node, but unselect any other node that is currently selected (aka only the single node will be selected)
node.setState({ state: SELECTED, options: { isSingle: true }}}; What do you think? |
Thank you for your valuable insights and suggestions! I fully understand the need for greater customization in select/hover flows and the limitations of a simple flag-based approach. Based on your suggestions, I agree that implementing a structured storage mechanism and introducing the I will work on making these changes into the library as per your recommendations. |
I am thinking of a class with below interface to store nodes and edges id by their state. The StateStorage class will provide methods to update and retrieve nodes and edges with specific states, ensuring easy and quick access. Additionally, I am planning to integrate this class with the graph.ts to ensure that any changes to the state of nodes or edges will be observed by graph.ts which will update the // Define the interface for StateStorage
export interface IStateStorage<N extends INodeBase, E extends IEdgeBase> {
// key defines the state and set contains the node/edge id that belongs to particular state
nodeStateMap: Map<number, Set<number>>;
edgeStateMap: Map<number, Set<number>>;
// update the map, to add particular node/edge to a given state
updateState(graphObject: INode<N, E> | IEdge<N, E>, state: number): void;
// remove node/edge from the map
clearState(graphObject: INode<N, E> | IEdge<N, E>): void;
// clear both nodes and edge state maps
clearAllState(): void;
// returns node id's belonging to given state
getNodesWithState(state: number): Set<number>;
// returns edge id's belonging to given state
getEdgesWithState(state: number): Set<number>;
} @tonilastre Kindly review the approach and provide your valuable feedback. Thank you! |
When any node is selected then its adjacent edges/nodes also gets selected. passing
isDefaultSelectEnabled
to false in strategy does not select any node/edge.any way to select only the node/edge which is clicked ?
The text was updated successfully, but these errors were encountered: