Skip to content

Instantly share code, notes, and snippets.

@vitch
Created August 1, 2012 13:44
Show Gist options
  • Save vitch/3226952 to your computer and use it in GitHub Desktop.
Save vitch/3226952 to your computer and use it in GitHub Desktop.
SVG background images on d3 fills
#graph svg g.us rect
{
fill: url(#tile-us) #cccccc;
}
#graph svg g.worldwide rect
{
fill: url(#tile-ww) #cccccc;
}
var svg = d3.select(this.el)
.append('svg')
.attr('class', 'chart')
.attr('width', this.graphWidth)
.attr('height', this.graphHeight),
defs = svg.append('svg:defs');
defs
.append('svg:pattern')
.attr('id', 'tile-ww')
.attr('patternUnits', 'userSpaceOnUse')
.attr('width', '6')
.attr('height', '6')
.append('svg:image')
.attr('xlink:href', '/images/tile-worldwide.png')
.attr('x', 0)
.attr('y', 0)
.attr('width', 6)
.attr('height', 6);
defs
.append('svg:pattern')
.attr('id', 'tile-us')
.attr('patternUnits', 'userSpaceOnUse')
.attr('width', '7')
.attr('height', '9')
.append('svg:image')
.attr('xlink:href', '/images/tile-us.png')
.attr('x', 0)
.attr('y', 0)
.attr('width', 7)
.attr('height', 9);
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment