Content deleted Content added
No edit summary |
Updates |
||
Line 46:
args = args or {}
-- Variables
local timeline = ''
local longestseason = -1
local average = args.average and 1 or 0
local season_title = args.season_title or 'Season'
Line 53 ⟶ 54:
:attr('align', 'center')
-- Create the timeline
-- Bar width
local barwidth
Line 112 ⟶ 114:
end
end
-- Plot data
timeline = timeline .. "PlotData =\n"
Line 121 ⟶ 123:
local season = 1
local thisseason = 0
for k,v in pairs(args) do
Line 148 ⟶ 149:
-- Add timeline to div
if args.nograph == nil then
root:node(frame:extensionTag('timeline', timeline))
end
-- Create ratings table
if args.notable == nil then
local rtable = mw.html.create('table')
:addClass('wikitable')
:css('text-align', 'center')
-- If there's a title, add it with the viewers caption, else just display the viewers caption by itself
if args.title ~= nil and args.title ~= '' then
rtable:tag('caption'):wikitext("''" .. args.title .. "''" .. frame:expandTemplate{ title = 'hsp' } .. ": Viewers per episode (millions)") rtable:tag('caption'):wikitext("Viewers per episode (millions)")
:attr('colspan','2')
for i = 1,longestseason do
:attr('scope','col')
:wikitext(frame:expandTemplate{ title='abbr', args={ 'Ep.', 'Episode' } } .. ' ' .. i) row:tag('th')
:attr('scope','col')
:wikitext("''Average''")
if tonumber(k) ~= nil then
-- New season marker, or final episode rating
if v == '-' or (average == 1 and args[k+1] == nil) then
if season > 1 then
-- Spanning empty cells with {{N/A}}
if thisseason < longestseason then
row:node(TVRG.NACell(frame,"N/A"):attr('colspan',longestseason-thisseason))
end
if average == 1 then
-- If averages included, then set the averages cell with value or TBD
if v ~= '' then
row:tag('td'):wikitext(args[k+1] ~= nil and args[k-1] or v)
else
row:node(TVRG.NACell(frame,"TBD"))
end
thisseason = thisseason + 1
end
end
if v == '-' then
:css('background-color', args['color' .. season])
row:tag('th')
:attr('scope','row')
:wikitext(args["legend" .. season] and args["legend" .. season] or season)
thisseason = 0
season = season + 1
end
elseif average == 0 or (average == 1 and args[k+1] ~= '-' and args[k+1] ~= nil) then
-- Viewer figures, either as a number or TBD
if v ~= '' then
row:tag('td'):wikitext(v)
else
row:node(TVRG.NACell(frame,"TBD"))
end
thisseason = thisseason + 1
end
end
end
-- Finish by checking if final row needs {{N/A}} cells
if thisseason < longestseason then
row:node(TVRG.NACell(frame,"N/A"):attr('colspan',longestseason-thisseason))
end
-- Add table to div root and return
root:node(rtable)
end
return tostring(root)
end
|