Created
May 21, 2014 00:00
-
-
Save jamesmccann-zz/81b7756f47bf565493df to your computer and use it in GitHub Desktop.
Using a clip-path for circular avatar images in D3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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