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 = "
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 = "
as = { "zipped" },
default
}
}
Line 158 ⟶ 159:
properties =
{
enter = { path = { field = "
update = { fill = { field = "zipped
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 = {
{
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 = "
}
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 = "
else
yscale.___domain = { data = "chart", field = "
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 = "
}
xscale.padding = 0.2 -- pad each bar group
Line 328 ⟶ 334:
enter =
{
x = { scale = "x", field = "
y = { scale = "y", field = "
},
-- chart update event handler
Line 337 ⟶ 343:
}
}
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 = "
else
--[[
Line 361 ⟶ 371:
if not stacked and #y > 1 then
marks.properties.enter.x.scale = "series"
marks.properties.enter.x.field = "
marks.properties.enter.width.scale = "series"
end
end
-- stacked charts have their own (stacked) y values
if stacked then marks.properties.enter.y.field = "
-- 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 = "
if alphaScale then marks.properties.update[colorField .. "Opacity"].field = "
-- apply a grouping (facetting) transformation
marks =
Line 387 ⟶ 397:
{
type = "facet",
}
}
Line 394 ⟶ 404:
-- for stacked charts apply a stacking transformation
if stacked then
table.insert( marks.from.transform
else
-- for bar charts the series are side-by-side grouped by x
if type == "rect" then
marks.from.transform[1].
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,
|