mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-06 12:51:53 +02:00
Add documentation grid generator.
This commit is contained in:
parent
409af73ca1
commit
dcd64fa91b
1 changed files with 76 additions and 0 deletions
76
map_machine/doc/icons.py
Normal file
76
map_machine/doc/icons.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
"""
|
||||
Icon grids for documentation.
|
||||
"""
|
||||
from pathlib import Path
|
||||
from typing import Iterable
|
||||
|
||||
from colour import Color
|
||||
|
||||
from map_machine.pictogram.icon import (
|
||||
Shape,
|
||||
Icon,
|
||||
ShapeSpecification,
|
||||
ShapeExtractor,
|
||||
)
|
||||
from map_machine.pictogram.icon_collection import IconCollection
|
||||
from map_machine.workspace import workspace
|
||||
|
||||
|
||||
SKIP: bool = True
|
||||
|
||||
|
||||
def draw_special_grid(all_shapes, function, path, color=None):
|
||||
"""Draw special icon grid to illustrate map feature."""
|
||||
icons = [
|
||||
Icon([ShapeSpecification(shape)])
|
||||
for shape in all_shapes
|
||||
if function(shape)
|
||||
]
|
||||
icons = sorted(icons)
|
||||
|
||||
if color:
|
||||
for icon in icons:
|
||||
icon.recolor(color)
|
||||
|
||||
IconCollection(icons).draw_grid(path, 8, scale=4.0)
|
||||
|
||||
|
||||
def draw_special_grids():
|
||||
"""Draw special icon grids."""
|
||||
extractor: ShapeExtractor = ShapeExtractor(
|
||||
workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH
|
||||
)
|
||||
all_shapes: Iterable[Shape] = extractor.shapes.values()
|
||||
|
||||
draw_special_grid(
|
||||
all_shapes,
|
||||
lambda shape: shape.id_.startswith("power_tower")
|
||||
or shape.id_.startswith("power_pole"),
|
||||
Path("doc/icons_power.svg"),
|
||||
)
|
||||
if SKIP:
|
||||
draw_special_grid(
|
||||
all_shapes,
|
||||
lambda shape: shape.group == "root_space",
|
||||
Path("doc/icons_space.svg"),
|
||||
)
|
||||
draw_special_grid(
|
||||
all_shapes,
|
||||
lambda shape: shape.group == "root_street_playground",
|
||||
Path("doc/icons_playground.svg"),
|
||||
)
|
||||
draw_special_grid(
|
||||
all_shapes,
|
||||
lambda shape: "emergency" in shape.categories,
|
||||
Path("doc/icons_emergency.svg"),
|
||||
color=Color("#DD2222"),
|
||||
)
|
||||
draw_special_grid(
|
||||
all_shapes,
|
||||
lambda shape: shape.id_.startswith("japan"),
|
||||
Path("doc/icons_japanese.svg"),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
draw_special_grids()
|
Loading…
Add table
Add a link
Reference in a new issue