{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "height": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/seattle-weather.csv", "format": {"type": "csv", "parse": {"date": "date"}}, "transform": [ { "field": "date", "type": "timeunit", "units": ["month"], "as": ["month_date", "month_date_end"] }, { "type": "aggregate", "groupby": ["month_date", "weather"], "ops": ["count"], "fields": [null], "as": ["__count"] }, { "type": "stack", "groupby": ["month_date"], "field": "__count", "sort": {"field": ["weather"], "order": ["descending"]}, "as": ["__count_start", "__count_end"], "offset": "zero" } ] } ], "signals": [ {"name": "x_step", "value": 20}, { "name": "width", "update": "bandspace(domain('x').length, 0.1, 0.05) * x_step" } ], "marks": [ { "type": "group", "from": { "facet": { "data": "source_0", "name": "stack_group_main", "groupby": ["month_date", "month_date_end"], "aggregate": { "fields": [ "__count_start", "__count_start", "__count_end", "__count_end" ], "ops": ["min", "max", "min", "max"] } } }, "encode": { "update": { "x": {"scale": "x", "field": "month_date"}, "width": {"scale": "x", "band": 1}, "y": { "signal": "min(scale('y',datum[\"min___count_start\"]),scale('y',datum[\"max___count_start\"]),scale('y',datum[\"min___count_end\"]),scale('y',datum[\"max___count_end\"]))" }, "y2": { "signal": "max(scale('y',datum[\"min___count_start\"]),scale('y',datum[\"max___count_start\"]),scale('y',datum[\"min___count_end\"]),scale('y',datum[\"max___count_end\"]))" }, "clip": {"value": true}, "cornerRadiusTopLeft": {"value": 8}, "cornerRadiusTopRight": {"value": 8} } }, "marks": [ { "type": "group", "encode": { "update": { "y": {"field": {"group": "y"}, "mult": -1}, "width": {"field": {"group": "width"}} } }, "marks": [ { "name": "marks", "type": "rect", "style": ["bar"], "from": {"data": "stack_group_main"}, "encode": { "update": { "fill": {"scale": "color", "field": "weather"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"date (month): \" + (timeFormat(datum[\"month_date\"], timeUnitSpecifier([\"month\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; Count of Records: \" + (format(datum[\"__count\"], \"\")) + \"; weather: \" + (isValid(datum[\"weather\"]) ? datum[\"weather\"] : \"\"+datum[\"weather\"])" }, "width": {"field": {"group": "width"}}, "y": {"scale": "y", "field": "__count_end"}, "y2": {"scale": "y", "field": "__count_start"}, "cornerRadiusTopLeft": {"value": 0}, "cornerRadiusTopRight": {"value": 0} } } } ] } ] } ], "scales": [ { "name": "x", "type": "band", "domain": {"data": "source_0", "field": "month_date", "sort": true}, "range": {"step": {"signal": "x_step"}}, "paddingInner": 0.1, "paddingOuter": 0.05 }, { "name": "y", "type": "linear", "domain": { "data": "source_0", "fields": ["__count_start", "__count_end"] }, "range": [{"signal": "height"}, 0], "nice": true, "zero": true }, { "name": "color", "type": "ordinal", "domain": {"data": "source_0", "field": "weather", "sort": true}, "range": "category" } ], "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": "Count of Records", "labelOverlap": true, "tickCount": {"signal": "ceil(height/40)"}, "zindex": 0 } ], "legends": [{"fill": "color", "symbolType": "square", "title": "weather"}], "config": { "style": {"bar": {"cornerRadiusTopLeft": 8, "cornerRadiusTopRight": 8}} } }