Module:SB tree: Difference between revisions
No edit summary |
Preparing module for use with a template |
||
| Line 104: | Line 104: | ||
return tree | return tree | ||
end | |||
-- Helper function that parses ratios entered as "p/q", returning it as an array { p, q } | |||
function p.parse_ratio(ratio_unparsed) | |||
local ratio = {} | |||
for number in string.gmatch(ratio_unparsed, '([^/]+)') do | |||
table.insert(ratio, number) | |||
end | |||
return ratio | |||
end | end | ||
| Line 109: | Line 118: | ||
-- To try this out, add the following text (not as a lua comment): | -- To try this out, add the following text (not as a lua comment): | ||
-- {{#invoke:SB_tree|sb_table}} | -- {{#invoke:SB_tree|sb_table}} | ||
-- TODO: | -- TODO: toggle whether the table is staggered | ||
function p.sb_table(frame) | function p.sb_table(frame) | ||
-- Call the sb function | -- Call the sb function | ||
-- Start/stop ratios are the same, depth is deeper, and edge-extend is allowed | -- Start/stop ratios are the same, depth is deeper, and edge-extend is allowed | ||
local depth = 4 | local depth = frame.args['Depth'] or 4 | ||
local edge_extend = 1 | local edge_extend = frame.args['Edge Extend'] or 2 | ||
local start_ratio_unparsed = frame.args['Start Ratio'] or "1/1" | |||
local stop_ratio_unparsed = frame.args['Stop Ratio'] or "1/0" | |||
-- Parse ratios | |||
local start_ratio = p.parse_ratio(start_ratio_unparsed) | |||
local stop_ratio = p.parse_ratio(stope_ratio_unparsed) | |||
-- Get the ratios and depths | |||
local sb_tree_depths = p.sb_tree_depths(depth, edge_extend) | local sb_tree_depths = p.sb_tree_depths(depth, edge_extend) | ||
local sb_tree_ratios = p.sb_tree_ratios(depth, | local sb_tree_ratios = p.sb_tree_ratios(depth, start_ratio, stop_ratio, edge_extend) | ||
-- Create the table | -- Create the table | ||