Skip to content

Instantly share code, notes, and snippets.

@jwasilgeo
Last active August 29, 2017 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwasilgeo/310c53db34962f992e06f0476a5d94a6 to your computer and use it in GitHub Desktop.
Save jwasilgeo/310c53db34962f992e06f0476a5d94a6 to your computer and use it in GitHub Desktop.
TopoJSON with Random Gaussian Blurs (counties)
license: gpl-3.0
height: 600
border: no
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
<style>
body {
background-color: black;
}
</style>
</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/topojson-client@3.0.0"></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.counties);
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