Skip to content

Commit

Permalink
feat: config.rect/bar.minBandSize
Browse files Browse the repository at this point in the history
fix #8351
  • Loading branch information
kanitw committed Jun 20, 2023
1 parent f54895c commit c5fdbb1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
22 changes: 22 additions & 0 deletions examples/specs/bar_grouped_thin_minBandSize.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"url": "data/movies.json"},
"width": 500,
"mark": "bar",
"encoding": {
"x": {"field": "Director", "type": "nominal"},
"xOffset": {"field": "Title", "type": "nominal"},
"y": {
"aggregate": "mean",
"field": "Rotten Tomatoes Rating",
"type": "quantitative"
},
"color": {
"condition": {
"test": "datum['IMDB Rating'] === null || datum['Rotten Tomatoes Rating'] === null",
"value": "#aaa"
}
}
},
"config": {"mark": {"invalid": null}, "bar": {"minBandSize": 4}}
}
11 changes: 4 additions & 7 deletions src/compile/mark/encode/position-rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as log from '../../../log';
import {BandSize, isRelativeBandSize} from '../../../mark';
import {hasDiscreteDomain} from '../../../scale';
import {isSignalRef, isVgRangeStep, VgEncodeEntry, VgValueRef} from '../../../vega.schema';
import {getMarkPropOrConfig, signalOrStringValue, signalOrValueRef} from '../../common';
import {getMarkConfig, getMarkPropOrConfig, signalOrStringValue, signalOrValueRef} from '../../common';
import {ScaleComponent} from '../../scale/component';
import {UnitModel} from '../../unit';
import {nonPosition} from './nonposition';
Expand All @@ -30,7 +30,6 @@ import * as ref from './valueref';
import {getOffsetScaleChannel} from '../../../channel';
import {getFirstDefined} from '../../../util';
import {Mark} from '../../../mark';
import {isExprRef} from '../../../expr';

export function rectPosition(model: UnitModel, channel: 'x' | 'y' | 'theta' | 'radius'): VgEncodeEntry {
const {config, encoding, markDef} = model;
Expand Down Expand Up @@ -77,7 +76,7 @@ function defaultSizeRef(
sizeChannel: 'width' | 'height',
scaleName: string,
scale: ScaleComponent,
config: Config,
config: Config<SignalRef>,
bandSize: BandSize,
hasFieldDef: boolean,
mark: Mark
Expand All @@ -90,8 +89,8 @@ function defaultSizeRef(
if (bandSize.band !== 1) {
bandWidth = `${bandSize.band} * ${bandWidth}`;
}
// TODO(#8351): make 0.25 here configurable
return {signal: `max(0.25, ${bandWidth})`};
const minBandSize = getMarkConfig('minBandSize', {type: mark}, config);
return {signal: `max(${signalOrStringValue(minBandSize)}, ${bandWidth})`};
} else if (bandSize.band !== 1) {
log.warn(log.message.cannotUseRelativeBandSizeWithNonBandScale(scaleType));
bandSize = undefined;
Expand Down Expand Up @@ -122,8 +121,6 @@ function defaultSizeRef(
return {signal: `(1 - (${padding.signal})) * ${sizeChannel}`};
} else if (isNumber(padding)) {
return {signal: `${1 - padding} * ${sizeChannel}`};
} else if (isExprRef(padding)) {
return {signal: `(1 - (${padding.expr})) * ${sizeChannel}`};
}
}
const defaultStep = getViewConfigDiscreteStep(config.view, sizeChannel);
Expand Down
8 changes: 8 additions & 0 deletions src/mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ export interface RectConfig<ES extends ExprRef | SignalRef> extends RectBinSpaci
* @minimum 0
*/
discreteBandSize?: number | RelativeBandSize;

/**
* The minimum band size for bar and rectangle marks.
* __Default value:__ `0.25`
*/
minBandSize?: number | ES;
}

export type BandSize = number | RelativeBandSize | SignalRef;
Expand Down Expand Up @@ -650,12 +656,14 @@ const DEFAULT_RECT_BAND_SIZE = 5;
export const defaultBarConfig: RectConfig<SignalRef> = {
binSpacing: 1,
continuousBandSize: DEFAULT_RECT_BAND_SIZE,
minBandSize: 0.25,
timeUnitBandPosition: 0.5
};

export const defaultRectConfig: RectConfig<SignalRef> = {
binSpacing: 0,
continuousBandSize: DEFAULT_RECT_BAND_SIZE,
minBandSize: 0.25,
timeUnitBandPosition: 0.5
};

Expand Down

0 comments on commit c5fdbb1

Please sign in to comment.