pyrbd 0.3.1__py3-none-any.whl → 0.3.2__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 CHANGED
@@ -1,7 +1,6 @@
1
1
  """Module containing Block, Series and Group class definitions."""
2
2
 
3
- from typing import Optional
4
- from itertools import combinations
3
+ from typing import Optional, Generator
5
4
  from copy import deepcopy
6
5
  from collections import namedtuple
7
6
 
@@ -137,6 +136,11 @@ class Block:
137
136
  )
138
137
  return node
139
138
 
139
+ def get_blocks(self) -> Generator["Block", None, None]:
140
+ """Yield child `Block` istances."""
141
+
142
+ yield self
143
+
140
144
  def __add__(self, block: "Block") -> "Series":
141
145
  """Add two `Block` instances to make a `Series` instance.
142
146
 
@@ -321,6 +325,11 @@ class Series(Block):
321
325
  )
322
326
  return series_node
323
327
 
328
+ def get_blocks(self) -> Generator[Block, None, None]:
329
+ yield from [
330
+ children for block in self.blocks for children in block.get_blocks()
331
+ ]
332
+
324
333
 
325
334
  class Group(Block):
326
335
  """Group of `Block` instances for vertical stacking.
@@ -449,16 +458,28 @@ class Group(Block):
449
458
 
450
459
  scaling = 0.75
451
460
 
461
+ series_blocks = [block for block in self.blocks if isinstance(block, Series)]
462
+ series_blocks.sort(
463
+ key=lambda block: len(list(block.get_blocks())), reverse=True
464
+ )
465
+
466
+ if len(series_blocks) > 0:
467
+ longest_series_index = self.blocks.index(series_blocks[0])
468
+ else:
469
+ longest_series_index = 0
470
+ blocks = deepcopy(self.blocks)
471
+ longest_series = blocks.pop(longest_series_index)
472
+
452
473
  return "\n".join(
453
474
  [
454
475
  " ".join(
455
476
  [
456
477
  f"\\draw[{self.arrow_options},",
457
478
  f"rectangle line={scaling * self.internal_arrow_length}cm]",
458
- f"({block1.id}.east) to ({block2.id}.east);\n",
479
+ f"({longest_series.id}.east) to ({block.id}.east);\n",
459
480
  ]
460
481
  )
461
- for (block1, block2) in combinations(self.blocks, 2)
482
+ for block in blocks
462
483
  ]
463
484
  )
464
485
 
@@ -500,3 +521,6 @@ class Group(Block):
500
521
  )
501
522
 
502
523
  return group_node
524
+
525
+ def get_blocks(self) -> Generator[Block, None, None]:
526
+ yield from self.blocks
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyrbd
3
- Version: 0.3.1
3
+ Version: 0.3.2
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
@@ -0,0 +1,8 @@
1
+ pyrbd/__init__.py,sha256=mpsb022BX9eDGSBhuYIr2gOr4sg_M9sYbPGHLPIdvl0,219
2
+ pyrbd/block.py,sha256=xRb4FnPTCA6CEAax2q3GRsngtzJvXlg9wCqr5q3nkEQ,14576
3
+ pyrbd/diagram.py,sha256=YiU2tslUh4HbtuVP2dXSsVQFKpOjLl_ArSYjCSiQoks,6806
4
+ pyrbd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ pyrbd-0.3.2.dist-info/METADATA,sha256=3JIMvqVdxlQq-30y4omd_yipT8YfgxZOmZxq5SopBBU,2402
6
+ pyrbd-0.3.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ pyrbd-0.3.2.dist-info/licenses/LICENSE,sha256=mxXMgWpFgk71JpEEElFrb9FJxeoaDgvrU8gjUUU9LzA,1069
8
+ pyrbd-0.3.2.dist-info/RECORD,,
@@ -1,8 +0,0 @@
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,,
File without changes