Skip to content

Commit

Permalink
fix: remove incorrect stack transform from charts with one linear Q-a…
Browse files Browse the repository at this point in the history
…xis one non-linear Q-axis. (vega#8871)

Co-authored-by: GitHub Actions Bot <vega-actions-bot@users.noreply.github.com>
  • Loading branch information
2 people authored and BradyJ27 committed Oct 19, 2023
1 parent bb5747c commit 150e025
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 11 deletions.
Binary file added examples/compiled/bar_q_qpow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/compiled/bar_q_qpow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions examples/compiled/bar_q_qpow.vg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"background": "white",
"padding": 5,
"width": 200,
"height": 200,
"style": "cell",
"data": [
{
"name": "source_0",
"values": [
{"a": 3000, "b": 55},
{"a": 3500, "b": 28},
{"a": 4000, "b": 55}
]
},
{
"name": "data_0",
"source": "source_0",
"transform": [
{
"type": "filter",
"expr": "isValid(datum[\"a\"]) && isFinite(+datum[\"a\"]) && isValid(datum[\"b\"]) && isFinite(+datum[\"b\"])"
}
]
}
],
"marks": [
{
"name": "marks",
"type": "rect",
"style": ["bar"],
"from": {"data": "data_0"},
"encode": {
"update": {
"fill": {"value": "#4c78a8"},
"ariaRoleDescription": {"value": "bar"},
"description": {
"signal": "\"a: \" + (format(datum[\"a\"], \"\")) + \"; b: \" + (format(datum[\"b\"], \"\"))"
},
"xc": {"scale": "x", "field": "a"},
"width": {"value": 5},
"y": {"scale": "y", "field": "b"},
"y2": {"scale": "y", "value": 0}
}
}
}
],
"scales": [
{
"name": "x",
"type": "linear",
"domain": {"data": "data_0", "field": "a"},
"range": [0, {"signal": "width"}],
"nice": true,
"zero": false,
"padding": 5
},
{
"name": "y",
"type": "pow",
"domain": {"data": "data_0", "field": "b"},
"range": [{"signal": "height"}, 0],
"nice": true,
"zero": true
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"gridScale": "y",
"grid": true,
"tickCount": {"signal": "ceil(width/40)"},
"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": "a",
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(width/40)"},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "b",
"labelOverlap": true,
"tickCount": {"signal": "ceil(height/40)"},
"zindex": 0
}
]
}
15 changes: 15 additions & 0 deletions examples/specs/bar_q_qpow.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"a": 3000, "b": 55},
{"a": 3500, "b": 28},
{"a": 4000, "b": 55}
]
},
"mark": "bar",
"encoding": {
"x": {"field": "a", "type": "quantitative"},
"y": {"field": "b", "type": "quantitative", "scale": {"type": "pow"}}
}
}
13 changes: 3 additions & 10 deletions src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,6 @@ function potentialStackedChannel(
// if there is no explicit stacking, only apply stack if there is only one aggregate for x or y
if (xAggregate !== yAggregate) {
return xAggregate ? x : y;
} else {
const xScale = xDef.scale?.type;
const yScale = yDef.scale?.type;

if (xScale && xScale !== 'linear') {
return y;
} else if (yScale && yScale !== 'linear') {
return x;
}
}

if (isCartesian && mark === 'bar') {
Expand Down Expand Up @@ -247,7 +238,9 @@ export function stack(m: Mark | MarkDef, encoding: Encoding<string>): StackPrope

// warn when stacking non-linear
if (stackedFieldDef?.scale?.type && stackedFieldDef?.scale?.type !== ScaleType.LINEAR) {
log.warn(log.message.cannotStackNonLinearScale(stackedFieldDef.scale.type));
if (stackedFieldDef?.stack) {
log.warn(log.message.cannotStackNonLinearScale(stackedFieldDef.scale.type));
}
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion test/stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ describe('stack', () => {
it(
'should always warn if the aggregated axis has non-linear scale',
log.wrap(localLogger => {
for (const s of [undefined, 'center', 'zero', 'normalize'] as const) {
for (const s of ['center', 'zero', 'normalize'] as const) {
for (const scaleType of [ScaleType.LOG, ScaleType.POW, ScaleType.SQRT]) {
const marks = s === undefined ? STACK_BY_DEFAULT_NON_POLAR_MARKS : STACKABLE_NON_POLAR_MARKS;
for (const mark of marks) {
Expand Down

0 comments on commit 150e025

Please sign in to comment.