How to count leaf nodes for every node visit using AQL?
My algorithm:
1. Find max depth of graph
2. For every node visit,
- If current node has no children then compute rowspan
- If current node has children then compute colspan
3. If parent node is filtered all children must be filtered too.
For example if B is filtered all children must not be included in
result.
columns.json:
[
{
"_key": "0",
"id": 0,
"title": "root",
"visible": false
},
{
"_key": "1",
"id": 1,
"title": "A",
"visible": true
},
{
"_key": "2",
"id": 2,
"title": "B",
"visible": false,
"verbosity": 2
},
{
"_key": "3",
"id": 3,
"title": "C",
"visible": true
},
{
"_key": "4",
"id": 4,
"title": "D",
"visible": true
},
{
"_key": "5",
"id": 5,
"title": "E",
"visible": true
},
{
"_key": "6",
"id": 6,
"title": "F",
"visible": true
},
{
"_key": "7",
"id": 7,
"title": "G",
"visible": true
},
{
"_key": "8",
"id": 8,
"title": "H",
"visible": true
},
{
"_key": "9",
"id": 9,
"title": "I",
"visible": true
},
{
"_key": "10",
"id": 10,
"title": "J",
"visible": true
},
{
"_key": "11",
"id": 11,
"title": "K",
"visible": true
},
{
"_key": "12",
"id": 12,
"title": "L",
"visible": true
},
{
"_key": "13",
"id": 13,
"title": "M",
"visible": true
},
{
"_key": "14",
"id": 14,
"title": "N",
"visible": true
},
{
"_key": "15",
"id": 15,
"title": "O",
"visible": true
},
{
"_key": "16",
"id": 16,
"title": "P",
"visible": true
}
]
table1-columns.json:
[
{
"_from": "columns/0",
"_to": "columns/1"
},
{
"_from": "columns/1",
"_to": "columns/2"
},
{
"_from": "columns/1",
"_to": "columns/3"
},
{
"_from": "columns/2",
"_to": "columns/4"
},
{
"_from": "columns/2",
"_to": "columns/5"
},
{
"_from": "columns/3",
"_to": "columns/6"
},
{
"_from": "columns/3",
"_to": "columns/7"
},
{
"_from": "columns/4",
"_to": "columns/8"
},
{
"_from": "columns/4",
"_to": "columns/9"
},
{
"_from": "columns/5",
"_to": "columns/10"
},
{
"_from": "columns/5",
"_to": "columns/11"
},
{
"_from": "columns/6",
"_to": "columns/12"
},
{
"_from": "columns/0",
"_to": "columns/13"
},
{
"_from": "columns/13",
"_to": "columns/14"
},
{
"_from": "columns/13",
"_to": "columns/15"
}
]
----------
Example:
| A | | | | | | M | |
|---|---|---|---|---|---|---|---|
| B | | | | C | | N | O |
| D | | E | | F | G | | |
| H | I | J | K | L | | | |
Leaf(A) = [H, I, J, K, L, G] = 6
Leaf(B) = [H, I, J, K] = 4
Leaf(C) = [F, G] = 2
Leaf(D) = [H, I] = 2
...
Leaf(M) = [N, O] = 2
----------
My pseudo AQL:
LET maxLevel = MAX_DEPTH('table1')
FOR v,e,p IN 1..10 OUTBOUND "columns/0" GRAPH "table"
LET currentLevel = LENGTH(p.vertices)
RETURN {
"id": v.id,
"title": v.title,
"rowspan": (RETURN LENGTH(FOR vv IN OUTBOUND v GRAPH "table1" LIMIT 1
RETURN 1) == 0 ? maxLevel - currentLevel : 0),
"colspan": (RETURN LENGTH(FOR vv IN OUTBOUND v GRAPH "table1" LIMIT 1
RETURN 1) > 0 ? COUNT(Leaf(v)) : 0)
}
--
You received this message because you are subscribed to the Google Groups
"ArangoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.