これは私のjsコードです。長方形をクリックすると幅と高さを調整する必要があります。たとえば、ツリーマップに5つの矩形があるとします.1つの矩形をクリックすると、全体の幅と高さが調整され、テキストも調整する必要があります。d3.jsを使用してマルチレベルツリーマップの四角形をクリックすると、幅と高さを調整する方法は?
このような何かを行う必要があります<script src="/js/jquery.min.js"></script>
<script src="/js/d3.v3.min.js"></script>
<script>
function transformrect(from, to) {
/* Returns the transform="" attribute to resize from rectangle to to rectangle */
var x, y,
xscale = to.width/from.width,
yscale = to.height/from.height;
if (xscale >= yscale) {
x = (to.x + to.width/2)/yscale - (from.x + from.width/2);
y = to.y/yscale - from.y;
scale = yscale;
} else {
y = (to.y + to.height/2)/xscale - (from.y + from.height/2);
x = to.x/xscale - from.x;
scale = xscale;
}
return 'scale(' + scale + ')translate(' + x + ',' + y + ')';
}
var root = {x:10, y:10, width:1150, height:400};
d3.selectAll('.l0').on('click', function() {
var transform = transformrect(d3.select(this).select('rect').node().getBBox(), root);
d3.selectAll('.zoommap rect, .zoommap text')
.transition()
.duration(500)
.attr('transform', transform);
d3.select(this).style('display', 'none');
});
d3.selectAll('.l1').on('click', function() {
var transform = transformrect(d3.select(this).select('rect').node().getBBox(), root);
d3.selectAll('.zoommap rect, .zoommap text')
.transition()
.duration(500)
.attr('transform', transform);
d3.select(this).style('display', 'none');
});
d3.selectAll('.l2').on('click', function() {
var transform = transformrect(d3.select(this).select('rect').node().getBBox(), root);
d3.selectAll('.zoommap rect, .zoommap text')
.transition()
.duration(500)
.attr('transform', transform);
d3.select(this).style('display', 'none');
});
d3.selectAll('.l3 rect').on('click', function() {
d3.selectAll('.zoommap rect, .zoommap text')
.transition()
.duration(500)
.attr('transform', 'scale(1)translate(0,0)')
.each('end', function() {
d3.selectAll('.l0').style('display', undefined);
});
})
</script>
あなたのコードのdoesntの実行。 – thatOneGuy
私のtreemapは私たち自身の製品を使って行われています...しかし、私はd3コードだけをズームしてオプションとクリック可能なオプションを適用しています。 –
このd3.jsコードを使ってどのように幅と高さを調整できますか? –