Skip to content

Commit

Permalink
fix: make timeUnit band respect x2Offset (#8956)
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 Jun 20, 2023
1 parent 39bc25a commit f8a0cfa
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 1 deletion.
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/line_month_center_band_offset.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 130 additions & 0 deletions examples/compiled/line_month_center_band_offset.vg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"$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/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", "month_date_end"],
"ops": ["mean"],
"fields": ["precipitation"],
"as": ["mean_precipitation"]
},
{
"type": "filter",
"expr": "(isDate(datum[\"month_date\"]) || (isValid(datum[\"month_date\"]) && isFinite(+datum[\"month_date\"]))) && isValid(datum[\"mean_precipitation\"]) && isFinite(+datum[\"mean_precipitation\"])"
}
]
}
],
"marks": [
{
"name": "marks",
"type": "rect",
"style": ["bar"],
"from": {"data": "source_0"},
"encode": {
"update": {
"fill": {"value": "#4c78a8"},
"ariaRoleDescription": {"value": "bar"},
"description": {
"signal": "\"date (month): \" + (timeFormat(datum[\"month_date\"], timeUnitSpecifier([\"month\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"}))) + \"; Mean of precipitation: \" + (format(datum[\"mean_precipitation\"], \"\"))"
},
"x2": {"scale": "x", "field": "month_date", "offset": 3},
"x": {"scale": "x", "field": "month_date_end", "offset": -2},
"y": {"scale": "y", "field": "mean_precipitation"},
"y2": {"scale": "y", "value": 0}
}
}
}
],
"scales": [
{
"name": "x",
"type": "time",
"domain": {
"data": "source_0",
"fields": ["month_date", "month_date_end"]
},
"range": [0, {"signal": "width"}]
},
{
"name": "y",
"type": "linear",
"domain": {"data": "source_0", "field": "mean_precipitation"},
"range": [{"signal": "height"}, 0],
"nice": true,
"zero": true
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"gridScale": "y",
"grid": true,
"tickMinStep": {
"signal": "datetime(2001, 1, 1, 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": "date (month)",
"format": {
"signal": "timeUnitSpecifier([\"month\"], {\"year-month\":\"%b %Y \",\"year-month-date\":\"%b %d, %Y \"})"
},
"labelFlush": true,
"labelOverlap": true,
"tickMinStep": {
"signal": "datetime(2001, 1, 1, 0, 0, 0, 0) - datetime(2001, 0, 1, 0, 0, 0, 0)"
},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "Mean of precipitation",
"labelOverlap": true,
"tickCount": {"signal": "ceil(height/40)"},
"zindex": 0
}
]
}
9 changes: 9 additions & 0 deletions examples/specs/line_month_center_band_offset.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"url": "data/seattle-weather.csv"},
"mark": {"type": "bar", "xOffset": -2, "x2Offset": 2},
"encoding": {
"x": {"timeUnit": "month", "field": "date", "type": "temporal"},
"y": {"aggregate": "mean", "field": "precipitation"}
}
}
3 changes: 2 additions & 1 deletion src/compile/mark/encode/position-rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ function rectBinPosition({
const vgChannel2 = getVgPositionChannel(channel2);

const {offset} = positionOffset({channel, markDef, encoding, model, bandPosition: 0});
const {offset: offset2} = positionOffset({channel: channel2, markDef, encoding, model, bandPosition: 0});

const bandPosition = isSignalRef(bandSize)
? {signal: `(1-${bandSize.signal})/2`}
Expand All @@ -315,7 +316,7 @@ function rectBinPosition({
fieldDef,
scaleName,
bandPosition,
offset: getBinSpacing(channel2, spacing, reverse, axisTranslate, offset)
offset: getBinSpacing(channel2, spacing, reverse, axisTranslate, offset2 ?? offset)
}),
[vgChannel]: rectBinRef({
fieldDef,
Expand Down

0 comments on commit f8a0cfa

Please sign in to comment.