Module:Croatian population data graph
![]() | This module uses TemplateStyles: |
This module implements the {{Croatian population data graph}} template.
It processes parameters in the format pYYYY=value
taken from the template, and displays the population data as a bar chart. Here, YYYY represents a year and value the corresponding population. In older syntax, the template also accepts up to 99 of annum/population pairs: aN=YYYY | pN=value
.
The chart is rendered as a table with bars made of <div>...</div>
elements, having the heights proportional to each value for a given year YYYY.
Other parameters taken from the template (or module invocation) include, in Croatian (for historical reasons) or English:
English | Croatian |
---|---|
title | naslov |
entity | područje |
note | napomena |
sources | izvori |
censuses=HRV | popisi=HRV |
The following labels can be modified only from the module invocation:
parameter | English text | Croatian text |
---|---|---|
trend | Population trends |
Kretanje broja stanovnika od
|
trendsep | – |
do
|
ord | population |
broj stanovnika
|
nb | '''Note: ''' |
'''Napomena:'''
|
ref | '''Sources: ''' |
'''Izvori:'''
|
YYYYsuf | .
|
Examples
{{Croatian population data graph|p2001=1|p2011=3|p2021=5|title=Title|entity=Entity|note=Note|sources=Sources}}
{{Croatian population data graph|a1=2001|p1=1|a2=2011|p2=3|a3=2021|p3=5|title=Title|entity=Entity|note=Note|sources=Sources}}
population | 1 | 3 | 5 |
2001 | 2011 | 2021 |
When censuses=HRV
only the years of the known Croatian population censuses are shown (1857, 1869, 1880, 1890, 1900, 1910, 1921, 1931, 1948, 1953, 1961, 1971, 1981, 1991, 2001, 2011, 2021), starting and ending with the years for which data are given.
If unset, any years can be shown.
{{Croatian population data graph|censuses=|p2025=5|p2020=9|p2015=12|p2010=8|p2005=4|p2000=2|p1995=1|p1990=0|title=Title|entity=Entity|note=Note|sources=Sources}}
population | ||||
1991 | 2001 | 2011 | 2021 |
local p = {}
-- ako je u predlošku popisi=HRV prikazat će sve poznate popise od 1857. do 2021.
-- bez obzira na to postoji li u članku podatak
-- bez tog parametra u predlošku, prikazat će samo godine upisane u članku
local godine_hr = {1857, 1869, 1880, 1890, 1900, 1910, 1921, 1931, 1948, 1953,
1961, 1971, 1981, 1991, 2001, 2011, 2021, }
local izvori_hr = "[[Template:Croatian population data graph/Sources|Croatian Bureau of Statistics publications]]"
local max_visina = 8 -- 8 em; podesiti i visinu ćelije u css-u predloška
function p.dijagram(frame)
local podatci = {}
local targs = frame:getParent().args --template arguments in template call
local margs = frame.args --module arguments in #invoke
--prođi kroz sve parametre; većinom su to parametri oblika pGGGG ili parovi aN/pN
for k, v in pairs(targs) do
local g = tonumber(string.match(k, "^p(%d%d%d%d)$")) -- parametri oblika p2021
if g then
local p = tonumber(v)
--mw.log(g,p)
if p then podatci[g] = p end
end
local n = string.match(k, "^a(%d%d?)$") -- do 99 parova parametara godina/populacija: a1/p1 … a99/p99
if n then
local g = tonumber(v)
local p = tonumber(targs["p"..n])
--mw.log(g,p)
if g and p then
podatci[g] = p
end
end
end
--godine prisutne u predlošku; trebamo ih u tablici radi sortiranja
local godine = {}
local podatci_max = 0
for k, v in pairs(podatci) do
table.insert(godine, k)
if podatci[k]>podatci_max then podatci_max=podatci[k] end
end
table.sort(godine)
--html tablica u kojoj će svaka ćelija sadržavati jedan stupac (div) stupčastog dijagrama
--ovdje stvaramo ćelije u dvama retcima
local tr1 = mw.html.create( 'tr' )
tr1 : tag("td") : addClass("kbs_ordinata")
: tag("span") : addClass("kbs_ordinata") : wikitext("population") : done()
local tr2 = mw.html.create( 'tr' )
tr2 : tag("td") : done()
if (targs["popisi"]=="HRV") or (margs["popisi"]=="HRV") then
prikazi = godine_hr
else
prikazi = godine
end
local prva, zadnja = Nil, Nil
for _, g in ipairs(prikazi) do
if godine[1]<=g and g<=godine[#godine] then --ne prikazuj lijevo i desno od jedinih poznatih, ali prikaži između
prva = prva or g
zadnja = g
local podatak = podatci[g] or 0
local biljeg = (podatak>0 and podatak) or "" -- do not show 0 or Nil
tr1 : tag("td") : addClass("kbs_za_stupce")
: tag("div") : addClass("kbs_podatci") : wikitext(biljeg) : done()
: tag("div") : addClass("kbs_stupci")
: cssText("height:"..0.01*math.floor(100*podatak*max_visina/podatci_max).."em;") : done()
tr2 : tag("td") : addClass("kbs_godine") : wikitext(g) : done()
end
end
-- naslov iznad tablice s dijagramom
-- u predlošku: Naselje X ili Općina Y ili Grad Z
local podatci_za = targs["područje"] and (targs["područje"] ~= "") and ("'''" .. targs["područje"] .. "''': ")
or ""
local kbs = "Population trends " .. prva .."–"..zadnja
local naslov = podatci_za .. (targs["naslov"] and (targs["naslov"] ~= "") and targs["naslov"] or kbs)
-- tablica za stupčasti dijagram
local tbl = mw.html.create( 'table' )
tbl : addClass("kbs_tablica")
: node(tr1)
: node(tr2)
local ttl = mw.html.create( 'div' )
ttl : addClass("kbs_naslov") : wikitext(naslov)
local tbl_ttl = mw.html.create( 'div' )
tbl_ttl : addClass("kbs_tablica_scrollable")
: tag("div") : addClass("kbs_tablica")
: node(ttl)
: node(tbl)
: done()
-- Napomena:… i Izvori:… ispod dijagrama
local napomena = targs["napomena"] or ""
local izvori = ""
if (targs["popisi"]=="HRV") or (margs["popisi"]=="HRV") then
izvori = izvori_hr
end
izvori = targs["izvor"] or izvori
local nte = mw.html.create( 'div' ) : addClass("kbs_napomena")
if napomena ~="" then
nte : wikitext("'''Note''': " .. napomena .. " ")
end
if izvori ~="" then
nte : wikitext("'''Sources''': " .. izvori)
end
local nap_izv = mw.html.create( 'div' )
nap_izv : addClass("kbs_napomena_nonscrollable")
: node(nte)
local vte_div = mw.html.create( 'div' ) : addClass("kbs_vte")
local vte = frame : expandTemplate{title = 'vte',
args = { 'Croatian population data graph' } }
vte_div : addClass("kbs_napomena_nonscrollable")
: node(vte)
local sve = mw.html.create() : node(tbl_ttl) : node(nap_izv) : node(vte_div)
return sve
end
return p