Open Awen-hub opened 2 years ago
It looks like error is caused by using wrong d3 version. (v6, v7 will not work)
Here is a same example working when I am including d3 v5
It's really strange because the error exists when I included "d3": "5.15.1"
in package.json as you do.
Here is the example
It works when I change the code.
function brushed(d) {
if (d.sourceEvent.type === "brush") return;
if (attrs.freezeMin) {
if (d.selection[0] < attrs.startSelection) {
d.selection[1] = Math.min(d.selection[0], d.selection[1]);
}
if (d.selection[0] >= attrs.startSelection) {
d.selection[1] = Math.max(d.selection[0], d.selection[1]);
}
d.selection[0] = 0;
d3.select(this).call(d.target.move, d.selection);
}
var d0 = d.selection.map(scaleX.invert);
const s = d.selection;
handle.attr("display", null).attr("transform", function (d, i) {
return (
"translate(" + (s[i] - 2) + "," + (calc.chartHeight / 2 - 25) + ")"
);
});
output({
range: d0,
});
}
It seems to have no related with react v18. But I don't know why it works on older react version.
By creating the project with react 18, I encounted the error
Cannot read properties of undefined (reading 'sourceEvent')
when selecting a range. example