Skip to content

Commit

Permalink
fix(#9173): make mark.size support relative band size (e.g., {"band":…
Browse files Browse the repository at this point in the history
… 0.5}) for bars
  • Loading branch information
kanitw committed Nov 14, 2023
1 parent c9a80de commit 8c588b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/compile/mark/encode/position-rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ function positionAndSize(

// Use size encoding / mark property / config if it exists
let sizeMixins;
if (encoding.size || markDef.size) {

// TODO(@kanitw): this sizeMixins logic here is a bit convoluted.
// It's sometimes set in the defaultSizeRef below and sometimes up here.
// We should refactor this logic to be simpler.
if (encoding.size || (markDef.size && !isRelativeBandSize(markDef.size))) {
if (useVlSizeChannel) {
sizeMixins = nonPosition('size', model, {
vgChannel: vgSizeChannel,
Expand Down
6 changes: 3 additions & 3 deletions src/mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export interface VLOnlyMarkConfig<ES extends ExprRef | SignalRef> extends ColorM

export interface MarkConfig<ES extends ExprRef | SignalRef>
extends VLOnlyMarkConfig<ES>,
MapExcludeValueRefAndReplaceSignalWith<Omit<VgMarkConfig, 'tooltip' | 'fill' | 'stroke'>, ES> {
MapExcludeValueRefAndReplaceSignalWith<Omit<VgMarkConfig, 'tooltip' | 'fill' | 'stroke' | 'size'>, ES> {
// ========== Overriding Vega ==========

/**
Expand All @@ -147,7 +147,7 @@ export interface MarkConfig<ES extends ExprRef | SignalRef>
/**
* Default size for marks.
* - For `point`/`circle`/`square`, this represents the pixel area of the marks. Note that this value sets the area of the symbol; the side lengths will increase with the square root of this value.
* - For `bar`, this represents the band size of the bar, in pixels.
* - For `bar`, this represents the band size of the bar, in pixels, or relative band size (e.g., `{"band": 0.5}` is half of the band).
* - For `text`, this represents the font size, in pixels.
*
* __Default value:__
Expand All @@ -158,7 +158,7 @@ export interface MarkConfig<ES extends ExprRef | SignalRef>
*
* @minimum 0
*/
size?: number | ES; // size works beyond symbol marks in VL
size?: number | ES | RelativeBandSize; // Unlike in VG where size is only for symbol marks (point in VL), size works beyond symbol marks in VL

/**
* X coordinates of the marks, or width of horizontal `"bar"` and `"area"` without specified `x2` or `width`.
Expand Down

0 comments on commit 8c588b5

Please sign in to comment.