ph_map = {
const svg = d3
.create('svg')
.attr('width', renderData.width)
.attr('height', renderData.height);
svg.append("g")
.attr("class", "legend_auto")
.style('font-size', 12)
.style('font-family', 'sans-serif')
.attr("transform", "translate(10,20)")
.call(legend_svg)
svg.selectAll('.label')
.attr("transform", "translate(20, 13)")
const circle = d3.symbol().type(d3Legend.symbolCircle);
const symbolScale = d3.scaleOrdinal()
.domain(['SM Supermall',])
.range([ circle] );
const margin_top_legend = 70;
const margin_right_legend = 250;
svg.select(".legend_auto")
.attr("transform", `translate(${width-margin_right_legend},${margin_top_legend})`)
const clippedWidth = renderData.width - renderData.margin * 2;
const clippedHeight = renderData.height - renderData.margin * 2;
const geoMercator = d3
.geoMercator()
.center([128, 36])
.fitSize([clippedWidth, clippedHeight], geoJson);
const pathGen = d3.geoPath(geoMercator);
const stage = svg
.append('g')
.attr('transform', `translate(${renderData.margin},${renderData.margin})`);
const textX = 10;
const textY = 10;
const infoText = stage
.append('g')
.attr('transform', `translate(${textX},${textY})`)
.append('text')
.style("font", "20px sans-serif");
infoText.text('no data');
const onMouseHover = d => {
stage
.selectAll('.geopath')
.filter(td => td.properties.ADM1_EN === d.properties.ADM1_EN)
.transition()
.duration(250)
.attr('fill', "rgba(255,69,0,0.5)")
.style('transform-origin', "center center")
.style('transform', "scale(1.02)")
.style("mix-blend-mode", "darken");
infoText.text(d.properties.ADM1_EN);
tooltip.html(`<div> <strong>Region: </strong>${d.properties.ADM1_EN}</div>
<div> <strong>Population: </strong>${population_format(d.properties.population)}</div>`)
.style('visibility', 'visible');
};
const onMouseMove = d => {
tooltip
.style('top', d3.event.pageY - 10 + 'px')
.style('left', d3.event.pageX + 10 + 'px');
}
const onMouseLeave = d => {
stage
.selectAll('.geopath')
.filter(td => td.properties.ADM1_EN === d.properties.ADM1_EN)
.transition()
.duration(250)
.attr('fill', td => colorScale(td.properties.population))
.style('transform-origin', "center center")
.style('transform', "scale(1)")
.attr('stroke-width' , 1);
infoText.text('Hover on a region');
tooltip.html(``).style('visibility', 'hidden');
};
const tEnter = enter =>
enter
.append('path')
.attr('d', pathGen)
.attr('stroke', 'white')
.attr('fill', td => colorScale(td.properties.population))
.classed('geopath', true)
.on('mouseenter', onMouseHover)
.on('mousemove', onMouseMove)
.on('mouseleave', onMouseLeave);
const tUpdate = null;
const tExit = null;
stage
.selectAll('.geopath')
.data(geoJson.features)
.join(tEnter, tUpdate, tExit);
return svg.node();
}