Content deleted Content added
changes from Github • Wikiploy |
Report unknown $var • Wikiploy |
||
(4 intermediate revisions by the same user not shown) | |||
Line 179:
return options
end
-- internal for testing legend rendering
p.__priv.legendDebug = false
--[[
Line 215 ⟶ 218:
if options.legend then
html = html .. p.renderLegend(data, options)
end
if p.__priv.legendDebug then
return html
end
Line 368 ⟶ 375:
local bcolor = entry.bcolor
local html = "\n<li>"
if p.__priv.legendDebug then
forPrinting = ""
end
html = html .. '<span class="l-color" style="'..forPrinting..bcolor..'"></span>'
html = html .. '<span class="l-label">'..label..'</span>'
Line 423 ⟶ 433:
if (value < 0.03) then
mw.log('value too small', value, label)
mw.addWarning("pie chart: Value too small ↆ "..value.."% ("..label..")")
return ""
end
Line 583 ⟶ 593:
Typical tpl:
"$L: $v" (same as: "$label: $auto")
will result in:
"Abc: 23%" -- when values are percentages
Line 589 ⟶ 599:
Advanced tpl:
"
"$L: $v" is the same as above when values are autoscaled
Long vs short variable names:
$label ($L)
$auto ($v)
$value ($d)
$percent ($p)
]]
function priv.prepareLabel(tpl, entry)
-- setup default tpl
if not tpl or tpl == "" then
-- simple if no label
Line 598 ⟶ 615:
tpl = "$v"
else
if
tpl = entry.label
else
Line 612 ⟶ 629:
local pp = pRaw .. "%%"
local label =
-- aliases
label = tpl:gsub("%$L", labelLabel)▼
label = label
:gsub("%$label", "$L")
:gsub("%$auto", "$v")
:gsub("%$value", "$d")
:gsub("%$percent", "$p")
-- replace variables
local d = priv.formatLargeNum(entry.raw and entry.raw or entry.value)
local v = entry.raw and (d .. " (" .. pp .. ")") or pp
Line 620 ⟶ 644:
:gsub("%$d", d)
:gsub("%$v", v)
-- Report unknown variables
for var in label:gmatch("%$[a-zA-Z]+") do
-- in preview
mw.addWarning("pie chart: Unknown variable (wrong format of your label): " .. var)
-- tracing links
_ = mw.title.new("Module:Piechart/tracing/unknown-variable").id
end
return label
end
|