{
const points = d3.select(plot).selectAll("circle").data(sorted_hospitals);
const points1 = d3.select(chicago).selectAll("circle").data(chicago_hospitals);
const bars = d3.select(stacked_bars).selectAll("rect");
let isClicked = false;
points.on("pointerover", function(event, d) {
drawPie(d, svg1);
});
points.on('pointerout', function(event, d) {
svg1.selectAll("svg > *").remove();
});
points1.on("pointerover", function(event, d) {
drawPie(d, svg1);
});
points1.on('pointerout', function(event, d) {
svg1.selectAll("svg > *").remove();
});
var selectedBars = [];
bars.on("click", function(event, d) {
var id = d3.select(this).text().substring(0, 6);
var index = selectedBars.indexOf(id);
if(index === -1) {
selectedBars.push(id);
bars.filter(function(d) {
return (d3.select(event.currentTarget).text() == d3.select(this).text());
}).classed("highlight", true);
points.filter(function(d) {
return d.entity_id == id;
}).classed("highlight", true);
points1.filter(function(d) {
return d.entity_id == id;
}).classed("highlight", true);
}
else {
selectedBars.splice(index, 1);
bars.filter(function(d) {
return (d3.select(event.currentTarget).text() == d3.select(this).text());
}).classed("highlight", false);
points.filter(function(d) {
return d.entity_id == id;
}).classed("highlight", false);
points1.filter(function(d) {
return d.entity_id == id;
}).classed("highlight", false);
}
});
}