{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "width": 200, "height": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/cars.json", "format": {"type": "json", "parse": {"Year": "date"}}, "transform": [ { "field": "Year", "type": "timeunit", "units": ["year"], "as": ["year_Year", "year_Year_end"] }, { "type": "aggregate", "groupby": ["year_Year", "Cylinders"], "ops": ["sum"], "fields": ["Weight_in_lbs"], "as": ["sum_Weight_in_lbs"] }, { "type": "impute", "field": "sum_Weight_in_lbs", "groupby": ["Cylinders"], "key": "year_Year", "method": "value", "value": 0 }, { "type": "stack", "groupby": ["year_Year"], "field": "sum_Weight_in_lbs", "sort": {"field": ["Cylinders"], "order": ["descending"]}, "as": ["sum_Weight_in_lbs_start", "sum_Weight_in_lbs_end"], "offset": "zero" } ] } ], "marks": [ { "name": "pathgroup", "type": "group", "from": { "facet": { "name": "faceted_path_main", "data": "source_0", "groupby": ["Cylinders"] } }, "encode": { "update": { "width": {"field": {"group": "width"}}, "height": {"field": {"group": "height"}} } }, "marks": [ { "name": "marks", "type": "area", "style": ["area"], "sort": {"field": "datum[\"year_Year\"]"}, "from": {"data": "faceted_path_main"}, "encode": { "update": { "interpolate": {"value": "monotone"}, "orient": {"value": "vertical"}, "fill": {"scale": "color", "field": "Cylinders"}, "description": { "signal": "\"Year (year): \" + (timeFormat(datum[\"year_Year\"], timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; Sum of Weight_in_lbs: \" + (format(datum[\"sum_Weight_in_lbs\"], \"\")) + \"; Cylinders: \" + (isValid(datum[\"Cylinders\"]) ? datum[\"Cylinders\"] : \"\"+datum[\"Cylinders\"])" }, "x": {"scale": "x", "field": "year_Year"}, "y": {"scale": "y", "field": "sum_Weight_in_lbs_end"}, "y2": {"scale": "y", "field": "sum_Weight_in_lbs_start"}, "defined": { "signal": "isValid(datum[\"year_Year\"]) && isFinite(+datum[\"year_Year\"]) && isValid(datum[\"sum_Weight_in_lbs\"]) && isFinite(+datum[\"sum_Weight_in_lbs\"])" } } } } ] } ], "scales": [ { "name": "x", "type": "time", "domain": {"data": "source_0", "field": "year_Year"}, "range": [0, {"signal": "width"}] }, { "name": "y", "type": "linear", "domain": { "data": "source_0", "fields": ["sum_Weight_in_lbs_start", "sum_Weight_in_lbs_end"] }, "range": [{"signal": "height"}, 0], "nice": true, "zero": true }, { "name": "color", "type": "ordinal", "domain": {"data": "source_0", "field": "Cylinders", "sort": true}, "range": "ordinal", "interpolate": "hcl" } ], "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": "Year (year)", "format": { "signal": "timeUnitSpecifier([\"year\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"})" }, "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Sum of Weight_in_lbs", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ], "legends": [{"fill": "color", "symbolType": "circle", "title": "Cylinders"}] }