TransWikia.com

How to generate non interfering SVGs (Cloud embedded)?

Mathematica Asked on September 22, 2020

The problem

Please run this in the Cloud:

StringJoin[
  ExportString[{},"SVG"]
, "<br>"
, ExportString[Plot[Sin[x],{x,0,6}],"SVG"]
]//EmbeddedHTML

enter image description here

Notice that x-axis 1 and 2 ticks were replaced with {}.

Probable cause

That is because they they are referenced within svg with e.g.:

<use xlink:href="#glyph0-2" x="130.22449" y="118.975691"></use>

and this glyph0-2 id is defined in <defs> for both svgs. Since ids are supposed to be unique only the very first one found is used in both images.

How to deal with this?

One Answer

Do not know how general it is but works for me atm:

UniqueSVGExport[expr_]:= Module[{uniqueRef}
, uniqueRef[s_String]:=uniqueRef[s] = CreateUUID[s]
; ExportString[expr, "SVG"] // 
    StringReplace[
      g : ("glyph" ~~ DigitCharacter .. ~~ "-" ~~ DigitCharacter ..) :> uniqueRef@g
    ]
]

enter image description here

Answered by Kuba on September 22, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP