Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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 generic type Cell.SyntheticJSON which marks the id argument of a provided JSON object as optional.

  • This is relevant for the graph.fromJSON() method, which accepts an array of Cell.SyntheticJSON<Cell.JSON> 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.

More precisely, graph.toJSON() actually works with an array of Element.JSON and/or Link.JSON items, while graph.fromJSON() actually works with an array of Cell.SyntheticJSON<Element.JSON> and/or Cell.SyntheticJSON<Element.JSON> items. (Because all cells are necessarily either Elements or Links, never just Cells.)


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
@zbynekstara zbynekstara marked this pull request as ready for review May 30, 2025 22:11
@zbynekstara zbynekstara requested a review from Copilot May 30, 2025 22:11
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

@zbynekstara zbynekstara changed the title types(Graph, Cell, Element, Link): add JSON and BaseJSON types types(Graph, Cell, Element, Link): add JSON and SyntheticJSON types May 30, 2025
Copy link

github-actions bot commented Aug 1, 2025

This PR is stale because it has been open 60 days with no activity. Please remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale This issue/PR shows no activity for an extended period of time. label Aug 1, 2025
@zbynekstara zbynekstara removed the stale This issue/PR shows no activity for an extended period of time. label Aug 4, 2025
@zbynekstara zbynekstara requested a review from kumilingus August 15, 2025 12:26
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