Module

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

A concise grammar of interactive graphics, built on Vega.
Latest
File
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "width": 963, "data": [ {"name": "brush_store"}, { "name": "source_0", "url": "data/flights-5k.json", "format": {"type": "json", "parse": {"date": "date"}}, "transform": [ { "type": "formula", "expr": "hours(datum.date) + minutes(datum.date) / 60", "as": "time" }, { "type": "extent", "field": "time", "signal": "concat_1_bin_maxbins_30_extent_selection_brush_time_extent" }, { "type": "bin", "field": "time", "as": [ "bin_maxbins_30_extent_selection_brush_time", "bin_maxbins_30_extent_selection_brush_time_end" ], "signal": "concat_1_bin_maxbins_30_extent_selection_brush_time_bins", "extent": { "signal": "concat_1_bin_maxbins_30_extent_selection_brush_time_extent" }, "span": {"signal": "span(brush[\"time\"])"}, "maxbins": 30 }, { "type": "extent", "field": "time", "signal": "concat_0_bin_maxbins_30_time_extent" }, { "type": "bin", "field": "time", "as": ["bin_maxbins_30_time", "bin_maxbins_30_time_end"], "signal": "concat_0_bin_maxbins_30_time_bins", "extent": {"signal": "concat_0_bin_maxbins_30_time_extent"}, "maxbins": 30 } ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": [ "bin_maxbins_30_extent_selection_brush_time", "bin_maxbins_30_extent_selection_brush_time_end" ], "ops": ["count"], "fields": [null], "as": ["__count"] }, { "type": "filter", "expr": "isValid(datum[\"bin_maxbins_30_extent_selection_brush_time\"]) && isFinite(+datum[\"bin_maxbins_30_extent_selection_brush_time\"])" } ] }, { "name": "data_1", "source": "source_0", "transform": [ { "type": "aggregate", "groupby": ["bin_maxbins_30_time", "bin_maxbins_30_time_end"], "ops": ["count"], "fields": [null], "as": ["__count"] }, { "type": "filter", "expr": "isValid(datum[\"bin_maxbins_30_time\"]) && isFinite(+datum[\"bin_maxbins_30_time\"])" } ] } ], "signals": [ {"name": "childHeight", "value": 100}, { "name": "unit", "value": {}, "on": [ {"events": "mousemove", "update": "isTuple(group()) ? group() : unit"} ] }, { "name": "brush", "update": "vlSelectionResolve(\"brush_store\", \"union\")" } ], "layout": {"padding": 20, "columns": 1, "bounds": "full", "align": "each"}, "marks": [ { "type": "group", "name": "concat_0_group", "style": "cell", "encode": { "update": { "width": {"signal": "width"}, "height": {"signal": "childHeight"} } }, "signals": [ { "name": "brush_x", "value": [], "on": [ { "events": { "source": "scope", "type": "mousedown", "filter": [ "!event.item || event.item.mark.name !== \"brush_brush\"" ] }, "update": "[x(unit), x(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_x[0], clamp(x(unit), 0, width)]" }, { "events": {"signal": "brush_scale_trigger"}, "update": "[scale(\"concat_0_x\", brush_time[0]), scale(\"concat_0_x\", brush_time[1])]" }, { "events": {"signal": "brush_translate_delta"}, "update": "clampRange(panLinear(brush_translate_anchor.extent_x, brush_translate_delta.x / span(brush_translate_anchor.extent_x)), 0, width)" }, { "events": {"signal": "brush_zoom_delta"}, "update": "clampRange(zoomLinear(brush_x, brush_zoom_anchor.x, brush_zoom_delta), 0, width)" }, { "events": [{"source": "scope", "type": "dblclick"}], "update": "[0, 0]" } ] }, { "name": "brush_time", "on": [ { "events": {"signal": "brush_x"}, "update": "brush_x[0] === brush_x[1] ? null : invert(\"concat_0_x\", brush_x)" } ] }, { "name": "brush_scale_trigger", "value": {}, "on": [ { "events": [{"scale": "concat_0_x"}], "update": "(!isArray(brush_time) || (+invert(\"concat_0_x\", brush_x)[0] === +brush_time[0] && +invert(\"concat_0_x\", brush_x)[1] === +brush_time[1])) ? brush_scale_trigger : {}" } ] }, { "name": "brush_tuple", "on": [ { "events": [{"signal": "brush_time"}], "update": "brush_time ? {unit: \"concat_0\", fields: brush_tuple_fields, values: [brush_time]} : null" } ] }, { "name": "brush_tuple_fields", "value": [{"field": "time", "channel": "x", "type": "R"}] }, { "name": "brush_translate_anchor", "value": {}, "on": [ { "events": [ { "source": "scope", "type": "mousedown", "markname": "brush_brush" } ], "update": "{x: x(unit), y: y(unit), extent_x: slice(brush_x)}" } ] }, { "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_0\"", "signal": "brush_x[0]" }, {"value": 0} ], "y": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_0\"", "value": 0 }, {"value": 0} ], "x2": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_0\"", "signal": "brush_x[1]" }, {"value": 0} ], "y2": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_0\"", "field": {"group": "height"} }, {"value": 0} ] } } }, { "name": "concat_0_marks", "type": "rect", "style": ["bar"], "interactive": true, "from": {"data": "data_1"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"time (binned): \" + (!isValid(datum[\"bin_maxbins_30_time\"]) || !isFinite(+datum[\"bin_maxbins_30_time\"]) ? \"null\" : format(datum[\"bin_maxbins_30_time\"], \"\") + \" – \" + format(datum[\"bin_maxbins_30_time_end\"], \"\")) + \"; Count of Records: \" + (format(datum[\"__count\"], \"\"))" }, "x2": [ { "test": "!isValid(datum[\"bin_maxbins_30_time\"]) || !isFinite(+datum[\"bin_maxbins_30_time\"])", "value": 0 }, { "scale": "concat_0_x", "field": "bin_maxbins_30_time", "offset": 1 } ], "x": [ { "test": "!isValid(datum[\"bin_maxbins_30_time\"]) || !isFinite(+datum[\"bin_maxbins_30_time\"])", "value": 0 }, {"scale": "concat_0_x", "field": "bin_maxbins_30_time_end"} ], "y": {"scale": "concat_0_y", "field": "__count"}, "y2": {"scale": "concat_0_y", "value": 0} } } }, { "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_0\"", "signal": "brush_x[0]" }, {"value": 0} ], "y": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_0\"", "value": 0 }, {"value": 0} ], "x2": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_0\"", "signal": "brush_x[1]" }, {"value": 0} ], "y2": [ { "test": "data(\"brush_store\").length && data(\"brush_store\")[0].unit === \"concat_0\"", "field": {"group": "height"} }, {"value": 0} ], "stroke": [ {"test": "brush_x[0] !== brush_x[1]", "value": "white"}, {"value": null} ] } } } ], "axes": [ { "scale": "concat_0_y", "orient": "left", "gridScale": "concat_0_x", "grid": true, "tickCount": {"signal": "ceil(childHeight/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "concat_0_x", "orient": "bottom", "grid": false, "title": "time (binned)", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/10)"}, "zindex": 0 }, { "scale": "concat_0_y", "orient": "left", "grid": false, "title": "Count of Records", "labelOverlap": true, "tickCount": {"signal": "ceil(childHeight/40)"}, "zindex": 0 } ] }, { "type": "group", "name": "concat_1_group", "style": "cell", "encode": { "update": { "width": {"signal": "width"}, "height": {"signal": "childHeight"} } }, "marks": [ { "name": "concat_1_marks", "type": "rect", "clip": true, "style": ["bar"], "interactive": false, "from": {"data": "data_0"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"time (binned): \" + (!isValid(datum[\"bin_maxbins_30_extent_selection_brush_time\"]) || !isFinite(+datum[\"bin_maxbins_30_extent_selection_brush_time\"]) ? \"null\" : format(datum[\"bin_maxbins_30_extent_selection_brush_time\"], \"\") + \" – \" + format(datum[\"bin_maxbins_30_extent_selection_brush_time_end\"], \"\")) + \"; Count of Records: \" + (format(datum[\"__count\"], \"\"))" }, "x2": [ { "test": "!isValid(datum[\"bin_maxbins_30_extent_selection_brush_time\"]) || !isFinite(+datum[\"bin_maxbins_30_extent_selection_brush_time\"])", "value": 0 }, { "scale": "concat_1_x", "field": "bin_maxbins_30_extent_selection_brush_time", "offset": 1 } ], "x": [ { "test": "!isValid(datum[\"bin_maxbins_30_extent_selection_brush_time\"]) || !isFinite(+datum[\"bin_maxbins_30_extent_selection_brush_time\"])", "value": 0 }, { "scale": "concat_1_x", "field": "bin_maxbins_30_extent_selection_brush_time_end" } ], "y": {"scale": "concat_1_y", "field": "__count"}, "y2": {"scale": "concat_1_y", "value": 0} } } } ], "axes": [ { "scale": "concat_1_y", "orient": "left", "gridScale": "concat_1_x", "grid": true, "tickCount": {"signal": "ceil(childHeight/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "concat_1_x", "orient": "bottom", "grid": false, "title": "time (binned)", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/10)"}, "zindex": 0 }, { "scale": "concat_1_y", "orient": "left", "grid": false, "title": "Count of Records", "labelOverlap": true, "tickCount": {"signal": "ceil(childHeight/40)"}, "zindex": 0 } ] } ], "scales": [ { "name": "concat_0_x", "type": "linear", "domain": { "signal": "[concat_0_bin_maxbins_30_time_bins.start, concat_0_bin_maxbins_30_time_bins.stop]" }, "range": [0, {"signal": "width"}], "bins": {"signal": "concat_0_bin_maxbins_30_time_bins"}, "zero": false }, { "name": "concat_0_y", "type": "linear", "domain": {"data": "data_1", "field": "__count"}, "range": [{"signal": "childHeight"}, 0], "nice": true, "zero": true }, { "name": "concat_1_x", "type": "linear", "domain": { "signal": "[concat_1_bin_maxbins_30_extent_selection_brush_time_bins.start, concat_1_bin_maxbins_30_extent_selection_brush_time_bins.stop]" }, "domainRaw": {"signal": "brush[\"time\"]"}, "range": [0, {"signal": "width"}], "bins": { "signal": "concat_1_bin_maxbins_30_extent_selection_brush_time_bins" }, "zero": false }, { "name": "concat_1_y", "type": "linear", "domain": {"data": "data_0", "field": "__count"}, "range": [{"signal": "childHeight"}, 0], "nice": true, "zero": true } ]}