Built with blockbuilder.org
This is an example of creating a graphic in Adobe Illustrator which is then exported as a SVG file. This image was designed as a new annotation element for another project. The reason for using a tool to generate SVGs is that doing any complex graphic manually does not scale and is very painful to create. However, there are things to consider when bringing external SVGs in, which I will discuss further down.
This SVG is composed of several layers that will support multiple interaction schemes. The red circle is a delete button. The blue circle will be draggable off the SVG to anywhere on the screen with a connecting line back to the parent g. The white space in the middle of the parent g will be for text annotation. Each layer created in Adobe Illustrator gets mapped to a new group element in the SVG each with its own generated ID. Each element in each group is assigned a CSS class for styling. All the CSS is then placed in the header of the SVG element. Each element in each group does not have its own ID.
This SVG is a set of images only. It has not been set up for any interaction yet. Look at the SVG defined in RectAnno3.xml to get an idea of the layout and naming.
The SVG file is read into a D3 based page via a call to d3.xml. The file read in for this example is RectAnno3.xml. Normally this would be a .svg but Gist does not like that so I just changed it to an xml extension and it works the same.
Unlike how you normally create a set of SVG elements in D3, importing a SVG requires a different approach. You explicitly attach your imported SVG directly to a DOM node.
Things to consider when importing external SVGs.
One Workflow could be:
This is my first effort to import SVGs so if there are any errors or comments about how to do this more effectively please revise.
Thanks
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js