Module

x/vega_lite/examples/compiled/test_aggregate_nested.vg.json

A concise grammar of interactive graphics, built on Vega.
Latest
File
{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "width": 200, "style": "cell", "data": [ { "name": "source_0", "values": { "features": [ { "properties": { "variety": "Manchuria", "yield": 27, "site": "University Farm" } }, { "properties": { "variety": "Wisconsin No. 38", "yield": 29.33333, "site": "Duluth" } } ], "type": "FeatureCollection" }, "format": {"type": "json", "property": "features"} }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "formula", "expr": "datum[\"properties\"] && datum[\"properties\"][\"variety\"]", "as": "properties.variety" }, { "type": "formula", "expr": "datum[\"properties\"] && datum[\"properties\"][\"yield\"]", "as": "properties.yield" }, { "type": "formula", "expr": "datum[\"properties\"] && datum[\"properties\"][\"site\"]", "as": "properties.site" }, { "type": "aggregate", "groupby": ["properties\\.variety", "properties\\.site"], "ops": ["sum"], "fields": ["properties\\.yield"], "as": ["sum_properties.yield"] }, { "type": "stack", "groupby": ["properties\\.variety"], "field": "sum_properties\\.yield", "sort": {"field": ["properties\\.site"], "order": ["ascending"]}, "as": ["sum_properties.yield_start", "sum_properties.yield_end"], "offset": "zero" }, { "type": "filter", "expr": "isValid(datum[\"sum_properties.yield\"]) && isFinite(+datum[\"sum_properties.yield\"])" } ] } ], "signals": [ {"name": "y_step", "value": 20}, { "name": "height", "update": "bandspace(domain('y').length, 0.1, 0.05) * y_step" } ], "marks": [ { "name": "marks", "type": "rect", "style": ["bar"], "from": {"data": "data_0"}, "encode": { "update": { "fill": {"scale": "color", "field": "properties\\.site"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"properties.variety: \" + (isValid(datum[\"properties.variety\"]) ? datum[\"properties.variety\"] : \"\"+datum[\"properties.variety\"]) + \"; Sum of properties.yield: \" + (format(datum[\"sum_properties.yield\"], \"\")) + \"; site: \" + (isValid(datum[\"properties.site\"]) ? datum[\"properties.site\"] : \"\"+datum[\"properties.site\"])" }, "x": {"scale": "x", "field": "sum_properties\\.yield_end"}, "x2": {"scale": "x", "field": "sum_properties\\.yield_start"}, "y": {"scale": "y", "field": "properties\\.variety"}, "height": {"scale": "y", "band": 1} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": { "data": "data_0", "fields": ["sum_properties\\.yield_start", "sum_properties\\.yield_end"] }, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "band", "domain": { "data": "data_0", "field": "properties\\.variety", "sort": true }, "range": {"step": {"signal": "y_step"}}, "paddingInner": 0.1, "paddingOuter": 0.05 }, { "name": "color", "type": "ordinal", "domain": {"data": "data_0", "field": "properties\\.site", "sort": true}, "range": "category" } ], "axes": [ { "scale": "x", "orient": "bottom", "gridScale": "y", "grid": true, "tickCount": {"signal": "ceil(width/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "x", "orient": "bottom", "grid": false, "title": "Sum of properties.yield", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "properties.variety", "zindex": 0 } ], "legends": [{"title": "site", "fill": "color", "symbolType": "square"}]}