Refactor text labels.

This commit is contained in:
Sergey Vartanov 2021-05-13 04:10:35 +03:00
parent c3828ec92f
commit afdf9416d5
5 changed files with 19 additions and 16 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Before After
Before After

View file

@ -184,9 +184,9 @@
showgrid="true"
inkscape:document-units="px"
inkscape:current-layer="layer1"
inkscape:cy="459.04494"
inkscape:cx="112.68908"
inkscape:zoom="2"
inkscape:cy="110.83427"
inkscape:cx="275.89976"
inkscape:zoom="16"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
borderopacity="1.0"

Before

Width:  |  Height:  |  Size: 832 KiB

After

Width:  |  Height:  |  Size: 832 KiB

Before After
Before After

View file

@ -368,7 +368,7 @@ class Constructor:
icon_set, priority = self.scheme.get_icon(
self.icon_extractor, line.tags, for_="line"
)
labels = self.scheme.construct_text(line.tags, True)
labels = self.scheme.construct_text(line.tags, "all")
self.nodes.append(Point(
icon_set, labels, line.tags, center_point,
@ -388,7 +388,7 @@ class Constructor:
icon_set, priority = self.scheme.get_icon(
self.icon_extractor, line.tags
)
labels = self.scheme.construct_text(line.tags, True)
labels = self.scheme.construct_text(line.tags, "all")
self.nodes.append(Point(
icon_set, labels, line.tags, center_point, center_coordinates,

View file

@ -10,8 +10,10 @@ from typing import Any, Dict, List, Optional, Set, Tuple, Union
import yaml
from colour import Color
from roentgen.icon import (DEFAULT_COLOR, DEFAULT_SHAPE_ID, Icon, IconSet,
ShapeExtractor, ShapeSpecification)
from roentgen.icon import (
DEFAULT_COLOR, DEFAULT_SHAPE_ID, Icon, IconSet, ShapeExtractor,
ShapeSpecification
)
from roentgen.text import Label, get_address, get_text
@ -296,7 +298,9 @@ class Scheme:
return line_styles
def construct_text(self, tags, draw_captions) -> List[Label]:
def construct_text(
self, tags: Dict[str, str], draw_captions: str
) -> List[Label]:
"""
Construct labels for not processed tags.
"""
@ -343,9 +347,7 @@ class Scheme:
if draw_captions == "main":
return texts
for text in get_text(tags): # type: str
if text:
texts.append(Label(text))
texts += get_text(tags)
if "route_ref" in tags:
texts.append(Label(tags["route_ref"].replace(";", " ")))

View file

@ -79,11 +79,11 @@ def format_frequency(value: str) -> str:
return value
def get_text(tags: Dict[str, Any]) -> List[str]:
def get_text(tags: Dict[str, Any]) -> List[Label]:
"""
Get text representation of writable tags.
"""
texts: List[str] = []
texts: List[Label] = []
values: List[str] = []
if "voltage:primary" in tags:
@ -92,11 +92,12 @@ def get_text(tags: Dict[str, Any]) -> List[str]:
values.append(tags["voltage:secondary"])
if "voltage" in tags:
values = tags["voltage"].split(";")
texts.append(", ".join(map(format_voltage, values)))
if values:
texts.append(Label(", ".join(map(format_voltage, values))))
if "frequency" in tags:
texts.append(", ".join(map(
texts.append(Label(", ".join(map(
format_frequency, tags["frequency"].split(";")
)))
))))
return texts