{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "Drag the sliders to highlight points.", "background": "white", "padding": 5, "width": 200, "height": 200, "style": "cell", "data": [ { "name": "CylYr_store", "values": [ { "unit": "layer_0", "fields": [ {"type": "E", "field": "Cylinders"}, {"type": "E", "field": "Year"} ], "values": [4, 1977] } ] }, { "name": "source_0", "url": "data/cars.json", "format": {"type": "json"}, "transform": [ {"type": "formula", "expr": "year(datum.Year)", "as": "Year"} ] }, { "name": "data_0", "source": "source_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"Horsepower\"]) && isFinite(+datum[\"Horsepower\"]) && isValid(datum[\"Miles_per_Gallon\"]) && isFinite(+datum[\"Miles_per_Gallon\"])" } ] }, { "name": "data_1", "source": "source_0", "transform": [ { "type": "filter", "expr": "!length(data(\"CylYr_store\")) || vlSelectionTest(\"CylYr_store\", datum)" }, { "type": "filter", "expr": "isValid(datum[\"Horsepower\"]) && isFinite(+datum[\"Horsepower\"]) && isValid(datum[\"Miles_per_Gallon\"]) && isFinite(+datum[\"Miles_per_Gallon\"])" } ] } ], "signals": [ { "name": "unit", "value": {}, "on": [ {"events": "mousemove", "update": "isTuple(group()) ? group() : unit"} ] }, { "name": "CylYr_Year", "init": "1977", "bind": {"input": "range", "min": 1969, "max": 1981, "step": 1} }, { "name": "CylYr_Cylinders", "init": "4", "bind": {"input": "range", "min": 3, "max": 8, "step": 1} }, { "name": "CylYr", "update": "vlSelectionResolve(\"CylYr_store\", \"union\", true, true)" }, { "name": "CylYr_tuple", "update": "CylYr_Cylinders !== null && CylYr_Year !== null ? {fields: CylYr_tuple_fields, values: [CylYr_Cylinders, CylYr_Year]} : null" }, { "name": "CylYr_tuple_fields", "value": [ {"type": "E", "field": "Cylinders"}, {"type": "E", "field": "Year"} ] }, { "name": "CylYr_modify", "on": [ { "events": {"signal": "CylYr_tuple"}, "update": "modify(\"CylYr_store\", CylYr_tuple, true)" } ] } ], "marks": [ { "name": "layer_0_marks", "type": "symbol", "style": ["circle"], "interactive": true, "from": {"data": "data_0"}, "encode": { "update": { "opacity": {"value": 0.7}, "fill": [ { "test": "!length(data(\"CylYr_store\")) || vlSelectionTest(\"CylYr_store\", datum)", "scale": "color", "field": "Origin" }, {"value": "grey"} ], "ariaRoleDescription": {"value": "circle"}, "description": { "signal": "\"Horsepower: \" + (format(datum[\"Horsepower\"], \"\")) + \"; Miles_per_Gallon: \" + (format(datum[\"Miles_per_Gallon\"], \"\")) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"])" }, "x": {"scale": "x", "field": "Horsepower"}, "y": {"scale": "y", "field": "Miles_per_Gallon"}, "shape": {"value": "circle"} } } }, { "name": "layer_1_marks", "type": "symbol", "style": ["circle"], "interactive": false, "from": {"data": "data_1"}, "encode": { "update": { "opacity": {"value": 0.7}, "fill": {"scale": "color", "field": "Origin"}, "ariaRoleDescription": {"value": "circle"}, "description": { "signal": "\"Horsepower: \" + (format(datum[\"Horsepower\"], \"\")) + \"; Miles_per_Gallon: \" + (format(datum[\"Miles_per_Gallon\"], \"\")) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"])" }, "x": {"scale": "x", "field": "Horsepower"}, "y": {"scale": "y", "field": "Miles_per_Gallon"}, "size": {"value": 100}, "shape": {"value": "circle"} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": { "fields": [ {"data": "data_0", "field": "Horsepower"}, {"data": "data_1", "field": "Horsepower"} ] }, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "linear", "domain": { "fields": [ {"data": "data_0", "field": "Miles_per_Gallon"}, {"data": "data_1", "field": "Miles_per_Gallon"} ] }, "range": [{"signal": "height"}, 0], "nice": true, "zero": true }, { "name": "color", "type": "ordinal", "domain": { "fields": [ {"data": "data_0", "field": "Origin"}, {"data": "data_1", "field": "Origin"} ], "sort": true }, "range": "category" } ], "axes": [ { "scale": "x", "orient": "bottom", "gridScale": "y", "grid": true, "tickCount": {"signal": "ceil(width/40)"}, "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "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": "Horsepower", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Miles_per_Gallon", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ], "legends": [ { "fill": "color", "symbolType": "circle", "title": "Origin", "encode": {"symbols": {"update": {"opacity": {"value": 0.7}}}} } ] }