d에 텍스트 높이 값을 저장하려고합니다. (그래서 적절한 크기의 사각형을 그릴 수 있습니다.)하지만 틱 기능이나 다른 곳에서는 정의되지 않았습니다.d3 라이브러리를 사용하여 d로 텍스트 높이를 저장해야합니다.
d.height
에는 값이 있어야합니다.
그래서 체크 한 기능 (의 일부) (그러나 그렇지 않습니다) :
function tick() {
z.attr('d', function(d) {
alert (d.height); //not defined
var sourceX = d.source.x + textWidth/2 + 10,
sourceY = d.source.y + d.height/2 + 10,
targetX = d.target.x + textWidth/2 + 10,
targetY = d.target.y + d.height/2 + 10;
return 'M' + sourceX + ',' + sourceY + 'L' + targetX + ',' + targetY;
});
shape.attr('transform', function(d) {
middle_rect.attr("height", d.height/2 + 20);
side_rect.attr("height", d.height/2 + 20);
return 'translate(' + d.x + ',' + d.y + ')';
});
그리고 여기 값 (코드 아래)
shape = shape.data(nodes);
// add new nodes
var g = shape.enter().append('svg:g').attr('class', function(d) { return d.type +' node'; });
middle_rect = svg.selectAll(".middle")
.append("svg:rect")
.attr("rx", "10")
.attr("ry", "10")
.style("stroke", "rgb(47,136,214)")
.style("fill", "url(#middle_gradient)");
side_rect = svg.selectAll(".side")
.append("svg:rect")
.attr("rx", "10")
.attr("ry", "10")
.style("stroke", "rgb(47,136,214)")
.style("fill", "url(#side_gradient)");
txt = g.append('svg:text')
.attr('class',function (d){return 'bigest ' + d.id ;} )
.attr('y', ".5em")
.attr("dy", "1em")
.style("fill", "black")
.each (function (d) {
d.height = this.getBoundingClientRect().height;
// alert (d.height); //here I have this value
});
을 저장하기 위해 노력하고있어 방법
글로벌화 할 수 있습니까? 또는이 값을 저장해야합니까?
? 어디에서 높이에 접근 할 수 있기를 원하십니까? .each 함수가 여러 항목을 통과하면 어떤 일이 일어나기를 원합니 까? – talegna