Module:Chart display/sandbox
| This is the module sandbox page for Module:Chart display. |
local p = {}
local notblank = function(v) return (v or '') ~= '' end
local ifblank = function (v, alt) if notblank(v) then return v else return alt end end
local getArgs = require('Module:Arguments').getArgs
function p._chart(args)
local values = {}
local chartArgs = {}
local templateArgs = {
right = 1, left = 1, center = 1, none = 1,
thumb = 1, thumbnail = 1, border = 1
}
local alignClasses = {center = 'none', none = 'none', left = 'left', right = 'right'}
for k, v in pairs(args) do --ipairs fails with blank positional arguments
if tonumber(k) then
local lv = mw.ustring.lower(v)
if v:sub(1,4) == 'arg:' then
chartArgs.insert(v)
elseif mw.ustring.match(lv, "%d+%s*px%s*$") then
values.width = lv
elseif templateArgs[lv] then
values[lv] = lv
elseif v ~= '' then
values.caption = v
end
end
end
local opts = {
align = ifblank(args.align, values.right or values.left or values.center or values.none),
thumb = notblank(args.thumb) or values.thumb or values.thumbnail,
width = ifblank(args.width, values.width),
border = notblank(args.border) or values.border,
chart = ifblank(args.chart, args.definition)
}
assert(notblank(opts.chart), 'Must specify chart= or definition=')
local caption = ifblank(args.caption, ifblank(
values.caption, notblank(args.title) and (args.title .. ".") or ""
))
if not notblank(args.hideSource) then
caption = caption .. ' See or edit [[c:Data:'
if notblank(ifblank(args.source, args.data)) then
caption = caption .. ifblank(args.source, args.data) .. '|source data]].'
else
caption = caption .. opts.chart .. '|chart definition]].'
end
end
local html = mw.html.create('div'):addClass((opts.align == 'center') and 'center' or nil)
if opts.thumb then
html = html:tag('div'):addClass('thumb'):addClass('t' .. (alignClasses[opts.align] or 'right'))
:css('width', (not opts.width) and '100%' or nil)
:tag('div'):addClass('thumbinner')
:css('width', opts.width and 'fit-content' or nil)
end
html = html:tag('div'):addClass('enwiki-chart')
:addClass(opts.thumb and 'thumbimage' or ('float' .. (alignClasses[opts.align] or 'none')))
:css('width', opts.width)
:css('border-style', opts.border and '1' or nil)
:cssText(ifblank(args.style))
:tag('div'):addClass('enwiki-chart-content')
:wikitext(mw.getCurrentFrame():preprocess(
"{{#chart:" ..
opts.chart ..
(notblank(args.data) and ("|data=" .. args.data) or "") ..
((#chartArgs > 0) and ("|" .. table.concat(chartArgs, '|')) or "") ..
"}}"
))
:done()
if opts.thumb then
html = html:done():tag('div'):addClass('thumbcaption')
else
html = html:tag('div'):addClass('center')
:tag('small')
end
return tostring(html:wikitext(caption):allDone()) ..
(opts.thumb and '' or '<div style="clear:both;"></div>')
end
function p.chart(frame)
return p._chart(getArgs(frame))
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.