tags:

views:

55

answers:

2

From my research, i understand there are three ways to place an svg file inside HTML:

using embed:

<embed src="plot1.svg" width="500" height="320" type="image/svg+xml" />


using object:

<object data="plot1.svg" width="500" height="320" type="image/svg+xml" />


using iframe:

<iframe src="plot1.svg" width="500" height="320"> </iframe>


I've experimented with all three on a test rig (django built-in dev server, rendering the pages in Firefox 3.6). Under this obviously sterile environment, i haven't noticed any difference between the three--w/r/t performance or resolution.

My Question is whether one of these is better than the other two, and if so, which one. The answer might of course depend on the facts, which i've tried to limit to what's relevant:

We frequently display data (e.g, time series) on our website, usually created in response to some user action; based on that user action, a call is made to a database, the data returned is crunched and sent to the plotting engine, which renders a static image which is then embedded in the page--very standard stuff.

This works fine, but i would like to add some interactive features to these charts (e.g., tooltips, hyperlinked axis labels, highlighting a group of points w/in a plot). Some of the charts are fairly sophisticated (e.g., multi-panel conditioning) and i have not found a javascript chart library that includes these features. I finally settled on using the same plotting library (Lattice in R) but rendering each chart in svg and then adding the user-interaction features in a post-processing step, which consists essentially of javascript functions which manipulate the XML directly.

+1  A: 

<embed> I would generally avoid. It's deprecated in HTML4, doesn't allow proper fallback content, and has had a selection of problems in IE.

<object> will allow you to include fallback HTML content for browsers without SVG support. <iframe> will fall back to prompting you to download the .svg file. Which of those is best probably depends on the application.

The other alternative, for modern browsers (including IE from version 9) is to serve your web page as application/xhtml+html and include the SVG elements in the page itself.

bobince
Or as `text/html` for html5-capable browsers, preferrably together with a js shim for older browsers, see http://svgboilerplate.com/.
Erik Dahlström
Whoa, IE supports SVG now? Never thought it would happen. Is VML still around too or what?
no
Well IE9 is still in beta but supports SVG (and pretty nicely, too). SVG boilerplate doesn't make SVG actually *work* down to IE6, it just makes it possible to put on a page without killing IE6. VML still exists, but would seem to be unwanted legacy; MS broke it quite badly in IE8, requiring another tedious round of workarounds for the people still using it.
bobince
+2  A: 

Just as a FYI, there are several other ways to include svg on a page.

Erik Dahlström