Skip to content

Commit

Permalink
fix: make durationExpr work for week (#8907)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Actions Bot <vega-actions-bot@users.noreply.github.com>
  • Loading branch information
kanitw and GitHub Actions Bot authored May 17, 2023
1 parent 9050e6b commit bf99571
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/compiled/bar_grouped_timeunit_yearweek.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
160 changes: 160 additions & 0 deletions examples/compiled/bar_grouped_timeunit_yearweek.vg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"background": "white",
"padding": 5,
"width": 400,
"height": 250,
"style": "cell",
"data": [
{
"name": "source_0",
"url": "data/cars.json",
"format": {"type": "json", "parse": {"Year": "date"}},
"transform": [
{
"type": "filter",
"expr": "inrange(time(datetime(year(datum[\"Year\"]), 0, 1, 0, 0, 0, 0)), [time(datetime(1970, 0, 1, 0, 0, 0, 0)), time(datetime(1971, 0, 1, 0, 0, 0, 0))])"
},
{
"field": "Year",
"type": "timeunit",
"units": ["year", "week"],
"as": ["yearweek_Year", "yearweek_Year_end"]
},
{
"type": "aggregate",
"groupby": ["yearweek_Year", "yearweek_Year_end", "Origin"],
"ops": ["count"],
"fields": [null],
"as": ["__count"]
},
{
"type": "filter",
"expr": "(isDate(datum[\"yearweek_Year\"]) || (isValid(datum[\"yearweek_Year\"]) && isFinite(+datum[\"yearweek_Year\"])))"
}
]
}
],
"marks": [
{
"name": "marks",
"type": "rect",
"style": ["bar"],
"from": {"data": "source_0"},
"encode": {
"update": {
"fill": {"scale": "color", "field": "Origin"},
"ariaRoleDescription": {"value": "bar"},
"description": {
"signal": "\"Year (year-week): \" + (timeFormat(datum[\"yearweek_Year\"], timeUnitSpecifier([\"year\",\"week\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; Number of Cars: \" + (format(datum[\"__count\"], \"\")) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"])"
},
"xc": {
"scale": "x",
"field": "yearweek_Year",
"offset": {"scale": "xOffset", "field": "Origin", "band": 0.5}
},
"width": {"signal": "max(0.25, bandwidth('xOffset'))"},
"y": {"scale": "y", "field": "__count"},
"y2": {"scale": "y", "value": 0}
}
}
}
],
"scales": [
{
"name": "x",
"type": "time",
"domain": {
"data": "source_0",
"fields": ["yearweek_Year", "yearweek_Year_end"]
},
"range": [0, {"signal": "width"}]
},
{
"name": "y",
"type": "linear",
"domain": {"data": "source_0", "field": "__count"},
"range": [{"signal": "height"}, 0],
"nice": true,
"zero": true
},
{
"name": "xOffset",
"type": "band",
"domain": {"data": "source_0", "field": "Origin", "sort": true},
"range": [
{
"signal": "0.1 * (scale('x', datetime(2001, 0, 8, 0, 0, 0, 0)) - scale('x', datetime(2001, 0, 1, 0, 0, 0, 0)))"
},
{
"signal": "0.9 * (scale('x', datetime(2001, 0, 8, 0, 0, 0, 0)) - scale('x', datetime(2001, 0, 1, 0, 0, 0, 0)))"
}
]
},
{
"name": "color",
"type": "ordinal",
"domain": {"data": "source_0", "field": "Origin", "sort": true},
"range": "category"
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"gridScale": "y",
"grid": true,
"tickCount": {"signal": "ceil(width/40)"},
"tickMinStep": {
"signal": "datetime(2001, 0, 8, 0, 0, 0, 0) - datetime(2001, 0, 1, 0, 0, 0, 0)"
},
"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-week)",
"format": {
"signal": "timeUnitSpecifier([\"year\",\"week\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"})"
},
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(width/40)"},
"tickMinStep": {
"signal": "datetime(2001, 0, 8, 0, 0, 0, 0) - datetime(2001, 0, 1, 0, 0, 0, 0)"
},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "Number of Cars",
"labelOverlap": true,
"tickCount": {"signal": "ceil(height/40)"},
"zindex": 0
}
],
"legends": [{"fill": "color", "symbolType": "square", "title": "Origin"}]
}
Loading

0 comments on commit bf99571

Please sign in to comment.