{
const width = 800;
const height = 800;
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.style("background", "#e6f3ff");
const projection = d3.geoStereographic()
.rotate([0, -90])
.scale(900)
.translate([width / 2, height / 2]);
const path = d3.geoPath(projection);
svg.append("path")
.datum(land.land)
.attr("d", path)
.attr("fill", "#cdc0b0")
.attr("stroke", "#333");
const canvas = d3.create("canvas")
.attr("width", width)
.attr("height", height)
.style("position", "absolute")
.style("left", "0px")
.style("top", "0px");
svg.node().appendChild(canvas.node());
const ctx = canvas.node().getContext("2d");
const nonZeroPoints = [];
for (let i = 0; i < processedData.tracers.dyeBering.length; i++) {
const val = processedData.tracers.dyeBering[i];
if (val > 0.01) {
nonZeroPoints.push({
lon: processedData.lonCell[i],
lat: processedData.latCell[i],
value: val
});
}
}
ctx.clearRect(0, 0, width, height);
const colorScale = d3.interpolateViridis;
nonZeroPoints.forEach(point => {
const [x, y] = projection([point.lon, point.lat]);
if (!isNaN(x)) {
const radius = 20;
ctx.fillStyle = colorScale(0.5);
ctx.beginPath();
ctx.arc(x, y, radius, 0, 2 * Math.PI);
ctx.fill();
}
});
svg.append("text")
.attr("x", 10)
.attr("y", 20)
.text(`Bering Strait Tracer (${nonZeroPoints.length} non-zero points)`)
.style("font-size", "16px")
.style("font-weight", "bold");
const legend = svg.append("g")
.attr("transform", `translate(20,${height - 40})`);
const gradient = legend.append("defs").append("linearGradient")
.attr("id", "gradient")
.attr("x1", "0%").attr("y1", "0%")
.attr("x2", "100%").attr("y2", "0%");
gradient.selectAll("stop")
.data(d3.range(0, 1.01, 0.1))
.enter().append("stop")
.attr("offset", d => `${d * 100}%`)
.attr("stop-color", d => colorScale(d));
legend.append("rect")
.attr("width", 200)
.attr("height", 20)
.attr("fill", "url(#gradient)");
legend.append("text")
.attr("x", 100)
.attr("y", 35)
.text("Tracer Concentration")
.style("font-size", "12px")
.style("text-anchor", "middle");
return svg.node();
}