Skip to content

Commit

Permalink
fix: fixed labels orientations
Browse files Browse the repository at this point in the history
  • Loading branch information
Raúl Gotor committed Jan 14, 2024
1 parent 73867db commit 4c2b225
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions examples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ areas:
- address: 0xe0017FFF
text: Random name
length: 30
directions: right
directions: ['in','out']
side: left
style:
stroke: 'black'
Expand All @@ -102,7 +102,7 @@ areas:
- address: 0xe0014FFF
text: Cool section
length: 30
directions: left
directions: out
style:
stroke: *pastel_green
stroke-width: 2
Expand Down
42 changes: 29 additions & 13 deletions map_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def __init__(self, area_view, links, file='map.svg', size=(500,500), **kwargs):
self.links_sections = self._get_valid_linked_sections(links.sections)
self.file = file
self.size = size
print(self.size[0])
self.dwg = svgwrite.Drawing(file,
profile='full',
size=(self.size)
Expand Down Expand Up @@ -554,18 +553,35 @@ def _make_label(self, label, area_view):
points = [(0 + pos_x_d, pos_y), (direction*(label_length + pos_x_d), pos_y)]

# TODO: FIX: direction is inverted if we change the label side
if 'right' in label.directions:
arrow_direction = 'right'
if label.side == Side.LEFT:
arrow_direction = 'left'
g.add(self._make_arrow_head(label, direction=arrow_direction)).translate(
direction*(label_length + pos_x_d), pos_y,)

if 'left' in label.directions:
arrow_direction = 'right'
if label.side == Side.RIGHT:
arrow_direction = 'left'
g.add(self._make_arrow_head(label, direction=arrow_direction)).translate(pos_x_d,pos_y,)

def add_arrow_head(_direction):
if 'in' == _direction:
if label.side == Side.LEFT:
arrow_direction = 'right'
elif label.side == Side.RIGHT:
arrow_direction = 'left'

arrow_head_x = pos_x_d

elif 'out' == _direction:
if label.side == Side.LEFT:
arrow_direction = 'left'
elif label.side == Side.RIGHT:
arrow_direction = 'right'

arrow_head_x = direction * (label_length + pos_x_d)

else:
print(f"WARNING, invalid direction {_direction} provided")
return

g.add(self._make_arrow_head(label, direction=arrow_direction)).translate(arrow_head_x, pos_y)

if type(label.directions) == str:
add_arrow_head(label.directions)
elif type(label.directions) == list:
for head_direction in label.directions:
add_arrow_head(head_direction)

g.add(self._make_text(text,
(direction*(pos_x_d + label_length + line_label_spacer), pos_y),
Expand Down

0 comments on commit 4c2b225

Please sign in to comment.