{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "height": 300, "style": "cell", "data": [ {"name": "selector003_store"}, { "name": "data-830c39fec90146253fb06a06c26374ef", "url": "https://raw.githubusercontent.com/vega/vega-datasets/main/data/seattle-weather.csv", "format": {"type": "csv", "parse": {"date": "date"}} }, { "name": "data_0", "source": "data-830c39fec90146253fb06a06c26374ef", "transform": [ {"type": "formula", "expr": "toDate(datum[\"date\"])", "as": "date"}, { "field": "date", "type": "timeunit", "units": ["month"], "as": ["month_date", "month_date_end"] } ] }, { "name": "data_1", "source": "data_0", "transform": [ { "type": "filter", "expr": "!length(data(\"selector003_store\")) || vlSelectionTest(\"selector003_store\", datum)" }, { "type": "aggregate", "groupby": [], "ops": ["mean"], "fields": ["precipitation"], "as": ["mean_precipitation"] }, { "type": "filter", "expr": "isValid(datum[\"mean_precipitation\"]) && isFinite(+datum[\"mean_precipitation\"])" } ] }, { "name": "data_2", "source": "data_0", "transform": [ { "type": "aggregate", "groupby": ["month_date"], "ops": ["mean"], "fields": ["precipitation"], "as": ["mean_precipitation"] }, { "type": "filter", "expr": "isValid(datum[\"mean_precipitation\"]) && isFinite(+datum[\"mean_precipitation\"])" } ] } ], "signals": [ {"name": "x_step", "value": 20}, { "name": "width", "update": "bandspace(domain('x').length, 0.1, 0.05) * x_step" }, { "name": "unit", "value": {}, "on": [ {"events": "mousemove", "update": "isTuple(group()) ? group() : unit"} ] }, { "name": "selector003", "update": "vlSelectionResolve(\"selector003_store\", \"union\")" }, { "name": "selector003_x", "value": [], "on": [ { "events": { "source": "scope", "type": "mousedown", "filter": [ "!event.item || event.item.mark.name !== \"selector003_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 !== \"selector003_brush\"" ] }, {"source": "window", "type": "mouseup"} ] }, "update": "[selector003_x[0], clamp(x(unit), 0, width)]" }, {"events": {"signal": "selector003_scale_trigger"}, "update": "[0, 0]"}, { "events": [{"source": "view", "type": "dblclick"}], "update": "[0, 0]" }, { "events": {"signal": "selector003_translate_delta"}, "update": "clampRange(panLinear(selector003_translate_anchor.extent_x, selector003_translate_delta.x / span(selector003_translate_anchor.extent_x)), 0, width)" }, { "events": {"signal": "selector003_zoom_delta"}, "update": "clampRange(zoomLinear(selector003_x, selector003_zoom_anchor.x, selector003_zoom_delta), 0, width)" } ] }, { "name": "selector003_month_date", "on": [ { "events": {"signal": "selector003_x"}, "update": "selector003_x[0] === selector003_x[1] ? null : invert(\"x\", selector003_x)" } ] }, { "name": "selector003_scale_trigger", "value": {}, "on": [ { "events": [{"scale": "x"}], "update": "(!isArray(selector003_month_date) || (invert(\"x\", selector003_x)[0] === selector003_month_date[0] && invert(\"x\", selector003_x)[1] === selector003_month_date[1])) ? selector003_scale_trigger : {}" } ] }, { "name": "selector003_tuple", "on": [ { "events": [{"signal": "selector003_month_date"}], "update": "selector003_month_date ? {unit: \"layer_0\", fields: selector003_tuple_fields, values: [selector003_month_date]} : null" } ] }, { "name": "selector003_tuple_fields", "value": [{"field": "month_date", "channel": "x", "type": "E"}] }, { "name": "selector003_translate_anchor", "value": {}, "on": [ { "events": [ { "source": "scope", "type": "mousedown", "markname": "selector003_brush" } ], "update": "{x: x(unit), y: y(unit), extent_x: slice(selector003_x)}" } ] }, { "name": "selector003_translate_delta", "value": {}, "on": [ { "events": [ { "source": "window", "type": "mousemove", "consume": true, "between": [ { "source": "scope", "type": "mousedown", "markname": "selector003_brush" }, {"source": "window", "type": "mouseup"} ] } ], "update": "{x: selector003_translate_anchor.x - x(unit), y: selector003_translate_anchor.y - y(unit)}" } ] }, { "name": "selector003_zoom_anchor", "on": [ { "events": [ { "source": "scope", "type": "wheel", "consume": true, "markname": "selector003_brush" } ], "update": "{x: x(unit), y: y(unit)}" } ] }, { "name": "selector003_zoom_delta", "on": [ { "events": [ { "source": "scope", "type": "wheel", "consume": true, "markname": "selector003_brush" } ], "force": true, "update": "pow(1.001, event.deltaY * pow(16, event.deltaMode))" } ] }, { "name": "selector003_modify", "on": [ { "events": {"signal": "selector003_tuple"}, "update": "modify(\"selector003_store\", selector003_tuple, true)" } ] } ], "marks": [ { "name": "selector003_brush_bg", "type": "rect", "clip": true, "encode": { "enter": {"fill": {"value": "#333"}, "fillOpacity": {"value": 0.125}}, "update": { "x": [ { "test": "data(\"selector003_store\").length && data(\"selector003_store\")[0].unit === \"layer_0\"", "signal": "selector003_x[0]" }, {"value": 0} ], "y": [ { "test": "data(\"selector003_store\").length && data(\"selector003_store\")[0].unit === \"layer_0\"", "value": 0 }, {"value": 0} ], "x2": [ { "test": "data(\"selector003_store\").length && data(\"selector003_store\")[0].unit === \"layer_0\"", "signal": "selector003_x[1]" }, {"value": 0} ], "y2": [ { "test": "data(\"selector003_store\").length && data(\"selector003_store\")[0].unit === \"layer_0\"", "field": {"group": "height"} }, {"value": 0} ] } } }, { "name": "layer_0_marks", "type": "rect", "style": ["bar"], "interactive": true, "from": {"data": "data_2"}, "encode": { "update": { "fill": {"value": "#4c78a8"}, "opacity": [ { "test": "!length(data(\"selector003_store\")) || vlSelectionTest(\"selector003_store\", datum)", "value": 1 }, {"value": 0.7} ], "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"date (month): \" + (timeFormat(datum[\"month_date\"], timeUnitSpecifier([\"month\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; Mean of precipitation: \" + (format(datum[\"mean_precipitation\"], \"\"))" }, "x": {"scale": "x", "field": "month_date"}, "width": {"scale": "x", "band": 1}, "y": {"scale": "y", "field": "mean_precipitation"}, "y2": {"scale": "y", "value": 0} } } }, { "name": "layer_1_marks", "type": "rule", "style": ["rule"], "interactive": false, "from": {"data": "data_1"}, "encode": { "update": { "stroke": {"value": "firebrick"}, "description": { "signal": "\"Mean of precipitation: \" + (format(datum[\"mean_precipitation\"], \"\"))" }, "x": {"field": {"group": "width"}}, "x2": {"value": 0}, "y": {"scale": "y", "field": "mean_precipitation"}, "strokeWidth": {"value": 3} } } }, { "name": "selector003_brush", "type": "rect", "clip": true, "encode": { "enter": {"fill": {"value": "transparent"}}, "update": { "x": [ { "test": "data(\"selector003_store\").length && data(\"selector003_store\")[0].unit === \"layer_0\"", "signal": "selector003_x[0]" }, {"value": 0} ], "y": [ { "test": "data(\"selector003_store\").length && data(\"selector003_store\")[0].unit === \"layer_0\"", "value": 0 }, {"value": 0} ], "x2": [ { "test": "data(\"selector003_store\").length && data(\"selector003_store\")[0].unit === \"layer_0\"", "signal": "selector003_x[1]" }, {"value": 0} ], "y2": [ { "test": "data(\"selector003_store\").length && data(\"selector003_store\")[0].unit === \"layer_0\"", "field": {"group": "height"} }, {"value": 0} ], "stroke": [ {"test": "selector003_x[0] !== selector003_x[1]", "value": "white"}, {"value": null} ] } } } ], "scales": [ { "name": "x", "type": "band", "domain": {"data": "data_2", "field": "month_date", "sort": true}, "range": {"step": {"signal": "x_step"}}, "paddingInner": 0.1, "paddingOuter": 0.05 }, { "name": "y", "type": "linear", "domain": { "fields": [ {"data": "data_2", "field": "mean_precipitation"}, {"data": "data_1", "field": "mean_precipitation"} ] }, "range": [{"signal": "height"}, 0], "nice": true, "zero": true } ], "axes": [ { "scale": "y", "orient": "left", "gridScale": "x", "grid": true, "tickCount": {"signal": "ceil(height/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "x", "orient": "bottom", "grid": false, "title": "date (month)", "format": { "signal": "timeUnitSpecifier([\"month\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"})" }, "formatType": "time", "labelOverlap": true, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Mean of precipitation", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ] }