pyrbd 0.3.0__py3-none-any.whl → 0.3.1__py3-none-any.whl
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.
- pyrbd/block.py +70 -26
- pyrbd/diagram.py +3 -1
- pyrbd/py.typed +0 -0
- {pyrbd-0.3.0.dist-info → pyrbd-0.3.1.dist-info}/METADATA +3 -2
- pyrbd-0.3.1.dist-info/RECORD +8 -0
- pyrbd-0.3.0.dist-info/RECORD +0 -7
- {pyrbd-0.3.0.dist-info → pyrbd-0.3.1.dist-info}/WHEEL +0 -0
- {pyrbd-0.3.0.dist-info → pyrbd-0.3.1.dist-info}/licenses/LICENSE +0 -0
pyrbd/block.py
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
from typing import Optional
|
4
4
|
from itertools import combinations
|
5
5
|
from copy import deepcopy
|
6
|
+
from collections import namedtuple
|
7
|
+
|
8
|
+
|
9
|
+
Padding = namedtuple("Padding", ["n", "e", "s", "w"])
|
6
10
|
|
7
11
|
|
8
12
|
class Block:
|
@@ -49,6 +53,7 @@ class Block:
|
|
49
53
|
)
|
50
54
|
|
51
55
|
arrow_options: str = "arrowcolor, thick"
|
56
|
+
arrow_length: float = 0.5
|
52
57
|
|
53
58
|
def __init__(
|
54
59
|
self,
|
@@ -70,7 +75,13 @@ class Block:
|
|
70
75
|
if self.parent is None:
|
71
76
|
return ""
|
72
77
|
|
73
|
-
return
|
78
|
+
return " ".join(
|
79
|
+
[
|
80
|
+
f"[right={self.arrow_length + self.shift[0]}cm",
|
81
|
+
f"of {self.parent.id},",
|
82
|
+
f"yshift={self.shift[1]}cm]",
|
83
|
+
]
|
84
|
+
)
|
74
85
|
|
75
86
|
def arrow(self, connector_position: float) -> str:
|
76
87
|
"""Get TikZ arrow string.
|
@@ -97,13 +108,13 @@ class Block:
|
|
97
108
|
]
|
98
109
|
)
|
99
110
|
|
100
|
-
def get_node(self, connector_position: float =
|
111
|
+
def get_node(self, connector_position: Optional[float] = None) -> str:
|
101
112
|
"""Get TikZ node string.
|
102
113
|
|
103
114
|
Parameters
|
104
115
|
----------
|
105
|
-
connector_position : float
|
106
|
-
distance in cm to right angle bend in connector
|
116
|
+
connector_position : Optional[float]
|
117
|
+
distance in cm to right angle bend in connector. Defaults to `0.5*arrow_length`.
|
107
118
|
|
108
119
|
Returns
|
109
120
|
-------
|
@@ -111,6 +122,9 @@ class Block:
|
|
111
122
|
TikZ string for rendering block
|
112
123
|
"""
|
113
124
|
|
125
|
+
if connector_position is None:
|
126
|
+
connector_position = self.arrow_length / 2
|
127
|
+
|
114
128
|
node = "".join(
|
115
129
|
[
|
116
130
|
"% Block\n",
|
@@ -208,6 +222,10 @@ class Series(Block):
|
|
208
222
|
]
|
209
223
|
)
|
210
224
|
|
225
|
+
internal_arrow_length = 0.3
|
226
|
+
pad = Padding(1, 1, 1, 2.5)
|
227
|
+
label_height = 5
|
228
|
+
|
211
229
|
def __init__(
|
212
230
|
self,
|
213
231
|
blocks: list[Block],
|
@@ -219,11 +237,13 @@ class Series(Block):
|
|
219
237
|
|
220
238
|
self.blocks = blocks
|
221
239
|
self.blocks[0].id = f"{self.id}+0"
|
240
|
+
self.blocks[0].shift = (self.internal_arrow_length, 0)
|
222
241
|
for i, (block, new_parent) in enumerate(
|
223
242
|
zip(self.blocks[1::], self.blocks[0:-1]), start=1
|
224
243
|
):
|
225
244
|
block.parent = new_parent
|
226
245
|
block.id = f"{self.id}+{i}"
|
246
|
+
block.arrow_length = self.internal_arrow_length
|
227
247
|
|
228
248
|
@property
|
229
249
|
def background(self) -> str:
|
@@ -232,11 +252,13 @@ class Series(Block):
|
|
232
252
|
if self.color in ("white", ""):
|
233
253
|
return ""
|
234
254
|
|
255
|
+
pad = self.pad
|
256
|
+
|
235
257
|
return "".join(
|
236
258
|
[
|
237
259
|
"\\begin{pgfonlayer}{background}\n",
|
238
|
-
f"\\coordinate (sw) at ($({self.id}.south west)+(-
|
239
|
-
f"\\coordinate (ne) at ($({self.id}.north east)+(
|
260
|
+
f"\\coordinate (sw) at ($({self.id}.south west)+(-{pad.w}mm, -{pad.s}mm)$);\n",
|
261
|
+
f"\\coordinate (ne) at ($({self.id}.north east)+({pad.e}mm, {pad.n}mm)$);\n",
|
240
262
|
f"\\draw[{self.color}, thick] (sw) rectangle (ne);\n",
|
241
263
|
"\\end{pgfonlayer}\n",
|
242
264
|
]
|
@@ -249,24 +271,27 @@ class Series(Block):
|
|
249
271
|
if len(self.text) == 0:
|
250
272
|
return ""
|
251
273
|
|
274
|
+
pad = self.pad
|
275
|
+
|
252
276
|
return "".join(
|
253
277
|
[
|
254
|
-
f"\\coordinate (nw) at ($({self.id}.north west)+(-
|
255
|
-
f"\\coordinate (ne) at ($({self.id}.north east)+(
|
256
|
-
|
278
|
+
f"\\coordinate (nw) at ($({self.id}.north west)+(-{pad.w}mm, {pad.n}mm)$);\n",
|
279
|
+
f"\\coordinate (ne) at ($({self.id}.north east)+({pad.e}mm, {pad.n}mm)$);\n",
|
280
|
+
"\\coordinate (n) at "
|
281
|
+
f"($({self.id}.north)+(0mm, {self.label_height / 2 + pad.n}mm)$);\n",
|
257
282
|
f"\\draw[{self.color}, fill={self.color}!50, thick] (nw) ",
|
258
|
-
"rectangle ($(ne)+(0,
|
259
|
-
f"\\node[anchor=
|
283
|
+
f"rectangle ($(ne)+(0, {self.label_height}mm)$);\n",
|
284
|
+
f"\\node[anchor=center, inner sep=0pt, outer sep=0pt] at (n) {{{self.text}}};\n",
|
260
285
|
]
|
261
286
|
)
|
262
287
|
|
263
|
-
def get_node(self, connector_position: float =
|
288
|
+
def get_node(self, connector_position: Optional[float] = None) -> str:
|
264
289
|
"""Get TikZ node string.
|
265
290
|
|
266
291
|
Parameters
|
267
292
|
----------
|
268
|
-
connector_position : float
|
269
|
-
distance in cm to right angle bend in connector
|
293
|
+
connector_position : Optional[float]
|
294
|
+
distance in cm to right angle bend in connector. Defaults to `0.5 * arrow_length`
|
270
295
|
|
271
296
|
Returns
|
272
297
|
-------
|
@@ -275,12 +300,15 @@ class Series(Block):
|
|
275
300
|
|
276
301
|
"""
|
277
302
|
|
303
|
+
if connector_position is None:
|
304
|
+
connector_position = self.arrow_length / 2
|
305
|
+
|
278
306
|
block_nodes = "\n".join(
|
279
307
|
block.get_node(connector_position) for block in self.blocks
|
280
308
|
)
|
281
309
|
series_node = "".join(
|
282
310
|
[
|
283
|
-
f"\\node[{self.tikz_options}]",
|
311
|
+
f"%%% Series\n\\node[{self.tikz_options}]",
|
284
312
|
f"({self.id})",
|
285
313
|
self.position,
|
286
314
|
"{\\begin{tikzpicture}\n",
|
@@ -322,6 +350,9 @@ class Group(Block):
|
|
322
350
|
"anchor=west",
|
323
351
|
]
|
324
352
|
)
|
353
|
+
internal_arrow_length = 0.3
|
354
|
+
pad = Padding(1, 1, 1, 1)
|
355
|
+
label_height = 5
|
325
356
|
|
326
357
|
def __init__(
|
327
358
|
self,
|
@@ -337,6 +368,7 @@ class Group(Block):
|
|
337
368
|
block.shift = (0, shift)
|
338
369
|
block.parent = self
|
339
370
|
block.id = f"{self.id}-{i}"
|
371
|
+
block.arrow_length = self.internal_arrow_length
|
340
372
|
|
341
373
|
@property
|
342
374
|
def shifts(self) -> list[float]:
|
@@ -359,11 +391,13 @@ class Group(Block):
|
|
359
391
|
if self.color in ("white", ""):
|
360
392
|
return ""
|
361
393
|
|
394
|
+
pad = self.pad
|
395
|
+
|
362
396
|
return "".join(
|
363
397
|
[
|
364
398
|
"\\begin{pgfonlayer}{background}\n",
|
365
|
-
f"\\coordinate (sw) at ($({self.id}.south west)+(-
|
366
|
-
f"\\coordinate (ne) at ($({self.id}.north east)+(
|
399
|
+
f"\\coordinate (sw) at ($({self.id}.south west)+(-{pad.w}mm, -{pad.s}mm)$);\n",
|
400
|
+
f"\\coordinate (ne) at ($({self.id}.north east)+({pad.e}mm, {pad.n}mm)$);\n",
|
367
401
|
f"\\draw[{self.color}, thick] (sw) rectangle (ne);\n",
|
368
402
|
"\\end{pgfonlayer}\n",
|
369
403
|
]
|
@@ -376,14 +410,17 @@ class Group(Block):
|
|
376
410
|
if len(self.text) == 0:
|
377
411
|
return ""
|
378
412
|
|
413
|
+
pad = self.pad
|
414
|
+
|
379
415
|
return "".join(
|
380
416
|
[
|
381
|
-
f"\\coordinate (nw) at ($({self.id}.north west)+(-
|
382
|
-
f"\\coordinate (ne) at ($({self.id}.north east)+(
|
383
|
-
|
417
|
+
f"\\coordinate (nw) at ($({self.id}.north west)+(-{pad.w}mm, {pad.n}mm)$);\n",
|
418
|
+
f"\\coordinate (ne) at ($({self.id}.north east)+({pad.e}mm, {pad.n}mm)$);\n",
|
419
|
+
"\\coordinate (n) at ",
|
420
|
+
f"($({self.id}.north)+(0mm, {self.label_height / 2 + pad.n}mm)$);\n",
|
384
421
|
f"\\draw[{self.color}, fill={self.color}!50, thick] (nw) ",
|
385
|
-
"rectangle ($(ne)+(0,
|
386
|
-
f"\\node[anchor=
|
422
|
+
f"rectangle ($(ne)+(0, {self.label_height}mm)$);\n",
|
423
|
+
f"\\node[anchor=center, inner sep=0pt, outer sep=0pt] at (n) {{{self.text}}};\n",
|
387
424
|
]
|
388
425
|
)
|
389
426
|
|
@@ -410,11 +447,14 @@ class Group(Block):
|
|
410
447
|
def arrows(self) -> str:
|
411
448
|
"""Get TikZ string for arrow connecting stacked blocks."""
|
412
449
|
|
450
|
+
scaling = 0.75
|
451
|
+
|
413
452
|
return "\n".join(
|
414
453
|
[
|
415
454
|
" ".join(
|
416
455
|
[
|
417
|
-
f"\\draw[{self.arrow_options},
|
456
|
+
f"\\draw[{self.arrow_options},",
|
457
|
+
f"rectangle line={scaling * self.internal_arrow_length}cm]",
|
418
458
|
f"({block1.id}.east) to ({block2.id}.east);\n",
|
419
459
|
]
|
420
460
|
)
|
@@ -422,13 +462,14 @@ class Group(Block):
|
|
422
462
|
]
|
423
463
|
)
|
424
464
|
|
425
|
-
def get_node(self, connector_position: float =
|
465
|
+
def get_node(self, connector_position: Optional[float] = None) -> str:
|
426
466
|
"""Get TikZ node string.
|
427
467
|
|
428
468
|
Parameters
|
429
469
|
----------
|
430
|
-
connector_position : float
|
431
|
-
distance in cm to right angle bend in connector
|
470
|
+
connector_position : Optional[float]
|
471
|
+
distance in cm to right angle bend in connector.
|
472
|
+
Locked to 0.0 for `Group` class
|
432
473
|
|
433
474
|
Returns
|
434
475
|
-------
|
@@ -436,12 +477,15 @@ class Group(Block):
|
|
436
477
|
TikZ string for rendering group
|
437
478
|
"""
|
438
479
|
|
480
|
+
connector_position = 0.0
|
481
|
+
|
439
482
|
block_nodes = "\n".join(
|
440
483
|
block.get_node(connector_position) for block in self.blocks
|
441
484
|
)
|
442
485
|
|
443
486
|
group_node = "".join(
|
444
487
|
[
|
488
|
+
"%%% Group\n"
|
445
489
|
f"\\node[anchor=west, outer sep=0pt, inner sep=0pt, align=center] ({self.id}) ",
|
446
490
|
self.position,
|
447
491
|
"{\\begin{tikzpicture}\n",
|
pyrbd/diagram.py
CHANGED
@@ -143,7 +143,9 @@ class Diagram:
|
|
143
143
|
"""
|
144
144
|
|
145
145
|
try:
|
146
|
-
subprocess.check_call(
|
146
|
+
subprocess.check_call(
|
147
|
+
["latexmk", "--lualatex", f"{self.filename}.tex", "--silent"]
|
148
|
+
)
|
147
149
|
subprocess.check_call(["latexmk", "-c", f"{self.filename}.tex"])
|
148
150
|
if clear_source:
|
149
151
|
subprocess.check_call(["rm", f"{self.filename}.tex"])
|
pyrbd/py.typed
ADDED
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pyrbd
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.1
|
4
4
|
Summary: Package for creating simple reliability block diagrams (RBDs) using LaTeX and TikZ.
|
5
5
|
Project-URL: Repository, https://github.com/hghugdal/pyrbd
|
6
6
|
Project-URL: Issues, https://github.com/hghugdal/pyrbd/issues
|
@@ -11,6 +11,7 @@ License-File: LICENSE
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
13
13
|
Requires-Python: >=3.10
|
14
|
+
Requires-Dist: pre-commit>=4.3.0
|
14
15
|
Requires-Dist: pymupdf>=1.26.3
|
15
16
|
Description-Content-Type: text/markdown
|
16
17
|
|
@@ -46,6 +47,6 @@ diagram.compile()
|
|
46
47
|
```
|
47
48
|
|
48
49
|
producing the following diagram
|
49
|
-
<div><img src="https://raw.githubusercontent.com/hghugdal/pyrbd/
|
50
|
+
<div><img src="https://raw.githubusercontent.com/hghugdal/pyrbd/e11808e9a40c902f0e1c2c2b0b42ca0d90170cd1/docs/examples/simple_RBD.svg" width=500/></div>
|
50
51
|
|
51
52
|
For more examples, visit the [documentation](https://hghugdal.github.io/pyrbd/).
|
@@ -0,0 +1,8 @@
|
|
1
|
+
pyrbd/__init__.py,sha256=mpsb022BX9eDGSBhuYIr2gOr4sg_M9sYbPGHLPIdvl0,219
|
2
|
+
pyrbd/block.py,sha256=l44FYLS9zQbyblDsVUb9GwvsFm_sU1IamlpbrjryVbw,13786
|
3
|
+
pyrbd/diagram.py,sha256=YiU2tslUh4HbtuVP2dXSsVQFKpOjLl_ArSYjCSiQoks,6806
|
4
|
+
pyrbd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
+
pyrbd-0.3.1.dist-info/METADATA,sha256=_IHhEyyaEaLB7lg1iicfWM4lZWg97I4wskgq3OuDqjc,2402
|
6
|
+
pyrbd-0.3.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
+
pyrbd-0.3.1.dist-info/licenses/LICENSE,sha256=mxXMgWpFgk71JpEEElFrb9FJxeoaDgvrU8gjUUU9LzA,1069
|
8
|
+
pyrbd-0.3.1.dist-info/RECORD,,
|
pyrbd-0.3.0.dist-info/RECORD
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
pyrbd/__init__.py,sha256=mpsb022BX9eDGSBhuYIr2gOr4sg_M9sYbPGHLPIdvl0,219
|
2
|
-
pyrbd/block.py,sha256=qQJx2Sn_SvAnm3Chz1f078nTzbS61LSFdxaEveu2RcY,12319
|
3
|
-
pyrbd/diagram.py,sha256=llZ0ncDmyJRg7zyQfTXAzbEM1W66wyHs9gfiovy-ujI,6762
|
4
|
-
pyrbd-0.3.0.dist-info/METADATA,sha256=KEMFXHPv7ykDCYbh2fOOjcKPyqhOchXl0Ck2pc3ODwQ,2369
|
5
|
-
pyrbd-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
6
|
-
pyrbd-0.3.0.dist-info/licenses/LICENSE,sha256=mxXMgWpFgk71JpEEElFrb9FJxeoaDgvrU8gjUUU9LzA,1069
|
7
|
-
pyrbd-0.3.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|