Last active
August 29, 2017 12:30
-
-
Save jwasilgeo/592f47160785ccf8de5b1ca7133df692 to your computer and use it in GitHub Desktop.
TopoJSON with Random Gaussian Blurs (states)
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
license: gpl-3.0 | |
height: 600 | |
border: no |
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> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" /> | |
</head> | |
<body> | |
<svg width="960" height="600" stroke-linejoin="round" stroke-linecap="round"> | |
<defs></defs> | |
</svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://unpkg.com/[email protected]"></script> | |
<script> | |
var svg = d3.select('svg'); | |
var defs = svg.select('defs'); | |
var path = d3.geoPath(); | |
d3.json('https://unpkg.com/us-atlas@1/us/10m.json', function(error, us) { | |
if (error) { | |
throw error; | |
} | |
var geoJsonFeatureCollection = topojson.feature(us, us.objects.states); | |
defs.selectAll('filter') | |
.data(geoJsonFeatureCollection.features) | |
.enter().append('filter') | |
.attr('id', function(d) { | |
return 'blur_' + d.id; | |
}) | |
.append('feGaussianBlur') | |
.attr('stdDeviation', d3.randomUniform(0.5, 5)); | |
svg.selectAll('path') | |
.data(geoJsonFeatureCollection.features) | |
.enter().append('path') | |
.attr('d', path) | |
.style('fill', 'transparent') | |
.style('stroke', 'steelblue') | |
.style('stroke-width', 0.5) | |
.style('filter', function(d) { | |
return 'url(#blur_' + d.id + ')'; | |
}) | |
.on('mouseover', function(d) { | |
d3.select(this) | |
.style('stroke-width', 2) | |
.style('filter', '') | |
.raise(); | |
}) | |
.on('mouseout', function(d) { | |
d3.select(this) | |
.transition() | |
.delay(150) | |
.style('stroke-width', 0.5) | |
.style('filter', 'url(#blur_' + d.id + ')'); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment