if bargs('RD'..j..toChar(k)..'-hide')=='yes' or bargs('RD'..j..toChar(k)..'-hide')=='y' then
hide[j][k]=true
end
end
end  
local function getByes(j,headerindex)
byes[j] = {}
for k=1,headerindex[j] do
if bargs('byes')=='yes' or bargs('byes')=='y' then
byes[j][k]=true else byes[j][k]=false
end
if bargs('RD'..j..'-byes')=='yes' or bargs('RD'..j..'-byes')=='y' then
byes[j][k]=true
elseif bargs('RD'..j..'-byes')=='no' or bargs('RD'..j..'-byes')=='n' then
byes[j][k]=false
end
if bargs('RD'..j..toChar(k)..'-byes')=='yes' or bargs('RD'..j..toChar(k)..'-byes')=='y' then
byes[j][k]=true
elseif bargs('RD'..j..'-byes')=='no' or bargs('RD'..j..'-byes')=='n' then
byes[j][k]=false
end
end
end  
local function getAltIndices
local teamindex=1
local textindex=1
local groupindex=1
for j=minc,c do
headerindex[j]=0
for i=1,r do
if entries[j][i]==nil and i==1 then
headerindex[j]=headerindex[j]+1
end
if entries[j][i]~=nil then
if entries[j][i]['ctype'] == 'header' then
entries[j][i]['altindex'] = headerindex[j]
teamindex=1
textindex=1
headerindex[j]=headerindex[j]+1
elseif entries[j][i]['ctype'] == 'team' then
entries[j][i]['altindex'] = teamindex
teamindex=teamindex+1
elseif entries[j][i]['ctype'] == 'text' then
entries[j][i]['altindex'] = textindex
textindex=textindex+1
elseif entries[j][i]['ctype'] == 'group' then
entries[j][i]['altindex'] = groupindex
groupindex=groupindex+1
elseif entries[j][i]['ctype'] == 'line' and entries[j][i]['hastext']==true then
entries[j][i]['altindex'] = textindex
textindex=textindex+1
end
entries[j][i]['headerindex'] = headerindex[j]
end
end
getByes(j,headerindex)
getHide(j,headerindex)
end
end  
local function pathCell(tbl,j,i,k,a,b,c,bg,rowspan)
if not hascross[j] and k==2 then return end
if pathcolor==nil then pathcolor='black' end
local cell=tbl:tag('td')
if rowspan~=1 then
cell:attr('rowspan',rowspan)
end
if notempty(bg[k]) then
cell:css('background',bg[k])
end
if a[k][1]~=0 or a[k][2]~=0 or a[k][3]~=0 or a[k][4]~=0 then
cell:css('','solid black')
:css('-width',a[k][1]..'px '..a[k][2]..'px '..a[k][3]..'px '..a[k][4]..'px')
end
if c[k][2]~=0 then
cell:css('-',c[k][2]..'px solid '..pathcolor)
end
if b[k][2]~=0 then
cell:css('box-shadow', ' '..b[k][2]..'px '..pathcolor)
end
if c[k][4]~=0 then
cell:css('-',c[k][4]..'px solid '..pathcolor)
end
return cell
end  
local function insertPath(tbl,j,i)
local function createCross(angle,color,percent)
local result = 'linear-gradient('..angle..', transparent calc('..percent..'% - ),'..color..' calc('..percent..'% - ),'..color..' calc('..percent..'% + ), transparent calc('..percent..'% + ))'
return result
end
local colspan = 2
if hascross[j] then colspan = 3 end  
if pathEntries['black'][j][i]=='blank' then return end  
if isempty(pathEntries['black'][j][i]) and isempty(pathEntries['color'][j][i]) then
if (pathEntries['black'][j][i-1]~='blank' and notempty(pathEntries['black'][j][i-1]) and (pathEntries['black'][j][i-1]['cross'][1] == 1 or pathEntries['black'][j][i-1]['cross'][2] == 1)) or (notempty(pathEntries['color'][j][i-1]) and (pathEntries['color'][j][i-1]['cross'][1] == 1 or pathEntries['color'][j][i-1]['cross'][2] == 1)) then
return
else
local cell = tbl:tag('td')
for k=1,colspan-1 do
cell:tag('td')
end
return cell
end
end  
for key,_ in pairs(pathEntries) do
if notempty(pathEntries[key][j]) and notempty(pathEntries[key][j][i-1]) and pathEntries[key][j][i-1]~='blank' then
if pathEntries[key][j][i-1]['cross'][1]==1 or pathEntries[key][j][i-1]['cross'][2]==1 then return end
end
end  
local a = {}
local b = {}
local c = {}
local bg = {}
local cross = {}
local rowspan = 1  
for k=1,3 do
a[k]={0,0,0,0}
b[k]={0,0}
c[k]={0,0,0,0}
bg[k] = ''
cross[k] = {}
for n=1,2 do
cross[k][n] = ''
end
end  
for key,_ in pairs(pathEntries) do
local color
if key=='black' then color='black' else color=pathcolor end
if notempty(pathEntries[key][j]) and notempty(pathEntries[key][j][i]) then
if key=='black' then
a[1][3] = 3*pathEntries['black'][j][i]['out'][1]
a[2][3] = 3*pathEntries['black'][j][i]['mid'][1]
a[3][3] = 3*pathEntries['black'][j][i]['in'][1]
a[1][2] = 2*pathEntries['black'][j][i]['out'][2]
a[3][4] = 2*pathEntries['black'][j][i]['in'][2]
else
if pathEntries['color'][j][i]['out'][3]=='below' then
b[1][2] = 4*pathEntries['color'][j][i]['out'][1]
end
if pathEntries['color'][j][i]['mid'][3]=='below' then
b[2][2] = 4*pathEntries['color'][j][i]['mid'][1]
end
if pathEntries['color'][j][i]['in'][3]=='below' then
b[3][2] = 4*pathEntries['color'][j][i]['in'][1]
end
c[1][2] = 2*pathEntries['color'][j][i]['out'][2]
c[3][4] = 2*pathEntries['color'][j][i]['in'][2]
end
if pathEntries[key][j][i]['cross'][1]==1 or pathEntries[key][j][i]['cross'][2]==1 then
rowspan = 2
if pathEntries[key][j][i]['cross'][1]==1 then
cross[1][1] = createCross('65.5deg',color,100)
cross[2][1] = createCross('to top ',color,50)
cross[3][1] = createCross('245.5deg',color,100)
end
if pathEntries[key][j][i]['cross'][2]==1 then
cross[1][2] = createCross('114.4deg',color,100)
cross[2][2] = createCross('to bottom ',color,50)
cross[3][2] = createCross('294.4deg',color,100)
end
end
end
end
if notempty(pathEntries['color'][j]) and notempty(pathEntries['color'][j][i-1]) then
if pathEntries['color'][j][i]['out'][3]=='above' then
b[1][2] = -4
end
if pathEntries['color'][j][i]['mid'][3]=='above' then
b[2][2] = -4
end
if pathEntries['color'][j][i]['in'][3]=='above' then
b[3][2] = -4
end
end
if notempty(cross[2][1]) and notempty(cross[2][2]) then
for k=1,3 do cross[k][1] = cross[k][1]..',' end
end
for k=1,3 do
bg[k] = cross[k][1]..cross[k][2]
end  
for k=1,3 do
pathCell(tbl,j,i,k,a,b,c,bg,rowspan)
end
end  
local function getPaths
local paths = {}
pathEntries['black'] = {}
pathEntries['color'] = {}
for j=minc,c-1 do
pathEntries['black'][j] = {}
pathEntries['color'][j] = {}
for i=1,r do
pathEntries['black'][j][i] = {['out']={0,0,nil},['mid']={0,0,nil},['in']={0,0,nil},['cross']={0,0,nil}}
pathEntries['color'][j][i] = {['out']={0,0,nil},['mid']={0,0,nil},['in']={0,0,nil},['cross']={0,0,nil}}
end
paths[j] = {}
hascross[j] = false
local crossloc = split((fargs['col'..j..'-col'..(j+1)..'-cross'] or ''):gsub("%s+", ""),{","},true)
local str = fargs['col'..j..'-col'..(j+1)..'-paths'] or ''
for val in str:gsub("%s+","")
:gsub(",",", ")
:gsub("%S+","\0%0\0")
:gsub("%b", function(s) return s:gsub("%z","") end)
:gmatch("%z(.-)%z") do
local result = split(val:gsub("%s+",""):gsub("%)",""):gsub("%(",""),{"-"})
for k,_ in pairs(result) do
result[k] = split(result[k],{","})
end
if notempty(result[2]) then
for m=1,#result[2] do
result[3] = {}
result[2][m] = split(result[2][m],{":"})
result[3][m] = result[2][m][2]
result[2][m] = result[2][m][1]
end
for n=1,#result[1] do
for m=1,#result[2] do
table.insert(paths[j],{tonumber(result[1][n]),tonumber(result[2][m]),['color']=result[3][m]})
end
end
end
end
if shift[j]~=0 and notempty(crossloc[1]) then
for n=1,#crossloc do
crossloc[n] = crossloc[n]+shift[j]
end
end
for k,v in ipairs(paths[j]) do
local color
local hidepath = false
if shift[j]~=0 then
paths[j][k][1] = paths[j][k][1]+shift[j]
end
if shift[j+1]~=0 then
paths[j][k][2] = paths[j][k][2]+shift[j+1]
end
local start = 2*paths[j][k][1]+(teams_per_match[j]-2)
local mid = {}
if notempty(crossloc[1]) then
for n=1,#crossloc do
mid[n] = 2*crossloc[n]+(teams_per_match[j]-2)
end
else
mid[1]=0
end
local stop = 2*paths[j][k][2]+(teams_per_match[j+1]-2)
if paths[j][k]['color']~=nil then
pathcolor = paths[j][k]['color']
color = 'color'
else
color = 'black'
end
if notempty(entries[j][start-1]) and (byes[j][entries[j][start-1]['headerindex']] and isBlankEntry(j,start-1) and isBlankEntry(j,start+1) or hide[j][entries[j][start-1]['headerindex']]) then
if bargs('show-bye-paths')~='y' and bargs('show-bye-paths')~='yes' then
hidepath=true
end
end
if notempty(entries[j+1][stop-1]) and (byes[j+1][entries[j+1][stop-1]['headerindex']] and isBlankEntry(j+1,stop-1) and isBlankEntry(j+1,stop+1) or hide[j+1][entries[j+1][stop-1]['headerindex']])then