Skip to content

Instantly share code, notes, and snippets.

Last active Jan 19, 2018
What would you like to do?
Simple map of Euskadi shchool zones with topojson and interactivity
license: gpl-3.0
height: 500
scrolling: no
border: no
<!DOCTYPE html>
<html dir="ltr" lang="es-ES">
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Single map</title>
<script src=""></script>
<script src=""></script>
html, body {
margin: 0;
padding: 0;
path:hover {
stroke-width:2px !important;
stroke:black !important;
h1 {
p {
<h1>Porcentaje de extranjeros en escuela pública</h1>
// basado en
var width = 400,
height = 350;
var svg ="body").append("svg")
.attr("width", width)
.attr("height", height)
var color = d3.scale.linear()
.domain([0, 38])
// Adds tooltip
var tooltip ="body")
.attr("class", "tooltip")
d3.json("limites-zonas-escolares-euskadi-con-variables-2014-15_simplify3.json", function(error, uk) {
// topojson creado con y simplificado con
if (error) return console.error(error);
// Variable con todos los datos
var subunits = topojson.feature(uk, uk.objects.barrios);
// Projection for Euskadi
var projection = d3.geo.mercator()
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.attr("d", path)
.attr("stroke", "grey");
.attr("class", function(d) { return "subunit z" +; })
.attr("fill", function(d) { return color(; })
.attr("d", path)
.on("mousemove", showTooltip) // AÑADIR EVENTO SHOW TOOLTIP
.on("mouseout", hideTooltip); // OCULTAR TOOLTIP
// Función para motrar el tooltip
function showTooltip(d) {
tooltip.html("<div class='table-responsive'><strong>" + + " " + + "%</strong> (zona " + + ")</div>").style("opacity", 1)
// Función para ocultar el tooltip
function hideTooltip(d) {"opacity", 0)
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