Fix code style.

This commit is contained in:
Sergey Vartanov 2021-05-05 22:30:16 +03:00
parent 19c49acaf3
commit c793b314c7
2 changed files with 44 additions and 38 deletions

View file

@ -320,8 +320,9 @@ class Constructor:
self.figures.append(Figure( self.figures.append(Figure(
line.tags, inners, outers, line.tags, inners, outers,
LineStyle({ LineStyle({
"fill": "none", "stroke": user_color.hex, "fill": "none", "stroke": user_color.hex, "stroke-width": 1
"stroke-width": 1}))) })
))
return return
if self.mode == "time": if self.mode == "time":
@ -329,8 +330,9 @@ class Constructor:
self.figures.append(Figure( self.figures.append(Figure(
line.tags, inners, outers, line.tags, inners, outers,
LineStyle({ LineStyle({
"fill": "none", "stroke": time_color.hex, "fill": "none", "stroke": time_color.hex, "stroke-width": 1
"stroke-width": 1}))) })
))
return return
if not line.tags: if not line.tags:
@ -343,22 +345,25 @@ class Constructor:
for line_style in line_styles: # type: LineStyle for line_style in line_styles: # type: LineStyle
if "building" in line.tags: if "building" in line.tags:
self.add_building(Building( self.add_building(Building(
line.tags, inners, outers, self.flinger, line_style)) line.tags, inners, outers, self.flinger, line_style
))
else: else:
self.figures.append( self.figures.append(
Figure(line.tags, inners, outers, line_style)) Figure(line.tags, inners, outers, line_style))
if (line.get_tag("area") == "yes" or if (
line.get_tag("area") == "yes" or
is_cycle(outers[0]) and line.get_tag("area") != "no" and is_cycle(outers[0]) and line.get_tag("area") != "no" and
self.scheme.is_area(line.tags)): self.scheme.is_area(line.tags)
):
priority: int priority: int
icon_set: Icon icon: Icon
icon_set, priority = self.scheme.get_icon( icon, priority = self.scheme.get_icon(
self.icon_extractor, line.tags, for_="line") self.icon_extractor, line.tags, for_="line"
)
self.nodes.append(Point( self.nodes.append(Point(
icon_set, line.tags, center_point, center_coordinates, icon, line.tags, center_point, center_coordinates,
is_for_node=False, priority=priority)) is_for_node=False, priority=priority
))
if not line_styles: if not line_styles:
if DEBUG: if DEBUG:

View file

@ -126,9 +126,7 @@ def construct_text(
def in_range(position, points) -> bool: def in_range(position, points) -> bool:
return ( return 0 <= position[0] < len(points) and 0 <= position[1] < len(points[0])
0 <= position[0] < len(points) and
0 <= position[1] < len(points[0]))
class Point(Tagged): class Point(Tagged):
@ -147,7 +145,7 @@ class Point(Tagged):
assert point is not None assert point is not None
self.icon_set: Icon = icon self.icon: Icon = icon
self.tags: Dict[str, str] = tags self.tags: Dict[str, str] = tags
self.point: np.array = point self.point: np.array = point
self.coordinates: np.array = coordinates self.coordinates: np.array = coordinates
@ -165,13 +163,15 @@ class Point(Tagged):
""" """
Draw main shape for one node. Draw main shape for one node.
""" """
if (self.icon_set.main_icon and if (
(not self.icon_set.main_icon[0].is_default() or self.icon.main_icon and
self.is_for_node)): (not self.icon.main_icon[0].is_default() or
self.is_for_node)
):
position = self.point + np.array((0, self.y)) position = self.point + np.array((0, self.y))
self.main_icon_painted: bool = self.draw_point_shape( self.main_icon_painted: bool = self.draw_point_shape(
svg, self.icon_set.main_icon, svg, self.icon.main_icon,
position, self.icon_set.color, occupied, position, self.icon.color, occupied,
tags=self.tags) tags=self.tags)
if self.main_icon_painted: if self.main_icon_painted:
self.y += 16 self.y += 16
@ -182,28 +182,28 @@ class Point(Tagged):
""" """
Draw secondary shapes. Draw secondary shapes.
""" """
if not self.icon_set.extra_icons or not self.main_icon_painted: if not self.icon.extra_icons or not self.main_icon_painted:
return return
is_place_for_extra: bool = True is_place_for_extra: bool = True
if occupied: if occupied:
left: float = -(len(self.icon_set.extra_icons) - 1) * 8 left: float = -(len(self.icon.extra_icons) - 1) * 8
for shape_ids in self.icon_set.extra_icons: for _ in self.icon.extra_icons:
if occupied.check( if occupied.check(
(int(self.point[0] + left), (int(self.point[0] + left), int(self.point[1] + self.y))
int(self.point[1] + self.y))): ):
is_place_for_extra = False is_place_for_extra = False
break break
left += 16 left += 16
if is_place_for_extra: if is_place_for_extra:
left: float = -(len(self.icon_set.extra_icons) - 1) * 8 left: float = -(len(self.icon.extra_icons) - 1) * 8
for shape_ids in self.icon_set.extra_icons: for shape_ids in self.icon.extra_icons:
self.draw_point_shape( self.draw_point_shape(
svg, shape_ids, self.point + np.array((left, self.y)), svg, shape_ids, self.point + np.array((left, self.y)),
Color("#888888"), occupied) Color("#888888"), occupied)
left += 16 left += 16
if self.icon_set.extra_icons: if self.icon.extra_icons:
self.y += 16 self.y += 16
def draw_point_shape( def draw_point_shape(
@ -248,7 +248,7 @@ class Point(Tagged):
Draw all labels. Draw all labels.
""" """
text_structures: List[TextStruct] = construct_text( text_structures: List[TextStruct] = construct_text(
self.tags, self.icon_set.processed, scheme, draw_captions) self.tags, self.icon.processed, scheme, draw_captions)
for text_struct in text_structures: # type: TextStruct for text_struct in text_structures: # type: TextStruct
text = text_struct.text text = text_struct.text
@ -257,7 +257,8 @@ class Point(Tagged):
text = text[:26] + ("..." if len(text) > 26 else "") text = text[:26] + ("..." if len(text) > 26 else "")
self.draw_text( self.draw_text(
svg, text, self.point + np.array((0, self.y)), svg, text, self.point + np.array((0, self.y)),
occupied, text_struct.fill, size=text_struct.size) occupied, text_struct.fill, size=text_struct.size
)
def draw_text( def draw_text(
self, svg: svgwrite.Drawing, text: str, point, occupied: Occupied, self, svg: svgwrite.Drawing, text: str, point, occupied: Occupied,