Skip to content
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

refactor(graph): optimize graph api, improve docs #6792

Open
wants to merge 1 commit into
base: v5
Choose a base branch
from

Conversation

Aarebecca
Copy link
Contributor

  • Optimize getNodeDatagetEdgeDatagetComboData API performance
  • Improve above APIs docs

Relative Issue: #6784

Copy link

Walkthrough

This pull request refactors the graph API by optimizing the performance of getNodeData, getEdgeData, and getComboData methods. It also enhances the documentation for these APIs, ensuring clarity on the necessity of existing IDs to avoid exceptions.

Changes

File Summary
packages/g6/src/runtime/graph.ts Optimized the methods getNodeData, getEdgeData, and getComboData by changing the way data is retrieved, replacing array-based retrieval with direct datum access. Added remarks in the documentation to clarify that IDs must exist to prevent exceptions.

*/
public getNodeData(ids: ID[]): NodeData[];
public getNodeData(id?: ID | ID[]): NodeData | NodeData[] {
if (id === undefined) return this.context.model.getNodeData();
if (Array.isArray(id)) return this.context.model.getNodeData(id);
return this.context.model.getNodeData([id])?.[0];
return this.context.model.getNodeLikeDatum(id);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from getNodeData([id])?.[0] to getNodeLikeDatum(id) improves performance by directly accessing the node datum without wrapping it in an array. Ensure that getNodeLikeDatum handles non-existent IDs appropriately to avoid runtime errors.

*/
public getEdgeData(ids: ID[]): EdgeData[];
public getEdgeData(id?: ID | ID[]): EdgeData | EdgeData[] {
if (id === undefined) return this.context.model.getEdgeData();
if (Array.isArray(id)) return this.context.model.getEdgeData(id);
return this.context.model.getEdgeData([id])?.[0];
return this.context.model.getEdgeDatum(id);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from getEdgeData([id])?.[0] to getEdgeDatum(id) enhances performance by directly accessing the edge datum. Verify that getEdgeDatum properly manages cases where the ID does not exist to prevent potential exceptions.

*/
public getComboData(ids: ID[]): ComboData[];
public getComboData(id?: ID | ID[]): ComboData | ComboData[] {
if (id === undefined) return this.context.model.getComboData();
if (Array.isArray(id)) return this.context.model.getComboData(id);
return this.context.model.getComboData([id])?.[0];
return this.context.model.getNodeLikeDatum(id);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update from getComboData([id])?.[0] to getNodeLikeDatum(id) optimizes the retrieval process by directly accessing the combo datum. Confirm that getNodeLikeDatum correctly handles scenarios where the combo ID is missing to avoid errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants