Issue #10: support priority for icons.

This commit is contained in:
Sergey Vartanov 2020-10-03 13:44:12 +03:00
parent fd70aa8f01
commit 081a6e5455
3 changed files with 27 additions and 13 deletions

View file

@ -340,11 +340,15 @@ class Constructor:
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)):
icon_set: IconSet = self.scheme.get_icon(
priority: int
icon_set: IconSet
icon_set, 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_set, line.tags, center_point, center_coordinates,
is_for_node=False)) is_for_node=False, priority=priority))
if not line_styles: if not line_styles:
if DEBUG: if DEBUG:
@ -353,11 +357,15 @@ class Constructor:
"stroke-width": 1} "stroke-width": 1}
self.figures.append(Figure( self.figures.append(Figure(
line.tags, inners, outers, LineStyle(style, 1000))) line.tags, inners, outers, LineStyle(style, 1000)))
icon_set: IconSet = self.scheme.get_icon(
priority: int
icon_set: IconSet
icon_set, priority = self.scheme.get_icon(
self.icon_extractor, line.tags) self.icon_extractor, line.tags)
self.nodes.append(Point( self.nodes.append(Point(
icon_set, line.tags, center_point, center_coordinates, icon_set, line.tags, center_point, center_coordinates,
is_for_node=False)) is_for_node=False, priority=priority))
def construct_relations(self) -> None: def construct_relations(self) -> None:
""" """
@ -410,7 +418,9 @@ class Constructor:
if not self.check_level(tags): if not self.check_level(tags):
continue continue
icon_set: IconSet = self.scheme.get_icon(self.icon_extractor, tags) priority: int
icon_set: IconSet
icon_set, priority = self.scheme.get_icon(self.icon_extractor, tags)
if self.mode in ["time", "user-coloring"]: if self.mode in ["time", "user-coloring"]:
if not tags: if not tags:
@ -421,7 +431,8 @@ class Constructor:
if self.mode == "time": if self.mode == "time":
icon_set.color = get_time_color(node.timestamp, self.map_.time) icon_set.color = get_time_color(node.timestamp, self.map_.time)
self.nodes.append(Point(icon_set, tags, flung, node.coordinates)) self.nodes.append(Point(
icon_set, tags, flung, node.coordinates, priority=priority))
missing_tags.update( missing_tags.update(
f"{key}: {tags[key]}" for key in tags f"{key}: {tags[key]}" for key in tags

View file

@ -230,7 +230,7 @@ class Painter:
occupied = Occupied( occupied = Occupied(
self.flinger.size[0], self.flinger.size[1], self.overlap) self.flinger.size[0], self.flinger.size[1], self.overlap)
nodes = sorted(constructor.nodes, key=lambda x: x.layer) nodes = sorted(constructor.nodes, key=lambda x: -x.priority)
for index, node in enumerate(nodes): # type: int, Point for index, node in enumerate(nodes): # type: int, Point
if (node.get_tag("natural") == "tree" and if (node.get_tag("natural") == "tree" and
("diameter_crown" in node.tags or ("diameter_crown" in node.tags or

View file

@ -8,7 +8,7 @@ import yaml
from colour import Color from colour import Color
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Set, Union from typing import Any, Dict, List, Optional, Set, Union, Tuple
from roentgen.icon import DEFAULT_SHAPE_ID, IconExtractor, Icon from roentgen.icon import DEFAULT_SHAPE_ID, IconExtractor, Icon
@ -104,7 +104,7 @@ class Scheme:
self.prefix_to_skip: List[str] = content["prefix_to_skip"] self.prefix_to_skip: List[str] = content["prefix_to_skip"]
# Storage for created icon sets. # Storage for created icon sets.
self.cache: Dict[str, IconSet] = {} self.cache: Dict[str, Tuple[IconSet, int]] = {}
def get_color(self, color: str) -> Color: def get_color(self, color: str) -> Color:
""" """
@ -156,7 +156,7 @@ class Scheme:
def get_icon( def get_icon(
self, icon_extractor: IconExtractor, tags: Dict[str, Any], self, icon_extractor: IconExtractor, tags: Dict[str, Any],
for_: str = "node") -> IconSet: for_: str = "node") -> Tuple[IconSet, int]:
""" """
Construct icon set. Construct icon set.
@ -172,11 +172,14 @@ class Scheme:
extra_icon_ids: List[List[str]] = [] extra_icon_ids: List[List[str]] = []
processed: Set[str] = set() processed: Set[str] = set()
fill: Color = DEFAULT_COLOR fill: Color = DEFAULT_COLOR
priority: int = 0
for matcher in self.icons: # type: Dict[str, Any] for index, matcher in enumerate(self.icons):
# type: (int, Dict[str, Any])
matched: bool = is_matched(matcher, tags) matched: bool = is_matched(matcher, tags)
if not matched: if not matched:
continue continue
priority = len(self.icons) - index
if "draw" in matcher and not matcher["draw"]: if "draw" in matcher and not matcher["draw"]:
processed |= set(matcher["tags"].keys()) processed |= set(matcher["tags"].keys())
if "icon" in matcher: if "icon" in matcher:
@ -229,9 +232,9 @@ class Scheme:
returned: IconSet = IconSet( returned: IconSet = IconSet(
main_icon, extra_icons, fill, processed, is_default) main_icon, extra_icons, fill, processed, is_default)
self.cache[tags_hash] = returned self.cache[tags_hash] = returned, priority
return returned return returned, priority
def get_style(self, tags: Dict[str, Any], scale): def get_style(self, tags: Dict[str, Any], scale):