{ "$schema": "https://vega.github.io/schema/vega/v5.json", "background": "white", "padding": 5, "width": 300, "height": 100, "style": "cell", "data": [ { "name": "source_0", "url": "data/stocks.csv", "format": {"type": "csv", "parse": {"date": "date"}}, "transform": [ {"type": "filter", "expr": "datum.symbol !== 'GOOG'"}, { "field": "date", "type": "timeunit", "units": ["year", "month", "date"], "as": ["yearmonthdate_date", "yearmonthdate_date_end"] }, { "type": "aggregate", "groupby": ["yearmonthdate_date", "symbol"], "ops": ["sum"], "fields": ["price"], "as": ["sum_price"] }, { "type": "filter", "expr": "isValid(datum[\"sum_price\"]) && isFinite(+datum[\"sum_price\"])" } ] } ], "marks": [ { "name": "marks", "type": "rect", "style": ["rect"], "from": {"data": "source_0"}, "encode": { "update": { "fill": {"scale": "color", "field": "sum_price"}, "description": { "signal": "\"Time: \" + (timeFormat(datum[\"yearmonthdate_date\"], '%Y')) + \"; symbol: \" + (isValid(datum[\"symbol\"]) ? datum[\"symbol\"] : \"\"+datum[\"symbol\"]) + \"; Price: \" + (format(datum[\"sum_price\"], \"\"))" }, "x": {"scale": "x", "field": "yearmonthdate_date"}, "width": {"scale": "x", "band": 1}, "y": {"scale": "y", "field": "symbol"}, "height": {"scale": "y", "band": 1} } } } ], "scales": [ { "name": "x", "type": "band", "domain": { "data": "source_0", "field": "yearmonthdate_date", "sort": true }, "range": [0, {"signal": "width"}], "paddingInner": 0, "paddingOuter": 0 }, { "name": "y", "type": "band", "domain": {"data": "source_0", "field": "symbol", "sort": true}, "range": [0, {"signal": "height"}], "paddingInner": 0, "paddingOuter": 0 }, { "name": "color", "type": "linear", "domain": {"data": "source_0", "field": "sum_price"}, "range": "heatmap", "interpolate": "hcl", "zero": false } ], "axes": [ { "scale": "x", "orient": "bottom", "grid": false, "title": "Time", "format": "%Y", "labelAngle": 0, "labelOverlap": false, "formatType": "time", "labelBaseline": "top", "encode": { "labels": { "update": { "fill": [ { "test": "time(datetime(2012, month(datum[\"value\"]), date(datum[\"value\"]), 0, 0, 0, 0))===time(datetime(2012, 0, 1, 0, 0, 0, 0))", "value": "black" }, {"value": null} ] } }, "ticks": { "update": { "stroke": [ { "test": "time(datetime(2012, month(datum[\"value\"]), date(datum[\"value\"]), 0, 0, 0, 0))===time(datetime(2012, 0, 1, 0, 0, 0, 0))", "value": "black" }, {"value": null} ] } } }, "zindex": 1 }, {"scale": "y", "orient": "left", "grid": false, "zindex": 1} ], "legends": [ { "title": "Price", "fill": "color", "gradientLength": {"signal": "clamp(height, 64, 200)"} } ] }