Module:Graph: Difference between revisions

Content deleted Content added
updated to latest
Allow omitted data for charts (i.e. y1=1,2,3,4,5,6; y2=, , , , 10, 20). Labels for line charts with a string (ordinal) scale are set at point ___location like for quantitative scales.
Line 5:
-- 2016-01-09 _PLEASE UPDATE when modifying anything_
-- 2016-01-28 For maps, always use wikiraw:// protocol. https:// will be disabled soon.
-- 2016-03-20 Allow omitted data for charts, labels for line charts with string (ordinal) scale at point ___location
 
local p = {}
Line 17 ⟶ 18:
local isInteger = true
for i = 1, #list do
resultif list[i] == tonumber(list"" then result[i]) = nil else
if not result[i] then= return endtonumber(list[i])
if isIntegernot result[i] then return end
if isInteger then
local int, frac = math.modf(result[i])
isInteger = frac == 0.0
{end
end
end
Line 271 ⟶ 274:
}
for i = 1, #y do
local yLen = table.maxn(y[i])
for j = 1, #x do
if j <= #yLen and y[i][j] then table.insert(data.values, { series = seriesTitles[i], x = x[j], y = y[i][j] }) end
end
end
Line 312 ⟶ 316:
else
if xType == "date" then xscale.type = "time"
elseif xType == "string" then
xscale.type = "ordinal" end
xscale.points = true
end
end
 
Line 718 ⟶ 725:
end
end
local y
y, yType, yMin, yMax = deserializeYData(yValues, yType, yMin, yMax)
 
Line 736 ⟶ 743:
chartType = string.sub(chartType, 8)
if #y > 1 then -- ignore stacked charts if there is only one series
stacked = true
-- aggregate data by cumulative y values
stats =
{
name = "stats", source = "chart", transform =
{
{
type = "aggregate",
name = "stats", source = "chart", transform =
groupby = { "x" },
summarize = { y = "sum" }
{
type = "aggregate",
groupby = { "x" },
summarize = { y = "sum" }
}
}
}
}
}
end
end
Line 783 ⟶ 790:
if showValues then
if type(showValues) == "string" then -- deserialize as table
local keyValues = mw.text.split(showValues, "%s*,%s*")
showValues = {}
for _, kv in ipairs(keyValues) do
local key, value = mw.ustring.match(kv, "^%s*(.-)%s*:%s*(.-)%s*$")
if key then showValues[key] = value end
end
end