Skip to content

Fix SVG coordinate formatting broken on non-English JVM locales (Czech, German, etc.) #3

Open
tombarys wants to merge 1 commit intoscicloj:mainfrom
tombarys:fix/svg-locale-formatting
Open

Fix SVG coordinate formatting broken on non-English JVM locales (Czech, German, etc.) #3
tombarys wants to merge 1 commit intoscicloj:mainfrom
tombarys:fix/svg-locale-formatting

Conversation

@tombarys
Copy link
Copy Markdown

@tombarys tombarys commented May 6, 2026

Hi, this is my third PR in my whole life, so I hope it will work. I found a small bug leading to something like this:

image

I cooperated with Claude and here is the solution.

plotje version: 0.2.0

Description:
Charts render nearly empty when the JVM runs under a locale that uses a comma as the decimal separator (e.g. cs_CZ, de_DE).

Root cause:
scicloj/plotje/render/svg.clj formats SVG coordinates using (format "%.2f" v), which is locale-sensitive. On Czech locale this produces "12,00" instead of "12.00", turning a valid translate(12.00,181.00) into a malformed translate(12,00,181,00) with four arguments — breaking all point and axis placement.

Minimal repro:

;; Start the JVM with Czech locale, e.g.: -Duser.language=cs -Duser.country=CZ
(require '[scicloj.metamorph.ml.rdatasets :as rdatasets]
         '[scicloj.plotje.api :as pj])

(-> (rdatasets/datasets-iris)
    (pj/lay-point :sepal-length :sepal-width))
;; => chart appears nearly empty; SVG contains translate(5,10,3,50) etc.

Workaround:

(java.util.Locale/setDefault java.util.Locale/ROOT)

or add to deps.edn:

:jvm-opts ["-Duser.language=en" "-Duser.country=US"]

Suggested fix sent in this PR:
In svg.clj, the fmt helper has to be changed to pin the locale explicitly:

(defn- fmt [v]
  (if v (String/format java.util.Locale/ROOT "%.2f" (to-array [(double v)])) "0.00"))

Best.

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