{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "style": "cell", "data": [ { "name": "source_0", "url": "data/cars.json", "format": {"type": "json"}, "transform": [ { "type": "aggregate", "groupby": ["Origin", "Cylinders"], "ops": ["count"], "fields": [null], "as": ["num_cars"] } ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"num_cars\"]) && isFinite(+datum[\"num_cars\"])" } ] } ], "signals": [ {"name": "x_step", "value": 20}, {"name": "width", "update": "bandspace(domain('x').length, 0, 0) * x_step"}, {"name": "y_step", "value": 20}, {"name": "height", "update": "bandspace(domain('y').length, 0, 0) * y_step"} ], "marks": [ { "name": "layer_0_marks", "type": "rect", "style": ["rect"], "from": {"data": "data_0"}, "encode": { "update": { "fill": {"scale": "color", "field": "num_cars"}, "description": { "signal": "\"Cylinders: \" + (isValid(datum[\"Cylinders\"]) ? datum[\"Cylinders\"] : \"\"+datum[\"Cylinders\"]) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"]) + \"; Count of Records: \" + (format(datum[\"num_cars\"], \"\"))" }, "x": {"scale": "x", "field": "Cylinders"}, "width": {"scale": "x", "band": 1}, "y": {"scale": "y", "field": "Origin"}, "height": {"scale": "y", "band": 1} } } }, { "name": "layer_1_marks", "type": "text", "style": ["text"], "from": {"data": "source_0"}, "encode": { "update": { "fill": [ {"test": "datum['num_cars'] < 40", "value": "black"}, {"value": "white"} ], "description": { "signal": "\"Cylinders: \" + (isValid(datum[\"Cylinders\"]) ? datum[\"Cylinders\"] : \"\"+datum[\"Cylinders\"]) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"]) + \"; num_cars: \" + (format(datum[\"num_cars\"], \"\"))" }, "x": {"scale": "x", "field": "Cylinders", "band": 0.5}, "y": {"scale": "y", "field": "Origin", "band": 0.5}, "text": {"signal": "format(datum[\"num_cars\"], \"\")"}, "align": {"value": "center"}, "baseline": {"value": "middle"} } } } ], "scales": [ { "name": "x", "type": "band", "domain": { "fields": [ {"data": "data_0", "field": "Cylinders"}, {"data": "source_0", "field": "Cylinders"} ], "sort": true }, "range": {"step": {"signal": "x_step"}}, "paddingInner": 0, "paddingOuter": 0 }, { "name": "y", "type": "band", "domain": { "fields": [ {"data": "data_0", "field": "Origin"}, {"data": "source_0", "field": "Origin"} ], "sort": true }, "range": {"step": {"signal": "y_step"}}, "paddingInner": 0, "paddingOuter": 0 }, { "name": "color", "type": "linear", "domain": {"data": "data_0", "field": "num_cars"}, "range": "heatmap", "interpolate": "hcl", "zero": false } ], "axes": [ { "scale": "x", "orient": "bottom", "gridScale": "y", "grid": true, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 1 }, { "scale": "y", "orient": "left", "gridScale": "x", "grid": true, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 1 }, { "scale": "x", "orient": "bottom", "grid": false, "title": "Cylinders", "labelAlign": "right", "labelAngle": 270, "labelBaseline": "middle", "zindex": 1 }, { "scale": "y", "orient": "left", "grid": false, "title": "Origin", "zindex": 1 } ], "legends": [ { "direction": "horizontal", "gradientLength": 120, "title": "Count of Records", "fill": "color" } ], "config": {"axis": {"grid": true, "tickBand": "extent"}} }