2013-12-16 25 views
0

我正在使用foreignObject在d3圓圈內使用HTML。d3 - 異物 - 獲得正確的範圍

我想要什麼:內D3

  • 使用HTML對象
  • 達到的HTML代碼

超出正常範圍現在我有問題要得到正確的範圍內使用的功能。 如果我用 「這個」 的

的.html內( 「.....」)

我得到D3的 「G」 元素。那麼有沒有辦法達到我的正常範圍?
還是有更好的方法來解決這個問題嗎?

var foreign = that._foreignObject = d3.select(this).append("foreignObject") 
.attr("width", 30) 
.attr("height", 30) 
.append("xhtml:div") 
.style("font", "15px 'Arial'") 
.html("<button name=Klickmich type=button value=play onclick=>"); 

編輯:二○一三年十二月一十六日

  var nodeEnter = node.enter().append("svg:g") 
       .attr("class", "node") 
       .attr("transform", function (d) { 
        return "translate(" + source.y0 + "," + source.x0 + ")"; 
       }) 

       //click once 
       .on("click", function (d) { 


       if (that._foreignObject) { 
        that._foreignObject.remove(); 
       } 



        that.toggle(d); 
        that.update(d); 
        that.onNodeClick(d); 


        var circle = d3.select(this).select("circle") 
         .transition() 
         .duration(750) 
         .attr("r", 17) 
         .attr("width", 40) 
         .attr("heigth", 40) 
         .style("stroke-dasharray", ("5,2")) 
         .style("stroke-width", 2) 
         .style("stroke", "black"); 



        var button = "<button name=Klickmich type=button value=play onclick=>"; 
        var foreign = that._foreignObject = d3.select(this).append("foreignObject") 
         .attr("width", 30) 
         .attr("height", 30) 
         .append("xhtml:div") 
         .style("font", "15px 'Arial'") 
         .html(button) 

        .on("click", function (d) { 
         console.log("heyho"); 

         }); 


        d3.select(this).select("text").transition() 
         .duration(750) 
         .style("font-size", 15) 
         .style("font-weight", "bold") 
         .attr("x", function (d) { 
          return d.children || d._children ? -20 : -20; 
         }); 



       }) 
+0

正常範圍是什麼意思?你想要'這個'是什麼? –

+0

對象{srcNodeRef:null,_connects:Array [0],_supportingWidgets:Array [0],params:Object,d3:Object ...} – freeFoodFred

+0

我自己明白了。只是用於點擊xhtml:div – freeFoodFred

回答

0

如果我點擊我的HTML按鈕i設置

this._clicked = 1;  

和節點被建立如下的onclick功能:

.on("click", function (d) { 
    if (this._clicked == null) { 

    // some code 

    } 
} 

this._clicked = null;