chart = {
const width=800, height=800;
const svg = d3.select(DOM.svg(width, height))
var projection = d3.geoMercator()
.fitExtent([[10, 10], [width, height]], bayAreaMap);
var path = d3.geoPath()
.projection(projection);
svg.append('g').selectAll('path')
.data(bayAreaMap.features)
.enter().append('path')
.attr('d', path)
.style('fill', 'white')
.style('stroke', '#ccc')
svg.selectAll('circle')
.data(dataset)
.join('circle')
.attr('cx', d => projection([d.latitude, d.longitude])[0])
.attr('cy', d => projection([d.latitude, d.longitude])[1])
.attr('fill', "purple")
.attr('r', 3)
.on("mouseover", function (event, d) {
svg.select("#tooltip-text")
.text(d.name);
svg.select("#tooltip-rating")
.text("Rating: " + d.rating);
svg.select("#tooltip-price")
.text("Price: " + d.price);
let positionOffest = 8;
svg.select("#tooltip")
// move the tooltip to where the cursor is
.attr("transform", `translate(${x(d.x) + positionOffest}, ${y(d.y) + positionOffest})`)
.style("display", "block"); // make tooltip visible
d3.select(this)
.attr("stroke", "#000")
.attr("stroke-width", 2);
svg.select("#tooltip")
// move the tooltip to where the cursor is
.attr("transform", `translate(${x(d.x) + positionOffest}, ${y(d.y) + positionOffest})`)
.style("display", "block"); // make tooltip visible
})
/* hide tooltip on mouseout ******/
.on("mouseout", function (event, d) {
svg.select("#tooltip").style("display", "none");
d3.select(this).attr("stroke", "none");
//.attr("stroke", "purple")
//.attr("stroke-width", 1);
});
const labels = svg.append("g").attr("id", "labels")
labels.selectAll("text")
.data(bayAreaMap)
.join('text')
.attr('text-anchor', 'middle')
.attr('fill', 'white')
.text(d => d.properties.CITY)
.attr('x', d => pathRenderer.centroid(d)[0])
.attr('y', d => pathRenderer.centroid(d)[1])
/* intersection circle 1 */
svg.append("circle")
.attr("id", "circleOne")
.attr("cx", d => projection([-122.3642615, 37.5863038])[0])
.attr("cy", d => projection([-122.3642615, 37.5863038])[1])
.attr("r", 50)
.attr("fill-opacity", 0.25)
.attr("fill", "steelblue")
.attr("stroke", "steelblue")
.call(drag);
/* intersection circle 2 */
svg.append("circle")
.attr("id", "circleTwo")
.attr("cx", d => projection([-122.3642615, 37.5863038])[0] + 100)
.attr("cy", d => projection([-122.3642615, 37.5863038])[1] + 100)
.attr("r", 50)
.attr("fill-opacity", 0.25)
.attr("fill", "steelblue")
.attr("stroke", "steelblue")
.call(drag);
/* tooltip code */
const tooltipGroup = svg.append("g")
.attr("id", "tooltip")
.style("display", "none")
.append("text")
.attr("id", "tooltip-text")
.attr("x", 5)
.attr("y", 15)
.attr("font-size", "14px")
.attr("font-weight", "bold")
.attr("fill", "black");
return svg.node()
}