Skip to content

Instantly share code, notes, and snippets.

@DeCotii
Created January 8, 2017 23:16
Show Gist options
  • Save DeCotii/ad260cea42cf60d806725e9b7ee56603 to your computer and use it in GitHub Desktop.
Save DeCotii/ad260cea42cf60d806725e9b7ee56603 to your computer and use it in GitHub Desktop.
var tip = d3.tip()
.attr('class', 'd3-tip-map')
.offset([0, 0])
.html(function (d) {
var tooltip = "<div>";
tooltip += "<h4>" + regionLabels[d.properties.REGION_ID].label + "</h4>";
Object.keys(mapData).forEach(function(goal) {
if (goalKeyToNameMapping[goal] === 'Index') {
tooltip += "<p class='tooltip-bottom pull-left'> Rank" + "<b><span>" + mapData[goal][d.properties.REGION_ID].ranking + "</span></b>"+ "</p>";
tooltip += "<p class='tooltip-bottom pull-right'> Index Score " + "<b><span>" + mapData[goal][d.properties.REGION_ID].score + "</span></b>"+ "</p>";
} else if (goalKeyToNameMapping[goal]) {
tooltip += "<p>" + goalKeyToNameMapping[goal] + ": " + "<b>" + mapData[goal][d.properties.REGION_ID].score + "</b>"+ "</p>";
}
});
tooltip += "</div>";
return tooltip;
});
var zoomed = function () {
projections.attr('transform', 'translate(' + d3.event.translate + ')scale(' + d3.event.scale + ')');
};
var zoom = d3.behavior.zoom()
.translate([0, 0])
.scale(1)
.scaleExtent([1,8])
.on('zoom', zoomed);
var scale = d3.scale.threshold()
.domain([25, 50, 75, 90])
.range(['legend-color-0', 'legend-color-1', 'legend-color-2', 'legend-color-3', 'legend-color-4']);
var svg = d3.select('.country-map-wrap').append('svg')
.attr('width', '100%')
.attr('height', height)
.attr('viewBox', '0 0 ' + width + ' ' + height);
var projections = svg.append('g').attr('class', 'projections');
var highseas = projections.append('g').attr('class', 'highseas');
var eezs = projections.append('g').attr('class', 'eezs');
var land = projections.append('g').attr('class', 'land');
svg
.call(zoom)
.call(zoom.event)
.call(tip);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment