Display an outline as a nested table: Difference between revisions

Content added Content deleted
Line 1,076: Line 1,076:
}
}
}
}
span=( spans and (spans.sum(0) + span - 1) or span );
span=( spans and (spans.sum(0) + span - 1) or span ).max(1);
parent[2]=span;
parent[2]=span;
return(rows,span);
return(rows,span);
Line 1,088: Line 1,088:
trees.append(tree);
trees.append(tree);
r,c := parse(ow,tree,cell,0,2,unit);
r,c := parse(ow,tree,cell,0,2,unit);
tree[0]=tree[0].max(c).max(1); // span for this "branch"
tree[0]=c; // span for this "branch"
rows,cols = rows.max(r), cols + tree[0];
rows,cols = rows.max(r), cols + c;
}
}
return(rows+1,cols,title,trees);
return(rows+1,cols,title,trees);
Line 1,104: Line 1,104:
foreach t in (trees){ // create this row
foreach t in (trees){ // create this row
span,clr := t[0], clrs.next();
span,clr := t[0], clrs.next();
cs,csz := t[1,*].filter('wrap([(d,_,text)]){ d==row }), cs.len();
col,cols := 1, t[1,*].filter('wrap([(d,_,text)]){ d==row });
foreach _,cpos,cspan,text in (cols){
if(row==1) out.writeln(cell(clr,span,cs[0][3])); // tree top/color root
else if(csz==0) out.writeln(cell(clr,span,"")); // or "| |\n"*span
if(col<cpos){ out.writeln(cell(clr,cpos-col,"")); col=cpos }
out.writeln(cell(clr,cspan,text)); col+=cspan;
else{
} // col is span+1 after loop if all cells had text
col:=1;
if(col<=span) out.writeln(cell(clr,span-col+1,""));
foreach _,cpos,cspan,text in (cs){
if(col<cpos){ out.writeln(cell(clr,cpos-col,"")); col=cpos }
out.writeln(cell(clr,cspan,text)); col+=cspan;
} // col is span+1 after loop if all cells had text
if(col<=span) out.writeln(cell(clr,span-col+1,""));
}
}
}
}
}
Line 1,161: Line 1,156:
| style="background: #e6ffff " colspan=2 |
| style="background: #e6ffff " colspan=2 |
|}
|}



And the Perl6 example:
And the Perl6 example:
Line 1,197: Line 1,193:
| style="background: #ffebd2 " colspan=1 | translating the indentation to a nested structure,
| style="background: #ffebd2 " colspan=1 | translating the indentation to a nested structure,
| style="background: #ffebd2 " colspan=1 | and padding the tree to even depth.
| style="background: #ffebd2 " colspan=1 | and padding the tree to even depth.
| style="background: #f0fff0 " colspan=1 | defining the width of a leaf as 1,
| style="background: #f0fff0 " colspan=2 | and the width of a parent node as a sum.
| style="background: #f0fff0 " colspan=2 | and the width of a parent node as a sum.
| style="background: #f0fff0 " colspan=1 | defining the width of a leaf as 1,
| style="background: #e6ffff " colspan=1 | either as a wiki table,
| style="background: #e6ffff " colspan=1 | either as a wiki table,
| style="background: #e6ffff " colspan=1 | or as HTML.
| style="background: #e6ffff " colspan=1 | or as HTML.
Line 1,204: Line 1,200:
|-
|-
| style="background: #ffebd2 " colspan=3 |
| style="background: #ffebd2 " colspan=3 |
| style="background: #f0fff0 " colspan=1 |
| style="background: #f0fff0 " colspan=1 | (The sum of the widths of its children)
| style="background: #f0fff0 " colspan=1 | (The sum of the widths of its children)
| style="background: #f0fff0 " colspan=1 | Propagating the sums upward as necessary.
| style="background: #f0fff0 " colspan=1 | Propagating the sums upward as necessary.
| style="background: #f0fff0 " colspan=1 |
| style="background: #e6ffff " colspan=2 |
| style="background: #e6ffff " colspan=2 |
| style="background: #ffeeff " colspan=1 |
| style="background: #ffeeff " colspan=1 |