I have to create chart that consists of a hierarchy of blocks (a big block that contains smaller blocks that contain other blocks).
The data is a hierarchy of these blocks
{
element: {name: test, geometry: [..], orientation: '180'}
element: {name: test2, geometry: [..], orientation: 'none'}
element: {name: test3, geometry: [..], orientation: 'flipX'}
element: {
name: test4,
geometry: [..],
orientation: '90'
children:
[
element: {name: test5, geometry: [..], orientation: '180'}
element: {name: test6, geometry: [..], orientation: 'none'}
]
}
}
Each block has a geometry (array of edges) and an orientation:
- no orientation
- flip on X (flip around the center of bounding box on X axis)
- flip on y (flip around the center of bounding box on Y axis)
- rotate 90 degrees (rotate around the point of origin 90 degrees)
- 180 degrees
The coordinates of the edges are relative to the parent block's origin.
So if the main block is rotated, the sub-block's coordinate system will also be rotated.
I need to draw this and then change the fill color of each block based on metrics.
The way i did it now is to recursively parse that hierarchy and append svg elements for each one:
<svg>
<g><path>
<g><path></g>
<g><path></g>
<g><path>
<g><path></g>
</g>
</g>
</svg>
This helps with all the coordinate inheritance as i draw inside groups that are already rotated.
I am not sure this is the best way as i am not using the .data() append() enter() functions because i don't know how to draw imbricated elements. The blocks also have labels and an indicator of where their origin is but i didn't include this to simplify.
Is there a better way to do this?
Thank you!