{
const width = 900;
const height = 900;
const margin = 100;
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height);
const background = svg
.append("rect")
.attr("width", width)
.attr("height", height)
.attr("fill", "#0E1721");
const gridX = d3
.scaleLinear()
.domain([0,10])
.range([margin, width-margin]);
const gridY = d3
.scaleLinear()
.domain([0,10])
.range([margin, height-margin]);
for (let i=0 ; i<11 ; i++) {
svg
.append("line")
.attr("x1", margin)
.attr("y1", gridY(i))
.attr("x2", width - margin)
.attr("y2", gridY(i))
.attr("fill", "none")
.attr("stroke", "#ffffff")
.attr("stroke-width", 0.5)
.attr("oppacity" , 0.5);
svg
.append("line")
.attr("x1", gridX(i))
.attr("y1", margin)
.attr("x2", gridX(i))
.attr("y2", height-margin)
.attr("fill", "none")
.attr("stroke", "#ffffff")
.attr("stroke-width", 0.5)
.attr("oppacity" , 0.5);
}
const frenchPerToX = d3
.scaleLinear()
.domain(d3.extent(alphabeticalStates, (d) => d.frenchPercent))
.range([margin, width-margin]);
const spanishPerToY = d3
.scaleLinear()
.domain(d3.extent(alphabeticalStates, (d) => d.spanishPercent))
.range([height-margin , margin]);
const colorParameter = d3
.scaleLinear()
.domain(d3.extent(alphabeticalStates, (d) => d.totalPopulation))
.range([0,1]);
for (let i = 0 ; i < alphabeticalStates.length ; i++) {
svg
.append("circle")
.attr("cx", frenchPerToX(alphabeticalStates[i].frenchPercent))
.attr("cy", spanishPerToY(alphabeticalStates[i].spanishPercent))
.attr("r", 3)
.attr(
"fill",
// "white"
d3.interpolateViridis(
colorParameter(alphabeticalStates[i].totalPopulation)
)
)
.attr("stroke" , "white")
.attr("stroke-width" , .5);
svg
.append("text")
.attr("x",frenchPerToX(alphabeticalStates[i].frenchPercent)+10)
.attr("y",spanishPerToY(alphabeticalStates[i].spanishPercent)+4)
.attr("font-size", 10)
.attr("fill" , "white")
.attr("text-anchor", "start")
.attr("alignment-baseline", "center")
.attr("font-family", "courier")
.text(alphabeticalStates[i].name);
svg
.append("text")
.attr("x", width/2)
.attr("y", margin/2)
.attr("font-size", 18)
.attr("fill" , "white")
.attr("text-anchor", "middle")
.attr("alignment-baseline", "center")
.attr("font-family", "courier")
.text("+ Percentage of Population that speak French compared to Spanish");
svg
.append("text")
.attr("x", margin/2)
.attr("y", margin)
.attr("font-size", 14)
.attr("fill" , "white")
.attr("text-anchor", "end")
.attr("alignment-baseline", "center")
.attr("font-family", "courier")
.text("+ French Percentage")
.attr("transform" , "rotate(-90 "+margin/2+","+margin+")")
svg
.append("text")
.attr("x", width-margin)
.attr("y", height-margin/2)
.attr("font-size", 14)
.attr("fill" , "white")
.attr("text-anchor", "end")
.attr("alignment-baseline", "center")
.attr("font-family", "courier")
.text("+ Spanish Percentage");
}
return svg.node();
}