diff --git a/examples/compiled/bar_1d.vg.json b/examples/compiled/bar_1d.vg.json
index 221acc9662..1b454b8fda 100644
--- a/examples/compiled/bar_1d.vg.json
+++ b/examples/compiled/bar_1d.vg.json
@@ -42,7 +42,7 @@
"x": {"scale": "x", "field": "sum_people"},
"x2": {"scale": "x", "value": 0},
"yc": {"signal": "height", "mult": 0.5},
- "height": {"value": 18}
+ "height": {"signal": "0.9 * height"}
}
}
}
diff --git a/examples/compiled/bar_1d_default_size.png b/examples/compiled/bar_1d_default_size.png
new file mode 100644
index 0000000000..ea366cce80
Binary files /dev/null and b/examples/compiled/bar_1d_default_size.png differ
diff --git a/examples/compiled/bar_1d_default_size.svg b/examples/compiled/bar_1d_default_size.svg
new file mode 100644
index 0000000000..eaf818e9a7
--- /dev/null
+++ b/examples/compiled/bar_1d_default_size.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/examples/compiled/bar_1d_default_size.vg.json b/examples/compiled/bar_1d_default_size.vg.json
new file mode 100644
index 0000000000..75b7638745
--- /dev/null
+++ b/examples/compiled/bar_1d_default_size.vg.json
@@ -0,0 +1,85 @@
+{
+ "$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/population.json",
+ "format": {"type": "json"},
+ "transform": [
+ {"type": "filter", "expr": "datum.year == 2000"},
+ {
+ "type": "aggregate",
+ "groupby": [],
+ "ops": ["sum"],
+ "fields": ["people"],
+ "as": ["sum_people"]
+ },
+ {
+ "type": "filter",
+ "expr": "isValid(datum[\"sum_people\"]) && isFinite(+datum[\"sum_people\"])"
+ }
+ ]
+ }
+ ],
+ "marks": [
+ {
+ "name": "marks",
+ "type": "rect",
+ "style": ["bar"],
+ "from": {"data": "source_0"},
+ "encode": {
+ "update": {
+ "fill": {"value": "#4c78a8"},
+ "ariaRoleDescription": {"value": "bar"},
+ "description": {
+ "signal": "\"population: \" + (format(datum[\"sum_people\"], \"\"))"
+ },
+ "x": {"scale": "x", "field": "sum_people"},
+ "x2": {"scale": "x", "value": 0},
+ "yc": {"signal": "height", "mult": 0.5},
+ "height": {"signal": "0.9 * height"}
+ }
+ }
+ }
+ ],
+ "scales": [
+ {
+ "name": "x",
+ "type": "linear",
+ "domain": {"data": "source_0", "field": "sum_people"},
+ "range": [0, {"signal": "width"}],
+ "nice": true,
+ "zero": true
+ }
+ ],
+ "axes": [
+ {
+ "scale": "x",
+ "orient": "bottom",
+ "grid": true,
+ "tickCount": {"signal": "ceil(width/40)"},
+ "domain": false,
+ "labels": false,
+ "aria": false,
+ "maxExtent": 0,
+ "minExtent": 0,
+ "ticks": false,
+ "zindex": 0
+ },
+ {
+ "scale": "x",
+ "orient": "bottom",
+ "grid": false,
+ "title": "population",
+ "labelFlush": true,
+ "labelOverlap": true,
+ "tickCount": {"signal": "ceil(width/40)"},
+ "zindex": 0
+ }
+ ]
+}
diff --git a/examples/compiled/bar_1d_step_config.png b/examples/compiled/bar_1d_step_config.png
index 640b472e77..c7c0d28763 100644
Binary files a/examples/compiled/bar_1d_step_config.png and b/examples/compiled/bar_1d_step_config.png differ
diff --git a/examples/compiled/bar_1d_step_config.svg b/examples/compiled/bar_1d_step_config.svg
index dcbfde67a3..d1f549eb10 100644
--- a/examples/compiled/bar_1d_step_config.svg
+++ b/examples/compiled/bar_1d_step_config.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/examples/compiled/bar_1d_step_config.vg.json b/examples/compiled/bar_1d_step_config.vg.json
index e95eacc6da..744c2debde 100644
--- a/examples/compiled/bar_1d_step_config.vg.json
+++ b/examples/compiled/bar_1d_step_config.vg.json
@@ -42,7 +42,7 @@
"x": {"scale": "x", "field": "sum_people"},
"x2": {"scale": "x", "value": 0},
"yc": {"signal": "height", "mult": 0.5},
- "height": {"value": 13}
+ "height": {"signal": "0.9 * height"}
}
}
}
diff --git a/examples/compiled/facet_bullet.png b/examples/compiled/facet_bullet.png
index e7024aa7da..47c4b4b62d 100644
Binary files a/examples/compiled/facet_bullet.png and b/examples/compiled/facet_bullet.png differ
diff --git a/examples/compiled/facet_bullet.svg b/examples/compiled/facet_bullet.svg
index bb8b5000b6..95bc21d861 100644
--- a/examples/compiled/facet_bullet.svg
+++ b/examples/compiled/facet_bullet.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/examples/compiled/facet_bullet.vg.json b/examples/compiled/facet_bullet.vg.json
index 1e49e16ae8..d594fea208 100644
--- a/examples/compiled/facet_bullet.vg.json
+++ b/examples/compiled/facet_bullet.vg.json
@@ -344,7 +344,7 @@
"x": {"scale": "child_x", "field": "ranges\\.2\\._end"},
"x2": {"scale": "child_x", "field": "ranges\\.2\\._start"},
"yc": {"signal": "child_height", "mult": 0.5},
- "height": {"value": 18}
+ "height": {"signal": "1 * height"}
}
}
},
@@ -363,7 +363,7 @@
"x": {"scale": "child_x", "field": "ranges\\.1\\._end"},
"x2": {"scale": "child_x", "field": "ranges\\.1\\._start"},
"yc": {"signal": "child_height", "mult": 0.5},
- "height": {"value": 18}
+ "height": {"signal": "1 * height"}
}
}
},
@@ -382,7 +382,7 @@
"x": {"scale": "child_x", "field": "ranges\\.0\\._end"},
"x2": {"scale": "child_x", "field": "ranges\\.0\\._start"},
"yc": {"signal": "child_height", "mult": 0.5},
- "height": {"value": 18}
+ "height": {"signal": "1 * height"}
}
}
},
diff --git a/examples/compiled/stacked_bar_1d.vg.json b/examples/compiled/stacked_bar_1d.vg.json
index 06163d49be..743ebb1d35 100644
--- a/examples/compiled/stacked_bar_1d.vg.json
+++ b/examples/compiled/stacked_bar_1d.vg.json
@@ -49,7 +49,7 @@
"x": {"scale": "x", "field": "sum_Acceleration_end"},
"x2": {"scale": "x", "field": "sum_Acceleration_start"},
"yc": {"signal": "height", "mult": 0.5},
- "height": {"value": 18}
+ "height": {"signal": "0.9 * height"}
}
}
}
diff --git a/examples/specs/bar_1d_default_size.vl.json b/examples/specs/bar_1d_default_size.vl.json
new file mode 100644
index 0000000000..0c4ca8b68f
--- /dev/null
+++ b/examples/specs/bar_1d_default_size.vl.json
@@ -0,0 +1,15 @@
+{
+ "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
+ "data": { "url": "data/population.json"},
+ "transform": [{
+ "filter": "datum.year == 2000"
+ }],
+ "mark": "bar",
+ "encoding": {
+ "x": {
+ "aggregate": "sum", "field": "people",
+ "title": "population"
+ }
+ },
+ "height": 200
+}
diff --git a/examples/specs/facet_bullet.vl.json b/examples/specs/facet_bullet.vl.json
index 3273be1799..2ca6ebe203 100644
--- a/examples/specs/facet_bullet.vl.json
+++ b/examples/specs/facet_bullet.vl.json
@@ -45,5 +45,5 @@
}]
},
"resolve": {"scale": {"x": "independent"}},
- "config": {"tick": {"thickness": 2}}
+ "config": {"tick": {"thickness": 2}, "scale": {"barBandPaddingInner": 0}}
}
diff --git a/examples/specs/normalized/facet_bullet_normalized.vl.json b/examples/specs/normalized/facet_bullet_normalized.vl.json
index 5557fa08c6..0bbe0d48e0 100644
--- a/examples/specs/normalized/facet_bullet_normalized.vl.json
+++ b/examples/specs/normalized/facet_bullet_normalized.vl.json
@@ -118,5 +118,5 @@
]
},
"resolve": {"scale": {"x": "independent"}},
- "config": {"tick": {"thickness": 2}}
+ "config": {"tick": {"thickness": 2}, "scale": {"barBandPaddingInner": 0}}
}
\ No newline at end of file
diff --git a/src/compile/mark/encode/position-rect.ts b/src/compile/mark/encode/position-rect.ts
index cb52d94ed2..59f4899e9e 100644
--- a/src/compile/mark/encode/position-rect.ts
+++ b/src/compile/mark/encode/position-rect.ts
@@ -28,6 +28,9 @@ import {pointPositionDefaultRef} from './position-point';
import {rangePosition} from './position-range';
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;
@@ -75,7 +78,9 @@ function defaultSizeRef(
scaleName: string,
scale: ScaleComponent,
config: Config,
- bandSize: BandSize
+ bandSize: BandSize,
+ hasFieldDef: boolean,
+ mark: Mark
): VgValueRef {
if (isRelativeBandSize(bandSize)) {
if (scale) {
@@ -110,6 +115,17 @@ function defaultSizeRef(
return {value: scaleRange.step - 2};
}
}
+ if (!hasFieldDef) {
+ const {bandPaddingInner, barBandPaddingInner, rectBandPaddingInner} = config.scale;
+ const padding = getFirstDefined(bandPaddingInner, mark === 'bar' ? barBandPaddingInner : rectBandPaddingInner); // this part is like paddingInner in scale.ts
+ if (isSignalRef(padding)) {
+ 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);
return {value: defaultStep - 2};
}
@@ -155,7 +171,15 @@ function positionAndSize(
const bandSize = getBandSize({channel, fieldDef, markDef, config, scaleType: scale?.get('type'), useVlSizeChannel});
sizeMixins = sizeMixins || {
- [vgSizeChannel]: defaultSizeRef(vgSizeChannel, offsetScaleName || scaleName, offsetScale || scale, config, bandSize)
+ [vgSizeChannel]: defaultSizeRef(
+ vgSizeChannel,
+ offsetScaleName || scaleName,
+ offsetScale || scale,
+ config,
+ bandSize,
+ !!fieldDef,
+ markDef.type
+ )
};
/*
diff --git a/test/compile/mark/bar.test.ts b/test/compile/mark/bar.test.ts
index 1aa15b011e..3451ae47d5 100644
--- a/test/compile/mark/bar.test.ts
+++ b/test/compile/mark/bar.test.ts
@@ -769,7 +769,7 @@ describe('Mark: Bar', () => {
const props = bar.encodeEntry(model);
it('should not use config.mark.size', () => {
- expect(props.width).toEqual({value: 18});
+ expect(props.width).toEqual({signal: '0.9 * width'});
});
});
diff --git a/test/compile/mark/encode/position-rect.test.ts b/test/compile/mark/encode/position-rect.test.ts
index a9117b3ac4..1a37f3a674 100644
--- a/test/compile/mark/encode/position-rect.test.ts
+++ b/test/compile/mark/encode/position-rect.test.ts
@@ -210,5 +210,24 @@ describe('compile/mark/encode/position-rect', () => {
signal: 't + (r ? -1 : 1) * (o + 0.5)'
});
});
+
+ it('produces correct default y-mixins for empty y encoding', () => {
+ const model = parseUnitModelWithScaleAndLayoutSize({
+ data: {values: []},
+ mark: {type: 'bar'},
+ encoding: {
+ x: {
+ field: 'x',
+ type: 'quantitative',
+ aggregate: 'mean'
+ }
+ }
+ });
+
+ const props = rectPosition(model, 'y');
+ expect(props.height).toEqual({
+ signal: '0.9 * height'
+ });
+ });
});
});