function chartBS(data) {
const barGraph = d3.create("svg")
.attr("viewBox", [0, 0, widthBar, heightBar])
.attr("font-family", "Arial");
barGraph.append("g")
.call(xAxisBS)
.selectAll("text").style("font-size", "16")
.attr("y", -10)
.attr("x", 4)
.attr("transform", "rotate(0)")
.style("text-anchor", "end");
barGraph.append("g")
.call(yAxisBS(data));
barGraph.append("g")
.style("stroke-width", 1)
.selectAll("rect")
.data(data)
.enter()
.append("rect")
.style("fill", d => d.ATeam == teamname? colorBS(d.yearChange): teamname == "All Premier League"? colorBS(d.yearChange): "Silver")
.style("stroke", "grey")
.attr("x", xBS(0))
.attr("y", d => yBS(strip(d.ATeam)))
.attr("height", yBS('bandwidth'))
.attr("width", d => xBS(d.barMetric) - xBS(0))
.on("mouseover", function(d) {
barGraph.selectAll("rect")
.style("fill", "silver")
.style("stroke", "grey");
d3.select(this)
.style("stroke", "grey")
.style("stroke-width",2)
.style("fill", d => colorBS(d.yearChange));
scatterGraph.selectAll("circle")
.style("fill", function(dHere) {
if (dHere.ATeam === d.ATeam) {
return colorBS(d.yearChange);
}
else {
return "lightgrey";
}
})
.style("stroke", function(dHere) {
if (dHere.ATeam === d.ATeam) {
return "grey";
}
else {
return "grey";
}
})
.style("stroke-width", function(dHere) {
if (dHere.ATeam === d.ATeam) {
return 1;
}
else {
return 1;
}
});
scatterGraph.select("g#circle-legend").selectAll("circle")
.style("fill", "#FFFFFF")
.style("stroke", "Silver");
})
.on("mousemove", function(d) {
return tooltipBS
.style("top", d3.event.pageY - 10 + "px")
.style("left", d3.event.pageX + 10 + "px")
.style("visibility", "visible")
.text(d.ATeam + ": " + d.barMetric + " " + sizeOb[barStat])
.style("font-size", "15px");
})
.on("mouseout", function(d) {
barGraph.selectAll("rect")
.style("fill", d => d.ATeam == teamname? colorBS(d.yearChange): teamname == "All Premier League"? colorBS(d.yearChange): "silver")
.style("stroke", "grey")
.style("stroke-width",1);
scatterGraph.selectAll("circle")
.style("fill", d => d.ATeam == teamname? colorBS(d.yearChange): teamname == "All Premier League"? colorBS(d.yearChange): "Silver")
.style("stroke", "grey")
.style("stroke-width", "1");
scatterGraph.select("g#circle-legend").selectAll("circle")
.style("fill", "White")
.style("stroke", "Silver");
return tooltipBS.style("visibility", "hidden");
});
const scatterGraph = d3.create("svg")
.attr("viewBox", [0, 0, width, heightBS])
.attr("font-family", "Open Sans");
const xlabelLine = scatterGraph.append("g")
.selectAll("g")
.data(ave1920)
.join("g");
xlabelLine.append("path")
.attr("fill", "none")
.attr("stroke", "lightgrey")
.attr("stroke-width", 1.5)
.attr("d", d3.line()
.x(d => XBS(d[scatXStat]))
.y((d,i) => ynum[i]));
const ylabelLine = scatterGraph.append("g")
.selectAll("g")
.data(ave1920)
.join("g");
ylabelLine.append("path")
.attr("fill", "none")
.attr("stroke", "lightgrey")
.attr("stroke-width", 1.5)
.attr("d", d3.line()
.x((d,i) => xnum[i])
.y(d => YBS(d[scatYStat])));
scatterGraph.append("text")
.style("font-size", 10)
.style("fill", "grey")
.attr("y", YBS(ave1920[0][0][scatYStat])-5)
.attr("x", marginScat.left+10)
.attr("text-anchor", "start")
.text("Last Season Average");
scatterGraph.append("text")
.style("font-size", 10)
.style("fill", "grey")
.attr("y", XBS(ave1920[0][0][scatXStat]) - 5)
.attr("x", - heightBS + marginScat.bottom + 10)
.attr("text-anchor", "start")
.text("Last Season Average")
.attr('transform', 'rotate(-90)');
scatterGraph.append("g")
.call(XAxisBS)
scatterGraph.append("g")
.call(YAxisBS)
scatterGraph.append("text")
.attr("y", heightBS-marginScat.bottom + 60)
.attr("x", (width+marginScat.left)/2)
.attr("text-anchor", "middle")
.attr("font-size", "15px")
.text(sizeOb[scatXStat]);
scatterGraph.append("text")
.attr("y", 40)
.attr("x",(-heightBar)/2)
.attr("text-anchor", "middle")
.attr("font-size", "15px")
.text(sizeOb[scatYStat])
.attr('transform', 'rotate(-90)');
scatterGraph.append("g")
.selectAll("dot")
.data(data)
.enter()
.append("circle")
.attr("r", d => sizeCirc(d.scatSize))
.attr("cx", d => XBS(d.scatX))
.attr("cy", d => YBS(d.scatY))
.style("fill", d => d.ATeam == teamname? colorBS(d.yearChange): teamname == "All Premier League"? colorBS(d.yearChange): "Silver")
.style("stroke", "grey")
.style("stroke-width", "1")
.on("mouseover", function(d) {
scatterGraph.selectAll("circle").style("fill", "Silver").style("stroke", "grey");
d3.select(this).style("fill", d => colorBS(d.yearChange))
.style("stroke", "grey")
.style("stroke-width", 1);
barGraph.selectAll("rect")
.style("fill", function(dHere) {
if (dHere.ATeam === d.ATeam) {
return colorBS(d.yearChange);
} else {
return "Silver";
}
})
.style("stroke", function(dHere) {
if (dHere.ATeam === d.ATeam) {
return "grey";
} else {
return "grey";
}
});
scatterGraph.select("g#circle-legend").selectAll("circle")
.style("fill", "white")
.style("stroke", "Silver");
})
.on("mousemove", function(d) {
return tooltipBS
.style("top", d3.event.pageY - 10 + "px")
.style("left", d3.event.pageX + 10 + "px")
.style("visibility", "visible")
.style("font-size", "15px")
.text(d.ATeam + ": " + d.scatX + " " + sizeOb[scatXStat] + ", " + d.scatY + " " + sizeOb[scatYStat]);
})
.on("mouseout", function(d) {
barGraph.selectAll("rect")
.style("fill", d => d.ATeam == teamname? colorBS(d.yearChange): teamname == "All Premier League"? colorBS(d.yearChange): "silver")
.style("stroke", "grey")
.style("stroke-width",1);
scatterGraph.selectAll("circle")
.style("fill", d => d.ATeam == teamname? colorBS(d.yearChange): teamname == "All Premier League"? colorBS(d.yearChange): "Silver")
.style("stroke", "grey")
.style("stroke-width", "1");
scatterGraph.select("g#circle-legend").selectAll("circle")
.style("fill", "White")
.style("stroke", "Silver");
return tooltipBS.style("visibility", "hidden");
});
scatterGraph.append("g")
.call(legendCirc)
.attr("id", "circle-legend")
.attr("transform", "translate(130,30)");
return [scatterGraph.node(), barGraph.node()];
}