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

#514 Refactor GlspElkLayoutEngine #5

Merged
merged 2 commits into from
Feb 3, 2022
Merged

#514 Refactor GlspElkLayoutEngine #5

merged 2 commits into from
Feb 3, 2022

Conversation

tortmayr
Copy link
Contributor

@tortmayr tortmayr commented Feb 2, 2022

  • Refactor the GlspElkLayoutEngine and related concepts to properly support layout computation for ports. In this process we also opted out of trying to reuse the existing SprottyElkLayoutEngine and instead implement a new layout engine specifically for the GLSP graphmodel. This implementation is more in line with the Java ELK-Layout Engine and implements similar features like automatic detection of common ancestors of edge source/targets to correctly transform them in the ELK graph.

  • Removes the no longer needed BasicTypeMapper

Also:

  • Provide utility functions for querying parent elements of a given element that match a predicate. (gmodel-util.ts)
  • Only rerexport the the subset of types that are really needed from "sprotty-elk" to avoid unncessary naming clashes.
  • Add jsdoc for GModelSerializer
  • Fix implementation of getAllEdges in GModelIndex
  • Remove unused (and unset) source and target references in GEdge

Contributed on behalf of STMicroelectronics

@tortmayr tortmayr changed the title #514 Refactpr GlspElkLayoutEngine #514 Refactor GlspElkLayoutEngine Feb 3, 2022
- Refactor the `GlspElkLayoutEngine` and related concepts to properly support layout computation for ports. In this process we also opted out of trying to reuse the existing `SprottyElkLayoutEngine` and instead implement a new layout engine specifically for the GLSP graphmodel. This implementation is more in line with the Java ELK-Layout Engine and implements similar features like automatic detection of common ancestors of edge source/targets to correctly transform them in the ELK graph.

- Removes the no longer needed `BasicTypeMapper`

Also: 
- Provide utility functions for querying parent elements of a given element that match a predicate. (gmodel-util.ts)
- Only rerexport the the subset of types that are really needed from "sprotty-elk" to avoid unncessary naming clashes.
- Add jsdoc for `GModelSerializer`
- Fix implementation of `getAllEdges` in `GModelIndex`
- Remove unused (and unset) `source` and `target` references in `GEdge`

Contributed on behalf of STMicroelectronics
Copy link
Contributor

@sgraband sgraband left a comment

Choose a reason for hiding this comment

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

Thanks @tortmayr!

Changes look good. Just a few inline comments below.

packages/layout-elk/src/element-filter.ts Outdated Show resolved Hide resolved
packages/layout-elk/src/element-filter.ts Outdated Show resolved Hide resolved
Comment on lines +147 to +148
elkGraph.edges = [];
this.elkEdges.push(...(this.findChildren(graph, GEdge).map(child => this.transformToElk(child)) as ElkEdge[]));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these edges not also be pushed into the elkGraph.edges? Otherwise the array is always empty, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, edges need special handling. ELK expects that edges are always set in their respective parent container (either the graph or another node in case of nested diagrams). Otherwise edges want be layouted correctly. However, the same assumption is not true for the graphical model. If we have an edge between A and B the edge doesn't have to be a child of the container of A and B. It could be placed anywhere in the graph (e.g. as child of A).

Hence I implemented the same mechanism that is used in the Java LayoutEngine. (Store the edges in a temporary map and then in a postprocess step find the most suitable parent container). (

this.elkEdges.forEach(elkEdge => {
)

Comment on lines +163 to +164
elkNode.edges = [];
this.elkEdges.push(...(this.findChildren(node, GEdge).map(child => this.transformToElk(child)) as ElkEdge[]));
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor

@sgraband sgraband left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@tortmayr tortmayr merged commit 607434c into main Feb 3, 2022
@tortmayr tortmayr deleted the issue/514 branch February 3, 2022 12:20
tortmayr added a commit that referenced this pull request Feb 3, 2022
* #514 Refactor GlspElkLayoutEngine

- Refactor the `GlspElkLayoutEngine` and related concepts to properly support layout computation for ports. In this process we also opted out of trying to reuse the existing `SprottyElkLayoutEngine` and instead implement a new layout engine specifically for the GLSP graphmodel. This implementation is more in line with the Java ELK-Layout Engine and implements similar features like automatic detection of common ancestors of edge source/targets to correctly transform them in the ELK graph.

- Removes the no longer needed `BasicTypeMapper`

Also: 
- Provide utility functions for querying parent elements of a given element that match a predicate. (gmodel-util.ts)
- Only rerexport the the subset of types that are really needed from "sprotty-elk" to avoid unncessary naming clashes.
- Add jsdoc for `GModelSerializer`
- Fix implementation of `getAllEdges` in `GModelIndex`
- Remove unused (and unset) `source` and `target` references in `GEdge`

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

Successfully merging this pull request may close these issues.

2 participants