Here is an example of how to "collapse child nodes to the middle tear and allow the user to expand or collapse a middle tear node at a time". This solution only adds a Vega signal to handle mouse event and a filter to the tree dataset.

View in Vega online Editor
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "An example of Cartesian layouts for a node-link diagram of hierarchical data.",
"width": 600,
"height": 600,
"padding": 5,
"signals": [
{
"name": "signal_selected_node_id",
"init": 1,
"on": [
{
"events": "symbol:mouseup",
"update": "datum['depth'] == 1 ? datum['id']: signal_selected_node_id"
}
]
}
],
"data": [
{
"name": "tree",
"values": [
{"id": 0, "parent": "", "type": "root"},
{"id": 1, "parent": 0, "type": "H-VC"},
{"id": 2, "parent": 0, "type": "H-VC"},
{"id": 3, "parent": 1, "type": "L-VC"},
{"id": 4, "parent": 2, "type": "L-VC"},
{"id": 5, "parent": 1, "type": "L-VC"}
],
"transform": [
{"type": "stratify", "key": "id", "parentKey": "parent"},
{
"type": "tree",
"method": "tidy",
"size": [{"signal": "height"}, {"signal": "width - 100"}],
"as": ["y", "x", "depth", "children"]
},
{
"type": "filter",
"expr": "datum['depth'] <= 1 || (datum['depth'] == 2 && datum['parent'] == signal_selected_node_id)"
}
]
},
{
"name": "links",
"source": "tree",
"transform": [
{"type": "treelinks"},
{"type": "linkpath", "orient": "horizontal", "shape": "diagonal"}
]
}
],
"scales": [
{
"name": "color",
"type": "linear",
"range": {"scheme": "magma"},
"domain": {"data": "tree", "field": "depth"},
"zero": true
}
],
"marks": [
{
"type": "path",
"from": {"data": "links"},
"encode": {
"update": {"path": {"field": "path"}, "stroke": {"value": "#ccc"}}
}
},
{
"type": "symbol",
"from": {"data": "tree"},
"encode": {
"enter": {"size": {"value": 100}, "stroke": {"value": "#fff"}},
"update": {
"x": {"field": "x"},
"y": {"field": "y"},
"fill": {"scale": "color", "field": "depth"}
}
}
},
{
"type": "text",
"from": {"data": "tree"},
"encode": {
"enter": {
"text": {"field": "type"},
"fontSize": {"value": 9},
"baseline": {"value": "middle"}
},
"update": {
"x": {"field": "x", "offset": 10},
"y": {"field": "y", "offset": -10}
}
}
}
]
}