{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "height": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/cars.json", "format": {"type": "json", "parse": {"Horsepower": "number"}}, "transform": [ { "type": "aggregate", "groupby": ["Cylinders"], "ops": ["min", "max"], "fields": ["Horsepower", "Horsepower"], "as": ["min_Horsepower", "max_Horsepower"] } ] }, { "name": "data_1", "source": "source_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"min_Horsepower\"]) && isFinite(+datum[\"min_Horsepower\"])" } ] }, { "name": "data_2", "source": "source_0", "transform": [ { "type": "filter", "expr": "isValid(datum[\"max_Horsepower\"]) && isFinite(+datum[\"max_Horsepower\"])" } ] } ], "signals": [ {"name": "x_step", "value": 20}, { "name": "width", "update": "bandspace(domain('x').length, 1, 0.5) * x_step" } ], "marks": [ { "name": "layer_0_layer_0_marks", "type": "line", "style": ["line"], "sort": {"field": "datum[\"Cylinders\"]"}, "from": {"data": "source_0"}, "encode": { "update": { "stroke": {"value": "darkred"}, "description": { "signal": "\"Cylinders: \" + (isValid(datum[\"Cylinders\"]) ? datum[\"Cylinders\"] : \"\"+datum[\"Cylinders\"]) + \"; Max of Horsepower: \" + (format(datum[\"max_Horsepower\"], \"\"))" }, "x": {"scale": "x", "field": "Cylinders"}, "y": {"scale": "y", "field": "max_Horsepower"}, "defined": { "signal": "isValid(datum[\"max_Horsepower\"]) && isFinite(+datum[\"max_Horsepower\"])" } } } }, { "name": "layer_0_layer_1_marks", "type": "symbol", "style": ["point"], "from": {"data": "data_2"}, "encode": { "update": { "opacity": {"value": 1}, "fill": {"value": "darkred"}, "ariaRoleDescription": {"value": "point"}, "description": { "signal": "\"Cylinders: \" + (isValid(datum[\"Cylinders\"]) ? datum[\"Cylinders\"] : \"\"+datum[\"Cylinders\"]) + \"; Max of Horsepower: \" + (format(datum[\"max_Horsepower\"], \"\"))" }, "x": {"scale": "x", "field": "Cylinders"}, "y": {"scale": "y", "field": "max_Horsepower"} } } }, { "name": "layer_1_layer_0_marks", "type": "line", "style": ["line"], "sort": {"field": "datum[\"Cylinders\"]"}, "from": {"data": "source_0"}, "encode": { "update": { "stroke": {"value": "#4c78a8"}, "description": { "signal": "\"Cylinders: \" + (isValid(datum[\"Cylinders\"]) ? datum[\"Cylinders\"] : \"\"+datum[\"Cylinders\"]) + \"; Min of Horsepower: \" + (format(datum[\"min_Horsepower\"], \"\"))" }, "x": {"scale": "x", "field": "Cylinders"}, "y": {"scale": "y", "field": "min_Horsepower"}, "defined": { "signal": "isValid(datum[\"min_Horsepower\"]) && isFinite(+datum[\"min_Horsepower\"])" } } } }, { "name": "layer_1_layer_1_marks", "type": "symbol", "style": ["point"], "from": {"data": "data_1"}, "encode": { "update": { "opacity": {"value": 1}, "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "point"}, "description": { "signal": "\"Cylinders: \" + (isValid(datum[\"Cylinders\"]) ? datum[\"Cylinders\"] : \"\"+datum[\"Cylinders\"]) + \"; Min of Horsepower: \" + (format(datum[\"min_Horsepower\"], \"\"))" }, "x": {"scale": "x", "field": "Cylinders"}, "y": {"scale": "y", "field": "min_Horsepower"} } } } ], "scales": [ { "name": "x", "type": "point", "domain": { "fields": [ {"data": "source_0", "field": "Cylinders"}, {"data": "data_2", "field": "Cylinders"}, {"data": "data_1", "field": "Cylinders"} ], "sort": true }, "range": {"step": {"signal": "x_step"}}, "padding": 0.5 }, { "name": "y", "type": "linear", "domain": { "fields": [ {"data": "source_0", "field": "max_Horsepower"}, {"data": "data_2", "field": "max_Horsepower"}, {"data": "source_0", "field": "min_Horsepower"}, {"data": "data_1", "field": "min_Horsepower"} ] }, "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": "Cylinders", "labelAlign": "right", "labelAngle": 270, "labelBaseline": "middle", "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Max of Horsepower, Min of Horsepower", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ] }