close
Sayahna Sayahna
Search

Template:Colevel/doc


Function

Purpose

{{colevel}} is a set of templates which allow a list of single items or a list of coupled items to be displayed in one or more columns and be automatically column depth balanced.

The templates are not designed to be called directly from an article, but are designed to be incorporated into other templates which are presenting tables of many items.

There are six entry point templates:

Item set produces a row for a table consisting of one or more "columns" of items or coupled items. It must always be enclosed within a table declaration.
This is used or linked to by pages
Headings places a set of headings above the "columns" produced by item set. It must always be enclosed within a table declaration, the same table as item set.
This is used or linked to by pages
Find first returns the positional number of the first instantiated item in an optionally populated list of items. If there are no items it returns 51.
This is used or linked to by pages
Find last returns the positional number of the last set item in an optionally populated list of items. If there are no items it returns 0.
This is used or linked to by pages
Count params returns the number of the set parameters in an optionally populated list of items.
This is used or linked to by pages
Count items returns the number of set items in an optionally populated list of items, between and including a start item and an end item.
This is used or linked to by pages

See templates {{event list}}, {{overlay}}, and {{Balanced columns list}} for typical applications.

Rationale

Often articles have tables of many items spread over multiple columns, and an editor has spent a non trivial amount of time getting the columns balanced and the table looking good.

One more item or several items are then required to be inserted in to the table, requiring the editing of the whole table to move items around and across and down columns. Or, the number of columns in the table needs to be changed to either allow it to better fit into the article or as more and more values are added. Not all editors are as good at editing tables as others and mistakes are made, or the potential content editor is put off altogether, or editors avoid constructing the table in the first place because it will be difficult to maintain.

These templates allow other templates which generate tables to be constructed to allow the table to be kept in the article as a simple list of items, allowing editors to be concerned only with content and article layout, and not with either table syntax or laborious table reconfiguration as the article grows.

Limitations

Number of items

The maximum number of single items or number of coupled items is 50, that is for coupled items a total of 100 items.

Column balancing

Column balancing does not allow for inconsistent text wrap of items, and text wrap can disturb column depth balancing.

If there is an equivalent number of text wrap new lines in each column then the columns will remain balanced.

Missing items

Items missing from within the list of items are treated as items and a blank position will be displayed in the column where the missing item would otherwise appear.

Usage

The main entry point template is {{colevel/item set}}

Item set

Skeleton

{{colevel/item set
|alpha1 =    |beta1 = 
(...up to 50...)
|firstitem  =
|lastitem   = 
|columns    = 
|alphawidth = 
}}

Item set uses named parameters:

  • alpha1, optional, text for an item, or for the first item of two coupled items, in a list of up to 50 items, optionally linked text
  • beta1, optional, text for the second item of two coupled items, optionally linked text
  • firstitem, mandatory, the positional number of the first item to be displayed from the list, number from 1 to 50
  • lastitem, mandatory, the positional number of the last item to be displayed from the list, number from 1 to 50
  • columns, mandatory, the number of columns to be displayed, number from 1
  • alphawidth, mandatory, the percentage width for the first item of two coupled items. If 100 then only the first item in the couple is displayed. If 0 then only the second item in the couple is displayed, number from 0 to 100

Headings

Skeleton

{{colevel/headings
|alphaheading = 
|betaheading  = 
|columns      = 
|alphawidth   = 
}}

Headings uses named parameters:

  • alphaheading, optional, text for the heading above the first item of two coupled items, optionally linked text
  • betaheading, optional, text for the heading above the second item of two coupled items, optionally linked text
  • columns, mandatory, the number of columns to be displayed, number from 1
  • alphawidth, mandatory, the percentage width for the alpha heading. If 100 then only the alphaheadin is displayed. If 0 then only the betaheading is displayed, number from 0 to 100.

Find first

Skeleton

{{colevel/find first
|item1
(...up to 50...)
}}

Find first uses positional parameters:

  • 1, optional, an item in a list, up to 50, any content

Find last

Skeleton

{{colevel/find last
|item1
(...up to 50...)
}}

Find last uses positional parameters:

  • 1, optional, an item in a list, up to 50, any content

Count params

Skeleton

{{colevel/count params
|item1
(...up to 50...)
}}

Count params uses positional parameters:

  • 1, optional, an item in a list, up to 50, any content

Count items

Skeleton

{{colevel/count items
|item1
(...up to 50...)
|firstitem = 
|lastitem  = 
}}

Count item uses positional parameters and named parameters:

  • 1, optional, an item in a list, up to 50, any content
  • firstitem, mandatory, items with a position before firstitem are ignored, number
  • lastitem, mandatory, items with a position after lastitem are ignored, number

Examples

Headings

Headings for four columns

{|
{{colevel/headings
|alphaheading = [[Letter (alphabet)|Letter]]s
|betaheading  = [[Word]]s
|columns      = 4
|alphawidth   = 25
}}
|}
Letters Words
Letters Words
Letters Words
Letters Words

Item set

Ten items in four columns

{|
{{colevel/item set
|alpha1 = A  |beta1 = One. Numero uno prima.
|alpha2 = BB  |beta2 = Two. Seconda mondo.
|alpha3 = CC C  |beta3 = Three. Triplet gamma.
|alpha4 = D DDD  |beta4 = Four. Quinella equina.
|alpha5 = EE EE E  |beta5 = Five. Cinque torri.
|alpha6 = FFF FFF  |beta6 = Six. Sex before zeben.
|alpha7 = GG GG GG G  |beta7 = Seven. Heptagonaloid.
|alpha8 = HHHH HHHH  |beta8 = Eight. Octapussy bond.
|alpha9 = III III III  |beta9 = Nine. El nina deci.
|alpha10 = J JJ JJJ JJJJ |beta10 = Ten. Decimal dextra.
|firstitem = 1
|lastitem  = 10
|columns   = 4
|alphawidth = 25
}}
|}
A One. Numero uno prima.
BB Two. Seconda mondo.
CC C Three. Triplet gamma.
D DDD Four. Quinella equina.
EE EE E Five. Cinque torri.
FFF FFF Six. Sex before zeben.
GG GG GG G Seven. Heptagonaloid.
HHHH HHHH Eight. Octapussy bond.
III III III Nine. El nina deci.
J JJ JJJ JJJJ Ten. Decimal dextra.

Combined headings and item set

Letters Words
Letters Words
Letters Words
Letters Words

A One. Numero uno prima.
BB Two. Seconda mondo.
CC C Three. Triplet gamma.
D DDD Four. Quinella equina.
EE EE E Five. Cinque torri.
FFF FFF Six. Sex before zeben.
GG GG GG G Seven. Heptagonaloid.
HHHH HHHH Eight. Octapussy bond.
III III III Nine. El nina deci.
J JJ JJJ JJJJ Ten. Decimal dextra.

Nine items in six columns

{|
{{colevel/item set
|alpha1 = A  |beta1 = One. Numero uno prima.
|alpha2 = B  |beta2 = Two. Seconda mondo.
|alpha3 = C  |beta3 = Three. Triplet gamma.
|alpha4 = D  |beta4 = Four. Quinella equina.
|alpha5 = E  |beta5 = Five. Cinque torri.
|alpha6 = F  |beta6 = Six. Sex before zeben.
|alpha7 = G  |beta7 = Seven. Heptagonaloid.
|alpha8 = H  |beta8 = Eight. Octapussy bond.
|alpha9 = I  |beta9 = Nine. El nina deci.
|alpha10 = J |beta10 = Ten. Decimal dextra.
|firstitem = 1
|lastitem  = 9
|columns   = 6
|alphawidth = 15
}}
|}
A One. Numero uno prima.
B Two. Seconda mondo.
C Three. Triplet gamma.
D Four. Quinella equina.
E Five. Cinque torri.
F Six. Sex before zeben.
G Seven. Heptagonaloid.
H Eight. Octapussy bond.
I Nine. El nina deci.

Seven items in three columns

{|
{{colevel/item set
|alpha1 = A A A  |beta1 = One. Numero uno prima.
|alpha2 = B B B  |beta2 = Two. Seconda mondo.
|alpha3 = C C C  |beta3 = Three. Triplet gamma.
|alpha4 = D D D  |beta4 = Four. Quinella equina.
|alpha5 = E E E  |beta5 = Five. Cinque torri.
|alpha6 = F F F  |beta6 = Six. Sex before zeben.
|alpha7 = G G G  |beta7 = Seven. Heptagonaloid.
|alpha8 = H H H  |beta8 = Eight. Octapussy bond.
|alpha9 = I I I  |beta9 = Nine. El nina deci.
|alpha10 = J J J |beta10 = Ten. Decimal dextra.
|firstitem = 2
|lastitem  = 8
|columns   = 3
|alphawidth = 5
}}
|}
B B B Two. Seconda mondo.
C C C Three. Triplet gamma.
D D D Four. Quinella equina.
E E E Five. Cinque torri.
F F F Six. Sex before zeben.
G G G Seven. Heptagonaloid.
H H H Eight. Octapussy bond.

Full item set test - 50 items in 6 columns

1 One
2 Two
3 Three
4 Four
5 Five
6 Six
7 Seven
8 Eight
9 Nine
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
20 20
21 21
22 22
23 23
24 24
25 25
26 26
27 27
28 28
29 29
30 30
31 31
32 32
33 33
34 34
35 35
36 36
37 37
38 38
39 39
40 40
41 41
42 42
43 43
44 44
45 45
46 46
47 47
48 48
49 49
50 50

Find first

Full list

{{colevel/find first |A|BB|CCC|DDDD|E E E E E|f f f f|g g g|h h|i|JjJjJjJj}}

First item is: 1

List with gaps

{{colevel/find first ||BB|CCC|DDDD||f f f f|g g g|h h|i|}}

First item is: 2

Empty list

{{colevel/find first ||||||||||}}

First item is: 51

Find last

Full list

{{colevel/find last |A|BB|CCC|DDDD|E E E E E|f f f f|g g g|h h|i|JjJjJjJj}}

Last item is: 10

List with gaps

{{colevel/find last ||BB|CCC|DDDD||f f f f|g g g|h h|i|}}

Last item is: 9

Empty list

{{colevel/find last ||||||||||}}

Last item is: 0

Count items

Full list

{{colevel/count items |firstitem = 3|lastitem = 7|A|BB|CCC|DDDD|E E E E E|f f f f|g g g|h h|i|JjJjJjJj}}

Item count is: 5

List with gaps

{{colevel/count items |firstitem = 3|lastitem = 7||BB|CCC|DDDD||f f f f|g g g|h h|i|}}

Item count is: 4

Empty list

{{colevel/count items |firstitem = 3|lastitem = 7 ||||||||||}}

Item count is: 0

Count parameters

Full list

{{colevel/count params |A|BB|CCC|DDDD|E E E E E|f f f f|g g g|h h|i|JjJjJjJj}}

Paameter count is: 10

List with gaps

{{colevel/count params ||BB|CCC|DDDD||f f f f|g g g|h h|i|}}

Parameter count is: 7

Empty list

{{colevel/count params ||||||||||}}

Parameter count is: 0

Notes for template editors

A "column" in the row produced by the template {{colevel/item set}} is actually a group of items or coupled items with each item placed on a new line.

Algorithm

The algorithms for this set of templates are:

Item set

The main challenge to be overcome to achieve depth blanced columns is that HTML tables and hence Wiki tables are "row major", that is rows are defined, not columns; the table is constructed row by row. Cells in rows are then aligned to make cells look like they are in columns.

This alogorithm emulates a rudimentrary "column major" table column by column and balances the depth of the columns so that no column is more than one item shorter than any other column, that is when there is a short fall of more than one item, instead of the last column being shorter than all other columns, the shortfall is evened out over multiple columns.

A "column" is a cell in a row with items separated by line breaks to emulate a column.

numberofitems := lastitem - firstitem + 1
rows := 1 + (numberofitems - 1 ) intdiv columns
fullcolumns := if numberofitems mod columns = 0
               then columns
               else numberofitems mod columns
itemsinfullcolumns := fullcolumns x rows
start a row of columns
for item := firstitem to lastitem
    eachitem := item - firstitem + 1
    if eachitem <= itemsinfullcolumns
    then if rows == 1
         then start column
              display list(item)
         else itemmodrows := eachitem mod rows
              if itemmodrows == 1
              then start column
                   display list(item)
                   continue column
              else display list(item)
                   if itemmodrows != 0
                   then continue column
    else if (rows - 1) == 1
         then start column
              display list(item)
         else itemmodrows := (eachitem - itemsinfullcolumns) mod (rows - 1)
              if itemmodrows == 1
              then start column
                   display list(item)
                   continue column
              else display list(item)
                   if itemmodrows != 0
                   then continue column
Other templates within colevel

{{colevel/all items}}

{{colevel/each item}}

{{colevel/process item}}:

if rows == 1
then start column
     display item
else if itemmodrows == 1
     then start column
          display item
          continue column
     else display item
          if itemmodrows != 0
          then continue column

{{colevel/start column}}

{{colevel/display item}}

Find first

item := 1
while item <= maxitem and list(item) is empty
      item := item + 1
firstitem := item

Find last

lastitem := maxitem + 1 - firstitem( reverse( list ) )

Structure

Two key factors have influenced the way the algorithms have been structured into templates:

  1. There is no looping or recursion available. This has required a loop to be simulated by expressing each iteration of the loop as a separate but incremented instantantion of the loop control and content.
  2. To reduce server load a bit, calculated values which are required multiple times within a template (module) (and some module as are called for evey item) and would otherwise be calculated there once and stored as a working variable, are calculated once by a template calling the template and passed as a parameter.


To increase number of items

The current maximum number of items is 50.

To increase the maximum number of items from 50 to MaxItem the following need to be done:

  • Template:Colevel/item set
Update the last item check from 51 to MaxItem + 1.
Add parameter passing from 51 to MaxItem.
  • Template:Colevel/all items
Add loop instantiations for each value from 51 to MaxItem.
  • Template:Colevel/find first
Add loop instantiations for each value from 51 to MaxItem.
Update 51 to MaxItem + 1.
  • Template:Colevel/find last
Update 51 to Maxitem + 1.
Add parameter passing from 51 to MaxItem.
  • Update this documentation wherever 50 or 51 appears to be MaxItem and MaxItem + 1 respectively.

While count items and count parameters are not currently used by item set, they should also be updated if MaxItem is updated:

  • Template:Colevel/count parameters
Add loop instantiations for each value from 51 to MaxItem.
  • Template:Colevel/count items
Add loop instantiations for each value from 51 to MaxItem.