Module:Graph: Difference between revisions

Content deleted Content added
m 1 revision imported
m 1 revision imported
 
(One intermediate revision by one other user not shown)
Line 13:
-- - arbitrary SVG path symbol shape as symbolsShape argument
-- - annotations
-- - vertical / horizontal line at specific values [DONE] 2020-09-01
-- - rectangle shape for x,y data range
-- - graph type serialization (deep rebuild reqired)
Line 19:
 
-- Version History (_PLEASE UPDATE when modifying anything_):
-- 2020-09-01 Vertical and horizontal line annotations
-- 2020-08-08 New logic for "nice" for x axis (problem with scale when xType = "date") and grid
-- 2020-06-21 Serializes symbol size
Line 397 ⟶ 398:
{
name = "y",
--type = yScaleType or "linear",
range = "height",
-- area charts have the lower boundary of their filling at y=0 (see marks.properties.enter.y2), therefore these need to start at zero
Line 797 ⟶ 799:
return symbolmarks
end
 
local function getAnnoMarks(chartvis, stroke, fill, opacity)
 
local vannolines, hannolines, vannoLabels, vannoLabels
vannolines =
{
type = "rule",
from = { data = "v_anno" },
properties =
{
update =
{
x = { scale = "x", field = "x" },
y = { value = 0 },
y2 = { field = { group = "height" } },
strokeWidth = { value = stroke },
stroke = { value = persistentGrey },
opacity = { value = opacity }
}
}
}
vannolabels =
{
type = "text",
from = { data = "v_anno" },
properties =
{
update =
{
x = { scale = "x", field = "x", offset = 3 },
y = { field = { group = "height" }, offset = -3 },
text = { field = "label" },
baseline = { value = "top" },
angle = { value = -90 },
fill = { value = persistentGrey },
opacity = { value = opacity }
}
}
}
hannolines =
{
type = "rule",
from = { data = "h_anno" },
properties =
{
update =
{
y = { scale = "y", field = "y" },
x = { value = 0 },
x2 = { field = { group = "width" } },
strokeWidth = { value = stroke },
stroke = { value = persistentGrey },
opacity = { value = opacity }
}
}
}
hannolabels =
{
type = "text",
from = { data = "h_anno" },
properties =
{
update =
{
y = { scale = "y", field = "y", offset = 3 },
x = { value = 0 , offset = 3 },
text = { field = "label" },
baseline = { value = "top" },
angle = { value = 0 },
fill = { value = persistentGrey },
opacity = { value = opacity }
}
}
}
return vannolines, vannolabels, hannolines, hannolabels
end
 
Line 802 ⟶ 880:
local xAxis, yAxis
if chartType ~= "pie" then
if xType == "integer" and not xAxisFormat then xAxisFormat = "d" end
-- if not xAxisFormat then xAxisFormat = "d" end
xAxis =
{
Line 868 ⟶ 945:
end
 
if yType == "integer" and not yAxisFormat then yAxisFormat = "d" end
if not yAxisFormat then yAxisFormat = "d" end
yAxis =
{
Line 984 ⟶ 1,060:
-- if not yType then yType = "number" end
-- end
 
 
-- show grid
Line 999 ⟶ 1,073:
-- show values as text
local showValues = frame.args.showValues or frame.args.showvalues
-- show v- and h-line annotations
local v_annoLineString = frame.args.vAnnotatonsLine or frame.args.vannotatonsline
local h_annoLineString = frame.args.hAnnotatonsLine or frame.args.hannotatonsline
local v_annoLabelString = frame.args.vAnnotatonsLabel or frame.args.vannotatonslabel
local h_annoLabelString = frame.args.hAnnotatonsLabel or frame.args.hannotatonslabel
 
 
 
 
 
-- decode annotations cvs
local v_annoLine, v_annoLabel, h_annoLine, h_annoLabel
if v_annoLineString and v_annoLineString ~= "" then
 
if xType == "number" or xType == "integer" then
v_annoLine = numericArray(v_annoLineString)
 
else
v_annoLine = stringArray(v_annoLineString)
 
end
v_annoLabel = stringArray(v_annoLabelString)
end
if h_annoLineString and h_annoLineString ~= "" then
 
if yType == "number" or yType == "integer" then
h_annoLine = numericArray(h_annoLineString)
 
else
h_annoLine = stringArray(h_annoLineString)
 
end
h_annoLabel = stringArray(h_annoLabelString)
end
 
 
 
 
 
-- pie chart radiuses
local innerRadius = tonumber(frame.args.innerRadius) or tonumber(frame.args.innerradius) or 0
Line 1,054 ⟶ 1,167:
end
end
-- add annotations to data
local vannoData, hannoData
if v_annoLine then
vannoData = { name = "v_anno", format = { type = "json", parse = { x = xType } }, values = {} }
for i = 1, #v_annoLine do
local item = { x = v_annoLine[i], label = v_annoLabel[i] }
table.insert(vannoData.values, item)
end
end
if h_annoLine then
hannoData = { name = "h_anno", format = { type = "json", parse = { y = yType } }, values = {} }
for i = 1, #h_annoLine do
local item = { y = h_annoLine[i], label = h_annoLabel[i] }
table.insert(hannoData.values, item)
end
end
 
 
-- create scales
Line 1,084 ⟶ 1,216:
local colorField
if chartType == "line" then colorField = "stroke" else colorField = "fill" end
 
 
 
-- create chart markings
Line 1,129 ⟶ 1,263:
-- symbol marks
if showSymbols and chartType ~= "rect" then
local chartmarks = chartvis
if chartmarks.marks then chartmarks = chartmarks.marks[1] end
Line 1,225 ⟶ 1,359:
table.insert(marks, symbolmarks)
end
end
 
 
local vannolines, vannolabels, hannolines, hannolabels = getAnnoMarks(chartmarks, persistentGrey, persistentGrey, 0.75)
if vannoData then
table.insert(marks, vannolines)
table.insert(marks, vannolabels)
end
if hannoData then
table.insert(marks, hannolines)
table.insert(marks, hannolabels)
end
 
Line 1,239 ⟶ 1,384:
width = graphwidth,
height = graphheight,
data = { data, stats },
scales = scales,
axes = { xAxis, yAxis },
Line 1,245 ⟶ 1,390:
legends = { legend }
}
if vannoData then table.insert(output.data, vannoData) end
if hannoData then table.insert(output.data, hannoData) end
if stats then table.insert(output.data, stats) end
 
local flags