transitions = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, heightSp]);
svg
.append("text")
.attr("y", margin.top)
.attr("x", width - marginSp.right * 4)
.attr("text-anchor", "end")
.attr("fill", "currentColor")
.attr("id", "cerealText")
.style("font-family", "sans-serif")
.style("font-size", "12px")
.text("Hover on a circle!");
svg
.selectAll(".cerealCircles")
.data(cereals)
.enter()
.append("circle")
.attr("cx", (d) => parseFloat(defaultxScale(d.sodium)))
.attr("cy", (d) => parseFloat(defaultyScale(d.potass)))
.attr("fill", (d) => d3.interpolateYlOrRd(colorScale(d.calories)))
.attr("r", (d) => parseFloat(radScale(d.rating)))
.attr("opacity", 1)
.attr("stroke", "currentColor")
.attr("stroke-width", "0")
.attr("class", "cerealCircles")
.on("mouseover", function (event, d) {
d3.select(this).raise().transition().attr("stroke-width", "2");
d3.select("#cerealText").text(d.name + " | " + setMfr(d.mfr));
})
.on("mouseout", function (d) {
d3.select(this).transition().attr("stroke-width", "0");
d3.select("#cerealText").text("Hover on a circle!");
});
svg
.append("g")
.attr("transform", `translate(0,${heightSp - margin.bottom})`)
.attr("class", "xAxis")
.call(d3.axisBottom(defaultxScale).tickSizeOuter(0));
svg
.append("g")
.attr("transform", `translate(${margin.left},0)`)
.attr("class", "yAxis")
.call(d3.axisLeft(defaultyScale))
.call((g) => g.select(".domain").remove());
//X-Axis--------------------------------------------------------------------------
svg
.append("text")
.attr("y", marginSp.top / 2)
.attr("x", margin.left * 2)
.attr("fill", "currentColor")
.style("font-family", "sans-serif")
.style("font-size", "11px")
.text("X-Axis:");
svg
.selectAll(".xMenu")
.data(xMenuSet)
.enter()
.append("text")
.attr("y", (d, i) => ((i + 1) / (xMenuSet.length + 1)) * marginSp.top)
.attr("x", marginSp.left * 3)
.attr("fill", "currentColor")
.attr("stroke", "currentColor")
.attr("stroke-width", 0)
.style("font-family", "sans-serif")
.style("font-size", "11px")
.attr("class", "xMenu")
.attr("id", (d) => d.value)
.text((d) => d.name)
.on("click", function (event, xC) {
d3.selectAll(".xMenu").attr("stroke-width", 0);
d3.select(this).attr("stroke-width", 1);
let cerealScale = d3
.scaleLinear()
.domain(d3.extent(cereals, (d) => parseFloat(d[xC.value])))
.range([marginSp.left, width - marginSp.right]);
d3.selectAll(".cerealCircles")
.transition()
.ease(d3.easeElasticOut)
.duration(1000)
.attr("cx", (d) => cerealScale(parseFloat(d[xC.value])));
svg
.selectAll(".xAxis")
.attr("transform", `translate(0,${heightSp - margin.bottom})`)
.call(d3.axisBottom(cerealScale).tickSizeOuter(0));
});
//Y-Axis--------------------------------------------------------------------------
svg
.append("text")
.attr("y", marginSp.top / 2)
.attr("x", margin.left * 5)
.attr("fill", "currentColor")
.style("font-family", "sans-serif")
.style("font-size", "11px")
.text("Y-Axis:");
svg
.selectAll(".yMenu")
.data(yMenuSet)
.enter()
.append("text")
.attr("y", (d, i) => ((i + 1) / (yMenuSet.length + 1)) * marginSp.top)
.attr("x", marginSp.left * 6)
.attr("fill", "currentColor")
.style("font-family", "sans-serif")
.style("font-size", "11px")
.attr("stroke", "currentColor")
.attr("stroke-width", 0)
.attr("class", "yMenu")
.attr("id", (d) => d.value)
.text((d) => d.name)
.on("click", function (event, yC) {
d3.selectAll(".yMenu").attr("stroke-width", 0);
d3.select(this).attr("stroke-width", 1);
let cerealScale = d3
.scaleLinear()
.domain(d3.extent(cereals, (d) => parseFloat(d[yC.value])))
.range([heightSp - margin.bottom, margin.top]);
d3.selectAll(".cerealCircles")
.transition()
.ease(d3.easeElasticOut)
.duration(1000)
.attr("cy", (d) => cerealScale(parseFloat(d[yC.value])));
svg
.selectAll(".yAxis")
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(cerealScale))
.call((g) => g.select(".domain").remove());
});
return svg.node();
}