Skip to content

Conversation

JesusTheHun
Copy link
Contributor

This PR adds a new optional argument to the serializeGraph function.
Similar to the identity function of deserializeGraph, the new argument is a function that returns a value that uniquely identify a node.

This value is then used when serializing links, leading to a more compact serialization. The serialization of nodes is not affected.

const nodeA = { id: 1, title: 'a' };
const nodeB = { id: 2, title: 'b' };

const graph = new Graph<{ id: number; title: string }>();
graph.addEdge(nodeA, nodeB);

const serialized = serializeGraph(graph);
// { links: [{ source: { id: 1, title: 'a' }, target: { id: 2, title: 'b' } }]}

const serializedWithIdentity = serializeGraph(graph, n => n.id);
// { links: [{ source: 1, target: 2 }]}

Copy link
Member

@curran curran left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you.

@curran curran merged commit 060a179 into datavis-tech:master Dec 4, 2024
@curran
Copy link
Member

curran commented Dec 4, 2024

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