Commit e0a8195
authored
refactor(cxx): move igraph to the standard library (#83)
This PR completely overhauls and unifies handling of the graph-like structures and visualizations on the library. This is a Phase 1 -- functionally complete, with the core tests added and working, but there are some leftover issues and polish that can be added in some follow-up PR.
The changes in this PR are split into several categories
- Utility and testing additions to the `hstd::` library: geometry types, geometry checks, various assertions etc, required to test or implement the main graph structure
- Base graph implementation: initial idea partially migrated from the org diagramming tool, but updated and expanded to accommodate various graph structures and accomodations. The base graph structure is designed to accommodate visualization needs (hierarchical vertex structures, ports), but everything should be abstracted.
- Base visualization class and visualiation backends for ELK, graphviz, libavoid and custom kiwi-based constraint placement solution.
- Cascading changes that were implemented to accommodate for the updated API
The code removed
- `org_diagram` tool -- the idea of using org-mode as a description for the diagram is sound, but the
- `adaptagrams_ir` and the adaptagrams wrapeprs: the libadaptagrams library, specifically the libcola component, proved to be too buggy and unreliable to use them consistently, so the whole part of the code was completely removed and replaced with the new, kiwi-based layout solution, which is much more precise and flexible (at the expense of having to specify a lot more underlying elements and not having any overlap avoidance mechanism)
The python interoperability for the new implementation is going to be done through protobuf data exchange.
- More complex parts of the imgui demo applications, or parts that relied on the old graph IR/visualization to function. This code was a poor example (too complex) and a poor tool (not polished enough, unlikely to be finished).
# Overall architecture of the new code
## Base graph structure
The graph structure is split into three parts: graph containers, graph objects and graphs IDs. Overall API is similar to the DOD in a sense that objects stored in the collection don't have access to the IDs, and relations between objects are managed through a separate lookup tables/map. The design differs from the regular DOD in a way the data is stored: the stores are virtual classes and may implement set/get functionality in any way they can. Additionally, each object is required to have a unique string ID and it might be used for the reverse lookup.
All collection types *may* store the associated objects, but *are not required to*.
- `IGraph`: main storage class, holds a collection of vertices and manages `Vertex <> ID` association. Holds the list of other collections: vertex hierarchies, edge collections and port collections. The `IGraph` has a single collection of vertices and vertex IDs that are used in any other operations.
- `IEdgeProvider`: base class for edge operations. Edges are managed as an additional overlay on top of the existing vertex collections. Does not support hyper-edges.
- `IVertexHierarchy`: tree-like arrangement of the nodes in the graph. Primarily used for the visualization purposes, but is designed in a way that would make it usable for a general tree-like data structures.
- `IEdgeCollection`: free-form collection of the edges. Each edge has its own unique associated ID, so the multi-edges and self-loops are possible.
- `IPortCollection`: collection of the ports associated with every vertex. The port connection can be related to a vertex or an intersection of a vertex and edge. The ports are not structural elements of the graph, instead they are managed as another overlay on top of the edges+vertices structure.
Collections associate IDs (`VertexID`, `PortID`, `EdgeID`) with the corresponding objects (`IVertex`, `IPort`, `IEdge`) respectively, and provide a way to track and un-track the elements in the graph.
Each object has a list of attributes: extra data associated with the graph object, in addition to the fields in the derived object itself. The attributes are currently used in the visualization backend to provide a general way to access the visualization data.
If protobuf build is enabled, every graph element: collection and object, can be serialized into a predefined protobuf schema, and de-serialized back from it.
## Visualization logic
All graph visualization backends were rewritten under a unified API structure, now it is possible to combine the different visualization backends together, and even partially route the edges across different backends.
The general algorithm for the visualization is based on the `IVisualAttribute` and its derivatives.
- Each backend may associate one visual-attribute derived object with each vertex.
- The attributes hold the necessary layout data for the backend.
- `IGroupVisualAttribute` holds additional context in form of the `IPlacementAlgorithm`-derived type. This type implements the actual layout logic and returns a mapping `(Vertex|Edge|Port)ID -> ILayoutAttribute` for placing the nodes. All results are relative to the parent, so the each layout algorithm does not require any additional context.
## Visualization backends
- **graphviz**: update and refactor of the existing backend, while leaving the original utility API in place. It is still possible to create a quick debug graphviz graph and render it to the PNG file
- **kiwi**: new backend created as a replacement to the removed cola constraints. Based on the kiwi constraint solving library, allows to describe the diagram structure as a collection of inequalities and higher-level constraints. The API is simiar to the cola, but less buggy. The backend uses libavoid to route the edges.
- **ELK**: Eclipse Layout Kernel, backend already existed in the `org_diagram` tool, now it is moved and integrated into the full package.297 files changed
Lines changed: 31195 additions & 29683 deletions
File tree
- docs
- scripts
- cxx_codegen
- cxx_executor
- cxx_repository
- py_ci/py_ci
- py_cli/py_cli/generate
- py_codegen/py_codegen
- py_haxorg
- py_haxorg
- py_repository/py_repository
- repo_hooks
- repo_tasks
- py_wrappers/py_wrappers
- src
- adaptagrams
- app
- log_viewer
- org_diagram
- app
- src
- gui
- items
- model
- graph
- layout
- nodes
- utils
- tests
- org_imgui
- gui_app
- gui_lib
- gui_test
- org_viewer
- cmake
- haxorg
- api
- base_lexer
- imm
- lexbase
- parse
- sem
- serde
- test
- hstd
- ext
- astdiff
- geometry
- graph
- base
- jni_elk
- include
- src
- main/java/com/example/elk
- visual
- stdlib
- system
- py_libs
- py_adaptagrams
- pyhaxorg
- wrappers
- c
- js
- tests
- hstd
- graph
- org
- python
- thirdparty
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | 6 | | |
10 | 7 | | |
11 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
| 553 | + | |
| 554 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | 3 | | |
6 | 4 | | |
7 | 5 | | |
| |||
This file was deleted.
0 commit comments