オプション A:ツリーマップを作成し、スティッキー オプションを true: に設定します.sticky(true)
。ツリーマップ レイアウトは、DOM/SVG の操作に使用できる x、y、幅、および高さの値を提供します。スティッキー オプションは、スムーズな遷移を処理します。
オプション Bdiv
: 要素の代わりになど、プレーンな html 要素を使用しsvg:rect
ます。本当に幅を操作するだけなら、それがより合理的なオプションです。
<style>
#container div{ float: left; }
</style>
<div id="container">
<div id="first" style="width:100px; height:100px; background-color:red;" ></div>
<div id="second" style="width:100px; height:100px; background-color:green;" ></div>
<div id="third" style="width:100px; height:100px; background-color:blue;" ></div>
</div>
プレーンな html を使用すると幅を操作でき、ブラウザのレイアウト/CSS エンジンがフローティングを処理します。D3 は SVG に限定されず、通常の html 要素も処理できます (ツリーマップの例では要素も使用されていdiv
ます)。
ところで: d3 では、DOM を直接操作しないでください。常に基礎となるデータを考え、更新をデータ駆動型にします。つまり、ツリーマップを使用する場合、ソース データ内item.value
のデータを設定します。たとえば、次のようになります。item
data = [ {value: 100}, {value:200}, {value:100} ]
//...
updateData() //changes some values in your data
drawChart() //draws the whole chart based on the data, e.g., computes the x, y,
//width, height from the `item.value` (e.g., via d3.layout.treemap)
//and manipulates/animates the DOM via d3