feat(media): add brand-agnostic flow_diagram core template#2898
Merged
Conversation
Adds a generic, spec-driven flow diagram template rendered server-side
via GDRenderer. Describe a graph as { nodes, edges } and get a
deterministic PNG/JPEG back — box/diamond/oval node shapes, directional
arrows, optional edge labels, horizontal or vertical layout, auto-fit
labels. Registered on the core datamachine/image_generation/templates
filter, so it's composable for free through the existing
datamachine/render-image-template ability (CLI, REST, MCP, PHP).
Core intentionally ships only generic structural templates; domain
templates (event cards, quote cards) remain downstream.
Also fixes a latent GDRenderer bug: draw_rounded_rect() called
imagefilledroundedrectangle() unconditionally, but that builtin is
PHP 8.4+. The plugin requires PHP 8.0, so rounded nodes fataled on
8.0-8.3. Added a manual rounded-rect fallback.
Includes a self-contained smoke test (renders a spec, asserts a valid
PNG, exercises the polyfill path).
Contributor
Homeboy Results —
|
Fixes 25 WordPress.Arrays.MultipleStatementAlignment warnings flagged by the release lint gate. Whitespace-only; no logic change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a generic, spec-driven flow diagram template to core, rendered server-side via the existing
GDRenderer. Describe a graph as{ nodes, edges }and get a deterministic PNG/JPEG back — no external services, no AI, no per-token cost.It registers on the core
datamachine/image_generation/templatesfilter, so it's composable for free through the existingdatamachine/render-image-templateability across every surface:wp datamachine image render --template_id=flow_diagram \ --data='{"title":"...","nodes":[{"id":"a","label":"A"},{"id":"b","label":"B"}],"edges":[{"from":"a","to":"b","label":"next"}]}'Any consumer of Data Machine (CLI, REST, MCP, PHP) now gets programmatic PHP diagram generation with zero extra wiring.
Design: generic templates in core, domain templates downstream
The GD engine (
GDRenderer+TemplateInterface+TemplateRegistry) has always lived in core, but core shipped zero templates by the original "core provides the engine, downstream brings the templates" rule (PR #449). That rule was written for domain-specific graphics (event cards, quote cards). Aflow_diagramis different: it's a domain-agnostic structural primitive, same abstraction level asPlatformPresets,BrandTokens, andGDRenderer::get_chart_palette()that core already ships. So it belongs in core; domain templates still stay downstream.Features
box(default),diamond,ovalcolor(hex) override; auto-shrink + wrap for long/unbreakable labelshorizontal(default) orverticallayoutBonus fix
GDRenderer::draw_rounded_rect()calledimagefilledroundedrectangle()unconditionally — but that builtin is PHP 8.4+, while the plugin requires PHP 8.0. Rounded nodes fataled on 8.0–8.3. Added a manual rounded-rect fallback (rects + corner ellipses).Test plan
tests/flow-diagram-template-smoke.php— renders a spec, asserts a valid PNG, exercises box/diamond/oval + edge labels + empty-nodes guard + the rounded-rect polyfill path. All 13 assertions pass locally on PHP 8.3.6.Notes
render()returnsstring[]per theTemplateInterfacecontract.