D3.js s、 职能(d){ 返回d.target.id; }); //在父对象的上一个位置输入任何新链接。 link.enter().insert(“路径”、“边缘容器”) .attr(“类”、“链接”) .attr(“id”,函数(d){ 返回(“rightli

D3.js s、 职能(d){ 返回d.target.id; }); //在父对象的上一个位置输入任何新链接。 link.enter().insert(“路径”、“边缘容器”) .attr(“类”、“链接”) .attr(“id”,函数(d){ 返回(“rightli,d3.js,tree,D3.js,Tree,s、 职能(d){ 返回d.target.id; }); //在父对象的上一个位置输入任何新链接。 link.enter().insert(“路径”、“边缘容器”) .attr(“类”、“链接”) .attr(“id”,函数(d){ 返回(“rightlink”+d.source.id+“-”+d.target.id) }) .attr(“d”,函数(d){ 变量o={ x:source.x0, y:source.y0 }; 返回对角线({ 资料来源:o, 目标:o }); })。打开(“单击”

s、 职能(d){ 返回d.target.id; }); //在父对象的上一个位置输入任何新链接。 link.enter().insert(“路径”、“边缘容器”) .attr(“类”、“链接”) .attr(“id”,函数(d){ 返回(“rightlink”+d.source.id+“-”+d.target.id) }) .attr(“d”,函数(d){ 变量o={ x:source.x0, y:source.y0 }; 返回对角线({ 资料来源:o, 目标:o }); })。打开(“单击”,移除链接) .on(“鼠标悬停”,显示移除按钮) .on(“鼠标位置”,隐藏按钮); 函数showRemoveButton(){ 控制台日志(“悬停”); } 函数hideRemoveButton(){ console.log(“悬停”); } var text=edge.selectAll(“text.text链接”) .数据(链接、功能(d){ 返回d.target.id+d.source.id; }); text.enter().insert(“文本”、“边缘容器”) .attr(“类”、“文本链接”) .attr(“x”,函数(d){ var x=(d.source.y+d.target.y)/2 返回parseInt(x+25); }) .attr(“y”,函数(d){ 变量y=(d.source.x+d.target.x)/2 返回y; }) .文本(“测试标签”) .attr(“文本锚定”、“开始”) .style(“字体大小”、“12px”); /*将标签转换到新位置*/ var label=svg.selectAll(“text.text链接”) .数据(链接、功能(d){ 返回d.target.id; }); //过渡链接到他们的新位置。 label.transition() .持续时间(0); //将退出节点转换到父节点的新位置。 label.exit().transition() .持续时间(持续时间) .attr(“d”,函数(d){ 变量o={ x:source.x, y:来源,y }; 返回对角线({ 资料来源:o, 目标:o }); }) .remove(); //d3.选择全部(“.right tree container.remove child”).remove(); //var removeButton=edge.selectAll(“.remove-child”) //.数据(链接、功能(d){ //返回d.target.id+d.source.id; // }); //removeButton.enter().insert(“rect”,“边缘容器”) //.attr(“类”、“删除子项”) //.attr(“x”,函数(d){ //var x=(d.source.y+d.target.y)/2 //返回parseInt(x+45); // }) //.attr(“y”,函数(d){ //变量y=(d.source.x+d.target.x)/2 //返回y; // }) //.attr(“宽度”、“20”) //.attr(“高度”、“20”) //.attr(“rx”、“10”) //.attr(“ry”、“10”) //.样式(“填充”、“白色”) //.style(“笔划”,“#444”) //.样式(“笔划宽度”、“2”); 函数removelink(d){ var confirmDelete=confirm(“您确定要删除吗?”); 如果(确认删除){ //这是要删除的链接目标节点 var目标=d目标; //做一套新的孩子 var children=[]; //反复浏览孩子们 target.parent.children.forEach(函数(子函数){ if(child.id!=target.id){ //如果目标id不相同,则添加到子列表 //这样就可以删除节点目标。 推(儿童); } }); //将目标父级设置为新的子级集(即已删除的子级集) target.parent.children=children; //由于父级的一个子级已删除,因此请重新绘制该父级 更新(d.target.parent) } } var link=svg.selectAll(“path.link”) .数据(链接、功能(d){ 返回d.target.id; }); //过渡链接到他们的新位置。 link.transition() .持续时间(持续时间) .attr(“d”,对角线); //将退出节点转换到父节点的新位置。 link.exit().transition() .持续时间(持续时间) .attr(“d”,函数(d){ 变量o={ x:source.x, y:来源,y }; 返回对角线({ 资料来源:o, 目标:o }); }) .remove(); //将旧位置隐藏起来,以便过渡。 nodes.forEach(函数(d){ d、 x0=d.x; d、 y0=d.y; }); addRightChild.on(“单击”,函数(d){ event.stopPropagation(); $(“#子信息”).show(); $(“#子文本”).val(“”); $(“#btn添加子项”).off('click'); $(“#btn添加子项”)。单击(函数(){ var childname=$(“#子文本”).val(); 如果(类型d.|子项=='undefined'| | d.|子项===null){ if(d.children的类型===“未定义”){ var newChild=[{ “名字”:孩子的名字, “父母”:“儿子”, }]; var newnodes=tree.nodes(newChild); d、 子节点=新节点[0]; //console.log(d.children); 更新(d); }否则{ var newChild={ “名字”:孩子的名字, “父母”:“儿子”, }; //console.log(d.children); d、 推(newChild); //console.log(d.children); 更新(d); } }否则{ var newChild={ “名字”:孩子的名字, “父母”:“儿子”, }; d、 儿童=d.\U儿童; d、 推(newChild); //console.log(d.children); 更新(d); } $(“#子信息”).hide(); }); });; } //在单击时切换子项。 功能点击(d){ 如果(d.儿童){ d、 _children=d.children; d、 children=null; }否则{ d、 儿童=d.\U儿童; d、 _children=null; } 更新(d); $(.addLeftChild.addRightChild”).hide(); 如果(d.id==1){ $(“.rightparent”).children(“.addRightChild”).show(); $(this.children(“.addRightChild”).show(); }否则{ $(this.children(“.addRightChild”).show(); } d3.selectAll(“rect”).style(“fill”和“#f1f1”);//重置所有节点列
    var edge = d3.select("#right-edges")
        .append("g")
        .attr("class", "edge-container")
        .data(links);

         var link = edge.selectAll("path.link")
        .data(links, function(d) {
            return d.target.id;
        });

    // Enter any new links at the parent's previous position.
    link.enter().insert("path", "edge-container")
        .attr("class", "link")
        .attr("id", function(d) {
            return ("rightlink" + d.source.id + "-" + d.target.id)
        })
        .attr("d", function(d) {
            var o = {
                x: source.x0,
                y: source.y0
            };

            return diagonal({
                source: o,
                target: o
            });
        }).on("click", removelink)
        .on("mouseover", showRemoveButton)
        .on("mouseout", hideRemoveButton);

    function showRemoveButton() {
        console.log("hover");
    }

    function hideRemoveButton() {
        console.log("hover-out");
    }




    var text = edge.selectAll("text.text-link")
        .data(links, function(d) {
            return d.target.id + d.source.id;
        });

    text.enter().insert("text", "edge-container")
        .attr("class", "text-link")

    .attr("x", function(d) {
            var x = (d.source.y + d.target.y) / 2
            return parseInt(x + 25);
        })
        .attr("y", function(d) {
            var y = (d.source.x + d.target.x) / 2
            return y;
        })
        .text("test-label")
        .attr("text-anchor", "start")
        .style("font-size", "12px");
.attr("x", function(d) {
        var x = (d.source.y + d.target.y) / 2;
     d.thisText =  "test-label";
        return x - d.thisText.length/2 + 5; //added 5 to make up for node width. This needs to be worked out properly
      })