Module:Television ratings graph: Difference between revisions

Content deleted Content added
Graph legend
Colour contrasting background border bars
Line 1:
-- This module implements {{Television ratings graph}}.
 
local contrast_ratio = require('Module:Color contrast')._ratio
 
--------------------------------------------------------------------------------
Line 76 ⟶ 78:
timeline = timeline .. "Colors =\n"
timeline = timeline .. " id:agray value:gray(0.7)\n"
-- Determine number of seasons
Line 88 ⟶ 90:
-- Colour and legend variables
local season = 1 for season = 1,num_seasons do
for season = 1,num_seasons do
local r,g,b = TVRG.hex2rgb(args['color' .. season] or '#006600')
Line 129 ⟶ 130:
timeline = timeline .. "Period = from:0 till:" .. math.ceil(maxviewers) .. "\n"
timeline = timeline .. "TimeAxis = orientation:vertical\n"
timeline = timeline .. "ScaleMajor = gridcolor:agray increment:" .. 10^math.ceil(math.log10(maxviewers)-math.log10(15)) .. " start:0\n"
timeline = timeline .. "Legend = orientation:horizontal\n"
Line 148 ⟶ 149:
timeline = timeline .. "PlotData =\n"
timeline = timeline .. " width:" .. (args.bar_width or barwidth) .. "\n"
timeline = timeline .. " mark:(line,black)\n"
-- Add bars to timeline, one per viewer figure
Line 168:
thisseason = 0
elseif average == 0 or (average == 1 and args[k+1] ~= '-' and args[k+1] ~= nil) then
-- Include white/black bar to act as border
local black_cr = contrast_ratio{args['color' .. season], 'black', ['error'] = 0}
timeline = timeline .. " color:black\n"
local white_cr = contrast_ratio{'white', args['color' .. season], ['error'] = 0}
local bgrnd_cr = (black_cr > white_cr and 'black' or 'gray')
timeline = timeline .. " mark:(line,black" .. bgrnd_cr .. ")\n"
timeline = timeline .. " color:black" .. bgrnd_cr .. "\n"
timeline = timeline .. " bar:" .. bar .. " width:" .. ((args.bar_width or barwidth)+2) .. " from:start till:" .. (v ~= '' and v or 'start') .. "\n"