map = function map(data, dataColorScale, createTooltip, legendTitle, tickThresholds, maptype){
let {geoObj, mapProjection} = getMapConf(tipoMapa);
const svg = d3.create("svg")
.style("width", "100%")
.style("height", "80%")
.attr("viewBox", function() {
return tipoMapa === 'País' ? "0 200 650 300": "-300 0 1200 750";
})
if (data && data.length) {
svg.append("g")
.attr("transform", function() {
return tipoMapa === 'País'? `translate(${width/2 - 60}, ${height - 200})`: `translate(${width/2 - 140}, ${height + 50}) `;
})
.append(() =>
legend({
color: color(dataColorScale, maptype),
title: legendTitle,
tickFormat: ".0f",
width: tipoMapa === 'País'? 200 : 380,
height: tipoMapa === 'País' ? 50 : 64,
titleFontSize: tipoMapa === 'País' ? "7px" : "14px",
titleFontWeight: "200",
tickFontSize: tipoMapa === 'País' ? "5px": "10px",
tickSize: tipoMapa === 'País' ? 8: 20,
tickWidth: tipoMapa === 'País' ? 0.7 : 1,
tickPos: tipoMapa === 'País' ? 4 : 7,
tickThresholds: tickThresholds,
roundedValues: false,
sin_info: true
})
);
}
if (createTooltip) {
var div = d3
.select("body")
.append("div")
.attr("class", "arrow_box");
}
svg.append("g")
.selectAll("path")
.data(geoObj.geometries)
.enter()
.append("path")
.attr("class", function() {
return tipoMapa === 'País'? "decideChilePais": "decideChileRegion";
})
.attr("fill", d => map_color(d.properties.canonical_key, data, dataColorScale, tickThresholds, maptype))
.attr("d", d3.geoPath(mapProjection))
.attr('transform', function() {
return tipoMapa === 'País' ? 'rotate(-90 300 300)': null;
})
.on('mouseover', function (d, i) {
svg.selectAll("path")
.attr("fill-opacity", 0.2)
d3.select(this).transition()
.duration('25')
.attr("fill-opacity", 0.8)
div.html(createTooltip(d, data, maptype))
.style("left", (d3.event.pageX + 20) + "px")
.style("top", (d3.event.pageY + 20) + "px")
.style("box-shadow", "0 10px 16px 0 rgba(0,0,0,0.2),8px 6px 15px 0 rgba(0,0,0,0.19)")
.transition()
.duration('25')
.style("opacity", 1) ;
})
.on('mouseout', function (d) {
svg.selectAll("path")
.attr("fill-opacity", 0.8)
d3.select(this).transition()
.duration('25')
div.transition()
.duration('25')
.style("opacity", 0);
});
return svg.node()
}