Module:Navbox timeline: Difference between revisions

From Wikipedia (https://en.wikipedia.org/wiki/Module:Navbox_timeline)
 
Trying out months change (AI)
Tag: Reverted
Line 10: Line 10:
if row and prev < current then
if row and prev < current then
if yesno(args.decades) == false then
if yesno(args.decades) == false then
row:tag('td')
if yesno(args.months) ~= false then
:addClass('timeline-blank')
-- Divide the cell up by months when showing months
:cssText(args.blankstyle)
local date = prev
:attr('colspan', current - prev)
while date < current do
local dur = math.min(1, current - date) -- 1 month duration
row:tag('td')
:addClass('timeline-blank')
:cssText(args.blankstyle)
:attr('colspan', dur)
date = date + dur
end
else
row:tag('td')
:addClass('timeline-blank')
:cssText(args.blankstyle)
:attr('colspan', current - prev)
end
else
else
-- Divide the cell up every decade if showing decades at the top
-- Divide the cell up every decade if showing decades at the top
Line 113: Line 129:


return rows
return rows
end
-- Get month abbreviation
local function getMonthAbbr(month)
local months = {'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'}
return months[month] or ''
end
end


Line 118: Line 141:
local function renderDates(args, tbl, rows, invert)
local function renderDates(args, tbl, rows, invert)
local showDecades = yesno(args.decades)
local showDecades = yesno(args.decades)
local showMonths = yesno(args.months)
local yearRow = tbl:tag('tr')
local yearRow = tbl:tag('tr')
:addClass('timeline-row')
:addClass('timeline-row')
Line 123: Line 147:
-- Create label
-- Create label
if args.label or rows.hasLabels then
if args.label or rows.hasLabels then
local rowspan = 1
if showDecades ~= false then
rowspan = 2
elseif showDecades == false and showMonths ~= false then
rowspan = 2
end
local labelCell = mw.html.create('th')
local labelCell = mw.html.create('th')
:attr('scope', 'col')
:attr('scope', 'col')
:addClass('navbox-group timeline-label')
:addClass('navbox-group timeline-label')
:cssText(args.labelstyle)
:cssText(args.labelstyle)
:attr('rowspan', showDecades ~= false and '2' or '1')
:attr('rowspan', tostring(rowspan))
:wikitext(args.label or '')
:wikitext(args.label or '')
Line 156: Line 187:
year = year + dur
year = year + dur
end
-- Create month row when decades are disabled but months are enabled
elseif showDecades == false and showMonths ~= false then
local monthRow = tbl:tag('tr')
:addClass('timeline-row')
-- Move month row
if not invert then
monthRow, yearRow = yearRow, monthRow
end
-- Calculate total months in range
local totalMonths = (rows.maxYear - rows.minYear) * 12
local monthWidth = 100 / totalMonths
for year = rows.minYear, rows.maxYear - 1 do
for month = 1, 12 do
monthRow:tag('th')
:attr('scope', 'col')
:addClass('timeline-month')
:cssText(args.datestyle)
:cssText(args.monthstyle)
:cssText('width:' .. monthWidth .. '%')
:wikitext(getMonthAbbr(month))
end
end
end
end
end
-- Populate year row element
-- Populate year row element
local width = 100 / (rows.maxYear - rows.minYear)
if showDecades == false and showMonths ~= false then
-- When showing months, each year spans 12 columns
for i = rows.minYear, rows.maxYear - 1 do
for year = rows.minYear, rows.maxYear - 1 do
yearRow:tag('th')
yearRow:tag('th')
:attr('scope', 'col')
:attr('scope', 'col')
:addClass('timeline-year')
:addClass('timeline-year')
:cssText(args.datestyle)
:cssText(args.datestyle)
:cssText(args.yearstyle)
:cssText(args.yearstyle)
:cssText('width:' .. width .. '%')
:attr('colspan', '12')
:wikitext(showDecades == false and i or i % 10)
:wikitext(tostring(year))
end
else
-- Normal year display
local width = 100 / (rows.maxYear - rows.minYear)
for i = rows.minYear, rows.maxYear - 1 do
yearRow:tag('th')
:attr('scope', 'col')
:addClass('timeline-year')
:cssText(args.datestyle)
:cssText(args.yearstyle)
:cssText('width:' .. width .. '%')
:wikitext(showDecades == false and i or i % 10)
end
end
end
end
end
Line 206: Line 276:
-- Shrink previous item so new item can start at the start year
-- Shrink previous item so new item can start at the start year
if prevItem and prev > prevEndYear then
if prevItem and prev > prevEndYear then
prevItem:attr('colspan', prevItem:getAttr('colspan') - prev + prevEndYear);
local colspan = prevItem:getAttr('colspan')
if yesno(args.decades) == false and yesno(args.months) ~= false then
-- Adjust for months
prevItem:attr('colspan', colspan - (prev - prevEndYear) * 12)
else
prevItem:attr('colspan', colspan - prev + prevEndYear)
end
end
end


Line 215: Line 291:
-- Add blanks before the cell
-- Add blanks before the cell
addBlank(args, rowElement, prevEndYear, cell.startYear)
addBlank(args, rowElement, prevEndYear, cell.startYear)
local colspan = cell.endYear - cell.startYear
if yesno(args.decades) == false and yesno(args.months) ~= false then
-- Each year represents 12 months
colspan = colspan * 12
end
prevItem = rowElement:tag('td')
prevItem = rowElement:tag('td')
Line 220: Line 302:
:cssText(args.itemstyle)
:cssText(args.itemstyle)
:cssText(cell.style or '')
:cssText(cell.style or '')
:attr('colspan', cell.endYear - cell.startYear)
:attr('colspan', colspan)
:wikitext(cell.item)
:wikitext(cell.item)