diff --git a/examples/compiled/line_month_center_band_offset.png b/examples/compiled/line_month_center_band_offset.png new file mode 100644 index 00000000000..cdb769d34d3 Binary files /dev/null and b/examples/compiled/line_month_center_band_offset.png differ diff --git a/examples/compiled/line_month_center_band_offset.svg b/examples/compiled/line_month_center_band_offset.svg new file mode 100644 index 00000000000..0465e434def --- /dev/null +++ b/examples/compiled/line_month_center_band_offset.svg @@ -0,0 +1 @@ +JanFebMarAprMayJunJulAugSepOctNovDecJandate (month)012345Mean of precipitation \ No newline at end of file diff --git a/examples/compiled/line_month_center_band_offset.vg.json b/examples/compiled/line_month_center_band_offset.vg.json new file mode 100644 index 00000000000..a10880bb8a5 --- /dev/null +++ b/examples/compiled/line_month_center_band_offset.vg.json @@ -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 + } + ] +} diff --git a/examples/specs/line_month_center_band_offset.vl.json b/examples/specs/line_month_center_band_offset.vl.json new file mode 100644 index 00000000000..d071860a4c4 --- /dev/null +++ b/examples/specs/line_month_center_band_offset.vl.json @@ -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"} + } +} diff --git a/src/compile/mark/encode/position-rect.ts b/src/compile/mark/encode/position-rect.ts index 59f4899e9e6..c33ff4f574f 100644 --- a/src/compile/mark/encode/position-rect.ts +++ b/src/compile/mark/encode/position-rect.ts @@ -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`} @@ -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,