Skip to content

Add scale option in MeTTaGrapher - #8

Open
ngeiswei wants to merge 4 commits into
MesTTo:mainfrom
ngeiswei:mettagrapher-cli-scale
Open

Add scale option in MeTTaGrapher#8
ngeiswei wants to merge 4 commits into
MesTTo:mainfrom
ngeiswei:mettagrapher-cli-scale

Conversation

@ngeiswei

Copy link
Copy Markdown

This is a fix for issue #7.

scale is a multiplier on the output width and height, applied after width is
resolved from the view's default. It composes with an explicit width
(scale: 2 with width: 240 produces 480 wide).

The side-by-side view had a rounding drift: each panel and the gap were
rounded independently, so cellW + gap + cellW could differ from the
requested width by a pixel, and labelH + panelH could drift the same way.
With scale that drift showed up as the doubled GIF being one pixel wider
than 2x the base, and its height two pixels short. Derive the gap from the
requested width (width - cellW * 2) and the labelH from the natural-scaled
total height (totalH - panelH) so the output dimensions match the requested
size exactly and scale produces linear dimensions.
scale must be a positive finite number. It is capped at 16 to keep the
raster-pixel budget in check (width * height * numFrames must stay under
the safety limit).

The new tests verify that scale multiplies the output width by the
requested factor across all three views (blocks, graph, side-by-side), and
that it composes with an explicit width. Unsafe values (zero, negative,
out of range) are rejected with a clear message.
metta graph already accepted --width for output resolution; --scale N is a
multiplier on the same value, defaulting to 1. Without --width, scale
multiplies the view's natural width (720 for blocks, 880 for graph, the
computed natural width for side-by-side). With --width, scale multiplies
that explicit width.

The CLI validates the argument (positive finite number) before reaching
the grapher so the user gets a clear error message.

Usage:
  metta graph --scale 2 program.metta -o out.gif   # 2x resolution
  metta graph --scale 0.5 program.metta -o out.gif # half resolution
  metta graph --width 240 --scale 3 program.metta  # 240 x 3 = 720 wide

Closes MesTTo#7
The node README picks up a one-line example of --scale 2. The node LLMS
note mentions --scale=N next to the metta graph entry. The grapher LLMS
note adds a 'scale multiplies the output pixel size' trap so callers who
discover the option through the docs know it caps at 16.
@ngeiswei

ngeiswei commented Aug 20, 2026

Copy link
Copy Markdown
Author

It's been 100% vibe coded by myself, and I'm pretty inexperienced about that so beware.

I did test it and it works though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant