Module:Step vis: Difference between revisions
Jump to navigation
Jump to search
ArrowHead294 (talk | contribs) +Yesno module |
m an underscore |
||
| (7 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
local tip = require("Module:Template input parse") | local tip = require("Module:Template input parse") | ||
local yesno = require("Module:Yesno") | local yesno = require("Module:Yesno") | ||
local p = {} | local p = {} | ||
-- Helper function | -- Helper function | ||
-- Create a step visualization | -- Create a step visualization | ||
function p. | function p._step_vis(step_pattern) | ||
local step_pattern = step_pattern or { 5, 2, 5, 0, 5, 2, 0 } | local step_pattern = step_pattern or { 5, 2, 5, 0, 5, 2, 0 } | ||
local left_border = | local left_border = "├" -- U+251C ├ | ||
local right_border = | local right_border = "┤" -- U+2524 ┤ | ||
local no_border = | local no_border = "─" -- U+2500 ─ | ||
local double_border = | local double_border = "╫" -- U+256B ╫ | ||
local double_border_left = | local double_border_left = "╟" -- U+255F ╟ | ||
local double_border_right = | local double_border_right = "╢" -- U+2562 ╢ | ||
local single_border = | local single_border = "┼" -- U+253C ┼ | ||
local step_visualization = "" | local step_visualization = "" | ||
| Line 42: | Line 42: | ||
of a 4-digit code point is 8 characters long, so removing the last box-drawing character means | of a 4-digit code point is 8 characters long, so removing the last box-drawing character means | ||
removing the last 8 characters representing it, between indices -1 and -9 | removing the last 8 characters representing it, between indices -1 and -9 | ||
- This removes the double centre border at the end if the second-to-last and last steps are both 0 | - This removes the double centre border at the end if the second-to-last and last steps are both 0. | ||
]]-- | ]]-- | ||
step_visualization = | step_visualization = string.sub(step_visualization, 1, -9) | ||
end | end | ||
current_step_vis = double_border_right | current_step_vis = double_border_right | ||
| Line 76: | Line 76: | ||
-- Wrapper function for step visualization | -- Wrapper function for step visualization | ||
function p. | function p.step_vis(frame) | ||
local step_pattern = tip.parse_numeric_entries(frame.args["Step Pattern"], " ") | local step_pattern = tip.parse_numeric_entries(frame.args["Step Pattern"], " ") | ||
local debugg = yesno(frame.args["debug"]) | local debugg = yesno(frame.args["debug"]) | ||
local result = p._step_vis(step_pattern) | |||
-- Debugger option | |||
if debugg == true then | |||
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" | |||
end | |||
return frame:preprocess(result) | |||
end | end | ||
return p | return p | ||
Latest revision as of 04:19, 4 July 2025
- This module may be invoked by templates using its corresponding template Template:Step vis, or used directly from other modules.
Generates a visual representation of a scale based on predefined step sizes.
| Introspection summary for Module:Step vis | |||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||||||||
No function descriptions were provided. The Lua code may have further information.
local tip = require("Module:Template input parse")
local yesno = require("Module:Yesno")
local p = {}
-- Helper function
-- Create a step visualization
function p._step_vis(step_pattern)
local step_pattern = step_pattern or { 5, 2, 5, 0, 5, 2, 0 }
local left_border = "├" -- U+251C ├
local right_border = "┤" -- U+2524 ┤
local no_border = "─" -- U+2500 ─
local double_border = "╫" -- U+256B ╫
local double_border_left = "╟" -- U+255F ╟
local double_border_right = "╢" -- U+2562 ╢
local single_border = "┼" -- U+253C ┼
local step_visualization = ""
local previous_step_size = 0
--[[
- For each step size of k, print a single border, followed by k-1 no-border symbols
- If this is the first step, print the left border instead
- If the step size is 0, print a double border only; if this happens, the next step should start with a border character
- If this is the last step, add a right border after the entire sequence
]]--
for i = 1, #step_pattern do
local current_step_vis = ""
local current_step_size = step_pattern[i]
if i == 1 then
-- Start of string
current_step_vis = (current_step_size == 0 and double_border_left or left_border .. string.rep(no_border, current_step_size - 1))
elseif i == #step_pattern then
-- End of string
if current_step_size == 0 then
-- If the last step size is 0, the last character will be a double right border
if (previous_step_size == 0) then
--[[
- The beginning of a string is index 1 in the first argument of string.sub
- The end of the string is index -1 in the second argument of string.sub, and an ampersand version
of a 4-digit code point is 8 characters long, so removing the last box-drawing character means
removing the last 8 characters representing it, between indices -1 and -9
- This removes the double centre border at the end if the second-to-last and last steps are both 0.
]]--
step_visualization = string.sub(step_visualization, 1, -9)
end
current_step_vis = double_border_right
else
-- If the last step size is not 0, add a single border, then add the horizontal bar and right border
if previous_step_size ~= 0 then
current_step_vis = current_step_vis .. single_border
end
current_step_vis = current_step_vis .. string.rep(no_border, current_step_size - 1) .. right_border
end
else
-- Steps in between
if current_step_size == 0 and previous_step_size ~= 0 then
-- Zero-size steps that are not first or last
current_step_vis = double_border
else
-- Other non-zero step sizes
if step_pattern[i - 1] ~= 0 then
current_step_vis = current_step_vis .. single_border
end
current_step_vis = current_step_vis .. string.rep(no_border, current_step_size - 1)
end
end
step_visualization = step_visualization .. current_step_vis
previous_step_size = current_step_size
end
return step_visualization
end
-- Wrapper function for step visualization
function p.step_vis(frame)
local step_pattern = tip.parse_numeric_entries(frame.args["Step Pattern"], " ")
local debugg = yesno(frame.args["debug"])
local result = p._step_vis(step_pattern)
-- Debugger option
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
return p