Last active
May 4, 2016 19:31
-
-
Save martgnz/41a55aadcd04a528eec2843f2916bea5 to your computer and use it in GitHub Desktop.
Spam.js choropleth with colors
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
<!DOCTYPE html> | |
<meta charset="utf-8" /> | |
<body> | |
<script src="d3.min.js"></script> | |
<script src="topojson.min.js"></script> | |
<script src="rbush.min.js"></script> | |
<script src="spam.min.js"></script> | |
<script type='text/javascript'> | |
var color = d3.scale.linear() | |
.domain([0.1, 0.18, 0.26, 0.33, 0.41]) | |
.range(["#ca0020", "#f4a582", "#f7f7f7", "#92c5de", "#0571b0"]) | |
d3.json("bcn.json", function(error, d) { | |
topojson.presimplify(d) | |
var map = new StaticCanvasMap({ | |
element: "body", | |
data: [{ | |
features: topojson.feature(d, d.objects["bcn"]), | |
static: { | |
paintfeature: function(parameters, d) { | |
parameters.context.fillStyle = color(d.properties.rate); | |
parameters.context.fill() | |
parameters.context.lineWidth = 0.5 / parameters.scale | |
parameters.context.strokeStyle = 'rgba(0,0,0,0.2)' | |
parameters.context.stroke() | |
} | |
} | |
} | |
] | |
}) | |
map.init() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment