如果自变量上的语句不会更新D3.js SVG组件
我在某些数据上有一个散点图图表:
svg.append('g')
.attr('transform', `translate(${margin.left},0)`)
.call(yAxis);
g
.selectAll('.scatter')
.data(data)
.join('circle')
.attr('class', 'scatter')
.attr('cx', (d) => xScale(d.x))
.attr('cy', (d) => yScale(d.y))
.attr('r', 3)
.attr('stroke', 'gray')
.attr('stroke-width', 0.5)
.style('fill', (d) => colorScale(d.label as number))
.style('fill-opacity', (d) => {
// Get data value
console.log("Filter is {}", filter);
if (filter === 'umap') {
return 0.2;
}
else
{
return 0.8;
}
});
我将过滤器字符串作为道具传递,并且可以正确更新。 但是,D3.js不会改变其不透明度。 因此,Console.log将输出一个不等于UMAP的字符串。 但是if语句像条件是正确的一样进入。
有人可以指出为什么吗? 这是我不正确理解的某些打字稿/JavaScript吗?
所有这些都被称为反应钩。
预先感谢!我仍然是初学者。
I have a scatter chart on some data that I define like this:
svg.append('g')
.attr('transform', `translate(${margin.left},0)`)
.call(yAxis);
g
.selectAll('.scatter')
.data(data)
.join('circle')
.attr('class', 'scatter')
.attr('cx', (d) => xScale(d.x))
.attr('cy', (d) => yScale(d.y))
.attr('r', 3)
.attr('stroke', 'gray')
.attr('stroke-width', 0.5)
.style('fill', (d) => colorScale(d.label as number))
.style('fill-opacity', (d) => {
// Get data value
console.log("Filter is {}", filter);
if (filter === 'umap') {
return 0.2;
}
else
{
return 0.8;
}
});
I pass the filter string as a prop, and it gets updated correctly.
However, d3.js does not change its opacity.
So console.log would output a string not equal to umap.
But the if statement enters as if the condition is true.
Can someone point out to why?
Is this some typescript/javascript I do not understand correctly?
All of this is called inside a react-hook.
Thanks a lot in advance! I am still a beginner.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,解决这个问题的答案是,我只依赖于数据变量的反应钩。更改此功能也对过滤器变量有效。
So the answer to this problem was that I had the react-hook only relying on the data variable. Changing this also to take effects on the filter variable worked.