chart_5 = {
const data = d3.range(10);
const labels = ["First node", "Second node", "Third node", "Fourth node", "Fifth node", "Sixth node", "Seventh node", "Eighth node", "Ninth node", "Tenth node"];
const nodeRadius = 20;
const nodeSpacing = 1500;
const height1 = 8400;
const width1 = 1200;
const visited = new Array(data.length).fill(false);
const svg = d3.create("svg")
.attr("width", width1)
.attr("height", height1);
const g = svg.append("g")
.attr("transform", "translate(" + width1/2 + "," + height1 / 15 + ")");
nodeSpacing
const nodes = g.selectAll(".node")
.data(data)
.enter()
.append("g")
.attr("class", "node")
.attr("transform", (d) => "translate(0," + (d * nodeSpacing) + ")");
nodes.append("circle")
.attr("r", 20)
.attr("fill", "gray");
nodes.append("text")
.attr("x", nodeRadius + 10)
.attr("y", 5)
.text((d, i) => labels[i]);
const lines = g.selectAll(".line")
.data(data.slice(0, -1))
.enter()
.append("path")
.attr("class", "line")
.attr("stroke", "gray")
.attr("stroke-width", 2)
.attr("marker-end", "url(#arrow)")
//.attr("d", (d) => "M0," + (d * 100 + 20) + "L0," + ((d + 1) * 100 - 20));
// .attr("d", (d) => "M0," + (d * 150 + 30) + "L0," + ((d + 1) * 150 - 30));
.attr("d", (d) => "M0," + (d * nodeSpacing + nodeRadius) + "L0," + ((d + 1) * nodeSpacing - nodeRadius));
const marker = svg.append("marker")
.attr("id", "arrow")
.attr("viewBox", "0 -5 10 10")
.attr("refX", 10)
.attr("refY", 0)
.attr("markerWidth", 8)
.attr("markerHeight", 8)
.attr("orient", "auto-start-reverse")
.append("path")
.attr("d", "M0,-5L10,0L0,5");
let currentIndex = 0;
// function updateNodes() {
// nodes
// .select("circle")
// .attr("fill", (d, i) => i === currentIndex ? "navy" : "gray");
// nodes
// .select("text")
// .attr("fill", (d, i) => i === currentIndex ? "navy" : "blue");
// lines
// .attr("stroke", (d, i) => i < currentIndex ? "navy" : "gray");
// }
// function updateNodes() {
// nodes
// .select("circle")
// .attr("fill", (d, i) => i === currentIndex ? "navy" : "gray");
// nodes
// .select("text")
// .attr("fill", (d, i) => i === currentIndex ? "navy" : "black")
// .style("font-weight", (d, i) => i === currentIndex ? "bold" : "normal");
// lines
// .attr("stroke", (d, i) => i < currentIndex ? "navy" : "gray");
// }
// function updateNodes() {
// const prevIndex = currentIndex - 1 >= 0 ? currentIndex - 1 : 0;
// nodes.select("circle")
// .attr("fill", (d, i) => i === currentIndex ? "navy" : (i === prevIndex ? "gray" : "lightgray"))
// .classed("current", (d, i) => i === currentIndex);
// nodes.select("text")
// .attr("fill", (d, i) => i === currentIndex ? "navy" : "black");
// lines.attr("stroke", (d, i) => i < currentIndex ? "navy" : "gray");
// }
function updateNodes() {
nodes
.select("circle")
.attr("fill", (d, i) => {
if (i === currentIndex) {
visited[i] = true;
return "navy";
} else if (visited[i]) {
return "navy";
} else {
return "gray";
}
});
nodes
.select("text")
.attr("fill", (d, i) => i === currentIndex ? "navy" : "black");
lines
.attr("stroke", (d, i) => i < currentIndex ? "navy" : "gray");
}
updateNodes();
window.addEventListener("wheel", (event) => {
if (event.deltaY < 0 && currentIndex > 0) {
currentIndex--;
updateNodes();
} else if (event.deltaY > 0 && currentIndex < data.length - 1) {
currentIndex++;
updateNodes();
}
});
return svg.node();
}