Skip to content

Instantly share code, notes, and snippets.

View cscheid's full-sized avatar

Carlos Scheidegger cscheid

View GitHub Profile
@cscheid
cscheid / README.md
Created November 28, 2012 18:41 — forked from mbostock/.block
Gradient Along Stroke

This example demonstrates how to create a gradient that follows a stroke. This technique is sometimes used to indicate directionality along a curved edge, such as with hierarchical edge bundling.

To start, take any SVG path element and uniformly sample points along the path using getPointAtLength. (This method can also be used for path tweening.) Then, for each segment between adjacent points, compute the miter joint via line-line intersection. Lastly fill each segment by interpolating the start and end colors, here green to red, using the normalized length t along the path. Although each segment is a constant color, there are many segments to give the appearance of a continuous gradient.

This example uses a thin stroke in addition to filling the segments. This avoids antialiasing artifacts due to most

@cscheid
cscheid / index.html
Created August 22, 2012 22:47
Some d3 tests
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.5.0"></script>
</head>
<body><div id="test"></div>
<script>
var names = ["v1",
"v2",
"v3",
"v4",