本文テキスト要素をSVGツリーノードのmouseoverイベントから最もよく更新するにはどうすればよいですか?私が以下を試すと、テキストは更新されますが、SVGはディスプレイから削除されます。ここでは、コードは次のとおりです。d3本文を更新する
var svg = d3.select('body')
.append('text').text('The Entry Point and M Code: ')
.attr('class', 'centralText')
.attr('x', 10)
.attr('y', 10)
.attr('text-anchor', 'middle')
.append('svg')
ここに私のイベントコードは次のとおりです。
var nodeEnter = node.enter().append('g')
.attr('class', node_class)
.attr('transform', function(d) {
return 'translate(' + source.x0 + ',' + source.y0 + ')'; })
.style('cursor', function(d) {
return (d.children || d._children) ? 'pointer' : '';})
.on('click', click)
.on("mouseover", function(d) {
d3.select('body')
.text('M Code: is this')
最後の行は 'body'全体を1行のテキストに置き換えます。したがって、SVGも消去されます – gdlmx