Display an outline as a nested table: Difference between revisions

Content added Content deleted
(J: bugfix (use generated colors as colors rather than as a limiting color range)
m (J: better contrast)
Line 673: Line 673:
=={{header|J}}==
=={{header|J}}==


Implementation (assigning colors randomly):
Implementation:


<lang J>depth=: (i.~ ~.)@(0 i."1~' '=];._2)
<lang J>depth=: (i.~ ~.)@(0 i."1~' '=];._2)
Line 685: Line 685:
NB. avoid dark colors
NB. avoid dark colors
NB. avoid dark colors
NB. avoid dark colors
NB. avoid dark colors
pastel=: {{256#.192+?m$,:3#64}}
pastel=: {{256#.192+?y$,:3#64}}


task=: {{
task=: {{
Line 696: Line 697:
widths=. width tr NB. column widths
widths=. width tr NB. column widths
top=. I.2>dr
top=. I.2>dr
color=.<"1 hfd ''pastel (I.tr e.pad)} (top top} tr)&{^:_ (#dr)pastel
color=.<"1 hfd 8421504 (I.tr e.pad)} (top top} tr)&{^:_ (<:2^24),pastel<:#dr
r=.'{| class="wikitable" style="text-align: center;"',LF
r=.'{| class="wikitable" style="text-align: center;"',LF
for_d.~.dr do. NB. descend through the depths
for_d.~.dr do. NB. descend through the depths
Line 729: Line 730:
{| class="wikitable" style="text-align: center;"
{| class="wikitable" style="text-align: center;"
|-
|-
| style="background: #cdead6" colspan=7 | Display an outline as a nested table.
| style="background: #ffffff" colspan=7 | Display an outline as a nested table.
|-
|-
| style="background: #c0f1e1" colspan=3 | Parse the outline to a tree,
| style="background: #e7d7cd" colspan=3 | Parse the outline to a tree,
| style="background: #f3dbd1" colspan=2 | count the leaves descending from each node,
| style="background: #e9c5d1" colspan=2 | count the leaves descending from each node,
| style="background: #cae2dc" colspan=2 | and write out a table with 'colspan' values
| style="background: #d8e9f4" colspan=2 | and write out a table with 'colspan' values
|-
|-
| style="background: #c0f1e1" colspan=1 | measuring the indent of each line,
| style="background: #e7d7cd" colspan=1 | measuring the indent of each line,
| style="background: #c0f1e1" colspan=1 | translating the indentation to a nested structure,
| style="background: #e7d7cd" colspan=1 | translating the indentation to a nested structure,
| style="background: #c0f1e1" colspan=1 | and padding the tree to even depth.
| style="background: #e7d7cd" colspan=1 | and padding the tree to even depth.
| style="background: #f3dbd1" colspan=1 | defining the width of a leaf as 1,
| style="background: #e9c5d1" colspan=1 | defining the width of a leaf as 1,
| style="background: #f3dbd1" colspan=1 | and the width of a parent node as a sum.
| style="background: #e9c5d1" colspan=1 | and the width of a parent node as a sum.
| style="background: #cae2dc" colspan=1 | either as a wiki table,
| style="background: #d8e9f4" colspan=1 | either as a wiki table,
| style="background: #cae2dc" colspan=1 | or as HTML.
| style="background: #d8e9f4" colspan=1 | or as HTML.
|-
|-
| style="background: #c9e3ff" colspan=1 |
| style="background: #808080" colspan=1 |
| style="background: #c9e3ff" colspan=1 |
| style="background: #808080" colspan=1 |
| style="background: #c9e3ff" colspan=1 |
| style="background: #808080" colspan=1 |
| style="background: #c9e3ff" colspan=1 |
| style="background: #808080" colspan=1 |
| style="background: #f3dbd1" colspan=1 | (The sum of the widths of its children)
| style="background: #e9c5d1" colspan=1 | (The sum of the widths of its children)
| style="background: #c9e3ff" colspan=1 |
| style="background: #808080" colspan=1 |
| style="background: #c9e3ff" colspan=1 |
| style="background: #808080" colspan=1 |
|}
|}