Module:Weather box/row/sandbox: Difference between revisions

Content deleted Content added
modify convert procedure to limit the output precision for some results
accept input "trace" (should only be provided for precipitation) to display "trace" counted as value 0; text can be set, for example |trace=TR per request at Template talk:Weather box#Suggestion: trace precipitation should show up as "T", not as "—"
Line 3:
local wbc = require( "Module:WeatherBoxColors" )
 
local traceText
local Value
Value = {
lang = mw.getContentLanguage(),
getDisplay = function (self, second)
if not self:isValid() then
return nil
end
local display = self.string
if display == 'trace' then
if second then
-- If a cell displays "cm (inch)", show "trace" not "trace (trace)".
return nil
end
return traceText or 'trace'
end
if math.abs(self.number) >= 1000 then
display = self.lang:formatNum(math.abs(self.number))
Line 37 ⟶ 45:
end,
new = function (v)
local val, str, precision
if type(v) == 'string' then
if v == 'trace' then
val, str = math_mod._cleanNumber(v)
val, str, precision = 0, 'trace', 0
else
val, str = math_mod._cleanNumber(v)
end
elseif type(v) == 'number' then
val, str = v, tostring(v)
Line 49 ⟶ 61:
number = val,
string = str,
precision = precision,
}, Value)
end,
Line 59 ⟶ 72:
setConvert = function (self, invalue, units)
-- Use method modified from [[Module:Convert]] to determine precision.
if invalue.string == 'trace' then
self.number, self.string, self.precision = 0, 'trace', 0
return
end
local convert = self.converts[units] or error('Unknown units')
local outnum = invalue.number * convert.factor
Line 122 ⟶ 139:
table.insert( result, display )
if second_values ~= nil then
display = second_values[i]:getDisplay(true)
if display then
table.insert( result, "<br />(" .. display .. ")" )
Line 306 ⟶ 323:
local metric_first = checkFlag( frame.args['metric first'] or pframe.args['metric first'] )
local single_line = checkFlag( frame.args['single line'] or pframe.args['single line'] )
local trace = pframe.args.trace
if trace and trace ~= '' then
traceText = trace
end
 
if imperial_first == nil then