{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "data": [ {"name": "brush_store"}, {"name": "source_0", "url": "data/cars.json", "format": {"type": "json"}}, { "name": "data_0", "source": "source_0", "transform": [ { "type": "filter", "expr": "!length(data(\"brush_store\")) || vlSelectionTest(\"brush_store\", datum)" } ] }, { "name": "data_1", "source": "data_0", "transform": [ { "type": "aggregate", "groupby": ["Name"], "ops": ["count"], "fields": [null], "as": ["__count"] } ] }, { "name": "data_2", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": ["Name"], "ops": ["count"], "fields": [null], "as": ["__count"] } ] } ], "signals": [ {"name": "concat_0_width", "value": 200}, {"name": "concat_0_y_step", "value": 20}, { "name": "concat_0_height", "update": "bandspace(domain('concat_0_y').length, 0.1, 0.05) * concat_0_y_step" }, {"name": "concat_1_width", "value": 50}, {"name": "concat_1_height", "value": 200}, { "name": "unit", "value": {}, "on": [ {"events": "mousemove", "update": "isTuple(group()) ? group() : unit"} ] }, { "name": "brush", "update": "vlSelectionResolve(\"brush_store\", \"union\")" } ], "layout": {"padding": 20, "bounds": "full", "align": "each"}, "marks": [ { "type": "group", "name": "concat_0_group", "style": "cell", "encode": { "update": { "width": {"signal": "concat_0_width"}, "height": {"signal": "concat_0_height"} } }, "marks": [ { "name": "concat_0_marks", "type": "rect", "style": ["bar"], "interactive": false, "from": {"data": "data_1"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"Count of Records: \" + (format(datum[\"__count\"], \"\")) + \"; Name: \" + (isValid(datum[\"Name\"]) ? datum[\"Name\"] : \"\"+datum[\"Name\"])" }, "x": {"scale": "concat_0_x", "field": "__count"}, "x2": {"scale": "concat_0_x", "value": 0}, "y": {"scale": "concat_0_y", "field": "Name"}, "height": {"scale": "concat_0_y", "band": 1} } } } ], "axes": [ { "scale": "concat_0_x", "orient": "top", "gridScale": "concat_0_y", "grid": true, "tickCount": {"signal": "ceil(concat_0_width/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "concat_0_x", "orient": "top", "grid": false, "title": "Count of Records", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(concat_0_width/40)"}, "zindex": 0 }, { "scale": "concat_0_y", "orient": "left", "grid": false, "minExtent": 200, "zindex": 0 } ] }, { "type": "group", "name": "concat_1_group", "style": "cell", "encode": { "update": { "width": {"signal": "concat_1_width"}, "height": {"signal": "concat_1_height"} } }, "signals": [ { "name": "brush_y", "value": [], "on": [ { "events": { "source": "scope", "type": "mousedown", "filter": [ "!event.item || event.item.mark.name !== \"brush_brush\"" ] }, "update": "[y(unit), y(unit)]" }, { "events": { "source": "window", "type": "mousemove", "consume": true, "between": [ { "source": "scope", "type": "mousedown", "filter": [ "!event.item || event.item.mark.name !== \"brush_brush\"" ] }, {"source": "window", "type": "mouseup"} ] }, "update": "[brush_y[0], clamp(y(unit), 0, concat_1_height)]" }, {"events": {"signal": "brush_scale_trigger"}, "update": "[0, 0]"}, { "events": [{"source": "view", "type": "dblclick"}], "update": "[0, 0]" }, { "events": {"signal": "brush_translate_delta"}, "update": "clampRange(panLinear(brush_translate_anchor.extent_y, brush_translate_delta.y / span(brush_translate_anchor.extent_y)), 0, concat_1_height)" }, { "events": {"signal": "brush_zoom_delta"}, "update": "clampRange(zoomLinear(brush_y, brush_zoom_anchor.y, brush_zoom_delta), 0, concat_1_height)" } ] }, { "name": "brush_Name", "on": [ { "events": {"signal": "brush_y"}, "update": "brush_y[0] === brush_y[1] ? null : invert(\"concat_1_y\", brush_y)" } ] }, { "name": "brush_scale_trigger", "value": {}, "on": [ { "events": [{"scale": "concat_1_y"}], "update": "(!isArray(brush_Name) || (invert(\"concat_1_y\", brush_y)[0] === brush_Name[0] && invert(\"concat_1_y\", brush_y)[1] === brush_Name[1])) ? brush_scale_trigger : {}" } ] }, { "name": "brush_tuple", "on": [ { "events": [{"signal": "brush_Name"}], "update": "brush_Name ? {unit: \"concat_1\", fields: brush_tuple_fields, values: [brush_Name]} : null" } ] }, { "name": "brush_tuple_fields", "value": [{"field": "Name", "channel": "y", "type": "E"}] }, { "name": "brush_translate_anchor", "value": {}, "on": [ { "events": [ { "source": "scope", "type": "mousedown", "markname": "brush_brush" } ], "update": "{x: x(unit), y: y(unit), extent_y: slice(brush_y)}" } ] }, { "name": "brush_translate_delta", "value": {}, "on": [ { "events": [ { "source": "window", "type": "mousemove", "consume": true, "between": [ { "source": "scope", "type": "mousedown", "markname": "brush_brush" }, {"source": "window", "type": "mouseup"} ] } ], "update": "{x: brush_translate_anchor.x - x(unit), y: brush_translate_anchor.y - y(unit)}" } ] }, { "name": "brush_zoom_anchor", "on": [ { "events": [ { "source": "scope", "type": "wheel", "consume": true, "markname": "brush_brush" } ], "update": "{x: x(unit), y: y(unit)}" } ] }, { "name": "brush_zoom_delta", "on": [ { "events": [ { "source": "scope", "type": "wheel", "consume": true, "markname": "brush_brush" } ], "force": true, "update": "pow(1.001, event.deltaY * pow(16, event.deltaMode))" } ] }, { "name": "brush_modify", "on": [ { "events": {"signal": "brush_tuple"}, "update": "modify(\"brush_store\", brush_tuple, true)" } ] } ], "marks": [ { "name": "brush_brush_bg", "type": "rect", "clip": true, "encode": { "enter": { "fill": {"value": "#333"}, "fillOpacity": {"value": 0.125} }, "update": { "x": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_1\"", "value": 0 }, {"value": 0} ], "y": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_1\"", "signal": "brush_y[0]" }, {"value": 0} ], "x2": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_1\"", "field": {"group": "width"} }, {"value": 0} ], "y2": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_1\"", "signal": "brush_y[1]" }, {"value": 0} ] } } }, { "name": "concat_1_marks", "type": "rect", "style": ["bar"], "interactive": true, "from": {"data": "data_2"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"Count of Records: \" + (format(datum[\"__count\"], \"\")) + \"; Name: \" + (isValid(datum[\"Name\"]) ? datum[\"Name\"] : \"\"+datum[\"Name\"])" }, "x": {"scale": "concat_1_x", "field": "__count"}, "x2": {"scale": "concat_1_x", "value": 0}, "y": {"scale": "concat_1_y", "field": "Name"}, "height": {"scale": "concat_1_y", "band": 1} } } }, { "name": "brush_brush", "type": "rect", "clip": true, "encode": { "enter": {"fill": {"value": "transparent"}}, "update": { "x": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_1\"", "value": 0 }, {"value": 0} ], "y": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_1\"", "signal": "brush_y[0]" }, {"value": 0} ], "x2": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_1\"", "field": {"group": "width"} }, {"value": 0} ], "y2": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_1\"", "signal": "brush_y[1]" }, {"value": 0} ], "stroke": [ {"test": "brush_y[0] !== brush_y[1]", "value": "white"}, {"value": null} ] } } } ] } ], "scales": [ { "name": "concat_0_x", "type": "linear", "domain": [0, 6], "range": [0, {"signal": "concat_0_width"}], "zero": true }, { "name": "concat_0_y", "type": "band", "domain": { "data": "data_0", "field": "Name", "sort": {"op": "count", "order": "descending"} }, "range": {"step": {"signal": "concat_0_y_step"}}, "paddingInner": 0.1, "paddingOuter": 0.05 }, { "name": "concat_1_x", "type": "linear", "domain": {"data": "data_2", "field": "__count"}, "range": [0, {"signal": "concat_1_width"}], "nice": true, "zero": true }, { "name": "concat_1_y", "type": "band", "domain": { "data": "source_0", "field": "Name", "sort": {"op": "count", "order": "descending"} }, "range": [0, {"signal": "concat_1_height"}], "paddingInner": 0.1, "paddingOuter": 0.05 } ] }