antvis / Graphin

🌌 A React toolkit for graph visualization based on G6.
https://github.com/antvis/graphin
MIT License
986 stars 264 forks source link

Add support for right-to-left text direction #421

Closed daniele-pini closed 1 year ago

daniele-pini commented 1 year ago

Description

This PR adds support for the right-to-left text direction to support languages like Arabic or Hebrew.

Details

Setting the dir attribute should be performed before the first graph.render() call, which is why I made this PR here on Graphin.

The added prop only includes values 'ltr' | 'rtl'. While the dir attribute in normal HTML nodes also supports 'auto', that option doesn't seem to work in canvas in the few examples I tried.

It's also not supported by <svg> nodes, which is a possible target for a G6 renderer if I get it right, see the direction attribute for SVG nodes.

Help required

Example

LTR direction (normal): ltr_direction

RTL direction: rtl_direction

What's the weird artifact in the LTR case?

I think it's due to a bad bounding box calculation for the area to repaint, should be considered a separate issue.

Expanded video: https://user-images.githubusercontent.com/16387428/182601923-d561e0d7-8de1-4a53-9f63-31992adb572e.mp4

Text being rendered, for reference: داستان SVG 1.1 SE طولا ني است.