# Why Vega Tree shows unnecessary leaf node at the end of the tree

**URL:** https://discuss.elastic.co/t/why-vega-tree-shows-unnecessary-leaf-node-at-the-end-of-the-tree/168020
**Category:** Kibana
**Tags:** vega
**Created:** [February 12, 2019, 11:31am UTC](https://discuss.elastic.co/t/why-vega-tree-shows-unnecessary-leaf-node-at-the-end-of-the-tree/168020 "2019-02-12T11:31:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![biji\_padhy](https://avatars.discourse-cdn.com/v4/letter/b/cab0a1/32.png) [@biji\_padhy](https://discuss.elastic.co/u/biji_padhy)
#### Post date: [February 12, 2019, 11:31am UTC](https://discuss.elastic.co/t/why-vega-tree-shows-unnecessary-leaf-node-at-the-end-of-the-tree/168020/1 "2019-02-12T11:31:21Z")

</div>

Hi All,  
I am trying to plot a flatten transformation tree using vega visualization type in Kibana. I am able to display all the data as expected. However there is an extra leaf node level shows up with no data. I want to remove this last leaf node at the end of the tree. I am adding the code and data snippet for your reference. Thanks in advance for your help.

{  
$schema: [https://vega.github.io/schema/vega/v3.0.json](https://vega.github.io/schema/vega/v3.0.json)  
signals: [  
{  
name: labels  
value: true  
bind: {input: "checkbox"}  
}  
{  
name: aspectRatio  
value: 1.6  
bind: {input: "range", min: 0.2, max: 5, step: 0.1}  
}  
{  
name: layout  
value: tidy  
bind: {  
input: radio  
options: ["tidy", "cluster"]  
}  
}  
{  
name: links  
value: diagonal  
bind: {  
input: select  
options: ["line", "curve", "diagonal", "orthogonal"]  
}  
}  
],  
data: [  
{  
name: tree  
url: {  
%context%: true  
// Filter the time picker (upper right corner) with this field  
%timefield%: last\_update\_time  
index: automataactivity  
body: {  
"aggs": {  
"business": {  
"composite": {  
"sources" : [  
{ "competency\_name": { "terms" : { "field": "busn\_competency\_name.keyword" } }  
},  
{ "component\_name": { "terms" : { "field": "busn\_component\_name.keyword" } }  
},  
{ "busn\_srvc\_name": { "terms" : { "field": "busn\_srvc\_name.keyword" } }  
}  
]  
},  
"aggs": {  
"Comp" : {  
"filter" : { "term": { "automata\_status.keyword": "Completed" } }  
},  
"Exp" : {  
"filter" : { "term": { "automata\_status.keyword": "Exception" } }  
},  
"percentage": {  
"bucket\_script": {  
"buckets\_path": {  
"excp": "Exp.\_count",  
"comp": "Comp.\_count"  
},  
"script": "Math.round((params.excp/params.comp) \* 100)"  
}  
}  
}  
}  
},  
}  
}  
// format: {property: "aggregations.mycount.buckets"}  
transform: [  
{  
type: flatten  
fields: ["aggregations.business.buckets"],  
as: ["a"]  
}  
{  
type: nest  
keys: ["a.key.competency\_name", "a.key.component\_name","a.key.busn\_srvc\_name", "a.percentage.value"],  
generate: true  
},  
{  
"type": "tree",  
"method": {"signal": "layout"},  
"size": [{"signal": "height - 100"}, {"signal": "width - 100"}],  
"as": ["y", "x", "depth", "children"]  
}  
]  
}  
{  
"name": "links",  
"source": "tree",  
"transform": [  
{ "type": "treelinks" },  
{  
"type": "linkpath",  
"orient": "horizontal",  
"shape": {"signal": "links"}  
}  
]  
}  
],  
scales: [  
{  
"name": "color",  
"type": "sequential",  
"range": {"scheme": "blues"},  
"domain": {"data": "tree", "field": "depth"},  
"zero": true  
}  
],  
marks: [  
{  
"type": "path",  
"from": {"data": "links"},  
"encode": {  
"update": {  
"path": {"field": "path"},  
"stroke": {"value": "#105bdd"}  
}  
}  
},  
{  
"type": "symbol",  
"from": {"data": "tree"},  
"encode": {  
"enter": {  
"size": {"value": 300},  
"stroke": {"value": "black"}  
},  
update: {  
"x": {"field": "x"},  
"y": {"field": "y"},  
"fill": {"scale": "color", "field": "depth"}  
}  
}  
}  
{  
"type": "text",  
"from": {"data": "tree"},  
"encode": {  
"enter": {  
"text": {"field": "key"},  
"fontSize": {"value": 12},  
"baseline": {"value": "top"},  
"fill": {"value": "#C0C0C0"}  
}  
update: {  
"x": {"field": "x"},  
"y": {"field": "y"},  
"dx": {"signal": "datum.children ? -7 : 7"},  
"align": {"signal": "datum.children ? 'right' : 'left'"},  
"opacity": {"signal": "labels ? 1 : 0"}  
}  
}  
}  
]  
}

---

<div class="post-metadata">

### Author: ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)
#### Post date: [February 19, 2019, 12:13am UTC](https://discuss.elastic.co/t/why-vega-tree-shows-unnecessary-leaf-node-at-the-end-of-the-tree/168020/2 "2019-02-19T00:13:43Z")

</div>

@nyuriks

Thanks,  
Bhavya

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 19, 2019, 12:23am UTC](https://discuss.elastic.co/t/why-vega-tree-shows-unnecessary-leaf-node-at-the-end-of-the-tree/168020/3 "2019-03-19T00:23:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
