Content deleted Content added
change lp |
Replace Module:No globals with require( "strict" ) |
||
(17 intermediate revisions by one other user not shown) | |||
Line 8:
now uses templatestyles
]]
require('
local p = {}
local pargs = {} -- parent arguments
Line 18:
local infoOutput
local reverseClade = false
--[[============================== main function ===========================
Line 61 ⟶ 57:
cladeString = cladeString .. p.templateStyle( frame, src ) .. '\n'
--end
local tableStyle = frame.args.style or ""
if tableStyle ~= "" then
tableStyle = ' style="' .. tableStyle .. '"' -- include style= in string to suppress empty style elements
Line 74 ⟶ 68:
--reverseClade = true
local captionName =
local captionStyle =
-- add an element to mimick nowiki WORKS BUT DISABLE FOR DEMO PURPOSES
Line 90 ⟶ 84:
end
-- global nodeParameters (unnumber, i.e. color, thickness, state) apply to whole node bracket, ▼
nodeThickness = tonumber(mw.getCurrentFrame():getParent().args['thickness']) or 1▼
nodeState = mw.getCurrentFrame():getParent().args['state'] or "solid"▼
local moreNeeded = true
Line 111 ⟶ 100:
childNumber = childNumber + 1 -- so we start with 1
local nodeLeaf =
local nodeLabel =
local newickString =
local listString =
if listString ~= "" then
Line 136 ⟶ 125:
end
local footerText =
local footerStyle =
if footerText ~= "" then
Line 162 ⟶ 151:
function p.addSubTrees(cladeString)
--local pargs = mw.getCurrentFrame():getParent().args
local suffix = { [1]="A", [2]="B", [3]="C", [4]="D", [5]="E", [6]="F", [7]="G", [8]="H", [9]="I", [10]="J",
Line 190 ⟶ 179:
function p.addTaxon(childNumber, nodeLeaf, nodeLabel, lastNode)
▲
branchParameters apply to individual branches
the node parameters have no number, e.g. |color, |thickness, |state
]]
local nodeColor = pargs['color'] or "" -- don't set default to allow green on black gadget
-- get border formating parameters for branch (default to global nodeParameters)
local branchColor =
▲ -- - the branch parameters have a number, e.g. |colorN, |thicknessN, |stateN
local branchThickness = tonumber(pargs['thickness'..tostring(childNumber)]) or nodeThickness
▲ -- - the node parameters have no number, e.g. |color, |thickness, |state
local
▲ local branchColor = mw.getCurrentFrame():getParent().args['color'..tostring(childNumber)] or nodeColor
local branchStyle = mw.getCurrentFrame():getParent().args['style'..tostring(childNumber)] or ""▼
local branchLength = mw.getCurrentFrame():getParent().args['length'] or mw.getCurrentFrame():getParent().args['length'..tostring(childNumber)] or ""▼
if branchState == 'double' then
if branchThickness < 2 then branchThickness = 3 end -- need thick line for double
end
▲ local branchStyle =
▲ local branchLength =
-- the left border takes node parameters, the bottom border takes branch parameters
Line 219 ⟶ 216:
-- variables for right hand bar or bracket
--local barColor = ""
local barRight =
local barBottom =
local barTop =
local barLabel =
local groupLabel =
local groupLabelStyle =
local labelStyle =
local sublabelStyle =
--replace colours with format string; need right bar for all three options
Line 242 ⟶ 239:
local classString = ''
local reverseClass = ''
local widthClass = ''
-- class to add if using reverse (rtl) cladogram;
Line 267 ⟶ 265:
local branchLengthStyle = ""
if branchLength ~= "" then
if childNumber > 1 then prefix = 'max-' end▼
end
▲ branchLengthStyle = prefix .. 'width:' .. branchLength .. ';'
▲ --if childNumber > 1 then prefix = 'max-' end
.. 'padding:0em;' -- remove padding to make calculation easier▼
branchLengthStyle = branchLengthStyle --= prefix .. 'width:' .. branchLength .. ';'
-- .. 'overflow-x:hidden;' -- clip labels longer than the width▼
-- .. 'text-overflow: ellipsis;'▼
-- following moved to styles.css
-- .. 'white-space:nowrap'
--if pargs['noclip'] then
if string.find(nodeLabel, '<div style="position:absolute;') then
branchLengthStyle = branchLengthStyle .. 'overflow:visible;'
end
widthClass = " clade-fixed-width"
end
styleString = 'style="' .. borderStyle .. branchLengthStyle .. branchStyle .. labelStyle .. '"'
Line 279 ⟶ 287:
if childNumber == 1 then
classString= 'class="clade-label first'.. widthClass .. '" ' -- add class "first" for top row
else
classString = 'class="clade-label' .. reverseClass .. widthClass .. '" ' -- add "reverse" class if ltr cladogram
end
Line 312 ⟶ 320:
it also means there are two newlines when it is a clade structure (which might explain some past issues)
]]
local content = '\n' .. nodeLeaf -- the
-- test using image parameter
local image = pargs['image'..tostring(childNumber)] or ""
if image ~= "" then
--content = content .. image --
content = '\n{| class="clade" style="width:auto;"
.. '\n| class="clade-leaf"
.. '\n| class="clade-leaf"
.. '\n|}'
-- note: the classes interfere with the node counter, so try simpler version with style
content = '\n{| style="width:100%;border-spacing:0;" ' --width:auto is "tight"; 100% needed for image alignment
.. '\n| style="border:0;padding:0;" ' .. '|\n' .. nodeLeaf
.. '\n| style="border:0;padding:0;" ' .. '|\n' .. image
.. '\n|}'
end
Line 366 ⟶ 379:
-- (6) add cell containing sublabel
local subLabel =
-- FOR TESTING: use subLabel for annotating the clade structues to use structure information (DEBUGGIING ONLY)
Line 385 ⟶ 398:
end
end
if borderStyle ~= '' or branchStyle ~= '' or branchLength ~= '' or sublabelStyle ~= "" then
local branchLengthStyle = ""
styleString = ' style="' .. borderStyle .. branchStyle .. sublabelStyle .. '"'▼
if branchLength ~= "" then
if childNumber == 1 then
--only set for label branchLengthStyle = 'width:' .. branchLength .. ';' -- add width to first element
end
--if childNumber > 1 then prefix = 'max-' end
branchLengthStyle = branchLengthStyle --= prefix .. 'width:' .. branchLength .. ';'
.. 'max-width:' .. branchLength ..';'
.. 'padding:0em;' -- remove padding to make calculation easier
--if pargs['noclip'] then
if string.find(subLabel, '<div style="position:absolute;') then
branchLengthStyle = branchLengthStyle .. 'overflow:visible;'
end
end
styleString = 'style="' .. borderStyle .. branchLengthStyle .. branchStyle .. sublabelStyle .. '"'
▲ --styleString = ' style="' .. borderStyle .. branchStyle .. sublabelStyle .. '"'
end
Line 392 ⟶ 420:
if childNumber == lastNode then
classString = 'class="clade-slabel last' .. widthClass .. '" '
else
classString = 'class="clade-slabel' .. reverseClass .. widthClass .. '" '
end
local sublabelCellString = '\n|' .. classString .. styleString .. '|' .. p.addLabel(childNumber,subLabel)
Line 426 ⟶ 454:
function p.addLabel(childNumber,nodeLabel)
if nodeLabel == "" then
--return '<br/>' --' <br/>' -- remove space to reduce post-expand include size (the width=1.5em handles spacing)
--return
else
-- spaces can cause wrapping and can break tree structure, hence use span with nowrap class
Line 445 ⟶ 469:
--TODO test following alternative
--if nodeLabel:find( "%b<>") then stylingElementDetected = true end
-- we know the no break is handled when using {{clade label}}
if string.find(nodeLabel, '<div style="position:absolute;') then stylingElementDetected = false end
if stylingElementDetected == true then
return '<span class="nowrap">' .. nodeLabel .. '</span>'
else
--local nowrapString = string.gsub(nodeLabel," ", " ") -- replace spaces with non-breaking space
local nowrapString = nodeLabel -- spaces are now handled by CSS "white-space:nowrap;""
if not nowrapString:find("UNIQ.-QINU") then -- unless a strip marker
nowrapString = string.gsub(nowrapString,"-", "‑") -- replace hyphen with non-breaking hyphen (‑)
Line 538 ⟶ 566:
function p.newickConverter(frame)
local newickString = frame.args['newickstring'] or
--if newickString == '{{{newickstring}}}' then return newickString end
Line 556 ⟶ 584:
local resultString = ''
local option =
if option == 'tree' then
--show the transcluded clade diagram
Line 646 ⟶ 674:
local maxPatterns = 5
local i = 0
local pargs =
local pattern = pargs['newick'..tostring(childNumber)..'-pattern'] -- unnumbered option for i=1
local replace = pargs['newick'..tostring(childNumber)..'-replace']
Line 694 ⟶ 722:
while childNumber < maxChildren do -- preprocessing loop
childNumber = childNumber + 1 -- so we start with 1
local nodeLeaf,data =
local newickString =
local listString =
if newickString ~= "" or nodeLeaf ~= "" or listString ~= "" then
--if nodeLeaf ~= "" then
Line 830 ⟶ 858:
function p.listConverter(frame)
local listString = frame.args['list'] or
-- show the list string
Line 843 ⟶ 871:
local resultString = ''
local option =
if option == 'tree' then
--show the transcluded clade diagram
|