Skip to content

Commit

Permalink
fix: apply bandPosition to offset channel for grouped bar (so band si…
Browse files Browse the repository at this point in the history
…ze works with grouped bars)

fix #9177
  • Loading branch information
kanitw committed Nov 16, 2023
1 parent efacdd0 commit 0d7ec05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/compile/mark/encode/offset.ts
Expand Up @@ -26,7 +26,7 @@ export function positionOffset({
markDef: MarkDef<Mark, SignalRef>;
encoding?: Encoding<string>;
model?: UnitModel;
bandPosition?: number;
bandPosition?: number | SignalRef;
}): Offset {
const channel = `${baseChannel}Offset` as
| 'xOffset'
Expand Down
21 changes: 11 additions & 10 deletions src/compile/mark/encode/position-rect.ts
Expand Up @@ -203,7 +203,16 @@ function positionAndSize(

const vgChannel = vgAlignedPositionChannel(channel, markDef, config, defaultBandAlign);
const center = vgChannel === 'xc' || vgChannel === 'yc';
const {offset, offsetType} = positionOffset({channel, markDef, encoding, model, bandPosition: center ? 0.5 : 0});

const bandPosition = center
? 0.5
: isSignalRef(bandSize)
? {signal: `(1-${bandSize})/2`}

Check warning on line 210 in src/compile/mark/encode/position-rect.ts

View check run for this annotation

Codecov / codecov/patch

src/compile/mark/encode/position-rect.ts#L210

Added line #L210 was not covered by tests
: isRelativeBandSize(bandSize)
? (1 - bandSize.band) / 2
: 0;

Check warning on line 213 in src/compile/mark/encode/position-rect.ts

View check run for this annotation

Codecov / codecov/patch

src/compile/mark/encode/position-rect.ts#L213

Added line #L213 was not covered by tests

const {offset, offsetType} = positionOffset({channel, markDef, encoding, model, bandPosition});

const posRef = ref.midPointRefWithPositionInvalidTest({
channel,
Expand All @@ -215,15 +224,7 @@ function positionAndSize(
stack,
offset,
defaultRef: pointPositionDefaultRef({model, defaultPos: 'mid', channel, scaleName, scale}),
bandPosition: center
? offsetType === 'encoding'
? 0
: 0.5
: isSignalRef(bandSize)
? {signal: `(1-${bandSize})/2`}
: isRelativeBandSize(bandSize)
? (1 - bandSize.band) / 2
: 0
bandPosition: offsetType === 'encoding' ? 0 : bandPosition
});

if (vgSizeChannel) {
Expand Down

0 comments on commit 0d7ec05

Please sign in to comment.