{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "data": [ { "name": "source_0", "values": [ {"r": "r1", "c": "c1", "a": "a1", "b": "b1"}, {"r": "r1", "c": "c1", "a": "a2", "b": "b2"}, {"r": "r2", "c": "c2", "a": "a1", "b": "b1"}, {"r": "r3", "c": "c2", "a": "a3", "b": "b2"} ] }, { "name": "cross_column_domain_row_domain", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": ["r", "c"], "fields": ["a", "b"], "ops": ["distinct", "distinct"] } ] }, { "name": "column_domain", "source": "cross_column_domain_row_domain", "transform": [ { "type": "aggregate", "groupby": ["c"], "fields": ["distinct_a"], "ops": ["max"], "as": ["distinct_a"] } ] }, { "name": "row_domain", "source": "cross_column_domain_row_domain", "transform": [ { "type": "aggregate", "groupby": ["r"], "fields": ["distinct_b"], "ops": ["max"], "as": ["distinct_b"] } ] } ], "signals": [ {"name": "child_x_step", "value": 20}, {"name": "child_y_step", "value": 20} ], "layout": { "padding": 20, "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": "r", "orient": "left", "style": "guide-title", "offset": 10 } }, { "name": "column-title", "type": "group", "role": "column-title", "title": {"text": "c", "style": "guide-title", "offset": 10} }, { "name": "row_header", "type": "group", "role": "row-header", "from": {"data": "row_domain"}, "sort": {"field": "datum[\"r\"]", "order": "ascending"}, "title": { "text": { "signal": "isValid(parent[\"r\"]) ? parent[\"r\"] : \"\"+parent[\"r\"]" }, "orient": "left", "style": "guide-label", "frame": "group", "offset": 10 }, "encode": { "update": { "height": { "signal": "bandspace(datum[\"distinct_b\"], 0, 0) * child_y_step" } } } }, { "name": "column_header", "type": "group", "role": "column-header", "from": {"data": "column_domain"}, "sort": {"field": "datum[\"c\"]", "order": "ascending"}, "title": { "text": { "signal": "isValid(parent[\"c\"]) ? parent[\"c\"] : \"\"+parent[\"c\"]" }, "style": "guide-label", "frame": "group", "offset": 10 }, "encode": { "update": { "width": { "signal": "bandspace(datum[\"distinct_a\"], 0, 0) * child_x_step" } } } }, { "name": "cell", "type": "group", "style": "cell", "from": { "facet": { "name": "facet", "data": "source_0", "groupby": ["r", "c"], "aggregate": { "cross": true, "fields": ["a", "b"], "ops": ["distinct", "distinct"], "as": ["distinct_a", "distinct_b"] } } }, "sort": { "field": ["datum[\"r\"]", "datum[\"c\"]"], "order": ["ascending", "ascending"] }, "encode": { "update": { "width": { "signal": "bandspace(datum[\"distinct_a\"], 0, 0) * child_x_step" }, "height": { "signal": "bandspace(datum[\"distinct_b\"], 0, 0) * child_y_step" } } }, "marks": [ { "name": "child_marks", "type": "rect", "style": ["rect"], "from": {"data": "facet"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "description": { "signal": "\"a: \" + (isValid(datum[\"a\"]) ? datum[\"a\"] : \"\"+datum[\"a\"]) + \"; b: \" + (isValid(datum[\"b\"]) ? datum[\"b\"] : \"\"+datum[\"b\"])" }, "x": {"scale": "child_x", "field": "a"}, "width": {"scale": "child_x", "band": 1}, "y": {"scale": "child_y", "field": "b"}, "height": {"scale": "child_y", "band": 1} } } } ], "scales": [ { "name": "child_x", "type": "band", "domain": {"data": "facet", "field": "a", "sort": true}, "range": {"step": {"signal": "child_x_step"}}, "paddingInner": 0, "paddingOuter": 0 }, { "name": "child_y", "type": "band", "domain": {"data": "facet", "field": "b", "sort": true}, "range": {"step": {"signal": "child_y_step"}}, "paddingInner": 0, "paddingOuter": 0 } ], "axes": [ { "scale": "child_x", "orient": "bottom", "grid": false, "title": "a", "labelAlign": "right", "labelAngle": 270, "labelBaseline": "middle", "zindex": 1 }, { "scale": "child_y", "orient": "left", "grid": false, "title": "b", "zindex": 1 } ] } ] }