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

types(Graph, Cell, Element, Link): add JSON and BaseJSON types #2850

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zbynekstara
Copy link
Contributor

@zbynekstara zbynekstara commented Jan 10, 2025

Description

Defines the type of the JSON generated by graph.toJSON() and the type of JSON accepted by graph.fromJSON(). Does so by defining Element.JSON and Link.JSON types to complement existing Cell.JSON type, and by defining a new type Cell.BaseJSON (and corresponding Element.BaseJSON and Link.BaseJSON) which omits the id argument.

  • This is relevant for the graph.fromJSON() method, which accepts an array of Cell.BaseJSON rather than Cell.JSON - it can generate an id for any cells that miss it. This has the practical effect that creators of synthetic graphs do not need to come up with IDs for their graph cells, and JointJS generates them for them using cell.generateId() method behind the scenes.

  • On the other hand, the graph.toJSON() method is defined as using the Cell.JSON type since it always returns cells with IDs. The reason is that these cells come from a real graph object where all IDs have certainly been generated already.

Additionally, splits Link.EndJSON into an OR statement of the signature with end cell ID or end point position, because Link.EndJSON requires exactly one of these sets of arguments to be present (but not both or neither).

@zbynekstara zbynekstara marked this pull request as draft January 14, 2025 03:12
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.

1 participant