Thank you, Jan. Your answer is work, but my question may not clear.

1. How to find max depth of the graph
LET maxLevel = MAX_DEPTH(table1)

2. For every node visit,

If current node has no children then
LET currentLevel =  LENGTH(path.vertices)
LET rowspan = COUNT_CHILDREN(node) == 0 ? maxLevel - currentLevel : 0

If current node has children then
LET colspan  = COUNT_CHILDREN(node) > 0 ? COUNT_LEAF_NODE(node) : 0


Example
| A |   |   |   |   |   |
|---|---|---|---|---|---|
| B |   |   |   | C |   |
| D |   | E |   | F | G |
| H | I | J | K | L |   |


LEAF_NODE(A) = [H, I, J, K, L, G] =  6
LEAF_NODE(B) = [H, I, J, K, L]      =  4
LEAF_NODE(C) = [L, G]                 =  2


   1. Can AQL Count leaf nodes?
   2. Can AQL find max depth of graph?



เมื่อ วันพฤหัสบดีที่ 16 มีนาคม ค.ศ. 2017 15 นาฬิกา 35 นาที 00 วินาที UTC+7, 
Jan เขียนว่า:
>
> Hi,
>
> one possible and rather generic solution is to run the actual query in a 
> subquery, calculate its number of rows and then return each row from it 
> augmented with rowspan and colspan.
>
> Example:
>
> /* this is a template for an empty row */
> /* it needs to contain all the attributes to be returned from the actual 
> query, plus default values should an attribute not be present */
> LET empty = { _id: null, _key: null, name: null } 
>
> LET keepColumns = ATTRIBUTES(empty) 
> LET colspan = LENGTH(keepColumns) + 3   /* LENGTH([ "row", "colspan", 
> "rowspan" ]) == 3 */
>
> LET result = ( 
>   /* actual query goes here, e.g. FOR doc IN collection RETURN doc */
> )
>
> LET rowspan = LENGTH(result) /* number of rows in result */
>
> /* iterate over result and emit it */
> FOR i IN 1..rowspan LET row = result[i - 1] 
>   RETURN MERGE(empty, KEEP(row, keepColumns), { row: i, rowspan, colspan })
>
>
> Best regards
> Jan
>
> Am Donnerstag, 16. März 2017 04:11:53 UTC+1 schrieb Frank Russell:
>>
>> I want to save html table header as graph. My question is
>>
>>
>>    1. Is it possible to calculate rowspan and colspan using only AQL? 
>>    For example, using edge attribute.
>>    2. How to do numbering for final result? For example, {"index": i + 1}
>>    
>>
>> Attachment:
>>
>>    - result.json : The final result json should look like.
>>    - columns.json: All columns (Nodes)
>>    - table1-columns.json: Table1 columns (Edges)
>>    
>>
>> table1: 
>> Graph({edges: "table1-columns", fromCollections: "columns", toCollections
>> : "columns"})
>>
>>
>>
>> My pseudo query:
>> LET index = 0
>> FOR v,e,p IN 1..10 OUTBOUND "columns/0"
>> GRAPH "table1"
>>   /* FILTER p.vertices[2].id != 2 */
>>   index = index + 1  
>> SORT LENGTH(p.vertices)-1,v.id
>> RETURN {
>>   "index": index,
>>   "id": v.id,
>>   "title": v.title,
>>   "row": LENGTH(p.vertices)-1,
>>   "root": p.vertices[1].id,
>>   "rowspan": rowspan,
>>   "colspan": colspan
>> }
>>
>>
>>
>> Thank you
>>
>

-- 
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.

Reply via email to