Skip to content

Parsed Diagram

src.drawpyo.drawio_import.drawio_parser.ParsedDiagram dataclass

High-level diagram representation with convenient access methods.

Source code in src/drawpyo/drawio_import/drawio_parser.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@dataclass
class ParsedDiagram:
    """High-level diagram representation with convenient access methods."""

    shapes: List[DiagramBase] = field(default_factory=list)
    edges: List[Edge] = field(default_factory=list)
    _id_map: Dict[str, DiagramBase] = field(default_factory=dict, repr=False)

    def get_by_id(self, cell_id: str) -> Optional[DiagramBase]:
        """Get an element by its Draw.io cell ID.

        Args:
            cell_id: The Draw.io cell ID

        Returns:
            The diagram element or None if not found
        """
        return self._id_map.get(cell_id)

    @property
    def element_count(self) -> int:
        """Total number of elements (shapes + edges)."""
        return len(self.shapes) + len(self.edges)

element_count property

Total number of elements (shapes + edges).

get_by_id(cell_id)

Get an element by its Draw.io cell ID.

Parameters:

Name Type Description Default
cell_id str

The Draw.io cell ID

required

Returns:

Type Description
Optional[DiagramBase]

The diagram element or None if not found

Source code in src/drawpyo/drawio_import/drawio_parser.py
22
23
24
25
26
27
28
29
30
31
def get_by_id(self, cell_id: str) -> Optional[DiagramBase]:
    """Get an element by its Draw.io cell ID.

    Args:
        cell_id: The Draw.io cell ID

    Returns:
        The diagram element or None if not found
    """
    return self._id_map.get(cell_id)