http://jsfiddle.net/pPMqQ/146/
少しの動きを提供するために、フォース チャートの派生物であるバブル チャート アプリケーションを開発しています。
コードの一部を次に示します。svg を作成するときに、viewBox も設定します。これは、グラフのサイズを調整するために使用できると思いますが、比率を適切に調整して正しいスケーリングを得ることができませんでした。
ノードを追加するコードもここに追加しました。ノードのサイズが計算されるので、スケール変数を使用してオーブのサイズに影響を与えます。
var svg = d3.select(selector)
.append("svg")
.attr("class", "bubblechart")
.attr("width", parseInt(w + margin.left + margin.right,10))
.attr("height", parseInt(h + margin.top + margin.bottom,10))
.attr('viewBox', "0 0 "+parseInt(w + margin.left + margin.right,10)+" "+parseInt(h + margin.top + margin.bottom,10))
.attr('perserveAspectRatio', "xMinYMid")
.append("g")
.attr("transform", "translate(0,0)");
methods.force = d3.layout.force()
.charge(1000)
.gravity(100)
.size([methods.width, methods.height])
var bubbleholder = svg.append("g")
.attr("class", "bubbleholder")
var bubbles = bubbleholder.append("g")
.attr("class", "bubbles")
var labelbubble = bubbleholder.append("g")
.attr("class", "labelbubble")
// Enter
nodes.enter()
.append("circle")
.attr("class", "node")
.attr("cx", function (d) { return d.x; })
.attr("cy", function (d) { return d.y; })
.attr("r", 1)
.style("fill", function (d) { return methods.fill(d.label); })
.call(methods.force.drag);
// Update
nodes
.transition()
.delay(300)
.duration(1000)
.attr("r", function (d) { return d.radius*scale; })
// Exit
nodes.exit()
.transition()
.duration(250)
.attr("cx", function (d) { return d.x; })
.attr("cy", function (d) { return d.y; })
.attr("r", 1)
.remove();
残りの問題があります
- スケーリングが問題
データ属性を介して幅/高さを設定しました。現在、チャートの幅に応じてオーブのサイズを調整するスケーリング変数を設定しています。それに応じてグラフのサイズが変更され、要素が常に中心にあるようにする(不明瞭にならない)ためのより科学的な方法を見つけたいと思います。
- 小さな要素が大きな要素の上にあることを確認する小さなオブジェクトが大きなオーブの下にランダムに落ちる可能性があることにも気付きました。サイズに応じてオーブのレンダリングを整理する方法はありますか?大きな要素は常に最下層に配置されます.