Module:Graph: Difference between revisions

Content deleted Content added
m 13 revisions imported from de:Modul:Graph
updated graphs to vega 2.0
Line 67:
name = "color",
type = scaleType,
___domain = { data = "highlights", field = "data.v" },
range = colorScale,
nice = true
Line 114:
local output =
{
version = 2,
width = 1, -- generic value as output size depends solely on map size and scaling factor
height = 1, -- ditto
Line 140 ⟶ 141:
{
-- join ("zip") of mutiple data source: here map paths data and highlights
type = "ziplookup",
keykeys = { "data.id" }, -- key for map paths data
withon = "highlights", -- name of highlight data source
withKeyonKey = "data.id", -- key for highlight data source
as = { "zipped" }, -- name of resulting table
default = { data = { v = defaultValue } } -- default value for geographic objects that could not be joined
}
}
Line 158 ⟶ 159:
properties =
{
enter = { path = { field = "pathlayout_path" } },
update = { fill = { field = "zipped.data.v" } },
hover = { fill = { value = "darkgrey" } }
}
Line 187 ⟶ 188:
-- mark colors (if no colors are given, the default 10 color palette is used)
local colors = stringArray(frame.args.colors) or "category10"
-- for line charts, the thickness of the line (strokeWidth)
local linewidth = tonumber(frame.args.linewidth) or 2.5
-- x and y axis caption
local xTitle = frame.args.xAxisTitle
Line 237 ⟶ 240:
stats =
{
name = "stats", source = "chart", transform = {
{
{ type = "facetaggregate", keys = { "data.x" } },
{ type groupby = "stats", value ={ "data.yx" },
summarize = { y = "sum" }
}
}
}
Line 254 ⟶ 259:
zero = false, -- do not include zero value
nice = true, -- force round numbers for y scale
___domain = { data = "chart", field = "data.x" }
}
if xMin then xscale.domainMin = xMin end
Line 274 ⟶ 279:
if yMin or yMax then yscale.clamp = true end
if stacked then
yscale.___domain = { data = "stats", field = "sumsum_y" }
else
yscale.___domain = { data = "chart", field = "data.y" }
end
local colorScale =
Line 282 ⟶ 287:
name = "color",
type = "ordinal",
range = colors,
___domain = { data = "chart", field = "series" }
}
local alphaScale
Line 310 ⟶ 316:
type = "ordinal",
range = "width",
___domain = { field = "data.series" }
}
xscale.padding = 0.2 -- pad each bar group
Line 328 ⟶ 334:
enter =
{
x = { scale = "x", field = "data.x" },
y = { scale = "y", field = "data.y" }
},
-- chart update event handler
Line 337 ⟶ 343:
}
}
marks.properties.update[if colorField] = { scale = "colorstroke" }then
marks.properties.enter["strokeWidth"] = { value = linewidth }
end
marks.properties.enter[colorField] = { scale = "color", field = "series" }
marks.properties.update[colorField] = { scale = "color", field = "series" }
marks.properties.hover[colorField] = { value = "red" }
if alphaScale then marks.properties.update[colorField .. "Opacity"] = { scale = "transparency" } end
Line 344 ⟶ 354:
if stacked then
-- for stacked charts this lower bound is cumulative/stacking
marks.properties.enter.y2 = { scale = "y", field = "y2layout_end" }
else
--[[
Line 361 ⟶ 371:
if not stacked and #y > 1 then
marks.properties.enter.x.scale = "series"
marks.properties.enter.x.field = "data.series"
marks.properties.enter.width.scale = "series"
end
end
-- stacked charts have their own (stacked) y values
if stacked then marks.properties.enter.y.field = "ylayout_start" end
-- set interpolation mode
Line 373 ⟶ 383:
if #y == 1 then marks.from = { data = "chart" } else
-- if there are multiple series, connect colors to series
marks.properties.update[colorField].field = "data.series"
if alphaScale then marks.properties.update[colorField .. "Opacity"].field = "data.series" end
-- apply a grouping (facetting) transformation
marks =
Line 387 ⟶ 397:
{
type = "facet",
keysgroupby = { "data.series" }
}
}
Line 394 ⟶ 404:
-- for stacked charts apply a stacking transformation
if stacked then
table.insert( marks.from.transform[2], =1, { type = "stack", pointgroupby = { "data.x" }, heightsortby = { "series" }, field = "data.y" } )
else
-- for bar charts the series are side-by-side grouped by x
if type == "rect" then
marks.from.transform[1].keysgroupby = "data.x"
marks.scales = { groupScale }
marks.properties = { enter = { x = { field = "key", scale = "x" }, width = { scale = "x", band = true } } }
Line 420 ⟶ 430:
local output =
{
version = 2,
width = graphwidth,
height = graphheight,