Last active
October 29, 2021 01:34
-
-
Save jkeefe/0109b55df2fd07aa94fef205c96469d7 to your computer and use it in GitHub Desktop.
d3 lines - with intermediary points
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
// assumes multiple lines on a graph | |
// like: {id: 'category one', values: [ [0,0], [1,1] [2,2] ... ]} | |
// define circles as markers for the line to use | |
lines.append('defs') | |
.append('marker') | |
.attr('id', d => `v-dot-${d.id}`) | |
.attr('viewBox', [0, 0, 10, 10]) | |
.attr('refX', 5) | |
.attr('refY', 5) | |
.attr('markerWidth', 5) | |
.attr('markerHeight', 5) | |
.attr('fill', d => color(d.id)) | |
.append('circle') | |
.attr('cx', 5) | |
.attr('cy', 5) | |
.attr('r', 5) | |
.style('fill', d => color(d.id)); | |
// draw lines using the markers | |
lines.append('path') | |
.attr('stroke', d => color(d.id)) | |
.attr('d', d => path(d.values)) | |
.attr('marker-mid', d => `url(#v-dot-${d.id})`) | |
.attr('marker-end', d => `url(#v-dot-${d.id})`) | |
.attr('fill', 'none'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment