chart = {
const width = 350,
height = 300;
const svg = d3.create("svg")
.attr("viewBox", [50, 30, width-100, height-100]);
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], BERbox);
var path1 = d3.geoPath().projection(projection);
var path2 = d3.geoPath().projection(projection);
var path3 = d3.geoPath().projection(projection);
var path4 = d3.geoPath().projection(projection);
var path5 = d3.geoPath().projection(projection);
var path6 = d3.geoPath().projection(projection);
var path7 = d3.geoPath().projection(projection);
var path8 = d3.geoPath().projection(projection);
var path9 = d3.geoPath().projection(projection);
var g = svg.append("g").attr("id", "paths");
g.selectAll("path4")
.data(BERwater.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path4)
.style('fill', 'slateblue')
.style("fill-opacity", ".3")
.style('stroke-opacity','.4')
.style("stroke-width", '.1')
.style('stroke', 'rebeccapurple')
g.selectAll("path6")
.data(BERbuildings.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path3)
.style('fill', 'lightblue')
.style("fill-opacity", ".6")
.style('stroke-opacity','.4')
.style("stroke-width", '.1')
.style('stroke', 'steelblue')
var c = svg.selectAll("circle")
.data(BERspots)
.enter()
.append("circle")
.attr("cx", function(d) {return projection([d.Long,d.Lat])[0]})
.attr("cy", function(d) {return projection([d.Long,d.Lat])[1]})
.attr('r', 3)
.attr('fill',colorType)
.attr('stroke-opacity','.65')
.attr("stroke-width", "2")
.attr('stroke', 'pink')
.style('fill-opacity','1')
function colorType(d,i) {
var color = 'black'
if(d.ActivityType=='club'){color = 'firebrick'}
if(d.ActivityType=='shop'){color = 'mediumvioletred'}
return color
}
{
const yTitle = g => g.append("text")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("y", 10)
.attr("transform", `translate(${100+margin.left},0)`)
.text("Violations")
const xTitle = g => g.append("text")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("x", width/2)
.attr("y", height)
.text("Number of Apprehensions")
svg.append("g")
.attr("fill", "green")
.selectAll("rect")
.data(BERspots)
.join("rect")
.attr("x", x(0))
.attr("y", d => y(d.violation))
.attr("width", d => x(d.number_of_apprehensions) - x(0))
.attr("height", y.bandwidth())
.on("mouseover", function(d) {
d3.select(this).attr("fill", "white");
var yPosition =
parseFloat(d3.select(this).attr("y")) +
y.bandwidth() / 2;
var xPosition =
parseFloat(d3.select(this).attr("x")) / 2 + width / 2;
tooltip
.html(
`<div> <strong>Violation: </strong>${d.violation}</div><div><strong>Number of Apprehensions:</strong> ${d.number_of_apprehensions}</div>`
)
.style('visibility', 'visible');
})
.on('mousemove', function () {
tooltip
.style('top', d3.event.pageY - 10 + 'px')
.style('left', d3.event.pageX + 10 + 'px');
})
.on('mouseout', function () {
tooltip.html(``).style('visibility', 'hidden');
d3.select(this).transition().attr('fill', 'blue');
});
var wrap = svg.selectAll("text.spots")
.each(function(d,i) {wrap_text(d3.select(this), 100) } );
}
return svg.node();
}