我正在尝试计算d3行的偏移量,以便我可以从该行绘制一个具有相同类或属性的图像。然后我将此值传递给一个名为draw connection lines的函数。例如画线,类乔到Joe的照片。 jQuery无法识别d3元素来计算它们的位置或偏移量。
例如,返回null:
var imageLeft = d3.selectAll('g.last - '+ lastname).offset()。left;
因此,如果我尝试根据悬停时的类名选择特定行 - 如何计算偏移量。我在这里尝试了不同的组合,但无济于事:
var imageLeft = d3.selectAll('g.last-'+lastname).classed('highlighted',true).node().getBoundingClientRect();
var imageLeft = document.getElementsById('g').offsetLeft;
var imageLeft = $(this).attr('id',lastname).offset().left;
var imageLeft = $(this).position().left ;
var imageLeft = d3.select(this).select('g.last-'+lastname).offset().left;
var imageLeft = $(this).find('.div-line').position().left ;
这是我需要这个值的函数(绘制线条):
function drawConnectLines(imageLeft,index) {
d3.selectAll('line.horizontal-line')
.attr('x1',imageLeft+$('.portrait img').width()/2)
.attr('x2',Settings.person_interval*index+Settings.chartLeft);
d3.selectAll('line.vertical-line.first')
.attr('x1',imageLeft+$('.portrait img').width()/2)
.attr('x2',imageLeft+$('.portrait img').width()/2);
d3.selectAll('line.vertical-line.second')
.attr('x1',Settings.person_interval*index+Settings.chartLeft)
.attr('x2',Settings.person_interval*index+Settings.chartLeft);
}
感谢任何帮助 - 请点击此处:http://tinyurl.com/m6eqwf3
要获得左偏移的原始线条如下:
Plot.experience.enter().append('g')
attr('class',function(d)
{return d.First+ ' last-' +d.Last;})
.attr('transform',function(d,i) {return 'translate('+ (Settings.person_interval*i+Settings.chartLeft)+',0)';})
.attr('x1',0)
.attr('x2',0)
.attr('y1',Settings.chartTop)
.attr('y2',options.height);