function version6() {
const svg = drawChessboard({"white": "white", "black": "lightgrey"});
const dataArray = game1;
const sel1 = d3.select(svg)
.selectAll("path.piece-move")
.data(dataArray);
sel1.join("path")
.attr("class", "piece-move")
.attr("d", (d, i) => {
let str = {};
const dx = (i % 2) ? -2 : 2;
const dy = (i % 2) ? -2 : 2;
str = "M " + (squareToPosition(d.from).x + dx) + " " + (squareToPosition(d.from).y + dy);
str += " L " + (squareToPosition(d.to).x + dx) + " " + (squareToPosition(d.to).y + dy);
return str;
})
.style("stroke", "white")
.style("stroke-width", 7)
.style("stroke-linejoin", "round")
.style("fill", "none");
sel1.join("path")
.attr("class", "piece-move")
.attr("id", (d,i) => "move-" + i)
.attr("d", (d, i) => {
let str = {};
const dx = (i % 2) ? -2 : 2;
const dy = (i % 2) ? -2 : 2;
str = "M " + (squareToPosition(d.from).x + dx) + " " + (squareToPosition(d.from).y + dy);
str += " L " + (squareToPosition(d.to).x + dx) + " " + (squareToPosition(d.to).y + dy);
return str;
})
// .style("stroke", (d, i) => (i % 2) ? "steelblue" : "orange")
.style("stroke", (d, i) => colorOfPieces.get(d.piece + d.color))
.style("fill", (d, i) => colorOfPieces.get(d.piece + d.color))
.style("stroke-width", 5)
.style("stroke-linejoin", "round");
// .style("fill", "none");
const pathText = sel1.join("text");
pathText.append("textPath")
.attr("href", (d,i) => "#move-" + i)
.attr("text-anchor","middle")
.attr("startOffset","50%")
.text(d => d.san);
pathText.attr("transform", rotate);
// pieces from, to
const sel2 = d3.select(svg)
.selectAll("circle")
.data(dataArray);
sel2
.join("circle")
.attr("class", "piece-square from")
// .style("fill", (d, i) => (i % 2) ? "steelblue" : "orange")
.style("fill", (d, i) => colorOfPieces.get(d.piece + d.color))
.attr("cx", (d, i) => {
const dx = (i % 2) ? -2 : 2;
return squareToPosition(d.from).x + dx;
})
.attr("cy", (d, i) => {
const dy = (i % 2) ? -2 : 2;
return squareToPosition(d.from).y + dy;
})
.attr("r", 8);
sel2
.join("circle")
.attr("class", "piece-square to")
// .style("fill", (d, i) => d.captured ? ((i % 2) ? "orange" : "steelblue") : (i % 2) ? "steelblue" : "orange")
// .style("stroke", (d, i) => d.captured ? ((i % 2) ? "steelblue" : "orange") : "none")
.style("fill", (d, i) =>
d.captured ?
(d.color === "w" ? colorOfPieces.get(d.captured + "b") : colorOfPieces.get(d.captured + "b") )
: colorOfPieces.get(d.piece + d.color))
.style("stroke", (d, i) => d.captured ? colorOfPieces.get(d.piece + d.color) : "none")
.style("stroke-width", 6)
.attr("cx", (d, i) => {
const dx = (i % 2) ? -2 : 2;
return squareToPosition(d.to).x + dx;
})
.attr("cy", (d, i) => {
const dy = (i % 2) ? -2 : 2;
return squareToPosition(d.to).y + dy;
})
.attr("r", 8);
d3.select(svg).selectAll(".piece-move")
.filter((d,i) => !(d.from[0] === d.to[0] || d.from[1] === d.to[1]))
.style("filter","url(#glow)");
return svg;
}