drawpyo 0.2.2__tar.gz → 0.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. drawpyo-0.2.4/LICENSE +21 -0
  2. {drawpyo-0.2.2 → drawpyo-0.2.4}/PKG-INFO +29 -60
  3. drawpyo-0.2.4/README.md +90 -0
  4. {drawpyo-0.2.2 → drawpyo-0.2.4}/pyproject.toml +15 -2
  5. drawpyo-0.2.4/src/drawpyo/__init__.py +25 -0
  6. drawpyo-0.2.4/src/drawpyo/diagram/__init__.py +33 -0
  7. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/diagram/base_diagram.py +50 -44
  8. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/diagram/edges.py +184 -128
  9. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/diagram/extended_objects.py +54 -12
  10. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/diagram/objects.py +232 -168
  11. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/diagram/text_format.py +89 -36
  12. drawpyo-0.2.4/src/drawpyo/diagram_types/__init__.py +5 -0
  13. drawpyo-0.2.4/src/drawpyo/diagram_types/bar_chart.py +426 -0
  14. drawpyo-0.2.4/src/drawpyo/diagram_types/binary_tree.py +372 -0
  15. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/diagram_types/class_diagram.py +9 -7
  16. drawpyo-0.2.4/src/drawpyo/diagram_types/legend.py +226 -0
  17. drawpyo-0.2.4/src/drawpyo/diagram_types/pie_chart.py +274 -0
  18. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/diagram_types/tree.py +187 -65
  19. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/file.py +42 -21
  20. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/page.py +49 -45
  21. drawpyo-0.2.4/src/drawpyo/shape_libraries/infographics.toml +18 -0
  22. drawpyo-0.2.4/src/drawpyo/utils/__init__.py +5 -0
  23. drawpyo-0.2.4/src/drawpyo/utils/color_scheme.py +90 -0
  24. drawpyo-0.2.4/src/drawpyo/utils/logger.py +16 -0
  25. drawpyo-0.2.4/src/drawpyo/utils/standard_colors.py +124 -0
  26. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/xml_base.py +34 -19
  27. drawpyo-0.2.2/README.md +0 -124
  28. drawpyo-0.2.2/src/drawpyo/__init__.py +0 -8
  29. drawpyo-0.2.2/src/drawpyo/diagram/__init__.py +0 -5
  30. drawpyo-0.2.2/src/drawpyo/diagram_types/__init__.py +0 -2
  31. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/formatting_database/edge_styles.toml +0 -0
  32. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/formatting_database/line_styles.toml +0 -0
  33. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/shape_libraries/flowchart.toml +0 -0
  34. {drawpyo-0.2.2 → drawpyo-0.2.4}/src/drawpyo/shape_libraries/general.toml +0 -0
drawpyo-0.2.4/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 MerrimanInd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,19 +1,26 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: drawpyo
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: A Python library for programmatically generating Draw.io charts.
5
5
  Keywords: draw.io,diagrams.net,diagrams
6
6
  Author-email: Xander Cesari <xander@merriman.industries>
7
- Requires-Python: >=3.8
7
+ Requires-Python: >=3.10
8
8
  Description-Content-Type: text/markdown
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Operating System :: OS Independent
12
+ License-File: LICENSE
12
13
  Requires-Dist: toml >= 0.10.2; python_version < '3.11'
14
+ Requires-Dist: pytest >= 7.0 ; extra == "dev"
13
15
  Project-URL: Homepage, https://github.com/MerrimanInd/drawpyo
14
16
  Project-URL: Issues, https://github.com/MerrimanInd/drawpyo/issues
17
+ Provides-Extra: dev
15
18
 
16
- # drawpyo
19
+ ![CI](https://github.com/MerrimanInd/drawpyo/actions/workflows/ci.yml/badge.svg) ![GitHub License](https://img.shields.io/github/license/MerrimanInd/drawpyo) ![PyPI Version](https://img.shields.io/pypi/v/drawpyo) ![PyPI Downloads](https://img.shields.io/pypi/dm/drawpyo)
20
+
21
+ <p align="left">
22
+ <img src="docs/img/logo.png" alt="drawpyo logo"/>
23
+ </p>
17
24
 
18
25
  Drawpyo is a Python library for programmatically generating Diagrams.net/Draw.io charts. It enables creating a diagram object, placing and styling objects, then writing the object to a file.
19
26
 
@@ -29,6 +36,10 @@ Available here!
29
36
 
30
37
  https://merrimanind.github.io/drawpyo/
31
38
 
39
+ # Discord Server
40
+
41
+ https://discord.gg/CSMHupUvRp
42
+
32
43
  # Basic Usage
33
44
 
34
45
  The basic mode of interacting with drawpyo is to manually create, style, and place objects just like you would using the Draw.io UI. There are a number of ways to style objects and you can write your own functionality for automatically handling style or placement.
@@ -75,66 +86,24 @@ item_from_stylestr.apply_style_string("rounded=1;whiteSpace=wrap;html=1;fillColo
75
86
  file.write()
76
87
  ```
77
88
 
78
- # Usage with a diagram type
79
-
80
- There is also functionality available in drawpyo that extends what can be done in Draw.io's app! These diagram types allow for easy and automatic creation of specific diagrams.
81
-
82
- The only diagram type that's released is the tree diagram. Varying level of conceptual work has been started for:
83
-
84
- - Automatic class/object/inheritance diagrams of a python module
85
-
86
- - Flowcharts
87
-
88
- - Process diagrams
89
-
90
- ## Working with TreeDiagrams
91
-
92
- Create a new tree diagram:
93
-
94
- ```python
95
- from drawpyo.diagram_types import TreeDiagram, NodeObject
96
-
97
- tree = TreeDiagram(
98
- file_path = path.join(path.expanduser('~'), "Test Drawpyo Charts"),
99
- file_name = "Coffee Grinders.drawio",
100
- direction = "down",
101
- link_style = "orthogonal",
102
- )
103
- ```
104
-
105
- The direction property sets which way the leaf nodes grow from the root: up, down, left, or right. The link_style can be orthogonal, straight, or curved.
106
-
107
- Create some NodeObjects:
108
-
109
- ```python
110
- # Top object
111
- grinders = NodeObject(tree=tree, value="Appliances for Grinding Coffee", base_style="rounded rectangle")
89
+ ## Usage with Diagram Types
112
90
 
113
- # Main categories
114
- blade_grinders = NodeObject(tree=tree, value="Blade Grinders", tree_parent=grinders)
115
- burr_grinders = NodeObject(tree=tree, value="Burr Grinders", tree_parent=grinders)
116
- blunt_objects = NodeObject(tree=tree, value="Blunt Objects", tree_parent=grinders)
117
- ```
91
+ Drawpyo also provides higher-level functionality that goes beyond what the Draw.io app offers. These **diagram types** allow you to generate complete structures automatically, without manually placing every element.
118
92
 
119
- Note that the base_style was manually declared for the first object. But NodeObjects will default to "rounded rectangle" so it's not necessary for every one. Any NodeObject can be a parent, so you can keep adding objects down the tree:
93
+ Currently, Drawpyo supports:
120
94
 
121
- ```python
122
- # Other
123
- elec_blade = NodeObject(tree=tree, value="Electric Blade Grinder", tree_parent=blade_grinders)
124
- mnp = NodeObject(tree=tree, value="Mortar and Pestle", tree_parent=blunt_objects)
125
-
126
- # Conical Burrs
127
- conical = NodeObject(tree=tree, value="Conical Burrs", tree_parent=burr_grinders)
128
- elec_conical = NodeObject(tree=tree, value="Electric", tree_parent=conical)
129
- manual_conical = NodeObject(tree=tree, value="Manual", tree_parent=conical)
130
- ```
95
+ * **Tree Diagrams**
96
+ * **Binary Tree Diagrams**
97
+ * **Bar Charts**
98
+ * **Pie Charts**
99
+ * **Color Legends**
131
100
 
132
- > **Important Note:** TreeDiagrams do not currently support NodeObjects with multiple parents! It may not ever as this seriously complicates the auto layout process. However, you can add links between any two objects in the tree and render them in the diagram. They just may look ugly until you manually rearrange the diagram.
101
+ For more details, refer to the [documentation](https://merrimanind.github.io/drawpyo/).
133
102
 
134
- Finally, before writing the diagram you'll want to run the magic penultimate step: auto layout.
103
+ Work has also begun on additional diagram types, including:
135
104
 
136
- ```python
137
- tree.auto_layout()
138
- tree.write()
139
- ```
105
+ * Automatic class/object/inheritance diagrams from a Python module
106
+ * Directed and undirected graphs from adjacency lists
107
+ * Flowcharts
108
+ * Process diagrams
140
109
 
@@ -0,0 +1,90 @@
1
+ ![CI](https://github.com/MerrimanInd/drawpyo/actions/workflows/ci.yml/badge.svg) ![GitHub License](https://img.shields.io/github/license/MerrimanInd/drawpyo) ![PyPI Version](https://img.shields.io/pypi/v/drawpyo) ![PyPI Downloads](https://img.shields.io/pypi/dm/drawpyo)
2
+
3
+ <p align="left">
4
+ <img src="docs/img/logo.png" alt="drawpyo logo"/>
5
+ </p>
6
+
7
+ Drawpyo is a Python library for programmatically generating Diagrams.net/Draw.io charts. It enables creating a diagram object, placing and styling objects, then writing the object to a file.
8
+
9
+ # History/Justification
10
+
11
+ I love Draw.io! Compared to expensive and heavy commercial options like Visio and Miro, Draw.io's free and lightweight app allows wider and more universal distribution of diagrams. Because the files are stored in plaintext they can be versioned alongside code in a repository as documentation. The XML-based file format makes these diagrams semi-portable, and could easily be ported to other applications if Draw.io ever failed you. For these reason, I think it's one of the best options for documentation diagrams.
12
+
13
+ When I had a need to generate heirarchical tree diagrams of requirement structures I was surprised to find there wasn't even a single existing Python library for working with these files. I took the project home and spent a weekend building the initial functionality. I've been adding functionality, robustness, and documentation intermittently since.
14
+
15
+ # Full Documentation
16
+
17
+ Available here!
18
+
19
+ https://merrimanind.github.io/drawpyo/
20
+
21
+ # Discord Server
22
+
23
+ https://discord.gg/CSMHupUvRp
24
+
25
+ # Basic Usage
26
+
27
+ The basic mode of interacting with drawpyo is to manually create, style, and place objects just like you would using the Draw.io UI. There are a number of ways to style objects and you can write your own functionality for automatically handling style or placement.
28
+
29
+ ## Make a new file
30
+
31
+ ```python
32
+ import drawpyo
33
+ file = drawpyo.File()
34
+ file.file_path = r"C:\drawpyo"
35
+ file.file_name = "Test Generated Edges.drawio"
36
+ # Add a page
37
+ page = drawpyo.Page(file=file)
38
+ ```
39
+
40
+ ## Add an object
41
+
42
+ ```python
43
+ item = drawpyo.diagram.Object(page=page, value="new object")
44
+ item.position = (0, 0)
45
+ ```
46
+
47
+ ## Create an object from the base style libraries available in the Draw.io UI
48
+
49
+ ```python
50
+ item_from_lib = drawpyo.diagram.object_from_library(
51
+ page=page,
52
+ library="general",
53
+ obj_name="process",
54
+ value="New Process",
55
+ )
56
+ ```
57
+
58
+ ## Style an object from a string
59
+
60
+ ```python
61
+ item_from_stylestr = drawpyo.diagram.Object(page=page)
62
+ item_from_stylestr.apply_style_string("rounded=1;whiteSpace=wrap;html=1;fillColor=#6a00ff;fontColor=#ffffff;strokeColor=#000000;gradientColor=#FF33FF;strokeWidth=4;")
63
+ ```
64
+
65
+ ## Write the file
66
+
67
+ ```python
68
+ file.write()
69
+ ```
70
+
71
+ ## Usage with Diagram Types
72
+
73
+ Drawpyo also provides higher-level functionality that goes beyond what the Draw.io app offers. These **diagram types** allow you to generate complete structures automatically, without manually placing every element.
74
+
75
+ Currently, Drawpyo supports:
76
+
77
+ * **Tree Diagrams**
78
+ * **Binary Tree Diagrams**
79
+ * **Bar Charts**
80
+ * **Pie Charts**
81
+ * **Color Legends**
82
+
83
+ For more details, refer to the [documentation](https://merrimanind.github.io/drawpyo/).
84
+
85
+ Work has also begun on additional diagram types, including:
86
+
87
+ * Automatic class/object/inheritance diagrams from a Python module
88
+ * Directed and undirected graphs from adjacency lists
89
+ * Flowcharts
90
+ * Process diagrams
@@ -14,7 +14,7 @@ classifiers = [
14
14
  "License :: OSI Approved :: MIT License",
15
15
  "Operating System :: OS Independent",
16
16
  ]
17
- requires-python = ">=3.8"
17
+ requires-python = ">=3.10"
18
18
  dynamic = ["version"]
19
19
  dependencies = [
20
20
  "toml >= 0.10.2; python_version < '3.11'"
@@ -24,7 +24,20 @@ dependencies = [
24
24
  Homepage = "https://github.com/MerrimanInd/drawpyo"
25
25
  Issues = "https://github.com/MerrimanInd/drawpyo/issues"
26
26
 
27
+ [project.optional-dependencies]
28
+ dev = [
29
+ "pytest >= 7.0"
30
+ ]
31
+
27
32
  [tool.pytest.ini_options]
28
33
  addopts = [
29
34
  "--import-mode=importlib",
30
- ]
35
+ ]
36
+
37
+ [dependency-groups]
38
+ dev = [
39
+ "mkdocs>=1.6.1",
40
+ "mkdocs-material>=9.7.0",
41
+ "mkdocstrings-python>=2.0.0",
42
+ "tox>=4.32.0",
43
+ ]
@@ -0,0 +1,25 @@
1
+ from .xml_base import XMLBase
2
+ from .file import File
3
+ from .page import Page
4
+
5
+ from .utils.standard_colors import StandardColor
6
+ from .utils.color_scheme import ColorScheme
7
+ from .utils.logger import logger
8
+
9
+ from . import utils
10
+ from . import diagram
11
+ from . import diagram_types
12
+
13
+ __all__ = [
14
+ XMLBase,
15
+ File,
16
+ Page,
17
+ StandardColor,
18
+ ColorScheme,
19
+ logger,
20
+ utils,
21
+ diagram,
22
+ diagram_types,
23
+ ]
24
+
25
+ __version__ = "0.2.4"
@@ -0,0 +1,33 @@
1
+ from .base_diagram import (
2
+ DiagramBase,
3
+ Geometry,
4
+ style_str_from_dict,
5
+ import_shape_database,
6
+ color_input_check,
7
+ width_input_check,
8
+ )
9
+ from .text_format import TextFormat
10
+ from .edges import Edge, BasicEdge, EdgeGeometry, EdgeLabel, Point
11
+ from .objects import Object, BasicObject, Group, object_from_library
12
+ from .extended_objects import List, PieSlice
13
+
14
+ __all__ = [
15
+ DiagramBase,
16
+ Geometry,
17
+ style_str_from_dict,
18
+ import_shape_database,
19
+ color_input_check,
20
+ width_input_check,
21
+ TextFormat,
22
+ Edge,
23
+ BasicEdge,
24
+ EdgeGeometry,
25
+ EdgeLabel,
26
+ Point,
27
+ Object,
28
+ BasicObject,
29
+ Group,
30
+ object_from_library,
31
+ List,
32
+ PieSlice,
33
+ ]
@@ -1,9 +1,14 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import List, Optional, Tuple, Dict, Any, Union
4
+
1
5
  from ..xml_base import XMLBase
2
6
  from os import path
3
7
 
4
8
 
5
9
  __all__ = [
6
10
  "DiagramBase",
11
+ "Geometry",
7
12
  "style_str_from_dict",
8
13
  "import_shape_database",
9
14
  "color_input_check",
@@ -11,7 +16,7 @@ __all__ = [
11
16
  ]
12
17
 
13
18
 
14
- def color_input_check(color_str):
19
+ def color_input_check(color_str: Optional[str]) -> Optional[str]:
15
20
  if color_str == None:
16
21
  return None
17
22
  elif color_str == "none":
@@ -20,9 +25,10 @@ def color_input_check(color_str):
20
25
  return color_str
21
26
  elif color_str[0] == "#" and len(color_str) == 7:
22
27
  return color_str
28
+ return None
23
29
 
24
30
 
25
- def width_input_check(width):
31
+ def width_input_check(width: Optional[Union[int, str]]) -> Optional[int]:
26
32
  if not width or (isinstance(width, str) and not width.isdigit()):
27
33
  return None
28
34
 
@@ -35,7 +41,7 @@ def width_input_check(width):
35
41
  return width
36
42
 
37
43
 
38
- def import_shape_database(file_name, relative=False):
44
+ def import_shape_database(file_name: str, relative: bool = False) -> Dict[str, Any]:
39
45
  """
40
46
  This function imports a TOML shape database and returns a dictionary of the
41
47
  shapes defined therein. It supports inheritance, meaning that if there is
@@ -86,7 +92,7 @@ def import_shape_database(file_name, relative=False):
86
92
  return data
87
93
 
88
94
 
89
- def style_str_from_dict(style_dict):
95
+ def style_str_from_dict(style_dict: Dict[str, Any]) -> str:
90
96
  """
91
97
  This function returns a concatenated style string from a style dictionary.
92
98
  This format is:
@@ -123,19 +129,19 @@ class DiagramBase(XMLBase):
123
129
  This class is the base for all diagram objects to inherit from. It defines some general creation methods and properties to make diagram objects printable and useful.
124
130
  """
125
131
 
126
- def __init__(self, **kwargs):
132
+ def __init__(self, **kwargs: Any) -> None:
127
133
  super().__init__(**kwargs)
128
- self._style_attributes = ["html"]
129
- self.page = kwargs.get("page", None)
130
- self.xml_parent = kwargs.get("xml_parent", None)
134
+ self._style_attributes: List[str] = ["html"]
135
+ self.page: Optional[Any] = kwargs.get("page", None)
136
+ self.xml_parent: Optional[DiagramBase] = kwargs.get("xml_parent", None)
131
137
 
132
138
  @classmethod
133
- def create_from_library(cls, library, obj):
134
- return cls
139
+ def create_from_library(cls, library: Dict[str, Any], obj: str) -> DiagramBase:
140
+ return cls()
135
141
 
136
142
  # XML_parent property
137
143
  @property
138
- def xml_parent_id(self):
144
+ def xml_parent_id(self) -> int:
139
145
  if self.xml_parent is not None:
140
146
  return self.xml_parent.id
141
147
  else:
@@ -143,11 +149,11 @@ class DiagramBase(XMLBase):
143
149
 
144
150
  # Parent object linking
145
151
  @property
146
- def xml_parent(self):
152
+ def xml_parent(self) -> Optional[DiagramBase]:
147
153
  return self._xml_parent
148
154
 
149
155
  @xml_parent.setter
150
- def xml_parent(self, p):
156
+ def xml_parent(self, p: Optional[DiagramBase]) -> None:
151
157
  if p is not None:
152
158
  p.add_object(self)
153
159
  self._xml_parent = p
@@ -155,13 +161,13 @@ class DiagramBase(XMLBase):
155
161
  self._xml_parent = None
156
162
 
157
163
  @xml_parent.deleter
158
- def xml_parent(self):
164
+ def xml_parent(self) -> None:
159
165
  self._xml_parent.remove_object(self)
160
166
  self._xml_parent = None
161
167
 
162
168
  # Page property
163
169
  @property
164
- def page_id(self):
170
+ def page_id(self) -> int:
165
171
  if self.page is not None:
166
172
  return self.page.id
167
173
  else:
@@ -169,11 +175,11 @@ class DiagramBase(XMLBase):
169
175
 
170
176
  # page object linking
171
177
  @property
172
- def page(self):
178
+ def page(self) -> Optional[Any]:
173
179
  return self._page
174
180
 
175
181
  @page.setter
176
- def page(self, p):
182
+ def page(self, p: Optional[Any]) -> None:
177
183
  if p is not None:
178
184
  p.add_object(self)
179
185
  self._page = p
@@ -181,22 +187,22 @@ class DiagramBase(XMLBase):
181
187
  self._page = None
182
188
 
183
189
  @page.deleter
184
- def page(self):
190
+ def page(self) -> None:
185
191
  self._page.remove_object(self)
186
192
  self._page = None
187
193
 
188
- def add_object(self, obj):
194
+ def add_object(self, obj: DiagramBase) -> None:
189
195
  self.page.add_object(obj)
190
196
 
191
197
  ###########################################################
192
198
  # Style properties
193
199
  ###########################################################
194
- def add_style_attribute(self, style_attr):
200
+ def add_style_attribute(self, style_attr: str) -> None:
195
201
  if style_attr not in self._style_attributes:
196
202
  self._style_attributes.append(style_attr)
197
203
 
198
204
  @property
199
- def style_attributes(self):
205
+ def style_attributes(self) -> List[str]:
200
206
  """
201
207
  The style attributes are the list of style tags that should be printed into the style XML attribute. This is a subset of the attributes defined on the object method.
202
208
 
@@ -206,11 +212,11 @@ class DiagramBase(XMLBase):
206
212
  return self._style_attributes
207
213
 
208
214
  @style_attributes.setter
209
- def style_attributes(self, value):
215
+ def style_attributes(self, value: List[str]) -> None:
210
216
  self._style_attributes = value
211
217
 
212
218
  @property
213
- def style(self):
219
+ def style(self) -> str:
214
220
  """
215
221
  This function returns the style string of the object to be appended into the style XML attribute.
216
222
 
@@ -246,14 +252,14 @@ class DiagramBase(XMLBase):
246
252
  style_str = style_str + self.text_format.style
247
253
  return style_str
248
254
 
249
- def _add_and_set_style_attrib(self, attrib, value):
255
+ def _add_and_set_style_attrib(self, attrib: str, value: Any) -> None:
250
256
  if hasattr(self, attrib):
251
257
  setattr(self, attrib, value)
252
258
  else:
253
259
  setattr(self, attrib, value)
254
260
  self.add_style_attribute(attrib)
255
261
 
256
- def apply_style_string(self, style_str):
262
+ def apply_style_string(self, style_str: str) -> None:
257
263
  """
258
264
  This function will apply a passed in style string to the object. This style string can be obtained from the Draw.io app by selecting Edit Style from the context menu of any object. This function will iterate through the attributes in the style string and assign the corresponding property the value.
259
265
 
@@ -278,12 +284,12 @@ class DiagramBase(XMLBase):
278
284
  else:
279
285
  self.baseStyle = attrib
280
286
 
281
- def _apply_style_from_template(self, template):
287
+ def _apply_style_from_template(self, template: DiagramBase) -> None:
282
288
  for attrib in template.style_attributes:
283
289
  value = getattr(template, attrib)
284
290
  self._add_and_set_style_attrib(attrib, value)
285
291
 
286
- def apply_attribute_dict(self, attr_dict):
292
+ def apply_attribute_dict(self, attr_dict: Dict[str, Any]) -> None:
287
293
  """
288
294
  This function takes in a dictionary of attributes and applies them
289
295
  to the object. These attributes can be style or properties. If the
@@ -305,7 +311,7 @@ class DiagramBase(XMLBase):
305
311
  self._add_and_set_style_attrib(attr, val)
306
312
 
307
313
  @classmethod
308
- def from_style_string(cls, style_string):
314
+ def from_style_string(cls, style_string: str) -> DiagramBase:
309
315
  """
310
316
  This classmethod allows the intantiation of an object from a style
311
317
  string. This is useful since Draw.io allows copying the style string
@@ -316,7 +322,7 @@ class DiagramBase(XMLBase):
316
322
  style_string (str): A Draw.io style string
317
323
 
318
324
  Returns:
319
- BaseDiagram: A BaseDiagram or subclass instantiated with the style from the Draw.io string
325
+ DiagramBase: A DiagramBase or subclass instantiated with the style from the Draw.io string
320
326
  """
321
327
  new_obj = cls()
322
328
  new_obj.apply_style_string(style_string)
@@ -324,35 +330,35 @@ class DiagramBase(XMLBase):
324
330
 
325
331
 
326
332
  class Geometry(DiagramBase):
327
- def __init__(self, **kwargs):
333
+ def __init__(self, **kwargs: Any) -> None:
328
334
  super().__init__(**kwargs)
329
- self.xml_class = "mxGeometry"
335
+ self.xml_class: str = "mxGeometry"
330
336
 
331
- self.parent_object = kwargs.get("parent_object", None)
332
- self.x = kwargs.get("x", 0)
333
- self.y = kwargs.get("y", 0)
334
- self.width = kwargs.get("width", 120)
335
- self.height = kwargs.get("height", 60)
336
- self.as_attribute = kwargs.get("as_attribute", "geometry")
337
+ self.parent_object: Optional[Any] = kwargs.get("parent_object", None)
338
+ self._x: Union[int, float] = kwargs.get("x", 0)
339
+ self._y: Union[int, float] = kwargs.get("y", 0)
340
+ self.width: Union[int, float] = kwargs.get("width", 120)
341
+ self.height: Union[int, float] = kwargs.get("height", 60)
342
+ self.as_attribute: str = kwargs.get("as_attribute", "geometry")
337
343
 
338
344
  @property
339
- def x(self):
345
+ def x(self) -> Union[int, float]:
340
346
  return self._x
341
347
 
342
348
  @x.setter
343
- def x(self, value):
349
+ def x(self, value: Union[int, float]) -> None:
344
350
  self._x = value
345
351
 
346
352
  @property
347
- def y(self):
353
+ def y(self) -> Union[int, float]:
348
354
  return self._y
349
355
 
350
356
  @y.setter
351
- def y(self, value):
357
+ def y(self, value: Union[int, float]) -> None:
352
358
  self._y = value
353
359
 
354
360
  @property
355
- def attributes(self):
361
+ def attributes(self) -> Dict[str, Union[int, float, str]]:
356
362
  return {
357
363
  "x": self.x,
358
364
  "y": self.y,
@@ -363,7 +369,7 @@ class Geometry(DiagramBase):
363
369
 
364
370
  # Size property
365
371
  @property
366
- def size(self):
372
+ def size(self) -> Tuple[Union[int, float], Union[int, float]]:
367
373
  """The size of the object. It's set with a tuple of ints, width and height respectively.
368
374
 
369
375
  (width, height)
@@ -374,6 +380,6 @@ class Geometry(DiagramBase):
374
380
  return (self.width, self.height)
375
381
 
376
382
  @size.setter
377
- def size(self, value):
383
+ def size(self, value: Tuple[Union[int, float], Union[int, float]]) -> None:
378
384
  self.width = value[0]
379
385
  self.height = value[1]