Module:Table graph
Jump to navigation
Jump to search
![]() | This module is rated as pre-alpha. It is unfinished, and may or may not be in active development. It should not be used from article namespace pages. Modules remain pre-alpha until the original editor (or someone who takes one over if it is abandoned for some time) is satisfied with the basic structure. |
This module produces charts from wikitables using Module:Chart and Module:Graph.
Usage
It can be invoked directly or through its associated template:
{{table graph|page|table|labels column|values column}}
local p = {}
function p.main(frame)
local frame = mw.getCurrentFrame()
local chart = frame:getParent().args[1]:lower():gsub('%s*(.+)%s*','%1')
local pagename = frame.args[2] or ''
local table_id = frame.args[3] or ''
local source = ''
local data = ''
local first = frame.args['first']
local count = 0
if pagename == '' then
source = frame:getParent():getTitle():getContent()
else
source = mw.title.new(pagename):getContent()
end
if table_id ~= '' then source = source:match('{|.-id -="?'..table_id..'"? -.-(\n|%-.+\n)|}') end
for x, y in source:gmatch('\n|%-.-\n[!|]%s*(.-)%s*[|\n]|%s*([^|\n]+)') do
count = count + 1
data = data.."("..y..":"..x..")\n"
if count == first then return require('Module:Chart')[chart](frame) end
end
if frame:getParent().args['debug'] then
return string.format(' chart: '..chart..'\n pagename: '..pagename..'\n table: '..table_id..'\n data: ' .. data)
else
if chart == 'pie chart' then
frame.args.slices = data
end
return require('Module:Chart')[chart](frame)
end
end
return p