Refactor the diagram representation
The data structure created by prepare_graph
55f4d51b does not really represent the abstraction of a diagram (the actual links are created in make_diagram
by processing the uplinks
values). We need a proper abstraction layer to represent the diagram data, to be useable by the future autolayout engines. Here's a proposal for such a structure:
- The graph is represented by two dictionaries,
nodes
andlinks
. - The keys of these dictionaries are strings, intended to be used as ID of the corresponding
mxCell
in the DrawIO output - The values of the
nodes
dictionary should represent all possible blocks (now the header block and the list blocks are treated separately). I think this is the good occasion to use class polymorphism. - Each node has mandatory fields
size
andposition
, initialized with zero default values. it also has a polymorphic method to update the size from a context (e.g. display options). The position will be manipulated externally by the layout engine. - Nodes have ports, indexed by integers. The class of nodes should provide methods
source_id
andtarget_id
, taking the port number as argument. - Nodes may provide layout hints (such as layer, preferred positions of connected nodes etc.), which could be used by the layout engine.
- Links have mandatory fields
source_id
,source_port
,target_id
andtarget_port
. They may have optional fields (e.g. cardinality labels).