<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.filipefonseca.pt/index.php?action=history&amp;feed=atom&amp;title=Module%3AHistorical_populations</id>
	<title>Module:Historical populations - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.filipefonseca.pt/index.php?action=history&amp;feed=atom&amp;title=Module%3AHistorical_populations"/>
	<link rel="alternate" type="text/html" href="http://wiki.filipefonseca.pt/index.php?title=Module:Historical_populations&amp;action=history"/>
	<updated>2026-04-19T18:07:17Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>http://wiki.filipefonseca.pt/index.php?title=Module:Historical_populations&amp;diff=7301&amp;oldid=prev</id>
		<title>FilipeFonseca: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="http://wiki.filipefonseca.pt/index.php?title=Module:Historical_populations&amp;diff=7301&amp;oldid=prev"/>
		<updated>2021-07-10T14:13:50Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--&lt;br /&gt;
-- This template implements {{Historical populations}}&lt;br /&gt;
--&lt;br /&gt;
local p = {}&lt;br /&gt;
local lang = mw.getContentLanguage()&lt;br /&gt;
local Date -- lazy initialization&lt;br /&gt;
&lt;br /&gt;
local function ifexist(page)&lt;br /&gt;
    if not page then return false end&lt;br /&gt;
    if mw.title.new(page).exists then return true end&lt;br /&gt;
    return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function isempty( s )&lt;br /&gt;
	return not s or s:match( '^%s*(.-)%s*$' ) == ''&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function splitnumandref( s )&lt;br /&gt;
	s = s:match( '^%s*(.-)%s*$' )&lt;br /&gt;
	local t1 = mw.text.unstrip(s)&lt;br /&gt;
        local t2 = s:match( '^([%d][%d,]*)' )&lt;br /&gt;
	if( t1 == t2 ) then&lt;br /&gt;
		local t3 = s:match( '^[%d][%d,]*(.-)$' )&lt;br /&gt;
		return t1, t3&lt;br /&gt;
	else&lt;br /&gt;
		return s, ''&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function formatnumR(num)&lt;br /&gt;
	return tonumber(lang:parseFormattedNumber(num))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function formatnum(num)&lt;br /&gt;
	return lang:parseFormattedNumber(num) and lang:formatNum(lang:parseFormattedNumber(num)) or num&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- this function creates an array with the {year, population, percent change}&lt;br /&gt;
local function getpoprow(year, popstr, pyear, ppopstr, linktype, percentages, current_year)&lt;br /&gt;
	local pop, popref = splitnumandref( popstr or '')&lt;br /&gt;
	local ppop, ppopref = splitnumandref( ppopstr or '')&lt;br /&gt;
	local percent = ''&lt;br /&gt;
	local yearnum = formatnumR(mw.ustring.gsub(year or '', '^%s*([%d][%d][%.%d]+).*$', '%1') or '')&lt;br /&gt;
	local pyearnum = formatnumR(mw.ustring.gsub(pyear or '', '^%s*([%d][%d][%.%d]+).*$', '%1') or '')&lt;br /&gt;
	local popnum = formatnumR(pop)&lt;br /&gt;
	local ppopnum = formatnumR(ppop)&lt;br /&gt;
	if( linktype == 'US' or linktype == 'USA' ) then&lt;br /&gt;
		if( (yearnum or 0) &amp;gt;= 1790 and yearnum &amp;lt;= current_year and math.fmod(math.floor(yearnum), 10) == 0) then&lt;br /&gt;
			if( yearnum &amp;lt; current_year ) then&lt;br /&gt;
				year = '[[' .. tostring(yearnum) .. ' United States Census|' .. year .. ']]'&lt;br /&gt;
  			elseif( ifexist(tostring(yearnum) .. ' United States Census') ) then&lt;br /&gt;
				year = '[[' .. tostring(yearnum) .. ' United States Census|' .. year .. ']]'&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if(percentages ~= 'off') then&lt;br /&gt;
		local pstr = '—&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;'&lt;br /&gt;
		if(popnum ~= nil and ppopnum ~= nil and (ppopnum &amp;gt; 0)) then&lt;br /&gt;
			if(percentages == 'pagr') then&lt;br /&gt;
				pstr = mw.ustring.format('%.2f', 100*math.abs(math.pow(popnum/ppopnum,1/(yearnum-pyearnum)) - 1))&lt;br /&gt;
			elseif(percentages == 'monthly') then&lt;br /&gt;
				if Date == nil then Date = require('Module:Date')._Date end&lt;br /&gt;
				local date1 = Date(year)&lt;br /&gt;
				local date2 = Date(pyear)&lt;br /&gt;
				local diff = date1 - date2&lt;br /&gt;
				local months = (diff.age_days/(365.25/12))&lt;br /&gt;
				pstr = mw.ustring.format('%.2f', 100*math.abs(math.pow(popnum/ppopnum,1/months) - 1))&lt;br /&gt;
			else&lt;br /&gt;
				pstr = mw.ustring.format('%.1f', 100*math.abs(popnum/ppopnum - 1))&lt;br /&gt;
			end&lt;br /&gt;
			if( popnum &amp;lt; ppopnum ) then&lt;br /&gt;
				pstr = '−' .. pstr .. '%'&lt;br /&gt;
			else&lt;br /&gt;
				pstr = '+' .. pstr .. '%'&lt;br /&gt;
			end&lt;br /&gt;
		elseif(popnum ~= nil and ppopnum ~= nil and (ppopnum == popnum)) then&lt;br /&gt;
			pstr = mw.ustring.format('%.2f', 0) .. '%'&lt;br /&gt;
		end&lt;br /&gt;
		percent = pstr&lt;br /&gt;
	end&lt;br /&gt;
	-- strip the fractional part of the year, if there is one&lt;br /&gt;
	year = mw.ustring.gsub(year or '', '^%s*([%d][%d][%d]+)%.[%d]*', '%1')&lt;br /&gt;
	&lt;br /&gt;
	return {year, formatnum(pop) .. popref, percent }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- this function creates an array with table header labels&lt;br /&gt;
local function getheadrow(percentages, popname, yearname, percentname)&lt;br /&gt;
	-- year cell	&lt;br /&gt;
	if(yearname == '') then&lt;br /&gt;
		yearname = 'Year'&lt;br /&gt;
	end&lt;br /&gt;
	-- population cell&lt;br /&gt;
	if(popname == '') then&lt;br /&gt;
		popname = '&amp;lt;abbr title=&amp;quot;Population&amp;quot;&amp;gt;Pop.&amp;lt;/abbr&amp;gt;'&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- percentages cell&lt;br /&gt;
	if( percentages ~= 'off' and percentname == '') then&lt;br /&gt;
		if( percentages == 'pagr' ) then&lt;br /&gt;
			percentname = '&amp;lt;abbr title=&amp;quot;Per annum growth rate&amp;quot;&amp;gt;±% p.a.&amp;lt;/abbr&amp;gt;'&lt;br /&gt;
		elseif( percentages == 'monthly' ) then&lt;br /&gt;
			percentname = '&amp;lt;abbr title=&amp;quot;Per month growth rate&amp;quot;&amp;gt;±% p.m.&amp;lt;/abbr&amp;gt;'&lt;br /&gt;
		else&lt;br /&gt;
			percentname = '&amp;lt;abbr title=&amp;quot;Percent change&amp;quot;&amp;gt;±%&amp;lt;/abbr&amp;gt;'&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return {yearname, popname, percentname}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- this function builds the json for the population graph&lt;br /&gt;
local function graphjson(data, gwidth, gheight)&lt;br /&gt;
	local yearcount = #data&lt;br /&gt;
	local graphargs = {&lt;br /&gt;
		['width'] = gwidth,&lt;br /&gt;
		['height'] = gheight,&lt;br /&gt;
		['type'] = 'line',&lt;br /&gt;
		['yAxisTitle'] = 'Population',&lt;br /&gt;
		['yAxisMin'] = 0,&lt;br /&gt;
		['xAxisTitle'] = 'Year',&lt;br /&gt;
		['xAxisAngle'] = '-45',&lt;br /&gt;
		['yGrid'] = 'y',&lt;br /&gt;
		['yAxisFormat'] = ',d',&lt;br /&gt;
		['x'] = '',&lt;br /&gt;
		['y'] = ''&lt;br /&gt;
	}&lt;br /&gt;
	local firstpoint = true&lt;br /&gt;
	for offset = 1,yearcount do&lt;br /&gt;
		local x,y = data[offset][1], data[offset][2]&lt;br /&gt;
		-- delink if necessary&lt;br /&gt;
		if x:match('^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]') then&lt;br /&gt;
			x = x:match('^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]')&lt;br /&gt;
		end&lt;br /&gt;
		y = formatnumR(y)&lt;br /&gt;
		if x and y then&lt;br /&gt;
			graphargs['x'] = graphargs['x'] .. (firstpoint and '' or ', ') .. x&lt;br /&gt;
			graphargs['y'] = graphargs['y'] .. (firstpoint and '' or ', ') .. y&lt;br /&gt;
			firstpoint = false&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local Graph = require('Module:Graph')&lt;br /&gt;
	&lt;br /&gt;
	return Graph.chart({args = graphargs})&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function rendergraph(frame, data, gwidth, gheight, gthumb)&lt;br /&gt;
	local graph = frame:extensionTag{&lt;br /&gt;
			name = 'templatestyles', &lt;br /&gt;
			args = { src = 'Graph:Chart/styles.css'} &lt;br /&gt;
		} .. frame:extensionTag{name = 'graph', content = graphjson(data, gwidth, gheight)}&lt;br /&gt;
&lt;br /&gt;
	if(gthumb ~= '') then&lt;br /&gt;
		local graphdiv = mw.html.create('div')&lt;br /&gt;
			:addClass('thumb')&lt;br /&gt;
			:addClass(gthumb == 'right' and 'tright' or 'tleft')&lt;br /&gt;
			:css('clear', 'none')&lt;br /&gt;
		graphdiv&lt;br /&gt;
			:tag('div')&lt;br /&gt;
			:addClass('thumbinner')&lt;br /&gt;
			:wikitext(graph)&lt;br /&gt;
		return tostring(graphdiv)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return '&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;' .. graph .. '&amp;lt;/div&amp;gt;'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- this function renders the population table in a vertical format&lt;br /&gt;
local function rendervertical(data, head, title, footnote, alignfn, class, style, width, shading, percol, cols, graphpos, graph)&lt;br /&gt;
	-- define a couple helper functions&lt;br /&gt;
	local function addrowcell(trow, tag, text, align, shading, style)&lt;br /&gt;
		cell = trow:tag(tag)&lt;br /&gt;
		cell&lt;br /&gt;
			:css('text-align', align)&lt;br /&gt;
			:css('padding', '1px')&lt;br /&gt;
			:wikitext(text)&lt;br /&gt;
			:css('border-bottom', shading ~= 'off' and '1px solid #bbbbbb' or nil)&lt;br /&gt;
			:cssText(style)&lt;br /&gt;
	end&lt;br /&gt;
	local function addheadcell(trow, text, align, width, pad)&lt;br /&gt;
		cell = trow:tag('th')&lt;br /&gt;
		cell&lt;br /&gt;
			:css('border-bottom', '1px solid black')&lt;br /&gt;
			:css('padding', pad and ('1px ' .. pad) or '1px')&lt;br /&gt;
			:css('text-align', align)&lt;br /&gt;
			:css('width', width)&lt;br /&gt;
			:wikitext(text)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local colspan = 3&lt;br /&gt;
	local yearcount = #data&lt;br /&gt;
	local argcount = 2*yearcount&lt;br /&gt;
	&lt;br /&gt;
	if( isempty(width) ) then&lt;br /&gt;
		width = '15em'&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- override the value of cols if percol has been specified&lt;br /&gt;
	if( percol &amp;gt; 0 ) then&lt;br /&gt;
		cols = math.floor( (yearcount - 1) / percol ) + 1&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- compute the number of rows per col&lt;br /&gt;
	local rowspercol = math.floor( (yearcount - 1) / cols ) + 1&lt;br /&gt;
&lt;br /&gt;
	-- specify the colspan for the title and footer lines&lt;br /&gt;
	if( cols &amp;gt; 1 ) then&lt;br /&gt;
		colspan = cols&lt;br /&gt;
	else&lt;br /&gt;
		if (head[3] == '') then &lt;br /&gt;
			colspan = 2&lt;br /&gt;
		else&lt;br /&gt;
			colspan = 3&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- compute outer table width&lt;br /&gt;
	local twidth = width&lt;br /&gt;
	if( (cols &amp;gt; 1) and width:match('^%s*[%d]+[%w]+%s*$') ) then&lt;br /&gt;
		local widthnum = mw.ustring.gsub( width, '^%s*([%d]+)([%w]+)%s*$', '%1' )&lt;br /&gt;
		local widthunit = mw.ustring.gsub( width, '^%s*([%d]+)([%w]+)%s*$', '%2' )&lt;br /&gt;
		twidth = tostring(widthnum*cols) .. widthunit&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- create the outer table&lt;br /&gt;
	local root = mw.html.create('table')&lt;br /&gt;
	root&lt;br /&gt;
		:addClass(class)&lt;br /&gt;
		:css('width', twidth)&lt;br /&gt;
		:css('border-top-width', '0')&lt;br /&gt;
		:cssText(style['table'])&lt;br /&gt;
	-- add title&lt;br /&gt;
	local caption = root:tag('caption')&lt;br /&gt;
	caption&lt;br /&gt;
		:css('border-top', '1px #aaa solid')&lt;br /&gt;
		:css('border-left', '1px #aaa solid')&lt;br /&gt;
		:css('border-right', '1px #aaa solid')&lt;br /&gt;
		:css('background-color', 'lavender')&lt;br /&gt;
		:css('padding', '0.25em')&lt;br /&gt;
		:css('font-weight', 'bold')&lt;br /&gt;
		:wikitext(title)&lt;br /&gt;
		&lt;br /&gt;
	-- add the graph line (if top graph)&lt;br /&gt;
	if((graphpos == 'top' or graphpos == 't') and graph ~= '') then&lt;br /&gt;
		row = root:tag('tr')&lt;br /&gt;
		cell = row:tag('td')&lt;br /&gt;
		cell&lt;br /&gt;
			:attr('colspan', colspan)&lt;br /&gt;
			:css('border-bottom', '1px solid black')&lt;br /&gt;
			:wikitext(graph)&lt;br /&gt;
		graph = ''&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- loop over columns and rows within columns&lt;br /&gt;
	local offset = 1&lt;br /&gt;
	local t = root&lt;br /&gt;
	for c = 1,cols do&lt;br /&gt;
		-- add inner tables if we are rendering more than one column&lt;br /&gt;
		if( cols &amp;gt; 1) then&lt;br /&gt;
			if (c == 1) then&lt;br /&gt;
				row = root:tag('tr')&lt;br /&gt;
				row:attr('valign', 'top')&lt;br /&gt;
				cell = row:tag('td')&lt;br /&gt;
				cell:css('padding', '0 0.5em')&lt;br /&gt;
			else&lt;br /&gt;
				cell = row:tag('td')&lt;br /&gt;
				cell&lt;br /&gt;
					:css('padding', '0 0.5em')&lt;br /&gt;
					:css('border-left', 'solid 1px #aaa')&lt;br /&gt;
			end&lt;br /&gt;
			t = cell:tag('table')&lt;br /&gt;
			t&lt;br /&gt;
				:css('border-spacing', '0')&lt;br /&gt;
				:css('width', width)&lt;br /&gt;
		end&lt;br /&gt;
		-- start column headers&lt;br /&gt;
		local hrow = t:tag('tr')&lt;br /&gt;
		hrow:css('font-size', '95%')&lt;br /&gt;
		-- year header&lt;br /&gt;
		addheadcell(hrow, head[1], nil, head[3] ~= '' and '3em' or 'auto', nil, nil)&lt;br /&gt;
		-- population header&lt;br /&gt;
		addheadcell(hrow, head[2], 'right', nil, '2px')&lt;br /&gt;
		-- percentages header&lt;br /&gt;
		if( head[3] ~= '' ) then&lt;br /&gt;
			addheadcell(hrow, head[3], 'right', nil, nil)&lt;br /&gt;
		end&lt;br /&gt;
		-- end column headers&lt;br /&gt;
		-- start population rows&lt;br /&gt;
		for r = 1,rowspercol do&lt;br /&gt;
			-- generate the row if we have not exceeded the rowcount&lt;br /&gt;
			-- shade every fifth row, unless shading = off&lt;br /&gt;
			local s = 'off'&lt;br /&gt;
			if( math.fmod((c - 1)*rowspercol + r, 5) == 0 and r ~= rowspercol) then&lt;br /&gt;
				s = shading&lt;br /&gt;
			end&lt;br /&gt;
			if(offset &amp;lt;= yearcount) then&lt;br /&gt;
				-- start population row&lt;br /&gt;
				local prow = t:tag('tr')&lt;br /&gt;
				-- year cell&lt;br /&gt;
				addrowcell(prow, 'th', data[offset][1], 'center', s, style['year'])&lt;br /&gt;
				-- population cell&lt;br /&gt;
				addrowcell(prow, 'td', data[offset][2], 'right', s, style['pop'])&lt;br /&gt;
				-- percentage cell&lt;br /&gt;
				if( not isempty(head[3]) ) then&lt;br /&gt;
					addrowcell(prow, 'td', data[offset][3], 'right', s, style['pct'])&lt;br /&gt;
				end&lt;br /&gt;
				-- end population row&lt;br /&gt;
				offset = offset + 1&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- add the graph line (if bottom graph)&lt;br /&gt;
	if((graphpos == 'bottom' or graphpos == 'b') and graph ~= '') then&lt;br /&gt;
		row = root:tag('tr')&lt;br /&gt;
		cell = row:tag('td')&lt;br /&gt;
		cell&lt;br /&gt;
			:attr('colspan', colspan)&lt;br /&gt;
			:css('border-top', '1px solid black')&lt;br /&gt;
			:wikitext(graph)&lt;br /&gt;
		graph = ''&lt;br /&gt;
	end&lt;br /&gt;
	-- add the footnote line 	&lt;br /&gt;
	if( footnote ~= '') then&lt;br /&gt;
		row = root:tag('tr')&lt;br /&gt;
		cell = row:tag('td')&lt;br /&gt;
		cell&lt;br /&gt;
			:attr('colspan', colspan)&lt;br /&gt;
			:css('border-top', '1px solid black')&lt;br /&gt;
			:css('font-size', '85%')&lt;br /&gt;
			:css('text-align', alignfn)&lt;br /&gt;
			:wikitext(footnote)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return graph .. tostring(root)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- this function renders the population table in a horizontal format&lt;br /&gt;
local function renderhorizontal(data, head, title, footnote, alignfn, class, style, width, shading, perrow, rows, graphpos, graph)&lt;br /&gt;
	local row&lt;br /&gt;
	local cell&lt;br /&gt;
	local yearcount = #data&lt;br /&gt;
	local argcount = 2*yearcount&lt;br /&gt;
	&lt;br /&gt;
	-- override the value of rows if perrow has been specified&lt;br /&gt;
	if( perrow &amp;gt; 0 ) then&lt;br /&gt;
		rows = math.floor( (yearcount - 1) / perrow ) + 1&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- compute the number of cols per row&lt;br /&gt;
	local colsperrow = math.floor( (yearcount - 1) / rows ) + 1&lt;br /&gt;
&lt;br /&gt;
	-- create the outer table&lt;br /&gt;
	local root = mw.html.create('table')&lt;br /&gt;
	root&lt;br /&gt;
		:addClass(class)&lt;br /&gt;
		:css('font-size', '90%')&lt;br /&gt;
		:cssText(style['table'])&lt;br /&gt;
	-- create title row&lt;br /&gt;
	row = root:tag('tr')&lt;br /&gt;
	cell = row:tag('th')&lt;br /&gt;
	cell&lt;br /&gt;
		:css('padding', '0.25em')&lt;br /&gt;
		:attr('colspan', colsperrow + 1)&lt;br /&gt;
		:wikitext(title)&lt;br /&gt;
&lt;br /&gt;
	-- add the graph line (if top graph)&lt;br /&gt;
	if((graphpos == 'top' or graphpos == 't') and graph ~= '') then&lt;br /&gt;
		row = root:tag('tr')&lt;br /&gt;
		cell = row:tag('td')&lt;br /&gt;
		cell&lt;br /&gt;
			:attr('colspan', colsperrow + 1)&lt;br /&gt;
			:css('border-bottom', '1px solid black')&lt;br /&gt;
			:wikitext(graph)&lt;br /&gt;
		graph = ''&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- loop over rows and columns within rows&lt;br /&gt;
	local offset = 1&lt;br /&gt;
	for r = 1,rows do&lt;br /&gt;
		local rowoffset = offset&lt;br /&gt;
		-- render the years&lt;br /&gt;
		row = root:tag('tr')&lt;br /&gt;
		cell = row:tag('th')&lt;br /&gt;
		cell:wikitext(head[1])&lt;br /&gt;
			:css('border-top', r &amp;gt; 1 and '2px solid #000' or nil)&lt;br /&gt;
		for c = 1,colsperrow do&lt;br /&gt;
			cell = row:tag('td')&lt;br /&gt;
			if(offset &amp;lt;= yearcount) then&lt;br /&gt;
				cell:wikitext(data[offset][1])&lt;br /&gt;
					:css('text-align', 'center')&lt;br /&gt;
					:css('border-top', r &amp;gt; 1 and '2px solid #000' or nil)&lt;br /&gt;
					:cssText(style['year'])&lt;br /&gt;
			else&lt;br /&gt;
				cell:css('border-width', r &amp;gt; 1 and '2px 0 0 0' or 0)&lt;br /&gt;
					:css('border-top', r &amp;gt; 1 and '2px solid #000' or nil)&lt;br /&gt;
			end&lt;br /&gt;
			offset = offset + 1&lt;br /&gt;
		end&lt;br /&gt;
		-- render the pop&lt;br /&gt;
		offset = rowoffset&lt;br /&gt;
		row = root:tag('tr')&lt;br /&gt;
		cell = row:tag('th')&lt;br /&gt;
		cell:wikitext(head[2])&lt;br /&gt;
		for c = 1,colsperrow do&lt;br /&gt;
			cell = row:tag('td')&lt;br /&gt;
			if(offset &amp;lt;= yearcount) then&lt;br /&gt;
				cell:wikitext(data[offset][2])&lt;br /&gt;
					:css('text-align', 'right')&lt;br /&gt;
					:css('padding-right', '2px')&lt;br /&gt;
					:cssText(style['pop'])&lt;br /&gt;
			else&lt;br /&gt;
				cell:css('border-width', 0)&lt;br /&gt;
			end&lt;br /&gt;
			offset = offset + 1&lt;br /&gt;
		end&lt;br /&gt;
		-- render the percentages&lt;br /&gt;
		if(head[3] ~= '') then&lt;br /&gt;
			offset = rowoffset&lt;br /&gt;
			row = root:tag('tr')&lt;br /&gt;
			cell = row:tag('th')&lt;br /&gt;
			cell:wikitext(head[3])&lt;br /&gt;
			for c = 1,colsperrow do&lt;br /&gt;
				cell = row:tag('td')&lt;br /&gt;
				if(offset &amp;lt;= yearcount) then&lt;br /&gt;
					cell:wikitext(data[offset][3])&lt;br /&gt;
						:css('text-align', 'right')&lt;br /&gt;
						:css('padding-right', '2px')&lt;br /&gt;
						:cssText(style['pct'])&lt;br /&gt;
				else&lt;br /&gt;
					cell:css('border-width', 0)&lt;br /&gt;
				end&lt;br /&gt;
				offset = offset + 1&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- add the graph line (if bottom graph)&lt;br /&gt;
	if((graphpos == 'bottom' or graphpos == 'b') and graph ~= '') then&lt;br /&gt;
		row = root:tag('tr')&lt;br /&gt;
		cell = row:tag('td')&lt;br /&gt;
		cell&lt;br /&gt;
			:attr('colspan', colsperrow + 1)&lt;br /&gt;
			:css('border-top', '1px solid black')&lt;br /&gt;
			:wikitext(graph)&lt;br /&gt;
		graph = ''&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- add the footnote line 	&lt;br /&gt;
	if( footnote ~= '') then&lt;br /&gt;
		row = root:tag('tr')&lt;br /&gt;
		cell = row:tag('td')&lt;br /&gt;
		cell&lt;br /&gt;
			:css('border-top', '2px solid black')&lt;br /&gt;
			:css('font-size', '85%')&lt;br /&gt;
			:css('text-align', alignfn)&lt;br /&gt;
			:attr('colspan', colsperrow + 1)&lt;br /&gt;
			:wikitext(footnote)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return graph .. tostring(root)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- this is the main function&lt;br /&gt;
function p.poptable(frame)&lt;br /&gt;
	local data = {}&lt;br /&gt;
	local style = {}&lt;br /&gt;
	local args = frame.args[1] and frame.args or frame:getParent().args&lt;br /&gt;
&lt;br /&gt;
	local title			= args['title']			or ''&lt;br /&gt;
	local align			= args['align']			or ''&lt;br /&gt;
	local clear			= args['clear']			or ''&lt;br /&gt;
	local direction		= args['direction']		or ''&lt;br /&gt;
	local percentages	= args['percentages']	or ''&lt;br /&gt;
	local state			= args['state']			or ''&lt;br /&gt;
	local linktype		= args['type']			or ''&lt;br /&gt;
	local shading		= args['shading']		or 'on'&lt;br /&gt;
	local width			= args['width']			or ''&lt;br /&gt;
	local subbox		= args['subbox']		or ''&lt;br /&gt;
	local popname		= args['pop_name']		or ''&lt;br /&gt;
	local yearname		= args['year_name']		or ''&lt;br /&gt;
	local percentname   = args['percent_name']  or ''&lt;br /&gt;
	local footnote		= args['footnote']		or ''&lt;br /&gt;
	local alignfn		= args['align-fn']		or ''&lt;br /&gt;
	local source		= args['source']		or ''&lt;br /&gt;
	local graphpos      = args['graph-pos']     or ''&lt;br /&gt;
	local graphwidth    = args['graph-width']   or ''&lt;br /&gt;
	local graphheight   = args['graph-height']  or ''&lt;br /&gt;
	local percol = tonumber(args['percol'])	or 0&lt;br /&gt;
	local cols	 = tonumber(args['cols'])	or 1&lt;br /&gt;
	local perrow = tonumber(args['perrow'])	or 0&lt;br /&gt;
	local rows	 = tonumber(args['rows'])	or 1&lt;br /&gt;
	style['year'] = args['year_style']&lt;br /&gt;
	style['pop']  = args['pop_style']&lt;br /&gt;
	style['pct']  = args['pct_style']&lt;br /&gt;
&lt;br /&gt;
	-- setup classes and styling for outer table&lt;br /&gt;
	local class = direction == 'horizontal' and 'wikitable' or 'toccolours'&lt;br /&gt;
	if( state == 'collapsed' ) then&lt;br /&gt;
		class = class .. ' collapsible collapsed'&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if( isempty(title) ) then&lt;br /&gt;
		title = 'Historical population'&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if( isempty(align) ) then&lt;br /&gt;
		align = direction ~= 'horizontal' and 'right' or 'center'&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if( isempty(alignfn) ) then&lt;br /&gt;
		alignfn = 'left'&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if( isempty(clear) ) then&lt;br /&gt;
		clear = align == 'center' and '' or align&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local margin = '0.5em 0 1em 0.5em'&lt;br /&gt;
	if( align == 'left' ) then&lt;br /&gt;
		margin = '0.5em 1em 0.5em 0'&lt;br /&gt;
	elseif( align == 'none' ) then&lt;br /&gt;
		margin = '0.5em 1em 0.5em 0'&lt;br /&gt;
	elseif( align == 'center' ) then&lt;br /&gt;
		margin = '0.5em auto'&lt;br /&gt;
		align = ''&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if( isempty(subbox) ) then&lt;br /&gt;
		style['table'] =&lt;br /&gt;
			'border-spacing: 0;' ..&lt;br /&gt;
			(align ~= '' and 'float:' .. align .. ';' or '') ..&lt;br /&gt;
			(clear ~= '' and 'clear:' .. clear .. ';' or '') ..&lt;br /&gt;
			'margin:' .. margin .. ';'&lt;br /&gt;
	else&lt;br /&gt;
		style['table'] =&lt;br /&gt;
			'margin:0;' ..&lt;br /&gt;
			'border-collapse:collapse;' ..&lt;br /&gt;
			'border:none;'&lt;br /&gt;
	end	&lt;br /&gt;
		&lt;br /&gt;
	-- setup the footer text&lt;br /&gt;
	if( source ~= '' ) then&lt;br /&gt;
		source = 'Source: ' .. source&lt;br /&gt;
		if( footnote ~= '' ) then&lt;br /&gt;
			footnote = footnote .. '&amp;lt;br/&amp;gt;'&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	footnote = footnote .. source&lt;br /&gt;
	&lt;br /&gt;
	-- setup the data header cols/rows&lt;br /&gt;
	local head = getheadrow(percentages, popname, yearname, percentname)&lt;br /&gt;
	&lt;br /&gt;
	-- count the total number of population rows&lt;br /&gt;
	local argcount = 0&lt;br /&gt;
	local rowcount = 0&lt;br /&gt;
	for k, v in pairs( args ) do&lt;br /&gt;
		if ( (type( k ) == 'number') and (not isempty(args[k])) ) then&lt;br /&gt;
			if( k &amp;gt;= 1 and math.floor(k) == k and k &amp;gt; argcount) then&lt;br /&gt;
				argcount = k&lt;br /&gt;
			end&lt;br /&gt;
			if( math.fmod(k - 1, 2) == 0 ) then&lt;br /&gt;
				rowcount = rowcount + 1&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- here is where we build all the data for the table&lt;br /&gt;
	-- loop over columns and rows within columns&lt;br /&gt;
	local pyear = ''&lt;br /&gt;
	local ppop = ''&lt;br /&gt;
	local offset = 1&lt;br /&gt;
	local current_year = tonumber(os.date(&amp;quot;%Y&amp;quot;, os.time()))&lt;br /&gt;
	for r = 1,rowcount do&lt;br /&gt;
		-- skip blank rows&lt;br /&gt;
		while(isempty(args[offset]) and offset &amp;lt;= argcount) do&lt;br /&gt;
			offset = offset + 2&lt;br /&gt;
		end&lt;br /&gt;
		-- generate the row if we have not exceeded the rowcount&lt;br /&gt;
		if(offset &amp;lt;= argcount) then&lt;br /&gt;
			table.insert(data, getpoprow(args[offset], args[offset + 1] or '', pyear, ppop, &lt;br /&gt;
				linktype, percentages, current_year) )&lt;br /&gt;
			pyear = args[offset]&lt;br /&gt;
			ppop = args[offset+1] or ''&lt;br /&gt;
			offset = offset + 2&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local graph = ''&lt;br /&gt;
	graphpos = graphpos:lower()&lt;br /&gt;
	-- now that we have the data for the table, render it in the requested format&lt;br /&gt;
&lt;br /&gt;
	if (direction == 'horizontal') then&lt;br /&gt;
		if graphpos ~= '' then&lt;br /&gt;
			local gwidth = tonumber(graphwidth) or 200&lt;br /&gt;
			local gheight= tonumber(graphheight) or 170&lt;br /&gt;
			local gthumb = &lt;br /&gt;
				(graphpos == 'r' or graphpos == 'right' and 'right') or&lt;br /&gt;
				(graphpos == 'l' or graphpos == 'left' and 'left') or ''&lt;br /&gt;
			graph = rendergraph(frame, data, gwidth, gheight, gthumb)&lt;br /&gt;
		end&lt;br /&gt;
		return renderhorizontal(data, head, title, footnote, alignfn, class, style, width, shading, perrow, rows, graphpos, graph)&lt;br /&gt;
	else&lt;br /&gt;
		if graphpos ~= '' then&lt;br /&gt;
			local gwidth = tonumber(graphwidth) or (170 * cols)&lt;br /&gt;
			local gheight= tonumber(graphheight) or 170&lt;br /&gt;
			local gthumb = &lt;br /&gt;
				(graphpos == 'r' or graphpos == 'right' and 'right') or&lt;br /&gt;
				(graphpos == 'l' or graphpos == 'left' and 'left') or ''&lt;br /&gt;
			graph = rendergraph(frame, data, gwidth, gheight, gthumb)&lt;br /&gt;
		end&lt;br /&gt;
		return rendervertical(data, head, title, footnote, alignfn, class, style, width, shading, percol, cols, graphpos, graph)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>FilipeFonseca</name></author>
	</entry>
</feed>