mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-07 13:21:49 +02:00
Refactor text labels.
This commit is contained in:
parent
c3828ec92f
commit
afdf9416d5
5 changed files with 19 additions and 16 deletions
BIN
doc/grid.png
BIN
doc/grid.png
Binary file not shown.
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
|
@ -184,9 +184,9 @@
|
||||||
showgrid="true"
|
showgrid="true"
|
||||||
inkscape:document-units="px"
|
inkscape:document-units="px"
|
||||||
inkscape:current-layer="layer1"
|
inkscape:current-layer="layer1"
|
||||||
inkscape:cy="459.04494"
|
inkscape:cy="110.83427"
|
||||||
inkscape:cx="112.68908"
|
inkscape:cx="275.89976"
|
||||||
inkscape:zoom="2"
|
inkscape:zoom="16"
|
||||||
inkscape:pageshadow="2"
|
inkscape:pageshadow="2"
|
||||||
inkscape:pageopacity="0.0"
|
inkscape:pageopacity="0.0"
|
||||||
borderopacity="1.0"
|
borderopacity="1.0"
|
||||||
|
|
Before Width: | Height: | Size: 832 KiB After Width: | Height: | Size: 832 KiB |
|
@ -368,7 +368,7 @@ class Constructor:
|
||||||
icon_set, priority = self.scheme.get_icon(
|
icon_set, priority = self.scheme.get_icon(
|
||||||
self.icon_extractor, line.tags, for_="line"
|
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(
|
self.nodes.append(Point(
|
||||||
icon_set, labels, line.tags, center_point,
|
icon_set, labels, line.tags, center_point,
|
||||||
|
@ -388,7 +388,7 @@ class Constructor:
|
||||||
icon_set, priority = self.scheme.get_icon(
|
icon_set, priority = self.scheme.get_icon(
|
||||||
self.icon_extractor, line.tags
|
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(
|
self.nodes.append(Point(
|
||||||
icon_set, labels, line.tags, center_point, center_coordinates,
|
icon_set, labels, line.tags, center_point, center_coordinates,
|
||||||
|
|
|
@ -10,8 +10,10 @@ from typing import Any, Dict, List, Optional, Set, Tuple, Union
|
||||||
import yaml
|
import yaml
|
||||||
from colour import Color
|
from colour import Color
|
||||||
|
|
||||||
from roentgen.icon import (DEFAULT_COLOR, DEFAULT_SHAPE_ID, Icon, IconSet,
|
from roentgen.icon import (
|
||||||
ShapeExtractor, ShapeSpecification)
|
DEFAULT_COLOR, DEFAULT_SHAPE_ID, Icon, IconSet, ShapeExtractor,
|
||||||
|
ShapeSpecification
|
||||||
|
)
|
||||||
from roentgen.text import Label, get_address, get_text
|
from roentgen.text import Label, get_address, get_text
|
||||||
|
|
||||||
|
|
||||||
|
@ -296,7 +298,9 @@ class Scheme:
|
||||||
|
|
||||||
return line_styles
|
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.
|
Construct labels for not processed tags.
|
||||||
"""
|
"""
|
||||||
|
@ -343,9 +347,7 @@ class Scheme:
|
||||||
if draw_captions == "main":
|
if draw_captions == "main":
|
||||||
return texts
|
return texts
|
||||||
|
|
||||||
for text in get_text(tags): # type: str
|
texts += get_text(tags)
|
||||||
if text:
|
|
||||||
texts.append(Label(text))
|
|
||||||
|
|
||||||
if "route_ref" in tags:
|
if "route_ref" in tags:
|
||||||
texts.append(Label(tags["route_ref"].replace(";", " ")))
|
texts.append(Label(tags["route_ref"].replace(";", " ")))
|
||||||
|
|
|
@ -79,11 +79,11 @@ def format_frequency(value: str) -> str:
|
||||||
return value
|
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.
|
Get text representation of writable tags.
|
||||||
"""
|
"""
|
||||||
texts: List[str] = []
|
texts: List[Label] = []
|
||||||
|
|
||||||
values: List[str] = []
|
values: List[str] = []
|
||||||
if "voltage:primary" in tags:
|
if "voltage:primary" in tags:
|
||||||
|
@ -92,11 +92,12 @@ def get_text(tags: Dict[str, Any]) -> List[str]:
|
||||||
values.append(tags["voltage:secondary"])
|
values.append(tags["voltage:secondary"])
|
||||||
if "voltage" in tags:
|
if "voltage" in tags:
|
||||||
values = tags["voltage"].split(";")
|
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:
|
if "frequency" in tags:
|
||||||
texts.append(", ".join(map(
|
texts.append(Label(", ".join(map(
|
||||||
format_frequency, tags["frequency"].split(";")
|
format_frequency, tags["frequency"].split(";")
|
||||||
)))
|
))))
|
||||||
|
|
||||||
return texts
|
return texts
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue