I am trying to render D3 tree data using the Vega API.
The Vega Tree documentation states that Vega uses the d3 tree hierarchy. That suggests it should be possible. The Vega page even includes a link to the D3 hierarchy, which looks like this:
{
"name": "Eve",
"children": [
{
"name": "Cain"
},
{
"name": "Seth",
"children": [
{
"name": "Enos"
},
{
"name": "Noam"
}
]
},
{
"name": "Abel"
},
{
"name": "Awan",
"children": [
{
"name": "Enoch"
}
]
},
{
"name": "Azura"
}
]
}
But using this directly in a Vega Tree diagram does not work.
Vega's own tree example includes a data file that does work, but the data format looks completely different. Is there a way to transform the D3 data hierarchy to the format that Vega supports? The Vega docs talk about transforms but I can't find an example.
The required Vega format looks like this. It uses ID's to know who the parent node is, instead of nested arrays.
[
{
"id": 1,
"name": "flare"
},
{
"id": 2,
"name": "analytics",
"parent": 1
},
{
"id": 3,
"name": "cluster",
"parent": 2
},
{
"id": 4,
"name": "AgglomerativeCluster",
"parent": 3,
"size": 3938
},
{
"id": 5,
"name": "CommunityStructure",
"parent": 3,
"size": 3812
}
How can I use D3 formatted tree data in Vega?