Skip to content

Instantly share code, notes, and snippets.

@apbryant
Created October 15, 2018 17:03
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 apbryant/58820a836a99e35386423b96d64f6de6 to your computer and use it in GitHub Desktop.
Save apbryant/58820a836a99e35386423b96d64f6de6 to your computer and use it in GitHub Desktop.
How expats feel
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>How expats feel</title>
<script src="https://d3js.org/d3.v5.min.js"></script>
</head>
<body>
<script type="text/javascript">
// Your beautiful D3 code will go here
var h = 1000;
var w = 500;
var w2 = 700
var projection = d3.geoAlbersUsa().translate([w / 2, 150])
.scale(500);
var projection2 = d3.geoMercator().translate([-200 , 600 ])
.scale(400).rotate([0, 0, 180]);
var path2 = d3.geoPath()
.projection(projection2);
var path = d3.geoPath()
.projection(projection);
var svg = d3.select('body')
.append('svg')
.attr('id', 'svg')
.attr('height', h)
.attr('width', w)
.attr('transform', 'translate(900, 200)');
var svg2 = d3.select('body')
.append('svg')
.attr('height', h)
.attr('id', svg2)
.attr('width', w)
.attr('transform', 'translate(-100, 400)');
var gMap = svg.append('g').attr('id', 'map');
var gMap2 = svg2.append('g').attr('id', 'map2');
var gPoint = svg.append('g').attr('id', 'point');
// data from: https://bit.ly/2noo4h9
d3.json('chile_regions.json').then(function(data){
gMap.selectAll('path')
.data(data.features)
.enter()
.append('path')
.attr('d', path2)
.attr('fill', '#F1FAEE')
.attr('stroke', '#A8DADC');
});
// data from: https://bit.ly/2OjHj8l
d3.json('us-states.json').then(function(data){
gMap2.selectAll('path')
.data(data.features)
.enter()
.append('path')
.attr('d', path)
.attr('fill', '#F1FAEE')
.attr('stroke', '#1D3557');
});
d3.select('#point').append('circle')
.attr('cx', 100)
.attr('cy', 350)
.attr('r', 7)
.attr('fill', '#E63946')
.attr('stroke', '#1D3557');
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment