<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.projectbasis.world/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="https://wiki.projectbasis.world/index.php?action=history&amp;feed=atom&amp;title=Module%3AHistorical_populations"/>
	<link rel="alternate" type="text/html" href="https://wiki.projectbasis.world/index.php?title=Module:Historical_populations&amp;action=history"/>
	<updated>2026-07-21T15:57:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wiki.projectbasis.world/index.php?title=Module:Historical_populations&amp;diff=6465&amp;oldid=prev</id>
		<title>WillSysAd: Created page with &quot;-- -- This template implements {{Historical populations}} -- local p = {} local lang = mw.getContentLanguage() local Date -- lazy initialization  local function ifexist(page)     if not page then return false end     if mw.title.new(page).exists then return true end     return false end  local function isempty( s ) 	return not s or s:match( &#039;^%s*(.-)%s*$&#039; ) == &#039;&#039; end  local function splitnumandref( s ) 	s = s:match( &#039;^%s*(.-)%s*$&#039; ) 	local t1 = mw.text.unstrip(s)...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.projectbasis.world/index.php?title=Module:Historical_populations&amp;diff=6465&amp;oldid=prev"/>
		<updated>2026-07-20T06:54:55Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;-- -- This template implements {{Historical populations}} -- local p = {} local lang = mw.getContentLanguage() local Date -- lazy initialization  local function ifexist(page)     if not page then return false end     if mw.title.new(page).exists then return true end     return false end  local function isempty( s ) 	return not s or s:match( &amp;#039;^%s*(.-)%s*$&amp;#039; ) == &amp;#039;&amp;#039; end  local function splitnumandref( s ) 	s = s:match( &amp;#039;^%s*(.-)%s*$&amp;#039; ) 	local t1 = mw.text.unstrip(s)...&amp;quot;&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( &amp;#039;^%s*(.-)%s*$&amp;#039; ) == &amp;#039;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function splitnumandref( s )&lt;br /&gt;
	s = s:match( &amp;#039;^%s*(.-)%s*$&amp;#039; )&lt;br /&gt;
	local t1 = mw.text.unstrip(s)&lt;br /&gt;
        local t2 = s:match( &amp;#039;^([%d][%d,]*)&amp;#039; )&lt;br /&gt;
	if( t1 == t2 ) then&lt;br /&gt;
		local t3 = s:match( &amp;#039;^[%d][%d,]*(.-)$&amp;#039; )&lt;br /&gt;
		return t1, t3&lt;br /&gt;
	else&lt;br /&gt;
		return s, &amp;#039;&amp;#039;&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 &amp;#039;&amp;#039;)&lt;br /&gt;
	local ppop, ppopref = splitnumandref( ppopstr or &amp;#039;&amp;#039;)&lt;br /&gt;
	local percent = &amp;#039;&amp;#039;&lt;br /&gt;
	local yearnum = formatnumR(mw.ustring.gsub(year or &amp;#039;&amp;#039;, &amp;#039;^%s*([%d][%d][%.%d]+).*$&amp;#039;, &amp;#039;%1&amp;#039;) or &amp;#039;&amp;#039;)&lt;br /&gt;
	local pyearnum = formatnumR(mw.ustring.gsub(pyear or &amp;#039;&amp;#039;, &amp;#039;^%s*([%d][%d][%.%d]+).*$&amp;#039;, &amp;#039;%1&amp;#039;) or &amp;#039;&amp;#039;)&lt;br /&gt;
	local popnum = formatnumR(pop)&lt;br /&gt;
	local ppopnum = formatnumR(ppop)&lt;br /&gt;
	if( linktype == &amp;#039;US&amp;#039; or linktype == &amp;#039;USA&amp;#039; ) 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 = &amp;#039;[[&amp;#039; .. tostring(yearnum) .. &amp;#039; United States census|&amp;#039; .. year .. &amp;#039;]]&amp;#039;&lt;br /&gt;
  			elseif( ifexist(tostring(yearnum) .. &amp;#039; United States census&amp;#039;) ) then&lt;br /&gt;
				year = &amp;#039;[[&amp;#039; .. tostring(yearnum) .. &amp;#039; United States census|&amp;#039; .. year .. &amp;#039;]]&amp;#039;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if(percentages ~= &amp;#039;off&amp;#039;) then&lt;br /&gt;
		local pstr = &amp;#039;—&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;#039;&lt;br /&gt;
		if(popnum ~= nil and ppopnum ~= nil and (ppopnum &amp;gt; 0)) then&lt;br /&gt;
			if(percentages == &amp;#039;pagr&amp;#039;) then&lt;br /&gt;
				pstr = mw.ustring.format(&amp;#039;%.2f&amp;#039;, 100*math.abs(math.pow(popnum/ppopnum,1/(yearnum-pyearnum)) - 1))&lt;br /&gt;
			elseif(percentages == &amp;#039;monthly&amp;#039;) then&lt;br /&gt;
				if Date == nil then Date = require(&amp;#039;Module:Date&amp;#039;)._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(&amp;#039;%.2f&amp;#039;, 100*math.abs(math.pow(popnum/ppopnum,1/months) - 1))&lt;br /&gt;
			else&lt;br /&gt;
				pstr = mw.ustring.format(&amp;#039;%.1f&amp;#039;, 100*math.abs(popnum/ppopnum - 1))&lt;br /&gt;
			end&lt;br /&gt;
			if( popnum &amp;lt; ppopnum ) then&lt;br /&gt;
				pstr = &amp;#039;−&amp;#039; .. pstr .. &amp;#039;%&amp;#039;&lt;br /&gt;
			else&lt;br /&gt;
				pstr = &amp;#039;+&amp;#039; .. pstr .. &amp;#039;%&amp;#039;&lt;br /&gt;
			end&lt;br /&gt;
		elseif(popnum ~= nil and ppopnum ~= nil and (ppopnum == popnum)) then&lt;br /&gt;
			pstr = mw.ustring.format(&amp;#039;%.2f&amp;#039;, 0) .. &amp;#039;%&amp;#039;&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 &amp;#039;&amp;#039;, &amp;#039;^%s*([%d][%d][%d]+)%.[%d]*&amp;#039;, &amp;#039;%1&amp;#039;)&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 == &amp;#039;&amp;#039;) then&lt;br /&gt;
		yearname = &amp;#039;Year&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	-- population cell&lt;br /&gt;
	if(popname == &amp;#039;&amp;#039;) then&lt;br /&gt;
		popname = &amp;#039;&amp;lt;abbr title=&amp;quot;Population&amp;quot; class=&amp;quot;abbr-header&amp;quot;&amp;gt;Pop.&amp;lt;/abbr&amp;gt;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- percentages cell&lt;br /&gt;
	if( percentages ~= &amp;#039;off&amp;#039; and percentname == &amp;#039;&amp;#039;) then&lt;br /&gt;
		if( percentages == &amp;#039;pagr&amp;#039; ) then&lt;br /&gt;
			percentname = &amp;#039;&amp;lt;abbr title=&amp;quot;Per annum growth rate&amp;quot; class=&amp;quot;abbr-header&amp;quot;&amp;gt;±% p.a.&amp;lt;/abbr&amp;gt;&amp;#039;&lt;br /&gt;
		elseif( percentages == &amp;#039;monthly&amp;#039; ) then&lt;br /&gt;
			percentname = &amp;#039;&amp;lt;abbr title=&amp;quot;Per month growth rate&amp;quot; class=&amp;quot;abbr-header&amp;quot;&amp;gt;±% p.m.&amp;lt;/abbr&amp;gt;&amp;#039;&lt;br /&gt;
		else&lt;br /&gt;
			percentname = &amp;#039;&amp;lt;abbr title=&amp;quot;Percent change&amp;quot; class=&amp;quot;abbr-header&amp;quot;&amp;gt;±%&amp;lt;/abbr&amp;gt;&amp;#039;&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;
local function rendergraph(frame, data, gwidth, gheight, gthumb, gtype)&lt;br /&gt;
	-- find some data limits&lt;br /&gt;
	local minyear, maxyear, maxpop = 999999, 0, 0&lt;br /&gt;
	local years = {}&lt;br /&gt;
	local pops = {}&lt;br /&gt;
	for i = 1, #data do&lt;br /&gt;
		local year,pop = data[i][1], data[i][2]&lt;br /&gt;
		-- delink if necessary&lt;br /&gt;
		if year:match(&amp;#039;^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]&amp;#039;) then&lt;br /&gt;
			year = year:match(&amp;#039;^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
		year = year:match(&amp;#039;^%s*([%d][%d]*).-$&amp;#039;)&lt;br /&gt;
		year = formatnumR(year)&lt;br /&gt;
		pop = formatnumR(pop)&lt;br /&gt;
		if ( year and pop ) then&lt;br /&gt;
			table.insert(years, year)&lt;br /&gt;
			table.insert(pops, pop)&lt;br /&gt;
			minyear = (year &amp;lt; minyear) and year or minyear&lt;br /&gt;
			maxyear = (year &amp;gt; maxyear) and year or maxyear&lt;br /&gt;
			maxpop = (pop &amp;gt; maxpop) and pop or maxpop&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local logbound = 10^(math.floor(math.log(maxpop)/math.log(10)+1))&lt;br /&gt;
	local scalemajor = logbound/10&lt;br /&gt;
	local scaleminor = scalemajor/2&lt;br /&gt;
	maxpop = scaleminor*(math.floor(maxpop/scaleminor + 1))&lt;br /&gt;
&lt;br /&gt;
	local timeline = {&lt;br /&gt;
		&amp;#039;Colors=&amp;#039;,&lt;br /&gt;
		&amp;#039;  id:lightgrey value:gray(0.9)&amp;#039;,&lt;br /&gt;
		&amp;#039;  id:darkgrey value:gray(0.3)&amp;#039;,&lt;br /&gt;
		&amp;#039;  id:sfondo value:rgb(1,1,1)&amp;#039;,&lt;br /&gt;
		&amp;#039;  id:barra value:rgb(0.664, 0.664, 0.930)&amp;#039;, -- dark lavender&lt;br /&gt;
		&amp;#039;&amp;#039;,&lt;br /&gt;
		&amp;#039;ImageSize = width:&amp;#039; .. tostring(gwidth) .. &amp;#039; height:&amp;#039; .. tostring(gheight),&lt;br /&gt;
		&amp;#039;PlotArea = left:44 bottom:27 top:20 right:10&amp;#039;,&lt;br /&gt;
		&amp;#039;DateFormat = x.y&amp;#039;,&lt;br /&gt;
		&amp;#039;Period = from:0 till:&amp;#039; .. tostring(maxpop),&lt;br /&gt;
		&amp;#039;TimeAxis = orientation:vertical&amp;#039;,&lt;br /&gt;
		&amp;#039;AlignBars = justify&amp;#039;,&lt;br /&gt;
		&amp;#039;ScaleMajor = gridcolor:darkgrey increment:&amp;#039; .. tostring(scalemajor) .. &amp;#039; start:0&amp;#039;,&lt;br /&gt;
		&amp;#039;ScaleMinor = gridcolor:lightgrey increment:&amp;#039; .. tostring(scaleminor) .. &amp;#039; start:0&amp;#039;,&lt;br /&gt;
		&amp;#039;BackgroundColors = canvas:sfondo&amp;#039;,&lt;br /&gt;
		&amp;#039;TextData =&amp;#039;,&lt;br /&gt;
		&amp;#039;  pos:(&amp;#039; .. tostring(math.floor(gwidth/2)) .. &amp;#039;,20) textcolor:black fontsize:M&amp;#039;,&lt;br /&gt;
		&amp;#039;  text:&amp;quot;year&amp;quot;&amp;#039;,&lt;br /&gt;
		&amp;#039;  pos:(&amp;#039; .. tostring(math.floor(gwidth/2)-15) .. &amp;#039;,&amp;#039; .. tostring(gheight+2) .. &amp;#039;) textcolor:black fontsize:M&amp;#039;,&lt;br /&gt;
		&amp;#039;  text:&amp;quot;population&amp;quot;&amp;#039;,&lt;br /&gt;
		&amp;#039;BarData=&amp;#039;&lt;br /&gt;
		}&lt;br /&gt;
	local yearlabels = math.max(math.floor(gwidth/60), 1)&lt;br /&gt;
	local yearscale = math.max(math.floor((maxyear - minyear)/yearlabels),1)&lt;br /&gt;
	yearscale = 5*math.max(math.floor(yearscale / 5), 1)&lt;br /&gt;
	local barwidth = math.min(math.max(math.floor(gwidth/((maxyear - minyear)*0.5)), 2),5)&lt;br /&gt;
	&lt;br /&gt;
	minyear = yearscale*math.floor(minyear/yearscale)&lt;br /&gt;
	maxyear = yearscale*math.ceil(maxyear/yearscale)&lt;br /&gt;
	&lt;br /&gt;
	for year = minyear,maxyear do&lt;br /&gt;
		local text = ( (year % yearscale) == 0) and &amp;#039; text:&amp;#039; .. year or &amp;#039;&amp;#039;&lt;br /&gt;
		table.insert(timeline, &amp;#039;  bar:&amp;#039; .. year .. text)&lt;br /&gt;
	end&lt;br /&gt;
	table.insert(timeline,&amp;#039;\nPlotData=\n  color:barra width:&amp;#039; .. barwidth .. &amp;#039; align:left\n&amp;#039;)&lt;br /&gt;
	for i = 1, #years do&lt;br /&gt;
		local year = years[i]&lt;br /&gt;
		local pop = pops[i]&lt;br /&gt;
		table.insert(timeline, &amp;#039;  bar:&amp;#039; .. year .. &amp;#039; from: 0 till:&amp;#039; .. pop)&lt;br /&gt;
	end&lt;br /&gt;
	local timeline = frame:extensionTag{ name = &amp;#039;timeline&amp;#039;, content = &amp;#039;\n&amp;#039; .. table.concat(timeline,&amp;#039;\n&amp;#039;) .. &amp;#039;\n&amp;#039; }&lt;br /&gt;
&lt;br /&gt;
	local graph = mw.html.create(&amp;#039;div&amp;#039;)&lt;br /&gt;
	if ( gthumb == &amp;#039;&amp;#039; ) then&lt;br /&gt;
		graph&lt;br /&gt;
			:addClass(&amp;#039;center&amp;#039;)&lt;br /&gt;
			:wikitext(timeline)&lt;br /&gt;
	else&lt;br /&gt;
		graph:addClass(&amp;#039;thumb&amp;#039;)&lt;br /&gt;
		if ( gthumb == &amp;#039;left&amp;#039; ) then&lt;br /&gt;
			graph:addClass(&amp;#039;floatleft&amp;#039;)&lt;br /&gt;
		elseif( gthumb == &amp;#039;right&amp;#039; ) then&lt;br /&gt;
			graph:addClass(&amp;#039;floatright&amp;#039;)&lt;br /&gt;
		else&lt;br /&gt;
			graph:addClass(&amp;#039;tnone&amp;#039;)&lt;br /&gt;
				:css(&amp;#039;margin-left&amp;#039;, &amp;#039;auto&amp;#039;)&lt;br /&gt;
				:css(&amp;#039;margin-right&amp;#039;, &amp;#039;auto&amp;#039;)&lt;br /&gt;
				:css(&amp;#039;clear&amp;#039;, &amp;#039;both&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
		graph:tag(&amp;#039;div&amp;#039;)&lt;br /&gt;
			:addClass(&amp;#039;thumbinner&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;width&amp;#039;, tostring(gwidth + 2) .. &amp;#039;px&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;max-width&amp;#039;, tostring(gwidth + 2) .. &amp;#039;px&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;height&amp;#039;, tostring(gheight + 2) .. &amp;#039;px&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;max-height&amp;#039;, tostring(gheight + 2) .. &amp;#039;px&amp;#039;)&lt;br /&gt;
			:wikitext(timeline)&lt;br /&gt;
	end&lt;br /&gt;
	return tostring(graph)&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(&amp;#039;text-align&amp;#039;, align)&lt;br /&gt;
			:css(&amp;#039;padding&amp;#039;, &amp;#039;1px&amp;#039;)&lt;br /&gt;
			:wikitext(text)&lt;br /&gt;
			:css(&amp;#039;border-bottom&amp;#039;, shading ~= &amp;#039;off&amp;#039; and &amp;#039;1px solid #bbbbbb&amp;#039; 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(&amp;#039;th&amp;#039;)&lt;br /&gt;
		cell&lt;br /&gt;
			:css(&amp;#039;border-bottom&amp;#039;, &amp;#039;1px solid var(--color-base, #000000)&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;padding&amp;#039;, pad and (&amp;#039;1px &amp;#039; .. pad) or &amp;#039;1px&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;text-align&amp;#039;, align)&lt;br /&gt;
			:css(&amp;#039;width&amp;#039;, 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 = &amp;#039;15em&amp;#039;&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] == &amp;#039;&amp;#039;) 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(&amp;#039;^%s*[%d]+[%w]+%s*$&amp;#039;) ) then&lt;br /&gt;
		local widthnum = mw.ustring.gsub( width, &amp;#039;^%s*([%d]+)([%w]+)%s*$&amp;#039;, &amp;#039;%1&amp;#039; )&lt;br /&gt;
		local widthunit = mw.ustring.gsub( width, &amp;#039;^%s*([%d]+)([%w]+)%s*$&amp;#039;, &amp;#039;%2&amp;#039; )&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(&amp;#039;table&amp;#039;)&lt;br /&gt;
	root&lt;br /&gt;
		:addClass(class)&lt;br /&gt;
		:css(&amp;#039;width&amp;#039;, twidth)&lt;br /&gt;
		:css(&amp;#039;border-top-width&amp;#039;, &amp;#039;0&amp;#039;)&lt;br /&gt;
		:cssText(style[&amp;#039;table&amp;#039;])&lt;br /&gt;
	-- add title&lt;br /&gt;
	if( cols &amp;lt;= 1) then&lt;br /&gt;
	local caption = root:tag(&amp;#039;caption&amp;#039;)&lt;br /&gt;
	caption&lt;br /&gt;
		:css(&amp;#039;padding&amp;#039;, &amp;#039;0.25em&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;font-weight&amp;#039;, &amp;#039;bold&amp;#039;)&lt;br /&gt;
		:attr(&amp;#039;class&amp;#039;, &amp;#039;caption-purple&amp;#039;)&lt;br /&gt;
		:wikitext(title)&lt;br /&gt;
	end&lt;br /&gt;
	if( cols &amp;gt; 1) then&lt;br /&gt;
	local caption = root:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
	caption&lt;br /&gt;
		:css(&amp;#039;padding&amp;#039;, &amp;#039;0.25em&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;font-weight&amp;#039;, &amp;#039;bold&amp;#039;)&lt;br /&gt;
		:attr(&amp;#039;colspan&amp;#039;, cols)&lt;br /&gt;
	divcaption = caption:tag(&amp;#039;div&amp;#039;)&lt;br /&gt;
	divcaption&lt;br /&gt;
		:css(&amp;#039;margin&amp;#039;, &amp;#039;-0.65em -0.565em 0 -0.565em&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;border-left&amp;#039;, &amp;#039;0&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;border-right&amp;#039;, &amp;#039;0&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;text-align&amp;#039;, &amp;#039;center&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;padding&amp;#039;, &amp;#039;0.3em 0&amp;#039;)&lt;br /&gt;
		:attr(&amp;#039;class&amp;#039;, &amp;#039;caption-purple&amp;#039;)&lt;br /&gt;
		:wikitext(title)&lt;br /&gt;
	root:attr(&amp;#039;role&amp;#039;, &amp;#039;presentation&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	-- add the graph line (if top graph)&lt;br /&gt;
	if((graphpos == &amp;#039;top&amp;#039; or graphpos == &amp;#039;t&amp;#039;) and graph ~= &amp;#039;&amp;#039;) then&lt;br /&gt;
		row = root:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
		cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
		cell&lt;br /&gt;
			:attr(&amp;#039;colspan&amp;#039;, colspan)&lt;br /&gt;
			:css(&amp;#039;border-bottom&amp;#039;, &amp;#039;1px solid var(--color-base, #000000)&amp;#039;)&lt;br /&gt;
			:wikitext(graph)&lt;br /&gt;
		graph = &amp;#039;&amp;#039;&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(&amp;#039;tr&amp;#039;)&lt;br /&gt;
				row:css(&amp;#039;vertical-align&amp;#039;, &amp;#039;top&amp;#039;)&lt;br /&gt;
				cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
				cell&lt;br /&gt;
					:css(&amp;#039;padding&amp;#039;, &amp;#039;0 0.5em&amp;#039;)&lt;br /&gt;
			else&lt;br /&gt;
				cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
				cell&lt;br /&gt;
					:css(&amp;#039;padding&amp;#039;, &amp;#039;0 0.5em&amp;#039;)&lt;br /&gt;
					:css(&amp;#039;border-left&amp;#039;, &amp;#039;solid 1px #aaa&amp;#039;)&lt;br /&gt;
			end&lt;br /&gt;
			t = cell:tag(&amp;#039;table&amp;#039;)&lt;br /&gt;
			t&lt;br /&gt;
				:css(&amp;#039;border-spacing&amp;#039;, &amp;#039;0&amp;#039;)&lt;br /&gt;
				:css(&amp;#039;width&amp;#039;, width)&lt;br /&gt;
		end&lt;br /&gt;
		-- start column headers&lt;br /&gt;
		local hrow = t:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
		hrow:css(&amp;#039;font-size&amp;#039;, &amp;#039;95%&amp;#039;)&lt;br /&gt;
		-- year header&lt;br /&gt;
		addheadcell(hrow, head[1], nil, head[3] ~= &amp;#039;&amp;#039; and &amp;#039;3em&amp;#039; or &amp;#039;auto&amp;#039;, nil, nil)&lt;br /&gt;
		-- population header&lt;br /&gt;
		addheadcell(hrow, head[2], &amp;#039;right&amp;#039;, nil, &amp;#039;2px&amp;#039;)&lt;br /&gt;
		-- percentages header&lt;br /&gt;
		if( head[3] ~= &amp;#039;&amp;#039; ) then&lt;br /&gt;
			addheadcell(hrow, head[3], &amp;#039;right&amp;#039;, 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 = &amp;#039;off&amp;#039;&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(&amp;#039;tr&amp;#039;)&lt;br /&gt;
				-- year cell&lt;br /&gt;
				addrowcell(prow, &amp;#039;th&amp;#039;, data[offset][1], &amp;#039;center&amp;#039;, s, style[&amp;#039;year&amp;#039;])&lt;br /&gt;
				-- population cell&lt;br /&gt;
				addrowcell(prow, &amp;#039;td&amp;#039;, data[offset][2], &amp;#039;right&amp;#039;, s, style[&amp;#039;pop&amp;#039;])&lt;br /&gt;
				-- percentage cell&lt;br /&gt;
				if( not isempty(head[3]) ) then&lt;br /&gt;
					addrowcell(prow, &amp;#039;td&amp;#039;, data[offset][3], &amp;#039;right&amp;#039;, s, style[&amp;#039;pct&amp;#039;])&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 == &amp;#039;bottom&amp;#039; or graphpos == &amp;#039;b&amp;#039;) and graph ~= &amp;#039;&amp;#039;) then&lt;br /&gt;
		row = root:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
		cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
		cell&lt;br /&gt;
			:attr(&amp;#039;colspan&amp;#039;, colspan)&lt;br /&gt;
			:css(&amp;#039;border-top&amp;#039;, &amp;#039;1px solid var(--color-base, #000000)&amp;#039;)&lt;br /&gt;
			:wikitext(graph)&lt;br /&gt;
		graph = &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	-- add the footnote line 	&lt;br /&gt;
	if( footnote ~= &amp;#039;&amp;#039;) then&lt;br /&gt;
		row = root:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
		cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
		cell&lt;br /&gt;
			:attr(&amp;#039;colspan&amp;#039;, colspan)&lt;br /&gt;
			:css(&amp;#039;border-top&amp;#039;, &amp;#039;1px solid var(--color-base, #000000)&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;font-size&amp;#039;, &amp;#039;85%&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;text-align&amp;#039;, alignfn)&lt;br /&gt;
			:wikitext(footnote)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if((graphpos == &amp;#039;right&amp;#039; or graphpos == &amp;#039;r&amp;#039;) and graph ~= &amp;#039;&amp;#039;) then&lt;br /&gt;
		root = mw.html.create(&amp;#039;table&amp;#039;)&lt;br /&gt;
			:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
				:css(&amp;#039;vertical-align&amp;#039;, &amp;#039;top&amp;#039;)&lt;br /&gt;
				:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
					:wikitext(tostring(root))&lt;br /&gt;
					:done()&lt;br /&gt;
				:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
					:wikitext(graph)&lt;br /&gt;
					:done()&lt;br /&gt;
			:done()&lt;br /&gt;
		:done()&lt;br /&gt;
		graph = &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if((graphpos == &amp;#039;left&amp;#039; or graphpos == &amp;#039;l&amp;#039;) and graph ~= &amp;#039;&amp;#039;) then&lt;br /&gt;
		root = mw.html.create(&amp;#039;table&amp;#039;)&lt;br /&gt;
			:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
				:css(&amp;#039;vertical-align&amp;#039;, &amp;#039;top&amp;#039;)&lt;br /&gt;
				:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
					:wikitext(graph)&lt;br /&gt;
					:done()&lt;br /&gt;
				:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
					:wikitext(tostring(root))&lt;br /&gt;
					:done()&lt;br /&gt;
			:done()&lt;br /&gt;
		:done()&lt;br /&gt;
		graph = &amp;#039;&amp;#039;&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(&amp;#039;table&amp;#039;)&lt;br /&gt;
	root&lt;br /&gt;
		:addClass(class)&lt;br /&gt;
		:css(&amp;#039;font-size&amp;#039;, &amp;#039;90%&amp;#039;)&lt;br /&gt;
		:cssText(style[&amp;#039;table&amp;#039;])&lt;br /&gt;
	-- create title row&lt;br /&gt;
	row = root:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
	cell = row:tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
	cell&lt;br /&gt;
		:css(&amp;#039;padding&amp;#039;, &amp;#039;0.25em&amp;#039;)&lt;br /&gt;
		:attr(&amp;#039;colspan&amp;#039;, 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 == &amp;#039;top&amp;#039; or graphpos == &amp;#039;t&amp;#039;) and graph ~= &amp;#039;&amp;#039;) then&lt;br /&gt;
		row = root:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
		cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
		cell&lt;br /&gt;
			:attr(&amp;#039;colspan&amp;#039;, colsperrow + 1)&lt;br /&gt;
			:css(&amp;#039;border-bottom&amp;#039;, &amp;#039;1px solid var(--color-base, #000000)&amp;#039;)&lt;br /&gt;
			:wikitext(graph)&lt;br /&gt;
		graph = &amp;#039;&amp;#039;&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(&amp;#039;tr&amp;#039;)&lt;br /&gt;
		cell = row:tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
		cell:wikitext(head[1])&lt;br /&gt;
			:css(&amp;#039;border-top&amp;#039;, r &amp;gt; 1 and &amp;#039;2px solid #000&amp;#039; or nil)&lt;br /&gt;
		for c = 1,colsperrow do&lt;br /&gt;
			cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
			if(offset &amp;lt;= yearcount) then&lt;br /&gt;
				cell:wikitext(data[offset][1])&lt;br /&gt;
					:css(&amp;#039;text-align&amp;#039;, &amp;#039;center&amp;#039;)&lt;br /&gt;
					:css(&amp;#039;border-top&amp;#039;, r &amp;gt; 1 and &amp;#039;2px solid #000&amp;#039; or nil)&lt;br /&gt;
					:cssText(style[&amp;#039;year&amp;#039;])&lt;br /&gt;
			else&lt;br /&gt;
				cell:css(&amp;#039;border-width&amp;#039;, r &amp;gt; 1 and &amp;#039;2px 0 0 0&amp;#039; or 0)&lt;br /&gt;
					:css(&amp;#039;border-top&amp;#039;, r &amp;gt; 1 and &amp;#039;2px solid #000&amp;#039; 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(&amp;#039;tr&amp;#039;)&lt;br /&gt;
		cell = row:tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
		cell:wikitext(head[2])&lt;br /&gt;
		for c = 1,colsperrow do&lt;br /&gt;
			cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
			if(offset &amp;lt;= yearcount) then&lt;br /&gt;
				cell:wikitext(data[offset][2])&lt;br /&gt;
					:css(&amp;#039;text-align&amp;#039;, &amp;#039;right&amp;#039;)&lt;br /&gt;
					:css(&amp;#039;padding-right&amp;#039;, &amp;#039;2px&amp;#039;)&lt;br /&gt;
					:cssText(style[&amp;#039;pop&amp;#039;])&lt;br /&gt;
			else&lt;br /&gt;
				cell:css(&amp;#039;border-width&amp;#039;, 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] ~= &amp;#039;&amp;#039;) then&lt;br /&gt;
			offset = rowoffset&lt;br /&gt;
			row = root:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
			cell = row:tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
			cell:wikitext(head[3])&lt;br /&gt;
			for c = 1,colsperrow do&lt;br /&gt;
				cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
				if(offset &amp;lt;= yearcount) then&lt;br /&gt;
					cell:wikitext(data[offset][3])&lt;br /&gt;
						:css(&amp;#039;text-align&amp;#039;, &amp;#039;right&amp;#039;)&lt;br /&gt;
						:css(&amp;#039;padding-right&amp;#039;, &amp;#039;2px&amp;#039;)&lt;br /&gt;
						:cssText(style[&amp;#039;pct&amp;#039;])&lt;br /&gt;
				else&lt;br /&gt;
					cell:css(&amp;#039;border-width&amp;#039;, 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 == &amp;#039;bottom&amp;#039; or graphpos == &amp;#039;b&amp;#039;) and graph ~= &amp;#039;&amp;#039;) then&lt;br /&gt;
		row = root:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
		cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
		cell&lt;br /&gt;
			:attr(&amp;#039;colspan&amp;#039;, colsperrow + 1)&lt;br /&gt;
			:css(&amp;#039;border-top&amp;#039;, &amp;#039;1px solid var(--color-base, #000000)&amp;#039;)&lt;br /&gt;
			:wikitext(graph)&lt;br /&gt;
		graph = &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- add the footnote line 	&lt;br /&gt;
	if( footnote ~= &amp;#039;&amp;#039;) then&lt;br /&gt;
		row = root:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
		cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
		cell&lt;br /&gt;
			:css(&amp;#039;border-top&amp;#039;, &amp;#039;2px solid var(--color-base, #000000)&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;font-size&amp;#039;, &amp;#039;85%&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;text-align&amp;#039;, alignfn)&lt;br /&gt;
			:attr(&amp;#039;colspan&amp;#039;, 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 raw_data = {}&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[&amp;#039;title&amp;#039;]			or &amp;#039;&amp;#039;&lt;br /&gt;
	local align			= args[&amp;#039;align&amp;#039;]			or &amp;#039;&amp;#039;&lt;br /&gt;
	local clear			= args[&amp;#039;clear&amp;#039;]			or &amp;#039;&amp;#039;&lt;br /&gt;
	local direction		= args[&amp;#039;direction&amp;#039;]		or &amp;#039;&amp;#039;&lt;br /&gt;
	local percentages	= args[&amp;#039;percentages&amp;#039;]	or &amp;#039;&amp;#039;&lt;br /&gt;
	local state			= args[&amp;#039;state&amp;#039;]			or &amp;#039;&amp;#039;&lt;br /&gt;
	local linktype		= args[&amp;#039;type&amp;#039;]			or &amp;#039;&amp;#039;&lt;br /&gt;
	local shading		= args[&amp;#039;shading&amp;#039;]		or &amp;#039;on&amp;#039;&lt;br /&gt;
	local width			= args[&amp;#039;width&amp;#039;]			or &amp;#039;&amp;#039;&lt;br /&gt;
	local subbox		= args[&amp;#039;subbox&amp;#039;]		or &amp;#039;&amp;#039;&lt;br /&gt;
	local popname		= args[&amp;#039;pop_name&amp;#039;]		or &amp;#039;&amp;#039;&lt;br /&gt;
	local yearname		= args[&amp;#039;year_name&amp;#039;]		or &amp;#039;&amp;#039;&lt;br /&gt;
	local percentname   = args[&amp;#039;percent_name&amp;#039;]  or &amp;#039;&amp;#039;&lt;br /&gt;
	local footnote		= args[&amp;#039;footnote&amp;#039;]		or &amp;#039;&amp;#039;&lt;br /&gt;
	local alignfn		= args[&amp;#039;align-fn&amp;#039;]		or &amp;#039;&amp;#039;&lt;br /&gt;
	local source		= args[&amp;#039;source&amp;#039;]		or &amp;#039;&amp;#039;&lt;br /&gt;
	local graphpos      = args[&amp;#039;graph-pos&amp;#039;]     or &amp;#039;&amp;#039;&lt;br /&gt;
	local graphwidth    = args[&amp;#039;graph-width&amp;#039;]   or &amp;#039;&amp;#039;&lt;br /&gt;
	local graphheight   = args[&amp;#039;graph-height&amp;#039;]  or &amp;#039;&amp;#039;&lt;br /&gt;
	local graphtype     = args[&amp;#039;graph-type&amp;#039;]    or &amp;#039;line&amp;#039;&lt;br /&gt;
	local datapage      = args[&amp;#039;data&amp;#039;]          or &amp;#039;&amp;#039;&lt;br /&gt;
	local percol = tonumber(args[&amp;#039;percol&amp;#039;])	or 0&lt;br /&gt;
	local cols	 = tonumber(args[&amp;#039;cols&amp;#039;])	or 1&lt;br /&gt;
	local perrow = tonumber(args[&amp;#039;perrow&amp;#039;])	or 0&lt;br /&gt;
	local rows	 = tonumber(args[&amp;#039;rows&amp;#039;])	or 1&lt;br /&gt;
	style[&amp;#039;year&amp;#039;] = args[&amp;#039;year_style&amp;#039;]&lt;br /&gt;
	style[&amp;#039;pop&amp;#039;]  = args[&amp;#039;pop_style&amp;#039;]&lt;br /&gt;
	style[&amp;#039;pct&amp;#039;]  = args[&amp;#039;pct_style&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
	-- setup classes and styling for outer table&lt;br /&gt;
	local class = direction == &amp;#039;horizontal&amp;#039; and &amp;#039;wikitable&amp;#039; or &amp;#039;table-pale&amp;#039;&lt;br /&gt;
	if( state == &amp;#039;collapsed&amp;#039; ) then&lt;br /&gt;
		class = class .. &amp;#039; collapsible collapsed&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if( isempty(title) ) then&lt;br /&gt;
		title = &amp;#039;Historical population&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if( isempty(align) ) then&lt;br /&gt;
		align = direction ~= &amp;#039;horizontal&amp;#039; and &amp;#039;right&amp;#039; or &amp;#039;center&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if( isempty(alignfn) ) then&lt;br /&gt;
		alignfn = &amp;#039;left&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if( isempty(clear) ) then&lt;br /&gt;
		clear = align == &amp;#039;center&amp;#039; and &amp;#039;&amp;#039; or align&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local margin = &amp;#039;0.5em 0 1em 0.5em&amp;#039;&lt;br /&gt;
	if( align == &amp;#039;left&amp;#039; ) then&lt;br /&gt;
		margin = &amp;#039;0.5em 1em 0.5em 0&amp;#039;&lt;br /&gt;
	elseif( align == &amp;#039;none&amp;#039; ) then&lt;br /&gt;
		margin = &amp;#039;0.5em 1em 0.5em 0&amp;#039;&lt;br /&gt;
	elseif( align == &amp;#039;center&amp;#039; ) then&lt;br /&gt;
		margin = &amp;#039;0.5em auto&amp;#039;&lt;br /&gt;
		align = &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if( isempty(subbox) ) then&lt;br /&gt;
		style[&amp;#039;table&amp;#039;] =&lt;br /&gt;
			&amp;#039;border-spacing: 0;&amp;#039; ..&lt;br /&gt;
			(align ~= &amp;#039;&amp;#039; and &amp;#039;float:&amp;#039; .. align .. &amp;#039;;&amp;#039; or &amp;#039;&amp;#039;) ..&lt;br /&gt;
			(clear ~= &amp;#039;&amp;#039; and &amp;#039;clear:&amp;#039; .. clear .. &amp;#039;;&amp;#039; or &amp;#039;&amp;#039;) ..&lt;br /&gt;
			&amp;#039;margin:&amp;#039; .. margin .. &amp;#039;;&amp;#039;&lt;br /&gt;
	else&lt;br /&gt;
		style[&amp;#039;table&amp;#039;] =&lt;br /&gt;
			&amp;#039;margin:0;&amp;#039; ..&lt;br /&gt;
			&amp;#039;border-collapse:collapse;&amp;#039; ..&lt;br /&gt;
			&amp;#039;border:none;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	style[&amp;#039;table&amp;#039;] = style[&amp;#039;table&amp;#039;] .. (args[&amp;#039;table_style&amp;#039;] or &amp;#039;&amp;#039;)&lt;br /&gt;
		&lt;br /&gt;
	-- setup the footer text&lt;br /&gt;
	if( source ~= &amp;#039;&amp;#039; ) then&lt;br /&gt;
		source = &amp;#039;Source: &amp;#039; .. source&lt;br /&gt;
		if( footnote ~= &amp;#039;&amp;#039; ) then&lt;br /&gt;
			footnote = footnote .. &amp;#039;&amp;lt;br/&amp;gt;&amp;#039;&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;
	-- counts for the total number of population rows&lt;br /&gt;
	local argcount = 0&lt;br /&gt;
	local rowcount = 0&lt;br /&gt;
	&lt;br /&gt;
	if ( not isempty(datapage) ) then&lt;br /&gt;
		-- load external data page from commons if it is specified&lt;br /&gt;
		local external_data = mw.ext.data.get(datapage).data&lt;br /&gt;
		for _, v in ipairs(external_data) do&lt;br /&gt;
			table.insert(raw_data, tostring(v[1])) -- year&lt;br /&gt;
			table.insert(raw_data, tostring(v[2])) -- population&lt;br /&gt;
			rowcount = rowcount + 1&lt;br /&gt;
			argcount = argcount + 2&lt;br /&gt;
		end&lt;br /&gt;
		if ( footnote ~= &amp;#039;&amp;#039; ) then&lt;br /&gt;
			footnote = footnote .. &amp;#039;&amp;lt;br /&amp;gt;&amp;#039;&lt;br /&gt;
		end&lt;br /&gt;
		footnote = footnote .. &amp;#039;[[:commons:Data:&amp;#039; .. datapage .. &amp;#039;|Source data]]&amp;#039;&lt;br /&gt;
	else&lt;br /&gt;
		-- load data from the args instead&lt;br /&gt;
		for k, v in pairs( args ) do&lt;br /&gt;
			if ( type( k ) == &amp;#039;number&amp;#039; and k &amp;gt;= 1 and math.floor(k) == k ) then&lt;br /&gt;
				raw_data[k] = v&lt;br /&gt;
				if ( not isempty(args[k]) ) then&lt;br /&gt;
					argcount = (k &amp;gt; argcount) and k or argcount&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;
		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 = &amp;#039;&amp;#039;&lt;br /&gt;
	local ppop = &amp;#039;&amp;#039;&lt;br /&gt;
	local offset = 1&lt;br /&gt;
	local current_year = tonumber(os.date(&amp;quot;%Y&amp;quot;))&lt;br /&gt;
	for r = 1,rowcount do&lt;br /&gt;
		-- skip blank rows&lt;br /&gt;
		while(isempty(raw_data[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(raw_data[offset], raw_data[offset + 1] or &amp;#039;&amp;#039;, pyear, ppop, &lt;br /&gt;
				linktype, percentages, current_year) )&lt;br /&gt;
			pyear = raw_data[offset]&lt;br /&gt;
			ppop = raw_data[offset+1] or &amp;#039;&amp;#039;&lt;br /&gt;
			offset = offset + 2&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local graph = &amp;#039;&amp;#039;&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 == &amp;#039;horizontal&amp;#039;) then&lt;br /&gt;
		if graphpos ~= &amp;#039;&amp;#039; then&lt;br /&gt;
			local gwidth = tonumber(graphwidth) or math.floor(math.max(math.min(220, rowcount*5), 800))&lt;br /&gt;
			local gheight= tonumber(graphheight) or 180&lt;br /&gt;
			local gthumb = &lt;br /&gt;
				(graphpos == &amp;#039;r&amp;#039; or graphpos == &amp;#039;right&amp;#039; and &amp;#039;right&amp;#039;) or&lt;br /&gt;
				(graphpos == &amp;#039;l&amp;#039; or graphpos == &amp;#039;left&amp;#039; and &amp;#039;left&amp;#039;) or &amp;#039;&amp;#039;&lt;br /&gt;
			graph = rendergraph(frame, data, gwidth, gheight, gthumb, graphtype)&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 ~= &amp;#039;&amp;#039; then&lt;br /&gt;
			local gwidth = tonumber(graphwidth) or (200 * cols)&lt;br /&gt;
			local gheight= tonumber(graphheight) or 180&lt;br /&gt;
			local gthumb = &lt;br /&gt;
				(graphpos == &amp;#039;r&amp;#039; or graphpos == &amp;#039;right&amp;#039; and &amp;#039;right&amp;#039;) or&lt;br /&gt;
				(graphpos == &amp;#039;l&amp;#039; or graphpos == &amp;#039;left&amp;#039; and &amp;#039;left&amp;#039;) or &amp;#039;&amp;#039;&lt;br /&gt;
			graph = rendergraph(frame, data, gwidth, gheight, gthumb, graphtype)&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>WillSysAd</name></author>
	</entry>
</feed>