2525 Sequence ,
2626 Tuple ,
2727 TYPE_CHECKING ,
28- Union ,
2928)
3029
3130import numpy as np
4544
4645_HorizontalLine = NamedTuple (
4746 '_HorizontalLine' ,
48- [
49- ('y' , Union [int , float ]),
50- ('x1' , Union [int , float ]),
51- ('x2' , Union [int , float ]),
52- ('emphasize' , bool ),
53- ('doubled' , bool ),
54- ],
47+ [('y' , float ), ('x1' , float ), ('x2' , float ), ('emphasize' , bool ), ('doubled' , bool )],
5548)
5649_VerticalLine = NamedTuple (
5750 '_VerticalLine' ,
58- [
59- ('x' , Union [int , float ]),
60- ('y1' , Union [int , float ]),
61- ('y2' , Union [int , float ]),
62- ('emphasize' , bool ),
63- ('doubled' , bool ),
64- ],
51+ [('x' , float ), ('y1' , float ), ('y2' , float ), ('emphasize' , bool ), ('doubled' , bool )],
6552)
6653_DiagramText = NamedTuple ('_DiagramText' , [('text' , str ), ('transposed_text' , str )])
6754
@@ -99,10 +86,10 @@ def __init__(
9986 self .vertical_lines : List [_VerticalLine ] = (
10087 [] if vertical_lines is None else list (vertical_lines )
10188 )
102- self .horizontal_padding : Dict [int , Union [ int , float ] ] = (
89+ self .horizontal_padding : Dict [int , float ] = (
10390 dict () if horizontal_padding is None else dict (horizontal_padding )
10491 )
105- self .vertical_padding : Dict [int , Union [ int , float ] ] = (
92+ self .vertical_padding : Dict [int , float ] = (
10693 dict () if vertical_padding is None else dict (vertical_padding )
10794 )
10895
@@ -171,24 +158,14 @@ def grid_line(
171158 raise ValueError ("Line is neither horizontal nor vertical" )
172159
173160 def vertical_line (
174- self ,
175- x : Union [int , float ],
176- y1 : Union [int , float ],
177- y2 : Union [int , float ],
178- emphasize : bool = False ,
179- doubled : bool = False ,
161+ self , x : float , y1 : float , y2 : float , emphasize : bool = False , doubled : bool = False
180162 ) -> None :
181163 """Adds a line from (x, y1) to (x, y2)."""
182164 y1 , y2 = sorted ([y1 , y2 ])
183165 self .vertical_lines .append (_VerticalLine (x , y1 , y2 , emphasize , doubled ))
184166
185167 def horizontal_line (
186- self ,
187- y : Union [int , float ],
188- x1 : Union [int , float ],
189- x2 : Union [int , float ],
190- emphasize : bool = False ,
191- doubled : bool = False ,
168+ self , y : float , x1 : float , x2 : float , emphasize : bool = False , doubled : bool = False
192169 ) -> None :
193170 """Adds a line from (x1, y) to (x2, y)."""
194171 x1 , x2 = sorted ([x1 , x2 ])
@@ -228,26 +205,21 @@ def height(self) -> int:
228205 max_y = max (max_y , v .y1 , v .y2 )
229206 return 1 + int (max_y )
230207
231- def force_horizontal_padding_after (self , index : int , padding : Union [ int , float ] ) -> None :
208+ def force_horizontal_padding_after (self , index : int , padding : float ) -> None :
232209 """Change the padding after the given column."""
233210 self .horizontal_padding [index ] = padding
234211
235- def force_vertical_padding_after (self , index : int , padding : Union [ int , float ] ) -> None :
212+ def force_vertical_padding_after (self , index : int , padding : float ) -> None :
236213 """Change the padding after the given row."""
237214 self .vertical_padding [index ] = padding
238215
239- def _transform_coordinates (
240- self ,
241- func : Callable [
242- [Union [int , float ], Union [int , float ]], Tuple [Union [int , float ], Union [int , float ]]
243- ],
244- ) -> None :
216+ def _transform_coordinates (self , func : Callable [[float , float ], Tuple [float , float ]]) -> None :
245217 """Helper method to transformer either row or column coordinates."""
246218
247- def func_x (x : Union [ int , float ] ) -> Union [ int , float ] :
219+ def func_x (x : float ) -> float :
248220 return func (x , 0 )[0 ]
249221
250- def func_y (y : Union [ int , float ] ) -> Union [ int , float ] :
222+ def func_y (y : float ) -> float :
251223 return func (0 , y )[1 ]
252224
253225 self .entries = {
@@ -271,19 +243,15 @@ def func_y(y: Union[int, float]) -> Union[int, float]:
271243 def insert_empty_columns (self , x : int , amount : int = 1 ) -> None :
272244 """Insert a number of columns after the given column."""
273245
274- def transform_columns (
275- column : Union [int , float ], row : Union [int , float ]
276- ) -> Tuple [Union [int , float ], Union [int , float ]]:
246+ def transform_columns (column : float , row : float ) -> Tuple [float , float ]:
277247 return column + (amount if column >= x else 0 ), row
278248
279249 self ._transform_coordinates (transform_columns )
280250
281251 def insert_empty_rows (self , y : int , amount : int = 1 ) -> None :
282252 """Insert a number of rows after the given row."""
283253
284- def transform_rows (
285- column : Union [int , float ], row : Union [int , float ]
286- ) -> Tuple [Union [int , float ], Union [int , float ]]:
254+ def transform_rows (column : float , row : float ) -> Tuple [float , float ]:
287255 return column , row + (amount if row >= y else 0 )
288256
289257 self ._transform_coordinates (transform_rows )
0 commit comments