Skip to content

Instantly share code, notes, and snippets.

@jamesmccann-zz
Created May 21, 2014 00:00
Show Gist options
  • Save jamesmccann-zz/81b7756f47bf565493df to your computer and use it in GitHub Desktop.
Save jamesmccann-zz/81b7756f47bf565493df to your computer and use it in GitHub Desktop.
Using a clip-path for circular avatar images in D3
# Add a clippath to defs for circular profile images
defs.append('clipPath')
.attr('id', 'clip-circle')
.append('circle')
.attr('r', PROFILE_IMAGE_RADIUS)
.attr('cx', 0)
.attr('cy', 0)
# Usage
nodeGroup.append('g')
.attr('class', 'image-group')
.append('image')
.attr('xlink:href', (d) -> d.profile_image_url)
.attr('clip-path', 'url(#clip-circle)')
.attr('x', -PROFILE_IMAGE_RADIUS)
.attr('y', -PROFILE_IMAGE_RADIUS)
.attr('width', 2*PROFILE_IMAGE_RADIUS)
.attr('height', 2*PROFILE_IMAGE_RADIUS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment