Difference between revisions of "Module:Clade/labels"

From blackwiki
Jump to navigation Jump to search
blackwiki>Jts1882
(add width and nowrap)
blackwiki>Jts1882
(add separate color parameter)
Line 20: Line 20:
 
     local bottomStyle = args['bottom']
 
     local bottomStyle = args['bottom']
 
     ]]
 
     ]]
 +
    -- parameters for all labels
 
     local width = args['width'] -- or "5em;"
 
     local width = args['width'] -- or "5em;"
 +
    --local style = args['style'] or ""
 +
    --local color = args['width'] or ""
 +
   
 
     local longestString = 0
 
     local longestString = 0
 
      
 
      
Line 29: Line 33:
 
     
 
     
 
    local style  = args['style'..i]  or args['style']  or ""   
 
    local style  = args['style'..i]  or args['style']  or ""   
 +
    local color  = args['color'..i]  or args['color']  or "" 
 
    local top    = args['top'..i]    or args['top']    or ""
 
    local top    = args['top'..i]    or args['top']    or ""
 
    local left  = args['left'..i]  or args['left']  or ""
 
    local left  = args['left'..i]  or args['left']  or ""
Line 37: Line 42:
 
    if right ~= ""  then right  = 'right:'  .. right  .. ';' end   
 
    if right ~= ""  then right  = 'right:'  .. right  .. ';' end   
 
    if bottom ~= "" then bottom = 'bottom:'  .. bottom .. ';' end  
 
    if bottom ~= "" then bottom = 'bottom:'  .. bottom .. ';' end  
    local position = top .. left .. right .. bottom
+
    --local position = top .. left .. right .. bottom
 
     
 
     
output = output .. '<div style="position:absolute;white-space:nowrap;' .. style .. position .. '">' .. label .. '</div>'
+
output = output .. '<div style="position:absolute;white-space:nowrap;'  
--background-color:#ffccff;top:75%;">
+
                .. style .. color                                      -- CSS styling
 +
                .. top .. left .. right .. bottom .. '">'               -- position of label
 +
                .. label                                               -- content of label
 +
                .. '</div>'
 
i=i+1
 
i=i+1
 
end
 
end

Revision as of 13:19, 10 November 2019

Documentation for this module may be created at Module:Clade/labels/doc

local p = {}

--local args =frame:getParent().args  -- get parent arguments
--local args = {}

p.getArgs = function(frame) 
	--return frame.args              -- use frame arguments
	return frame:getParent().args  -- use parent arguments
end
p.main = function(frame)
     
    args = p.getArgs(frame) 
    
    local i = 1                     -- index for labels
    local output = ""
    --[[local groupStyle = args['style']
    local topStyle = args['top']
    local leftStyle = args['left']
    local rightStyle = args['right']
    local bottomStyle = args['bottom']
    ]]
    -- parameters for all labels
    local width = args['width'] -- or "5em;"
    --local style = args['style'] or ""
    --local color = args['width'] or ""
    
    local longestString = 0
    
    while  args['label'..i] do
    	
	    local label = args['label'..i]     or ""
	    if #label > longestString then longestString = #label end
	    
	    local style  = args['style'..i]  or args['style']  or ""  
	    local color  = args['color'..i]  or args['color']  or ""  
	    local top    = args['top'..i]    or args['top']    or ""
	    local left   = args['left'..i]   or args['left']   or ""
	    local right  = args['right'..i]  or args['right']  or ""
	    local bottom = args['bottom'..i] or args['bottom'] or ""
	    if top ~= ""    then top    = 'top:'     .. top    .. ';' end  
	    if left ~= ""   then left   = 'left:'    .. left   .. ';' end  
	    if right ~= ""  then right  = 'right:'   .. right  .. ';' end  
	    if bottom ~= "" then bottom = 'bottom:'  .. bottom .. ';' end 
	    --local position = top .. left .. right .. bottom
	    
		output = output .. '<div style="position:absolute;white-space:nowrap;' 
		                .. style .. color                                       -- CSS styling
		                .. top .. left .. right .. bottom .. '">'               -- position of label
		                .. label                                                -- content of label
		                .. '</div>'
		i=i+1
	end
	if output ~= "" then
		local styleStr = ""
		--widthStr = 'width:' .. (longestString*0.5)..'em;' -- can't take account of formatting or <br/>
		if width then styleStr = 'style="width:' .. width .. '"' end
 		
		output = '<div ' .. styleStr ..'>' .. output .. '</div>'
	end
	return output
end

return p