plotly.js
plotly.js copied to clipboard
Automargin breaks with dir=rtl
As found by @saber1440 in https://github.com/plotly/react-plotly.js/issues/334, automargin fails if you use plotly.js on a page with <body dir="rtl">
:
https://codepen.io/alexcjohnson/pen/gOErOzO
Anyone aware of a workaround for this? Related: #2390
I'm worried that this may be related to the off-screen but in-DOM tester element:
https://github.com/plotly/plotly.js/blob/9664ca9253829bf2ecb70599765baa29e2eb3e5a/src/components/drawing/index.js#L1244-L1255
But <svg>
elements don't support the dir
attribute so it doesn't work to for example add a rule like:
#js-plotly-tester {dir: ltr}
. We could wrap it in a <div>
with that attribute, perhaps that would fix it.
I tried wrapping it in a div with that attribute. It didn't work. Interesting, the dir
attribute in the <body>
element, affects automargin
for x-axis too.
As a workaround in react, I am avoiding document.body.lang = i18n.resolvedLanguage;
and setting dir='auto'
for the highest level parent div
. @alexcjohnson, Thanks for the help debugging this and coming up with a workaround.