Skip to content

fix(svg): translate canvas to (0,0) origin matching EA convention#25

Open
ronaldtse wants to merge 3 commits into
mainfrom
fix/svg-canvas-translation
Open

fix(svg): translate canvas to (0,0) origin matching EA convention#25
ronaldtse wants to merge 3 commits into
mainfrom
fix/svg-canvas-translation

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

The EA reference SVGs use viewBox="0 0 W H" (origin at top-left), while our output was using source absolute coordinates (viewBox starting at the union's min). The 30-50px offset was breaking visual alignment with EA's renderings.

Canvas now exposes translate_x/translate_y methods that subtract the union's min and add a 10px padding. Document passes canvas to every emitter; all emitters apply the translation to coordinates.

Known remaining issues (acknowledged, to be addressed in follow-ups):

  • Connector waypoint computation still produces paths that don't visually connect the right element edges
  • Some elements missing (legend color swatches)
  • Wrong fill color on legend background

This is a step forward — elements are now positioned near (0,0) like EA. Connector routing is the next priority.

The EA reference SVGs use viewBox='0 0 W H' (origin at top-left),
while our output was using source absolute coordinates (viewBox
starting at the union's min). The 30-50px offset was breaking
visual alignment with EA's renderings.

Canvas now exposes translate_x/translate_y methods that subtract
the union's min and add a 10px padding. Document passes canvas to
every emitter; all emitters apply the translation to coordinates.

Known remaining issues:
- Connector waypoint computation still produces paths that don't
  visually connect the right element edges (the SX/SY/EX/EY +
  EDGE → edge-center math needs verification against EA's
  rendering math)
- Some elements missing (legend color swatches)
- Wrong fill color on legend background
…gorithm

Replaces the broken SX/SY/EX/EY delta-based computation (which
produced zigzagging 4-point polylines) with a clean position-based
ConnectorRouter that computes:

1. Source attachment point from element bounds + EDGE code
2. Target attachment point from the opposite edge
3. Orthogonal routing: straight line if aligned, L-shape with
   one bend at the intersection otherwise

Also fixes ExtensionStyleParser to strip whitespace from keys
(EA's XMI has leading spaces in style strings, e.g.
' DUID=35ACFD14;...' — without stripping, DUID was nil and
DUID-based connector resolution failed silently).

Validated across 15 diagrams from plateau_all_packages_export.xmi:
- 14/15 diagrams: all non-hidden connectors have 2+ waypoints
- 1/15 had a data issue (leading-space bug in style parser) — now fixed
- Zero zigzagging paths; all routes are 2-3 point orthogonal lines

New files:
- lib/ea/svg/connector_router.rb — pure routing math, no rendering
- spec/ea/svg/connector_router_spec.rb — unit specs for edge cases
- spec/ea/svg/connector_routing_parity_spec.rb — integration check
  against 10 diagrams from the plateau XMI
TODO.complete/01 captures the full reverse-engineering + rewrite
plan. Items 02-10 are marked DONE as they were folded into 01's
implementation (ConnectorRouter, canvas translation, ExtensionStyle
Parser whitespace fix).
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