ft-interactive/svg-wrapper

Name: svg-wrapper

Owner: FT Interactive News

Description: Load an SVG or define an image as a fallback.

Created: 2013-10-07 18:43:21.0

Updated: 2014-03-06 16:45:56.0

Pushed: 2014-03-06 16:45:56.0

Homepage:

Size: 224

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

svg-wrapper

Load an SVG or define an image as a fallback.

Usage

Example

ame src="http://{hostname}/svg-wrapper/img.html#http://example.com/mygraphic.svg__.thing-to-hide__true__ff0000" width="100" height="0" scrolling="no" frameborder="0"></iframe>

In the iframe above you will notice that parameters to the SVG wrapper are provided via the hash/fragment. The hash is used to improve caching.

In the example above the SVG wrapper is being passed four parameters:

Parameters are separated by a double underscore (__) and recognised by their position, for example the first param is the SVG url and the second is the fallback. If you don't want to provide a value for a particular param then you need to use 4 underscores (____).

Params
0 : Full absolute URL to the SVG 1 : Fallback content. 2 : Append to parent window 3: Background color
iframe dimensions

The iframe's dimensions are used to set the size of the SVG (or the fallback image) nicely scaling the image automatically.

If one or either of the dimensions are 0 (or not defined) then these will automatically be calculated.

You can either use the width or height attributes or an inline style on the iframe e.g. style="width:0;height:100px;".

If the SVG is being loaded into the iframe (rather than the parent window) then both the iframe and the image inside it will be the same size.

Examples:

width="100" height="0" : the SVG will be scaled so that it's 100px wide and the height will be set to whatever it needs to be to maintain the SVG's aspect ratio.

width="0" height="100" : the SVG will be scaled so that it's 100px high and the width will be set to whatever it needs to be to maintain the SVG's aspect ratio.

width="0" height="0" : the SVG (and the parent iframe) will be set to whatever the original dimension of the graphic are.

width="100" height="100" : the SVG (and the parent iframe) will resized to best fit the defined dimensions will maintaining aspect ratio.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.