مۆدیوول:Historical populations: جیاوازیی نێوان پێداچوونەوەکان

ناوەڕۆکی سڕاو ناوەڕۆکی زیادکراو
کوردیکردن (ماویەتی)
No edit summary
تاگ: گەڕێندراوە
ھێڵی ٤٨:
if( (yearnum or 0) >= 1790 and yearnum <= current_year and math.fmod(math.floor(yearnum), 10) == 0) then
if( yearnum < current_year ) then
year = '[[' .. tostring(yearnum) .. ' United States Censuscensus|' .. year .. ']]'
elseif( ifexist(tostring(yearnum) .. ' United States Censuscensus') ) then
year = '[[' .. tostring(yearnum) .. ' United States Censuscensus|' .. year .. ']]'
end
end
ھێڵی ٨٩:
-- year cell
if(yearname == '') then
yearname = 'ساڵYear'
end
-- population cell
if(popname == '') then
popname = '<abbr title="دانیشتوانPopulation">دانPop.</abbr>'
end
 
ھێڵی ١٠٧:
end
return {yearname, popname, percentname}
end
 
-- this function builds the json for the population graph
local function graphjson(data, gwidth, gheight, gtype)
local yearcount = #data
local graphargs = {
['width'] = gwidth,
['height'] = gheight,
['type'] = gtype or 'line',
['yAxisTitle'] = 'Population',
['yAxisMin'] = 0,
['xAxisTitle'] = 'Year',
['xAxisAngle'] = '-45',
['yGrid'] = 'y',
['yAxisFormat'] = ',d',
['x'] = '',
['y'] = ''
}
local firstpoint = true
for offset = 1,yearcount do
local x,y = data[offset][1], data[offset][2]
-- delink if necessary
if x:match('^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]') then
x = x:match('^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]')
end
y = formatnumR(y)
if x and y then
graphargs['x'] = graphargs['x'] .. (firstpoint and '' or ', ') .. x
graphargs['y'] = graphargs['y'] .. (firstpoint and '' or ', ') .. y
firstpoint = false
end
end
local Graph = require('Module:Graph')
return Graph.chart({args = graphargs})
end
 
local function rendergraph(frame, data, gwidth, gheight, gthumb, gtype)
local graph = frame:extensionTag{name = 'graph', content = graphjson(data, gwidth, gheight, gtype)}
 
if(gthumb ~= '') then
local graphdiv = mw.html.create('div')
:addClass('thumb')
:addClass(gthumb == 'right' and 'tright' or 'tleft')
:css('clear', 'none')
graphdiv
:tag('div')
:addClass('thumbinner')
:wikitext(graph)
return tostring(graphdiv)
end
return '<div class="center">' .. graph .. '</div>'
end
 
-- this function renders the population table in a vertical format
local function rendervertical(data, head, title, footnote, alignfn, class, style, width, shading, percol, cols, graphpos, graph)
-- define a couple helper functions
local function addrowcell(trow, tag, text, align, shading, style)
Line ١٧١ ⟶ ٢٢٤:
:addClass(class)
:css('width', twidth)
:css('border-top-width', '0')
:cssText(style['table'])
-- add title
local rowcaption = root:tag('trcaption')
caption
local cell = row:tag('th')
:css('border-top', '1px #aaa solid')
cell
:css('border-left', '1px #aaa solid')
:addClass('navbox-title')
:attrcss('colspanborder-right', colspan'1px #aaa solid')
:css('background-color', 'lavender')
:css('padding', '0.25em')
:css('font-weight', 'bold')
:wikitext(title)
-- add the graph line (if top graph)
if((graphpos == 'top' or graphpos == 't') and graph ~= '') then
row = root:tag('tr')
cell = row:tag('td')
cell
:attr('colspan', colspan)
:css('border-bottom', '1px solid black')
:wikitext(graph)
graph = ''
end
-- loop over columns and rows within columns
Line ٢٤٠ ⟶ ٣٠٧:
end
 
-- add the graph line (if bottom graph)
if((graphpos == 'bottom' or graphpos == 'b') and graph ~= '') then
row = root:tag('tr')
cell = row:tag('td')
cell
:attr('colspan', colspan)
:css('border-top', '1px solid black')
:wikitext(graph)
graph = ''
end
-- add the footnote line
if( footnote ~= '') then
Line ٢٥١ ⟶ ٣٢٨:
:wikitext(footnote)
end
 
return graph .. tostring(root)
end
 
-- this function renders the population table in a horizontal format
local function renderhorizontal(data, head, title, footnote, alignfn, class, style, width, shading, perrow, rows, graphpos, graph)
local row
local cell
Line ٢٨٣ ⟶ ٣٦٠:
:attr('colspan', colsperrow + 1)
:wikitext(title)
 
-- add the graph line (if top graph)
if((graphpos == 'top' or graphpos == 't') and graph ~= '') then
row = root:tag('tr')
cell = row:tag('td')
cell
:attr('colspan', colsperrow + 1)
:css('border-bottom', '1px solid black')
:wikitext(graph)
graph = ''
end
 
-- loop over rows and columns within rows
Line ٣٤٣ ⟶ ٤٣١:
end
end
 
-- add the graph line (if bottom graph)
if((graphpos == 'bottom' or graphpos == 'b') and graph ~= '') then
row = root:tag('tr')
cell = row:tag('td')
cell
:attr('colspan', colsperrow + 1)
:css('border-top', '1px solid black')
:wikitext(graph)
graph = ''
end
-- add the footnote line
if( footnote ~= '') then
Line ٣٥٥ ⟶ ٤٥٤:
:wikitext(footnote)
end
 
return graph .. tostring(root)
end
 
Line ٣٨١ ⟶ ٤٨٠:
local alignfn = args['align-fn'] or ''
local source = args['source'] or ''
local graphpos = args['graph-pos'] or ''
local graphwidth = args['graph-width'] or ''
local graphheight = args['graph-height'] or ''
local graphtype = args['graph-type'] or 'line'
local percol = tonumber(args['percol']) or 0
local cols = tonumber(args['cols']) or 1
Line ٣٩٦ ⟶ ٤٩٩:
 
if( isempty(title) ) then
title = 'دانیشتوانیHistorical مێژوویییانەpopulation'
end
 
Line ٤٣٢ ⟶ ٥٣٥:
'border-collapse:collapse;' ..
'border:none;'
end
style['table'] = style['table'] .. (args['table_style'] or '')
-- setup the footer text
if( source ~= '' ) then
source = 'سەرچاوەSource: ' .. source
if( footnote ~= '' ) then
footnote = footnote .. '<br/>'
Line ٤٨١ ⟶ ٥٨٦:
end
 
local graph = ''
graphpos = graphpos:lower()
-- now that we have the data for the table, render it in the requested format
 
if (direction == 'horizontal') then
if (direction == 'horizontal') then
return renderhorizontal(data, head, title, footnote, alignfn, class, style, width, shading, perrow, rows)
if graphpos ~= '' then
local gwidth = tonumber(graphwidth) or 200
local gheight= tonumber(graphheight) or 170
local gthumb =
(graphpos == 'r' or graphpos == 'right' and 'right') or
(graphpos == 'l' or graphpos == 'left' and 'left') or ''
graph = rendergraph(frame, data, gwidth, gheight, gthumb, graphtype)
end
return renderhorizontal(data, head, title, footnote, alignfn, class, style, width, shading, perrow, rows, graphpos, graph)
else
if graphpos ~= '' then
return rendervertical(data, head, title, footnote, alignfn, class, style, width, shading, percol, cols)
local gwidth = tonumber(graphwidth) or (170 * cols)
local gheight= tonumber(graphheight) or 170
local gthumb =
(graphpos == 'r' or graphpos == 'right' and 'right') or
(graphpos == 'l' or graphpos == 'left' and 'left') or ''
graph = rendergraph(frame, data, gwidth, gheight, gthumb, graphtype)
end
return rendervertical(data, head, title, footnote, alignfn, class, style, width, shading, percol, cols, graphpos, graph)
end
 
end