chart2 = {
const height = 480;
const arbitrary_padding = 160;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
const x = d3.scaleLinear()
.domain([0, d3.max(data2, d => d.Funding_Amount)]).nice()
.range([arbitrary_padding+margin.left, width - margin.right]);
const y = d3.scaleBand()
.domain(data2.map(d => d.Company))
.range([480 - margin.bottom, margin.top])
.padding(0.2);
const xAxis = g => g
.attr('transform', `translate(0,${480 - margin.bottom})`)
.call(d3.axisBottom(x).ticks(width / 100))
const yAxis = g => g
.attr("transform", `translate(${arbitrary_padding+margin.left},0)`)
.call(d3.axisLeft(y).tickSizeOuter(0))
const yTitle = g => g.append("text")
.attr("font-family", "sans-serif")
.attr("font-size", 14)
.attr("y", 10)
.attr("transform", `translate(${100+margin.left},0)`)
.text("Company Name")
const xTitle = g => g.append("text")
.attr("font-family", "sans-serif")
.attr("font-size", 14)
.attr("x", width/2)
.attr("y", height-10)
.text("Funding Awarded Between 2002 and 2023")
svg.append("g")
.attr("fill", color)
.selectAll("rect")
.data(data2)
.join("rect")
.attr("x", x(0))
.attr("y", d => y(d.Company))
.attr("width", d => x(d.Funding_Amount) - x(0))
.attr("height", y.bandwidth())
.on("mouseover", function(d) {
d3.select(this).attr("fill", highlight_color);
//Get this bar's x/y values, then augment for the tooltip
//Get this bar's x/y values, then augment for the tooltip
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>Projects Sponsored: </strong>${d.Projects_Sponsored}</div><div><strong>Projects Proposed:</strong> ${d.Projects_Proposed}</div>`
)
.style('visibility', 'visible');
//Update the tooltip position and value
//d3.select("#tooltip")
// .style("left", xPosition + "px")
// .style("top", yPosition + "px")
// .select("#value")
// .text(d.violation);
//Show the tooltip
//d3.select("#tooltip").classed("hidden", false);
})
.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', color);
});
svg.append('g')
.call(xAxis);
svg.append('g')
.call(yAxis);
svg.call(yTitle);
svg.call(xTitle);
return svg.node();
}