Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ when W110 puts the regions in zooms of their own, their groups get a note instea
- Ranges are inclusive: end = start + size - 1.
- Prefer `size` over `end`, and sequential placement over explicit `start`.
- Display tweaks go in `view`, never by changing `memory`.
- The look is fixed on purpose: font family, address format, outlines, connectors and label side
have no keys.
- The look is fixed on purpose: font family, address format, outlines and label side have no
keys. Connectors only choose solid or dashed lines (`style.connectors`).
- Use `--strict` on `check` and `render` to fail on warnings. Without it they exit 0 with
warnings, and a flash sector misalignment (W100) or colliding text (W106) is a warning.
- PNG and PDF need the `raster` extra and the system cairo library. Without cairo, `render`
Expand All @@ -68,6 +68,7 @@ when W110 puts the regions in zooms of their own, their groups get a note instea
- Boundary + prev end: view.defaults.labels.address: both
- Hide addresses: view.defaults.labels.address: none
- Zoom into a region: view.expand: [region_id]
- Dashed zoom lines: style.connectors: dashed
- Title a column: view.columns: [{ id: a, root: flash, title: Flash }]
- Title a zoom: view.expand: [{ region: flash, title: Flash }]
- Datasheet look: style.palette: datasheet, view.defaults.scale.mode: equal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ scripts and agents.
| [nrf52840_boot_chain.yaml](examples/nrf52840_boot_chain.yaml) | Chained zooms, column `range`, per-column labels and scale, `start_of_next` |
| [riscv64_soc.yaml](examples/riscv64_soc.yaml) | 64-bit addresses, `collapse_reserved_over`, relative heights, style options |
| [rtos_mpu_ram.yaml](examples/rtos_mpu_ram.yaml) | `check_alignment`, `fill_gaps: none`, `depth`, two columns of one memory |
| [ota_package_format.yaml](examples/ota_package_format.yaml) | A file format instead of memory: `address: none`, byte sizes, a zoom to the left |
| [ota_package_format.yaml](examples/ota_package_format.yaml) | A file format instead of memory: `address: none`, byte sizes, a dashed zoom to the left |

To render them all into `build/`:

Expand Down
2 changes: 1 addition & 1 deletion examples/ota_package_format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ view:
expand:
- { region: header, from: package_col, to: header_col }

style: { palette: color }
style: { palette: color, connectors: dashed }
3 changes: 2 additions & 1 deletion memmap/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ def layout_figure(
target = by_id[link.target.id]
pieces = [block for block in source.blocks if block.node is link.region]
between = lanes_between(layouts, source.lane, target.lane)
lines, clear = connector_lines(pieces, target, [column_box(other) for other in between])
boxes = [column_box(other) for other in between]
lines, clear = connector_lines(pieces, target, boxes, style.connectors == "dashed")
primitives += lines
if not clear:
out.append(_through_columns(link.region.id, link.region.path, target, between))
Expand Down
10 changes: 7 additions & 3 deletions memmap/layout/connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
from .primitives import INK, Polyline
from .routing import Box, make_fan, route, straight

DASH = "4 3" # px on, px off, for style.connectors: dashed


def connector_lines(
source_blocks: list[Block], target: ColumnLayout, between: list[Box]
source_blocks: list[Block], target: ColumnLayout, between: list[Box], dashed: bool = False
) -> tuple[list[Polyline], bool]:
"""One line for the top edge and one for the bottom edge of the expanded region. Each is
straight, or bent at a corner to go around `between`, the columns in the lanes the lines
cross. The flag is False when they cannot go around and run straight through them."""
cross. The flag is False when they cannot go around and run straight through them. With
`dashed` the lines are drawn dashed."""
top = min(block.y for block in source_blocks)
bottom = max(block.y + block.h for block in source_blocks)
left = source_blocks[0].x
Expand All @@ -21,4 +24,5 @@ def connector_lines(
clear = lines is not None
if lines is None:
lines = straight(fan)
return [Polyline(points, INK) for points in lines], clear
dash = DASH if dashed else None
return [Polyline(points, INK, dash=dash) for points in lines], clear
4 changes: 3 additions & 1 deletion memmap/layout/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ class Line:

@dataclass
class Polyline:
"""A line through a list of points, as used for fan lines."""
"""A line through a list of points, as used for fan lines. `dash` is an SVG dash pattern
such as "4 3"; None draws a solid line."""

points: list[tuple[float, float]]
stroke: str
width: float = 1
dash: str | None = None


@dataclass
Expand Down
2 changes: 2 additions & 0 deletions memmap/render/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def _element(primitive: Primitive) -> str:
"stroke": primitive.stroke,
"stroke-width": primitive.width,
}
if primitive.dash is not None:
values["stroke-dasharray"] = primitive.dash
return f"<polyline {_attributes(values)}/>"
if isinstance(primitive, Text):
values = {
Expand Down
3 changes: 3 additions & 0 deletions memmap/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ class Style(Model):
sector_ticks: bool = Field(
default=True, description="Draw tick marks at flash sector boundaries.", examples=[False]
)
connectors: Literal["solid", "dashed"] = Field(
default="solid", description="Line style of the zoom fan lines.", examples=["dashed"]
)


class ColumnStyle(Model):
Expand Down
4 changes: 2 additions & 2 deletions tests/golden/example_ota_package.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def test_group_help_points_to_the_guide():
["view.defaults.labels.address=both"],
["view.defaults.labels.address=none"],
["view.columns[0]={id: a, root: /}", "view.expand=[flash]"],
["view.columns[0]={id: a, root: /}", "view.expand=[flash]", "style.connectors=dashed"],
["view.columns[0]={id: a, root: flash, title: Flash}"],
["view.columns[0]={id: a, root: /}", "view.expand=[{region: flash, title: Flash}]"],
["style.palette=datasheet", "view.defaults.scale.mode=equal"],
Expand Down
10 changes: 10 additions & 0 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

from memmap.describe import describe_data
from memmap.layout.columns import LANE_STACK_GAP, MAX_STRETCH
from memmap.layout.connectors import DASH
from memmap.layout.primitives import Line, Polyline
from memmap.layout.routing import _clear, column_box
from memmap.layout.text import text_width, wrap
from memmap.options import OptionResolver
from memmap.pipeline import run
from memmap.render.svg import render_svg


def blocks(result, column=0):
Expand Down Expand Up @@ -171,6 +173,14 @@ def test_negative_offset_stays_on_the_canvas():
assert blocks(result)[-1].y > 0


@pytest.mark.parametrize("style, dash", [("solid", None), ("dashed", DASH)])
def test_connector_style_sets_the_dash_of_every_fan_line(style, dash):
result = run(ROOT / "examples" / "stm32f303_fig8.yaml", [f"style.connectors={style}"])
lines = [p for p in drawn(result).primitives if isinstance(p, Polyline)]
assert lines and all(line.dash == dash for line in lines)
assert ("stroke-dasharray" in render_svg(drawn(result))) == (dash is not None)


def test_connectors_run_corner_to_corner():
from memmap.layout.primitives import Polyline

Expand Down
Loading