JSFiddle - React, Tailwind, and code Playground

by mamounothman

HTML

<!DOCTYPE html>
<html>
<meta charset="utf-8">
<body>
<script src="//d3js.org/d3.v4.min.js"></script>
<script src="//d3js.org/queue.v1.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3-tip/0.7.0/d3-tip.js"></script>
</body>
</html>

CSS

.names {
  fill: none;
  stroke: #fff;
  stroke-linejoin: round;
}

/* Tooltip CSS */
.d3-tip {
  line-height: 1.5;
  font-weight: 400;
  font-family:"avenir next", Arial, sans-serif;
  padding: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #FFA500;
  border-radius: 1px;
  pointer-events: none;
}

/* Creates a small triangle extender for the tooltip */
.d3-tip:after {      
  box-sizing: border-box;
  display: inline;
  font-size: 8px;
  width: 100%;
  line-height: 1.5;
  color: rgba(0, 0, 0, 0.6);
  position: absolute;
  pointer-events: none; 
}

/* Northward tooltips */
.d3-tip.n:after {
  content: "\25BC";
  margin: -1px 0 0 0;
  top: 100%;
  left: 0;
  text-align: center;
}

/* Eastward tooltips */
.d3-tip.e:after {
  content: "\25C0";
  margin: -4px 0 0 0;
  top: 50%;
  left: -8px;
}

/* Southward tooltips */
.d3-tip.s:after {
  content: "\25B2";
  margin: 0 0 1px 0;
  top: -8px;
  left: 0;
  text-align: center;
}

/* Westward tooltips */
.d3-tip.w:after {
  content: "\25B6";
  margin: -4px 0 0 -1px;
  top: 50%;
  left: 100%;
}


.details{
  color:white;
}

JavaScript

var format = d3.format(",");

// Set tooltips
var tip = d3.tip()
    .attr('class', 'd3-tip')
    .offset([-10, 0])
    .html(function(d) {
        return "<strong>Country: </strong><span class='details'>" + d.properties.name + "<br></span>" + "<strong>Population: </strong><span class='details'>" + format(d.population) + "</span>";
    })

var margin = {
        top: 0,
        right: 0,
        bottom: 0,
        left: 0
    },
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

var color = d3.scaleThreshold()
    .domain([10000, 100000, 500000, 1000000, 5000000, 10000000, 50000000, 100000000, 500000000, 1500000000])
    .range(["rgb(247,251,255)", "rgb(222,235,247)", "rgb(198,219,239)", "rgb(158,202,225)", "rgb(107,174,214)", "rgb(66,146,198)", "rgb(33,113,181)", "rgb(8,81,156)", "rgb(8,48,107)", "rgb(3,19,43)"]);

var path = d3.geoPath();

var svg = d3.select("body")
    .append("svg")
    .attr("width", width)
    .attr("height", height)
    .append('g')
    .attr('class', 'map');

var projection = d3.geoMercator()
    .scale(130)
    .translate([width / 2, height / 1.5]);

var path = d3.geoPath().projection(projection);


svg.call(tip);

queue()
		 .defer(d3.json, "https://gist.githubusercontent.com/micahstubbs/8e15870eb432a21f0bc4d3d527b2d14f/raw/a45e8709648cafbbf01c78c76dfa53e31087e713/world_countries.json")
    .await(ready);

function ready(error, data) {



var population = [{
        "id": "CHN",
        "name": "China",
        "population": "1330141295"
    },
    {
        "id": "IND",
        "name": "India",
        "population": "1173108018"
    },
    {
        "id": "USA",
        "name": "United States",
        "population": "310232863"
    },
    {
        "id": "IDN",
        "name": "Indonesia",
        "population": "242968342"
    },
    {
        "id": "BRA",
        "name": "Brazil",
        "population": "201103330"
    }
];



   var populationById = {};

    population.forEach(function(d) {
...