1
ノード値に基づいてシェイプを割り当てようとしています。D3でノードにプログラムでノードをシェイプに割り当てる
TypeError: Argument 1 ('node') to Node.appendChild must be an instance of Node
と私はシェーピング機能にノードオブジェクトを返すに失敗するので、この問題が発生し、ある:私が手にエラーがある
// some variables from the UI
var anodezoom = d3.select("#nodezoom").property("value");
var asize = d3.select("#ona").property("value");
var acolor = d3.select("#color").property("value");
var ameasure = d3.select("#shape").property("value");
// build, resize, recolor and reshape the nodes
nodes = svg.selectAll('.node')
.data(graph.nodes.filter(function (d) {
return d.degree > 0;
}))
.enter()
.append(function (d) {
shaping(ameasure, d);
})
.attr('class', 'node')
.attr('r', function (d) {
return resizing(anodezoom, asize, d);
})
.style('fill', function (d) {
return coloring(acolor, d);
})
.style('stroke', function (d) {
return coloring(acolor, d);
})
.call(force.drag);
:
function shaping(ashape, anode) {
var shape = null;
if (ashape === "gender") {
if (anode.gender === "M") {
shape = d3.svg.symbolTypes[0];
} else if (anode.gender === "F") {
shape = d3.svg.symbolTypes[1];
} else {
shape = d3.svg.symbolTypes[2];
}
return shape;
};
私のコードは次のようなものです
私は基本的に文字列を返します。文字列を返すことは正当であるため、私にはうってつけです。
.append('circle')
しかし、それは動作していないので、私のshaping()関数で割り当てられた正しいシェイプのNodeオブジェクトを返す方法はありますか?何...
nodes = svg.selectAll('path')
.data(graph.nodes.filter(function (d) {
return d.degree > 0;
}))
.enter()
.append('path')
.attr('d', d3.svg.symbol().type(function (d) {
return shaping(ashape, d);
}))
.attr('class', 'node')
.attr('r', function (d) {
return resizing(anodezoom, asize, d);
})
.style('fill', function (d) {
return coloring(acolor, d);
})
.style('stroke', function (d) {
return coloring(acolor, d);
})
.call(force.drag);
が、期待通りにリンクが表示されている間、すべてのノードは、左上隅にかろうじて見える:私は私のコードを変更した
EDIT
私はここで行方不明ですか?
私はあなたが私を置くと思いますしながら、リあなたが秒を持っている場合私の編集した質問を見てください – user299791
シンボルパスに適切に配置するために変換を適用する必要があります、上記のスニペットを参照してください。そして、サイズの代わりに、rの代わりにシンボル自体に '.size'を使う必要があります。私はスニペットの両方にサイズパラメータを含めるように答えを編集しました。 –
変換の問題は私には分かりませんが、今私はtick()関数に従ってそれらの位置を割り当てていますが、フォースレイアウトのデフォルトの位置は何ですか? – user299791