local p = local compress_sparse_array = require('Module:TableTools').compressSparseArray
local function arg_or_default(arg, default) if arg and mw.text.trim(arg) ~= then return arg else return default endend
local incoming_args =
local graph_colors = local function get_graph_color(nth_item) return graph_colors[math.max(math.min(nth_item, #graph_colors), 1)]end
local function get_css_for_slices(args) local slices = local degree_ratio = 360/100
for k, v in pairs(args) do if k:match('value%d+') then local number = k:find('(%d+)') slices[number] = end end -- second loop because we need to guarantee that we've found all the potential slices -- before attempting to add their labels and colors for k, v in pairs(args) do if k:match('label%d+') then local number = k:find('(%d)') if slices[number] then -- if we don't have a value, then no label set slices[number]['label'] = v end end if k:match('color%d+') then local number = k:find('(%d)') if slices[number] then -- if we don't have a value, then no color set slices[number]['color'] = v end end end compress_sparse_array(slices) local conical_css_for_slices = local accumulated_value = 0 for i, slice in ipairs(slices) do local value = slice.value local color = slice.color or get_graph_color(i) local next_accumulated_value = accumulated_value + value if i
#slices then -- we only need the start degree for the last table.insert(conical_css_for_slices, color .. ' ' .. accumulated_value .. 'deg') end accumulated_value = next_accumulated_value end return 'background: conic-gradient(' .. table.concat(conical_css_for_slices) .. ')'end
function p._main(args) local root = mw.html.create('div') root:addClass('pie-chart thumb') :cssText(arg_or_default(args.style, nil)) local thumb = arg_or_default(args.thumb, nil) local thumb_class = 'tright' if thumb and (thumb
'none') then thumb_class = 'tnone' elseif thumb and thumb
if thumb and thumb
return root end
function p.main(frame) return p._main(frame:getParent.args)end
return p