earthjs
Version:
D3 Earth JS using SVG, Canvas & THREE js, build with some plugins.
41 lines (40 loc) • 1.73 kB
HTML
<html>
<head>
<link type="text/css" rel="stylesheet" href="../css/earthjs.css">
<link type="text/css" rel="stylesheet" href="./style.css">
<script type='text/javascript' src="../js/d3.min.js"></script>
<script type='text/javascript' src="../js/topojson.min.js"></script>
<script type='text/javascript' src="../js/d3-scale-chromatic.v1.min.js"></script>
<script type='text/javascript' src='../js/earthjs.js'></script>
<style id="choropleth"></style>
</head>
<body>
<h4 id="title">CHOROPLETH</h4>
<div class="selected-country">
<div class="content"></div>
</div>
<div class="svg-container">
<svg id="earth-js" class="ej-center"/>
</div>
<script>
const {offsetWidth, offsetHeight} = d3.select('body').node();
const g = earthjs({width: offsetWidth, height: offsetHeight, padding:5,map: true})
.register(earthjs.plugins.zoomPlugin())
.register(earthjs.plugins.choroplethCsv('../data/2010_alcohol_consumption_by_country.csv'))
.register(earthjs.plugins.worldSvg('../d/world-110m.json'));
g.choroplethCsv.ready = function(err, json) {
json.forEach(x => x.alcohol = +x.alcohol);
g.choroplethCsv.data(json);
}
g.ready(function(){
const countries = g.worldSvg.allData().countries;
g.choroplethCsv.countries(countries.features);
g.choroplethCsv.mergeData(countries, ['properties.cid:cid', 'properties.value:alcohol']);
g.choroplethCsv.colorize('alcohol', 'schemeReds');
g.choroplethCsv.setColorRange('body');
g.choroplethCsv.setCss('#choropleth');
g.create();
})
</script>
</body>
</html>