Skip to content

Instantly share code, notes, and snippets.

@jklemmack
Forked from mbostock/.block
Created July 31, 2013 16:21
Show Gist options
  • Select an option

  • Save jklemmack/6123570 to your computer and use it in GitHub Desktop.

Select an option

Save jklemmack/6123570 to your computer and use it in GitHub Desktop.

D3 2.10 adds support for threshold scales which make it easy to apply arbitrary quantization.

<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="https://raw.github.com/mbostock/d3/2.10.0/d3.v2.min.js"></script>
<script>
var width = 960,
height = 500;
var color = d3.scale.threshold()
.domain([2, 4, 6, 8, 10])
.range(["#f2f0f7", "#dadaeb", "#bcbddc", "#9e9ac8", "#756bb1", "#54278f"]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("unemployment.json", function(data) {
d3.json("readme.json", function(collection) {
svg.selectAll("path")
.data(collection.features)
.enter().append("path")
.attr("d", path)
.attr("class", function(d) { return color(data[d.id]); });
});
});
</script>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment