Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all plots are empty #5

Open
behrica opened this issue Oct 10, 2017 · 1 comment
Open

all plots are empty #5

behrica opened this issue Oct 10, 2017 · 1 comment

Comments

@behrica
Copy link

behrica commented Oct 10, 2017

I can not get any plots to work.

I believe it has to do with the id mangling, which eventually with the latest version of svglite is broken.

This fork works for me:

https://github.com/tentamen/gg4clj

which basically removes id mangling

@michaelcole-LN
Copy link

The problem is just that the regex in the mangling needs a slight change. It seems the svglite now produces ids set off with ' rather than ".

The comment in mangle-ids that svglite reuses the ids in each plot still holds, so multi-plot documents might be affected.

Here is the function with the regex changes:

(defn- mangle-ids
"ggplot produces SVGs with elements that have id attributes. These ids are unique within each plot, but are
generated in such a way that they clash when there's more than one plot in a document. This function takes
an SVG string and replaces the ids with globally unique ids. It returns a string.
This is a workaround which could be removed if there was a way to generate better SVG in R. Also:
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454
"
[svg]
(let [ ;ids (map last (re-seq #"id="([^\"])"" svg))
ids (map last (re-seq #"id='([^']
)'" svg))
id-map (zipmap ids (repeatedly (count ids) #(str (UUID/randomUUID))))]
(-> svg
(s/replace #"id='([^'])'" #(str "id='" (get id-map (last %)) "'"))
(s/replace #"'#([^']
)'" #(str "'#" (get id-map (last %)) "'"))
(s/replace #"url(#([^']))" #(str "url(#" (get id-map (last %)) ")")))
;(-> svg
; (s/replace #"id="([^\"]
)"" #(str "id="" (get id-map (last %)) """))
; (s/replace #""#([^\"])"" #(str ""#" (get id-map (last %)) """))
; (s/replace #"url(#([^\"]
))" #(str "url(#" (get id-map (last %)) ")")))
; svg
))

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

No branches or pull requests

2 participants