vis = {
const w = width;
const aspect = MAP.length / MAP[0].length;
const height = w * aspect;
const cellsz = height / MAP.length;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, w, height])
.attr("width", w)
.attr("height", height)
.attr("style", "max-width: 100%; height: auto;");
let hs = []
MAP.forEach((row, ri) => row.forEach((v, ci) => {
if (v == '#') {
hs.push([ri, ci]);
}
}));
const SW = 3;
let o_circles = svg
.selectAll(".o")
.data(JSON.parse(solution[curiter.value]))
.join("circle")
.attr('class', 'o')
.attr("cx", d => (d[1]+0.5) * cellsz)
.attr("cy", d=> (d[0]+0.5) * cellsz)
.attr("r", d => cellsz/2.0)
.attr("fill", "#001b42")
let h_circles = svg
.selectAll(".h")
.data(hs)
.join("circle")
.attr('class', 'h')
.attr("cx", d => (d[1]+0.5) * cellsz)
.attr("cy", d=> (d[0]+0.5) * cellsz)
.attr("r", d => cellsz/2.0)
.attr("fill", "#8a8471");
function update(data) {
o_circles
.data(JSON.parse(solution[curiter.value]))
.transition()
.duration(100)
.attr("cx", d => (d[1]+0.5) * cellsz)
.attr("cy", d=> (d[0]+0.5) * cellsz)
.ease(d3.easeLinear);
}
curiter.addEventListener('input', e => {
update(JSON.parse(solution[curiter.value]));
})
return svg.node();
}