Content deleted Content added
protect against null value |
Update from sandbox |
||
Line 36:
-- Variables
local timeline =
local longestseason = -1
local average = args.average and 1 or 0
Line 100:
-- Basis parameters
timeline = timeline .. "\nImageSize = width:auto height:"..(args.height or 500).." barincrement:"..(barwidth+4).."\n"
timeline = timeline .. "\nPlotArea = left:50 bottom:50 top:10 right:100\n"
timeline
timeline = timeline .. "\nPeriod = from:0 till:"..math.ceil(maxviewers).."\n"
timeline = timeline .. "\nTimeAxis = orientation:vertical format:y\n"
-- Colors
timeline
for season = 1,num_seasons do
args["color" .. season] = args["color" .. season] or '#CCCCFF'
hex = args["color" .. season]:gsub("#","")
rgbR = tonumber("0x"..hex:sub(1,2))/256
rgbG = tonumber("0x"..hex:sub(3,4))/256
rgbB = tonumber("0x"..hex:sub(5,6))/256
timeline = timeline .. "\n id:season"..season.." value:rgb("..rgbR..", "..rgbG..", "..rgbB..") legend:Season_"..season.."\n"
end
timeline = timeline .. "\n id:bars value:gray(0.95)"
timeline = timeline .. "\nLegend = orientation:vertical position:right\n"
timeline = timeline .. "\nBackgroundColors = bars:bars\n"
local countryDisplayUS, countryDisplayUK, countryDisplayOther▼
timeline = timeline .. "\nScaleMajor = unit:year increment:1 start:1\n"
if args.country ~= nil and args.country ~= '' then▼
timeline = timeline .. "\nScaleMinor = unit:year increment:1 start:1\n"
if args.country == "U.S." or args.country == "US" or args.country == "United States" then countryDisplayUS = 'U.S.'▼
timeline = timeline .. "\nBarData=\n"
elseif args.country == "U.K." or args.country == "UK" or args.country == "United Kingdom" then countryDisplayUK = 'UK'▼
else countryDisplayOther = args.country▼
timeline = timeline .. "\n bar:"..episode.." text:"..episode.."\n"
end
-- Add bars to timeline, one per viewer figure
local bar = 1
Line 139 ⟶ 133:
local thisseason = 0
local counted_episodes = 0
timeline = timeline .. "\nPlotData=\n"
timeline = timeline .. "\n width:"..barwidth.." textcolor:black align:left anchor:from shift:(10,-4)\n"
for k,v in ipairs(args) do
Line 146 ⟶ 143:
-- Hyphen means new season
season = season + 1
-- Determine highest number of counted_episodes in a season
Line 158 ⟶ 151:
elseif average == 0 or (average == 1 and args[k+1] ~= '-' and args[k+1] ~= nil) then
-- Include bar for viewer figure, do not include if averages are included and the next parameter is a new season marker
timeline
-- Increment tracking variables
Line 171 ⟶ 164:
end
--
▲ local countryDisplayUS, countryDisplayUK, countryDisplayOther
▲ for ep = 1,num_episodes do
▲ if args.country ~= nil and args.country ~= '' then
▲ if args.country == "U.S." or args.country == "US" or args.country == "United States" then countryDisplayUS = 'U.S.'
▲ elseif args.country == "U.K." or args.country == "UK" or args.country == "United Kingdom" then countryDisplayUK = 'UK'
▲ else countryDisplayOther = args.country end
end
Line 183 ⟶ 179:
end
root:tag('div'):css('clear','both')
-- Add timeline to div
if args.no_graph == nil then
timelineBase = frame:preprocess("<timeline>"..timeline.."</timeline>")
root:node(timelineBase)
root:tag('div'):css('clear','both')
end
|