{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "A simple grid of bar charts to compare performance data.", "background": "white", "padding": 5, "data": [ { "name": "source_0", "values": [ {"a": "a1", "b": "b1", "c": "x", "p": "0.14"}, {"a": "a1", "b": "b1", "c": "y", "p": "0.60"}, {"a": "a1", "b": "b1", "c": "z", "p": "0.03"}, {"a": "a1", "b": "b2", "c": "x", "p": "0.80"}, {"a": "a1", "b": "b2", "c": "y", "p": "0.38"}, {"a": "a1", "b": "b2", "c": "z", "p": "0.55"}, {"a": "a1", "b": "b3", "c": "x", "p": "0.11"}, {"a": "a1", "b": "b3", "c": "y", "p": "0.58"}, {"a": "a1", "b": "b3", "c": "z", "p": "0.79"}, {"a": "a2", "b": "b1", "c": "x", "p": "0.83"}, {"a": "a2", "b": "b1", "c": "y", "p": "0.87"}, {"a": "a2", "b": "b1", "c": "z", "p": "0.67"}, {"a": "a2", "b": "b2", "c": "x", "p": "0.97"}, {"a": "a2", "b": "b2", "c": "y", "p": "0.84"}, {"a": "a2", "b": "b2", "c": "z", "p": "0.90"}, {"a": "a2", "b": "b3", "c": "x", "p": "0.74"}, {"a": "a2", "b": "b3", "c": "y", "p": "0.64"}, {"a": "a2", "b": "b3", "c": "z", "p": "0.19"}, {"a": "a3", "b": "b1", "c": "x", "p": "0.57"}, {"a": "a3", "b": "b1", "c": "y", "p": "0.35"}, {"a": "a3", "b": "b1", "c": "z", "p": "0.49"}, {"a": "a3", "b": "b2", "c": "x", "p": "0.91"}, {"a": "a3", "b": "b2", "c": "y", "p": "0.38"}, {"a": "a3", "b": "b2", "c": "z", "p": "0.91"}, {"a": "a3", "b": "b3", "c": "x", "p": "0.99"}, {"a": "a3", "b": "b3", "c": "y", "p": "0.80"}, {"a": "a3", "b": "b3", "c": "z", "p": "0.37"} ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "stack", "groupby": ["c", "a", "b"], "field": "p", "sort": {"field": [], "order": []}, "as": ["p_start", "p_end"], "offset": "zero" }, { "type": "filter", "expr": "isValid(datum[\"p\"]) && isFinite(+datum[\"p\"])" } ] }, { "name": "column_domain", "source": "data_0", "transform": [{"type": "aggregate", "groupby": ["b"]}] }, { "name": "row_domain", "source": "data_0", "transform": [{"type": "aggregate", "groupby": ["a"]}] } ], "signals": [ {"name": "child_width", "value": 60}, {"name": "y_step", "value": 8}, { "name": "child_height", "update": "bandspace(domain('y').length, 0.1, 0.05) * y_step" } ], "layout": { "padding": 5, "offset": {"rowTitle": 10, "columnTitle": 10}, "columns": {"signal": "length(data('column_domain'))"}, "bounds": "full", "align": "all" }, "marks": [ { "name": "row-title", "type": "group", "role": "row-title", "title": { "text": "Factor A", "orient": "left", "style": "guide-title", "offset": 10 } }, { "name": "column-title", "type": "group", "role": "column-title", "title": {"text": "Factor B", "style": "guide-title", "offset": 10} }, { "name": "row_header", "type": "group", "role": "row-header", "from": {"data": "row_domain"}, "sort": {"field": "datum[\"a\"]", "order": "ascending"}, "title": { "text": { "signal": "isValid(parent[\"a\"]) ? parent[\"a\"] : \"\"+parent[\"a\"]" }, "orient": "left", "style": "guide-label", "frame": "group", "baseline": "middle", "align": "right", "angle": 0, "offset": 10 }, "encode": {"update": {"height": {"signal": "child_height"}}} }, { "name": "column_header", "type": "group", "role": "column-header", "from": {"data": "column_domain"}, "sort": {"field": "datum[\"b\"]", "order": "ascending"}, "title": { "text": { "signal": "isValid(parent[\"b\"]) ? parent[\"b\"] : \"\"+parent[\"b\"]" }, "style": "guide-label", "frame": "group", "offset": 10 }, "encode": {"update": {"width": {"signal": "child_width"}}} }, { "name": "column_footer", "type": "group", "role": "column-footer", "from": {"data": "column_domain"}, "sort": {"field": "datum[\"b\"]", "order": "ascending"}, "encode": {"update": {"width": {"signal": "child_width"}}}, "axes": [ { "scale": "x", "orient": "bottom", "grid": false, "format": "%", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(child_width/40)"}, "zindex": 0 } ] }, { "name": "cell", "type": "group", "style": "cell", "from": { "facet": { "name": "facet", "data": "data_0", "groupby": ["a", "b"], "aggregate": {"cross": true} } }, "sort": { "field": ["datum[\"a\"]", "datum[\"b\"]"], "order": ["ascending", "ascending"] }, "encode": { "update": { "width": {"signal": "child_width"}, "height": {"signal": "child_height"} } }, "marks": [ { "name": "child_marks", "type": "rect", "style": ["bar"], "from": {"data": "facet"}, "encode": { "update": { "fill": {"scale": "color", "field": "c"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"p: \" + (format(datum[\"p\"], \"%\")) + \"; c: \" + (isValid(datum[\"c\"]) ? datum[\"c\"] : \"\"+datum[\"c\"]) + \"; settings: \" + (isValid(datum[\"c\"]) ? datum[\"c\"] : \"\"+datum[\"c\"])" }, "x": {"scale": "x", "field": "p_end"}, "x2": {"scale": "x", "field": "p_start"}, "y": {"scale": "y", "field": "c"}, "height": {"scale": "y", "band": 1} } } } ], "axes": [ { "scale": "x", "orient": "bottom", "gridScale": "y", "grid": true, "tickCount": {"signal": "ceil(child_width/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 } ] } ], "scales": [ { "name": "x", "type": "linear", "domain": {"data": "data_0", "fields": ["p_start", "p_end"]}, "range": [0, {"signal": "child_width"}], "nice": true, "zero": true }, { "name": "y", "type": "band", "domain": {"data": "data_0", "field": "c", "sort": true}, "range": {"step": {"signal": "y_step"}}, "paddingInner": 0.1, "paddingOuter": 0.05 }, { "name": "color", "type": "ordinal", "domain": {"data": "data_0", "field": "c", "sort": true}, "range": "category" } ], "legends": [ { "orient": "bottom", "title": "settings", "titleOrient": "left", "fill": "color", "direction": "horizontal", "symbolType": "square" } ] }