Partition layout (rotated).
From D3 in Depth book by Peter Cook.
| license: gpl-3.0 | |
| height: 230 | |
| border: no |
Partition layout (rotated).
From D3 in Depth book by Peter Cook.
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <head> | |
| <title>Partition layout (rotated)</title> | |
| </head> | |
| <style> | |
| rect { | |
| fill: #333; | |
| opacity: 0.3; | |
| stroke: white; | |
| } | |
| </style> | |
| <body> | |
| <svg width="420" height="220"> | |
| <g></g> | |
| </svg> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script> | |
| <script> | |
| var data = { | |
| "name": "A1", | |
| "children": [ | |
| { | |
| "name": "B1", | |
| "children": [ | |
| { | |
| "name": "C1", | |
| "size": 100 | |
| }, | |
| { | |
| "name": "C2", | |
| "size": 300 | |
| }, | |
| { | |
| "name": "C3", | |
| "size": 200 | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "B2", | |
| "size": 200 | |
| } | |
| ] | |
| }; | |
| var partitionLayout = d3.partition() | |
| .size([200, 400]); | |
| var rootNode = d3.hierarchy(data) | |
| rootNode.sum(function(d) { | |
| return d.size; | |
| }); | |
| partitionLayout(rootNode); | |
| d3.select('svg g') | |
| .selectAll('rect') | |
| .data(rootNode.descendants()) | |
| .enter() | |
| .append('rect') | |
| .attr('x', function(d) { return d.y0; }) | |
| .attr('y', function(d) { return d.x0; }) | |
| .attr('width', function(d) { return d.y1 - d.y0; }) | |
| .attr('height', function(d) { return d.x1 - d.x0; }) | |
| </script> | |
| </body> | |
| </html> |