Illustrator / SVG for working with JavaScript? (Template library?)

When Illustrator uses Save As SVG, this is a typical result:

<?xml version="1.0" encoding="iso-8859-1"?> <!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="841.89px" height="595.28px" viewBox="0 0 841.89 595.28" style="enable-background:new 0 0 841.89 595.28;" xml:space="preserve"> <g id="symbol1" ... > <path ... /> <path ... /> <path ... /> </g> </svg> 

I would like to know if there is any JavaScript template library (e.g. mustache, rudder, etc.) that will allow me to use SVG similarly to HTML?
This would allow me to save a bunch of SVG element templates and dynamically set their style attributes and content ...

+4
source share
2 answers

I'm not sure if this answers your question, since it is not clear what you mean by “[using] SVG is similar to HTML”, but there is a JavaScript library called Raphaël that allows you to manipulate SVG graphics in a way that is similar to using jQuery for HTML page controls. This means that you can animate images, attach event handlers, and change colors or shapes on the page. (The bonus is that Raphaël uses VML for Internet Explorer without SVG support.) Another way is to use jQuery SVG or some other library .

Of course, SVG is just XML, which is a text format, so any template engine should work with it, but the difference is in using Raphaël, jQuery SVG, etc. the fact is that they do not manipulate the source text of the basic XML format, but the resulting DOM tree, which means not only that you can see the results live while you modify the tree, but also it’s much more difficult to create invalid documents, which is quite common if You manipulate the XML source with templates that usually do not understand XML, but instead process it like any text.

I recommend reading the Illustrator for Raphael JS: A Guide and see how the Raphaël SVG Import Plug-in and Raphaël SVG Import Classic on GitHub.

0
source

According to https://groups.google.com/forum/#!topic/d3-js/qVZ7hacBGrE you can use underline patterns.

The forum also discusses an alternative:

  • create svg "defs"
  • insert svg object with "use"
  • change it using d3.js
  • make visible
0
source

All Articles