Jump to content

Module:Graph: Difference between revisions

Undid revision 1141810373 by Frietjes (talk)
m (1 revision imported)
(Undid revision 1141810373 by Frietjes (talk))
Line 13: Line 13:
-- - arbitrary SVG path symbol shape as symbolsShape argument
-- - arbitrary SVG path symbol shape as symbolsShape argument
-- - annotations
-- - annotations
-- - vertical / horizontal line at specific values  
-- - vertical / horizontal line at specific values [DONE] 2020-09-01
-- - rectangle shape for x,y data range
-- - rectangle shape for x,y data range
-- - graph type serialization (deep rebuild reqired)
-- - graph type serialization (deep rebuild reqired)
Line 19: Line 19:


-- Version History (_PLEASE UPDATE when modifying anything_):
-- 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-08-08 New logic for "nice" for x axis (problem with scale when xType = "date") and grid
--  2020-06-21 Serializes symbol size
--  2020-06-21 Serializes symbol size
Line 397: Line 398:
{
{
name = "y",
name = "y",
--type = yScaleType or "linear",
range = "height",
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
-- 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: Line 799:
      
      
return symbolmarks
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
end


Line 802: Line 880:
local xAxis, yAxis
local xAxis, yAxis
if chartType ~= "pie" then
if chartType ~= "pie" then
if xType == "integer" then xAxisFormat = "d" end
if xType == "integer" and not xAxisFormat then xAxisFormat = "d" end
-- if not xAxisFormat then xAxisFormat = "d" end
xAxis =
xAxis =
{
{
Line 868: Line 945:
end
end


if yType == "integer" then yAxisFormat = "d" end
if yType == "integer" and not yAxisFormat then yAxisFormat = "d" end
if not yAxisFormat then yAxisFormat = "d" end
yAxis =
yAxis =
{
{
Line 984: Line 1,060:
-- if not yType then yType = "number" end
-- if not yType then yType = "number" end
-- end
-- end


-- show grid
-- show grid
Line 999: Line 1,073:
-- show values as text
-- show values as text
local showValues = frame.args.showValues or frame.args.showvalues  
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
-- pie chart radiuses
local innerRadius = tonumber(frame.args.innerRadius) or tonumber(frame.args.innerradius) or 0
local innerRadius = tonumber(frame.args.innerRadius) or tonumber(frame.args.innerradius) or 0
Line 1,054: Line 1,167:
end
end
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
-- create scales
Line 1,084: Line 1,216:
local colorField
local colorField
if chartType == "line" then colorField = "stroke" else colorField = "fill" end
if chartType == "line" then colorField = "stroke" else colorField = "fill" end


-- create chart markings
-- create chart markings
Line 1,129: Line 1,263:
      
      
-- symbol marks
-- symbol marks
if showSymbols and chartType ~= "rect" then
if showSymbols and chartType ~= "rect" then
local chartmarks = chartvis
local chartmarks = chartvis
if chartmarks.marks then chartmarks = chartmarks.marks[1] end
if chartmarks.marks then chartmarks = chartmarks.marks[1] end
Line 1,225: Line 1,359:
table.insert(marks, symbolmarks)
table.insert(marks, symbolmarks)
end
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
end


Line 1,239: Line 1,384:
width = graphwidth,
width = graphwidth,
height = graphheight,
height = graphheight,
data = { data, stats },
data = { data },
scales = scales,
scales = scales,
axes = { xAxis, yAxis },
axes = { xAxis, yAxis },
Line 1,245: Line 1,390:
legends = { legend }
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
local flags
Anonymous user