Content deleted Content added
debug |
m Ahecht moved page Module:Xviews/sandbox to Module:Sandbox/Ahecht/Xviews without leaving a redirect: Move to personal sandbox |
||
(5 intermediate revisions by the same user not shown) | |||
Line 3:
local function ifblank(v, alt) return notblank(v) and v or alt end
local function red(v) return '<span style="color: red;">' .. v .. '</span>' end
local function getContent(page) return
local function diffDays(dargs)
return require('Module:diff days')['diff_days'](
Line 29:
))
else --not stale:
return p._xvmain(page, {ct = ifblank(args.days, ifblank(args.ct, p.gCOUNT()))}) ..
((notblank(args.log) or notblank(args.mode)) and '' or p._xAxis(page, {}))
end
else
Line 52:
end
function p._nthView(page,
local
content = string.gsub(content, "^%s*,%s*(.-)%s*,$", "%1")
return Text.split(views, ',', true)[tonumber(number)]▼
local items = {}
for item in string.gmatch(content, "([^,]+)") do
table.insert(items, mw.text.trim(item))
end
index = tonumber(index)
if index < 0 then
index = #items + index + 1
end
return items[index]
end
function p.nthView(frame)
Line 64 ⟶ 73:
function p._viewCount(page) -- {{xviews/view count}}
local str =
str =
-- Remove leading and trailing delimiters (along with any surrounding whitespace)
str = str:gsub("^%s*,%s*", ""):gsub("%s*,%s*$", "")
Line 90 ⟶ 99:
for n = start, stop do
iargs.n = n
table.insert(output, p.
end
return table.concat(output)
end
function p.xvmain(frame)
local xargs = frame.args
xargs.ct = ifblank(xargs.ct, 93)
return p._xvmain(ifblank(xargs[1], 'Talk:Liberation of France/pageviews'), xargs)
Line 110 ⟶ 119:
end
local nthview = p._nthView(iargs.page, ifblank(iargs.n, 1))
error("Error generating item bar for item #" .. ifblank(iargs.n, 1) .. ". Range may be invalid")
local width = val * 100 * 0.88 / p._maxViews(page)▼
end
▲ local width = val * 100 * 0.88 / p._maxViews(iargs.page)
width = tonumber(string.format("%.2f", width))
local label = p._xlabel(Text.split(nthview, ':', true)[1], 'y')
Line 117 ⟶ 129:
end
function p.itemBar(frame)
local iargs = frame.args
iargs.page = ifblank(iargs.page, 'Talk:House of the Dragon/pageviews')
iargs.n = ifblank(iargs.n, 1)
Line 151 ⟶ 163:
end
function p.vbar(frame)
local vargs = frame.args
return p._vbar(ifblank(vargs[1], 75), ifblank(vargs[2], ifblank(vargs.val, 2136)), vargs)
end
function p._xlabel(date, bold01) -- {{xviews/xlabel}}
local replace = ((date:sub(-3) == '-01') and notblank(bold01)) and "'''%1'''" or "%1"
return
end
function p.xlabel(frame)
Line 165 ⟶ 177:
function p._maxViews(page) -- {{xviews/max views}}
local views = 0
for v in Text.gsplit(content, ',', true) do
v = tonumber(v)
if (v and v > views) then views = v end
Line 172 ⟶ 185:
end
function p.maxViews(frame)
return p._maxViews(ifblank(frame.
end
function p._xAxis(page, xargs) -- {{xviews/x-axis}}
-- xargs contains shift, caption, ff
local div = mw.html.create('div')
:css('margin', '-22px 0 0 ' .. ifblank(xargs.shift, '16px'))
:wikitext(
|