Template:Colevel

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Template documentationview · edit · history · purge ]
This documentation is transcluded from Template:Colevel/doc.

Function[edit]

Purpose[edit]

{{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 automtically 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 three entry point templates:

  • {{colevel/item set}}
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
  • {{colevel/find first}}
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 31.
This is used or linked to by pages
  • {{colevel/find last}}
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
  • {{colevel/count params}}
Count params returns the number of the set parameters in an optionally populated list of items.
This is used or linked to by pages
  • {{colevel/count items}}
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}} and {{overlay}} for typical applications.

Rationale[edit]

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[edit]

Number of items[edit]

The maximum number of single items or number of coupled items is 30, that is for coupled items a total of 60 items.

Column balancing[edit]

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[edit]

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[edit]

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

Item set[edit]

Skeleton[edit]

{{colevel/item set
|alpha1 =    |beta1 = 
(...up to 30...)
|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 30 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 30
  • lastitem, mandatory, the positional number of the last item to be displayed from the list, number from 1 to 30
  • 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

Find first[edit]

Skeleton[edit]

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

Find first uses positional parameters:

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

Find last[edit]

Skeleton[edit]

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

Find last uses positional parameters:

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

Count params[edit]

Skeleton[edit]

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

Count params uses positional parameters:

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

Count items[edit]

Skeleton[edit]

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

Count item uses positional parameters and named parameters:

  • 1, optional, an item in a list, up to 30, 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[edit]

Item set[edit]

Ten items in four columns[edit]

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

Nine items in six columns[edit]

{|
{{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[edit]

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

Find first[edit]

Full list[edit]

{{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[edit]

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

First item is: 2

Empty list[edit]

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

First item is: 31

Find last[edit]

Full list[edit]

{{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[edit]

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

Last item is: 9

Empty list[edit]

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

Last item is: 0

Count items[edit]

Full list[edit]

{{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: Template:Colevel/count items

List with gaps[edit]

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

Item count is: Template:Colevel/count items

Empty list[edit]

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

Item count is: Template:Colevel/count items

Count parameters[edit]

Full list[edit]

{{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: Template:Colevel/count params

List with gaps[edit]

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

Parameter count is: Template:Colevel/count params

Empty list[edit]

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

Parameter count is: Template:Colevel/count params

Notes for template editors[edit]

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[edit]

The algorithms for this set of templates are:

Item set[edit]

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[edit]

{{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[edit]

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

Find last[edit]

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

Structure[edit]

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[edit]

The current maximum number of items is 30.

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

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