chart = {
const zoom = d3.zoom()
.on("zoom", zoomed);
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const dot = svg.append("g")
.attr("display", "none");
dot.append("text")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("text-anchor", "middle");
const g = svg.append("g")
.attr("fill", "none")
.attr("stroke-linecap", "round");
g.selectAll("path")
.data(data)
.join("path")
.attr("d", d => `M${x(d.val[0])},${y(d.val[1])}h0`)
.attr("stroke", d => z(d.val[2]))
.on('mousemove', function (d) {
d3.select(this).transition()
.duration('50')
.attr('opacity', '0.5');
dot.attr("transform", `translate(${[d3.event.pageX, d3.event.pageY]})`);
dot.attr("display", null);
dot.select('text').text(d.word);
})
.on('mouseout', function (d) {
d3.select(this).transition()
.duration('50')
.attr('opacity', '1');
dot.attr("display", "none");
});
const gx = svg.append("g");
const gy = svg.append("g");
svg.call(zoom.transform, viewof transform.value);
function zoomed() {
const transform = d3.event.transform;
g.attr("transform", transform).attr("stroke-width", 5 / transform.k);
gx.call(xAxis, transform.rescaleX(x));
gy.call(yAxis, transform.rescaleY(y));
}
return Object.assign(svg.node(), {
update(transform) {
svg.transition()
.duration(1500)
.call(zoom.transform, transform);
}
});
}