Skip to content

feat: support right-to-left (RTL) rendering for all infographics - #262

Open
arash16 wants to merge 5 commits into
antvis:mainfrom
arash16:feat/rtl
Open

arash16 wants to merge 5 commits into
antvis:mainfrom
arash16:feat/rtl

Conversation

@arash16

@arash16 arash16 commented Oct 7, 2026 •

Copy link
Copy Markdown

Adds RTL rendering via a new direction: 'ltr' | 'rtl' option (also a top-level direction key in the syntax). It is implemented as a single post-render pass (src/renderer/rtl.ts) that mirrors the whole layout with an SVG transform and flips text, icons and illustrations back in place, swaps alignment and asymmetric padding, and lets the browser's native bidi pick each text's base direction — so it applies automatically to every existing and future chart, with no changes to src/designs/ and no RTL work for chart authors, while LTR output stays byte-identical. The editor works on RTL layouts too, and a latent <use> transform-order bug in exportToSVG({ removeIds: true }) that RTL exposed is fixed generically.

… inlining

removeIds inlining composed translate(x,y) before the <use> transform for
element targets, and copied the transform onto a nested <svg> for
symbol/svg targets, which SVG 1.1 consumers (WebKit) ignore.
With `direction: 'rtl'` the rendered infographic is mirrored horizontally
in a post-render pass; text, item icons and illustrations are flipped back
in place so they stay readable. SVG text gets swapped anchors and
`unicode-bidi: plaintext`; foreignObject text gets `dir="auto"` with
physical alignment. Left and right padding are swapped. Editing in RTL
emits a warning. Designs are untouched and LTR output is unchanged.
`direction ltr|rtl` in the syntax sets the layout direction and overrides
the `direction` option passed to the Infographic constructor.
Box atoms (foreignObject text, icon and illustration uses) are flipped back
by a wrapping group owned by the RTL pass, so the editor reads, writes and
persists their own geometry unchanged; the flip is re-centred wherever the
editor writes geometry. Pointer input is mapped into the layout's own
(mirrored) space, while pan and zoom keep the viewBox space; overlays live
in the layout space. Align buttons and resize cursors act on screen sides;
stored alignment stays logical. Editing in RTL no longer emits a warning.

This branch has not been deployed

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

Labels

None yet

1 participant