Module:Database report

From Wikidata
Jump to navigation Jump to search
Lua
CodeDiscussionLinksLink count SubpagesDocumentationTestsResultsSandboxLive code All modules

Documentation for this module may be created at Module:Database report/doc

Code

local p = {}

function p.itemlist(frame)
	local data = require('Module:StatTables/' .. frame.args[1]).data
	local lang = frame:preprocess( "{{int:lang}}" )
	local out = mw.html.create('table')
	local maxval = data[1].value
	for i, j in pairs(data) do
		local row = mw.html.create('tr')
		local label = ''
		local value = j.value
		-- textual label if less than 200 items, otherwise times out
		if i < 200 then 
			label = mw.wikibase.getLabelWithLang("Q" .. j['item'], lang)
		end
		
		row
			:tag('td'):wikitext('[[Q' .. j['item'] .. ']]'):done()
			:tag('td')
				:css({['width'] = '30%'})
				:wikitext(label)
				:done()
			:tag('td'):wikitext(value):done()
			:done()
			:tag('td')
				:css({['width'] = '100%'})
				:tag('div')
					:css({['background-color']= '#b0c4de', ['width'] = tostring(100 * value / maxval) .. '%', ['overflow'] = 'hidden'})
					:tag('span')
						:css({['visibility'] = 'hidden'})
						:wikitext('d')-- dummy text so that the graph shows
						:done()
					:done()
				:done()
			:done()
		out:node(row)
	end
	out:allDone()
	return tostring(out)-- tostring(outputtable) --tostring(outputtable)
--	return frame:preprocess('{{#invoke:Chart|bar chart|group 1=  1500000 : 2500000 : 3500000|group names = toto|x legends = 1 : 2 : 3}}')
end 

return p