wnc_zoom = {
again;
let w = window.innerWidth;
let h;
if (window.innerHeight < 2500) {
h = window.innerHeight;
} else {
h = 0.6 * w;
}
let div = d3
.create('div')
.style('width', `${w}px`)
.style('height', `${h}px`)
.style('position', 'relative');
let canvas = div
.append('canvas')
.attr('width', w)
.attr('height', h);
let context = canvas.node().getContext('2d');
let r = 9;
let projection = d3
.geoOrthographic()
.translate([w / 2, h / 2])
.scale(r);
let path = d3.geoPath(projection, context);
if (speed_test() < 50) {
let a0 = 40;
let ma = 82.88;
let spinSpeed = .2;
let s = ((8 * h) / r) ** (spinSpeed / (-a0 + ma));
canvas.angle = a0;
while (canvas.angle < ma) {
r = s * r;
projection.rotate([(canvas.angle += spinSpeed), -35.65]).scale(r);
context.clearRect(0, 0, w, h);
context.lineWidth = 2;
context.strokeStyle = 'black';
context.fillStyle = d3.interpolateRdBu(0.66);
context.beginPath();
context.arc(w / 2, h / 2, r, 0, 2 * Math.PI);
context.fill();
context.stroke();
draw(context, canvas, projection, path, r, w, h);
yield div.node();
}
}
if (r == 9) {
canvas.angle = 83;
r = 4800;
}
projection.rotate([canvas.angle, -35.65]).scale(r);
context.clearRect(0, 0, w, h);
context.lineWidth = 2;
context.strokeStyle = 'black';
context.fillStyle = d3.interpolateRdBu(0.66);
context.beginPath();
context.arc(w / 2, h / 2, r, 0, 2 * Math.PI);
context.fill();
context.stroke();
draw(context, canvas, projection, path, r, w, h);
yield div.node();
let svg = div
.append('svg')
.attr('width', w - 2)
.attr('height', h - 2)
.style('position', 'absolute')
.style('top', 0)
.style('left', 0);
let svg_path = d3.geoPath(projection);
svg
.append('path')
.attr('d', svg_path(features.d11_boundary.features[0]))
.style('stroke', 'black')
.style('stroke-linejoin', 'round')
.style('fill', 'rgba(0,0,0,0)')
.style("cursor", "pointer")
.on('mouseenter', function() {
d3.select(this).style('stroke-width', '3px');
})
.on('mouseleave', function() {
d3.select(this).style('stroke-width', '1px');
})
.on('click', function() {
window.open("https://wncviz.com/demos/Gerrymandering_in_NC/");
});
}