mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-10 14:51:49 +02:00
Change collections JSON format.
Use dictionaries instead of lists.
This commit is contained in:
parent
1d0e9aea0d
commit
5e7cb1ce38
2 changed files with 94 additions and 81 deletions
|
@ -1,78 +1,80 @@
|
|||
[
|
||||
[
|
||||
"Tag:man_made=mast",
|
||||
{"man_made": "mast"},
|
||||
"tower:construction",
|
||||
["freestanding", "lattice", "guyed_tube", "guyed_lattice"],
|
||||
"tower:type",
|
||||
["", "communication", "lighting", "monitoring", "siren"]
|
||||
],
|
||||
[
|
||||
"Tag:natural=volcano",
|
||||
{"natural": "volcano"},
|
||||
"volcano:type",
|
||||
["stratovolcano", "shield", "scoria"],
|
||||
"volcano:status",
|
||||
[ "", "active", "dormant", "extinct"]
|
||||
],
|
||||
[
|
||||
"Tag:tower:construction=guyed_tube",
|
||||
{"man_made": "mast", "tower:construction": "guyed_tube"},
|
||||
"tower:type",
|
||||
["", "communication", "lighting", "monitoring", "siren"]
|
||||
],
|
||||
[
|
||||
"Tag:tower:construction=guyed_lattice",
|
||||
{"man_made": "mast", "tower:construction": "guyed_lattice"},
|
||||
"tower:type",
|
||||
["", "communication", "lighting", "monitoring", "siren"]
|
||||
],
|
||||
[
|
||||
"Key:communication:mobile_phone",
|
||||
{"communication:mobile_phone": "yes"}
|
||||
],
|
||||
[
|
||||
"Key:traffic_calming",
|
||||
{},
|
||||
"traffic_calming",
|
||||
[
|
||||
{
|
||||
"page": "Tag:man_made=mast",
|
||||
"id": "mast",
|
||||
"tags": {"man_made": "mast"},
|
||||
"row_key": "tower:construction",
|
||||
"row_values": ["freestanding", "lattice", "guyed_tube", "guyed_lattice"],
|
||||
"column_key": "tower:type",
|
||||
"column_values": ["", "communication", "lighting", "monitoring", "siren"]
|
||||
},
|
||||
{
|
||||
"page": "Tag:natural=volcano",
|
||||
"id": "volcano",
|
||||
"tags": {"natural": "volcano"},
|
||||
"row_key": "volcano:type",
|
||||
"row_values": ["stratovolcano", "shield", "scoria"],
|
||||
"column_key": "volcano:status",
|
||||
"column_values": [ "", "active", "dormant", "extinct"]
|
||||
},
|
||||
{
|
||||
"page": "Tag:tower:construction=guyed_tube",
|
||||
"tags": {"man_made": "mast", "tower:construction": "guyed_tube"},
|
||||
"row_key": "tower:type",
|
||||
"row_values": ["", "communication", "lighting", "monitoring", "siren"]
|
||||
},
|
||||
{
|
||||
"page": "Tag:tower:construction=guyed_lattice",
|
||||
"tags": {"man_made": "mast", "tower:construction": "guyed_lattice"},
|
||||
"row_key": "tower:type",
|
||||
"row_values": ["", "communication", "lighting", "monitoring", "siren"]
|
||||
},
|
||||
{
|
||||
"page": "Key:communication:mobile_phone",
|
||||
"tags": {"communication:mobile_phone": "yes"}
|
||||
},
|
||||
{
|
||||
"page": "Key:traffic_calming",
|
||||
"tags": {},
|
||||
"column_key": "traffic_calming",
|
||||
"column_values": [
|
||||
"bump", "mini_bumps", "hump", "table", "cushion", "rumble_strip",
|
||||
"dip", "double_dip"
|
||||
]
|
||||
],
|
||||
[
|
||||
"Key:crane:type",
|
||||
{"man_made": "crane"},
|
||||
"crane:type",
|
||||
[
|
||||
},
|
||||
{
|
||||
"page": "Key:crane:type",
|
||||
"tags": {"man_made": "crane"},
|
||||
"column_key": "crane:type",
|
||||
"column_values": [
|
||||
"gantry_crane", "floor-mounted_crane", "portal_crane",
|
||||
"travel_lift", "tower_crane"
|
||||
]
|
||||
],
|
||||
[
|
||||
"Tag:tower:type=diving",
|
||||
{"man_made": "tower", "tower:type": "diving"}
|
||||
],
|
||||
[
|
||||
"Key:design",
|
||||
{},
|
||||
"power",
|
||||
["tower", "pole"],
|
||||
"design",
|
||||
[
|
||||
},
|
||||
{
|
||||
"page": "Tag:tower:type=diving",
|
||||
"tags": {"man_made": "tower", "tower:type": "diving"}
|
||||
},
|
||||
{
|
||||
"page": "Key:design",
|
||||
"tags": {},
|
||||
"row_key": "power",
|
||||
"row_values": ["tower", "pole"],
|
||||
"column_key": "design",
|
||||
"column_values": [
|
||||
"one-level", "two-level", "three-level", "four-level", "asymmetric",
|
||||
"triangle", "flag", "delta", "delta_two-level", "delta_three-level"
|
||||
]
|
||||
],
|
||||
[
|
||||
"Key:design_2",
|
||||
{},
|
||||
"power",
|
||||
["tower"],
|
||||
"design",
|
||||
[
|
||||
},
|
||||
{
|
||||
"page": "Key:design_2",
|
||||
"tags": {},
|
||||
"row_key": "power",
|
||||
"row_values": ["tower"],
|
||||
"column_key": "design",
|
||||
"column_values": [
|
||||
"donau", "donau_inverse", "barrel", "y-frame", "x-frame", "h-frame",
|
||||
"guyed_h-frame", "portal", "portal_two-level", "portal_three-level"
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -4,7 +4,7 @@ Special icon collections for documentation.
|
|||
import json
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
import numpy as np
|
||||
import svgwrite
|
||||
|
@ -46,19 +46,22 @@ class Collection:
|
|||
column_values: list[str] = field(default_factory=list)
|
||||
|
||||
@classmethod
|
||||
def deserialize(cls, structure):
|
||||
def deserialize(cls, structure: dict[str, Any]):
|
||||
"""Deserialize icon collection from structure."""
|
||||
row_key = structure[2] if len(structure) > 2 else None
|
||||
row_values = structure[3] if len(structure) > 3 else []
|
||||
column_key = structure[4] if len(structure) > 4 else None
|
||||
column_values = structure[5] if len(structure) > 5 else []
|
||||
|
||||
row_key: Optional[str] = (
|
||||
structure["row_key"] if "row_key" in structure else None
|
||||
)
|
||||
row_values: list[str] = (
|
||||
structure["row_values"] if "row_values" in structure else []
|
||||
)
|
||||
column_key: Optional[str] = (
|
||||
structure["column_key"] if "column_key" in structure else None
|
||||
)
|
||||
column_values: list[str] = (
|
||||
structure["column_values"] if "column_values" in structure else []
|
||||
)
|
||||
return cls(
|
||||
structure[1],
|
||||
row_key,
|
||||
row_values,
|
||||
column_key,
|
||||
column_values,
|
||||
structure["tags"], row_key, row_values, column_key, column_values
|
||||
)
|
||||
|
||||
|
||||
|
@ -98,12 +101,13 @@ class SVGTable:
|
|||
max(map(len, self.collection.row_values)) * self.font_width,
|
||||
len(self.collection.row_key) * self.font_width
|
||||
+ (self.offset if self.collection.column_values else 0),
|
||||
170.0,
|
||||
)
|
||||
if self.collection.row_values
|
||||
else 25.0,
|
||||
else 0.0,
|
||||
max(map(len, self.collection.column_values)) * self.font_width
|
||||
if self.collection.column_values
|
||||
else 25.0,
|
||||
else 0.0,
|
||||
]
|
||||
self.start_point: np.ndarray = (
|
||||
2 * self.border + np.array(self.size) + self.half_step
|
||||
|
@ -285,6 +289,7 @@ class SVGTable:
|
|||
)
|
||||
)
|
||||
* self.step
|
||||
- self.half_step
|
||||
+ self.border
|
||||
)
|
||||
|
||||
|
@ -293,10 +298,14 @@ def draw_svg_tables(output_path: Path, html_file_path: Path) -> None:
|
|||
"""Draw SVG tables of icon collections."""
|
||||
|
||||
with Path("data/collections.json").open() as input_file:
|
||||
collections: list[list] = json.load(input_file)
|
||||
collections: list[dict[str, Any]] = json.load(input_file)
|
||||
|
||||
with html_file_path.open("w+") as html_file:
|
||||
for structure in collections:
|
||||
path: Path = output_path / f"{structure[0]}.svg"
|
||||
if "id" not in structure:
|
||||
continue
|
||||
|
||||
path: Path = output_path / f"{structure['id']}.svg"
|
||||
svg: Drawing = svgwrite.Drawing(path.name)
|
||||
|
||||
collection: Collection = Collection.deserialize(structure)
|
||||
|
@ -306,7 +315,9 @@ def draw_svg_tables(output_path: Path, html_file_path: Path) -> None:
|
|||
|
||||
with path.open("w+") as output_file:
|
||||
svg.write(output_file)
|
||||
html_file.write(f'<img src="{path}" />\n')
|
||||
html_file.write(
|
||||
f'<img src="{path}" style="border: 1px solid #DDD;" />\n'
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue