Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/arc_quantitative_stacked_theta.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions examples/compiled/arc_quantitative_stacked_theta.vg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"$schema": "https://vega.github.io/schema/vega/v6.json",
"background": "white",
"padding": 5,
"width": 300,
"height": 300,
"style": "view",
"data": [
{
"name": "source_0",
"values": [
{"segment": 1, "value": 8},
{"segment": 2, "value": 7},
{"segment": 3, "value": 6}
]
},
{
"name": "data_0",
"source": "source_0",
"transform": [
{
"type": "stack",
"groupby": [],
"field": "segment",
"sort": {"field": [], "order": []},
"as": ["segment_start", "segment_end"],
"offset": "zero"
},
{
"type": "filter",
"expr": "isValid(datum[\"segment\"]) && isFinite(+datum[\"segment\"]) && isValid(datum[\"value\"]) && isFinite(+datum[\"value\"])"
}
]
}
],
"marks": [
{
"name": "marks",
"type": "arc",
"style": ["arc"],
"from": {"data": "data_0"},
"encode": {
"update": {
"opacity": {"value": 0.5},
"stroke": {"value": "#fff"},
"innerRadius": {"value": 20},
"fill": {"value": "#4c78a8"},
"description": {
"signal": "\"segment: \" + (format(datum[\"segment\"], \"\")) + \"; value: \" + (format(datum[\"value\"], \"\"))"
},
"x": {"signal": "width", "mult": 0.5},
"y": {"signal": "height", "mult": 0.5},
"outerRadius": {"scale": "radius", "field": "value"},
"startAngle": {"scale": "theta", "field": "segment_end"},
"endAngle": {"scale": "theta", "field": "segment_start"}
}
}
}
],
"scales": [
{
"name": "theta",
"type": "linear",
"domain": {"data": "data_0", "fields": ["segment_start", "segment_end"]},
"range": [0, 6.283185307179586],
"zero": true
},
{
"name": "radius",
"type": "sqrt",
"domain": {"data": "data_0", "field": "value"},
"range": [20, {"signal": "min(width,height)/2"}],
"zero": true
}
]
}
40 changes: 40 additions & 0 deletions examples/specs/arc_quantitative_stacked_theta.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v6.json",
"data": {
"values": [
{
"segment": 1,
"value": 8
},
{
"segment": 2,
"value": 7
},
{
"segment": 3,
"value": 6
}
]
},
"mark": {
"type": "arc",
"innerRadius": 20,
"stroke": "#fff",
"opacity": 0.5
},
"encoding": {
"theta": {
"field": "segment",
"type": "quantitative",
"stack": true
},
"radius": {
"field": "value",
"scale": {
"type": "sqrt",
"zero": true,
"rangeMin": 20
}
}
}
}
10 changes: 7 additions & 3 deletions src/stack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {array, hasOwnProperty, isBoolean} from 'vega-util';
import {Aggregate, SUM_OPS} from './aggregate.js';
import {getSecondaryRangeChannel, NonPositionChannel, NONPOSITION_CHANNELS} from './channel.js';
import {getSecondaryRangeChannel, NonPositionChannel, NONPOSITION_CHANNELS, isPolarPositionChannel} from './channel.js';
import {
channelDefType,
FieldName,
Expand Down Expand Up @@ -176,8 +176,13 @@ export function stack(m: Mark | MarkDef, encoding: Encoding<string>): StackPrope
if (encoding[dimensionChannel]) {
const dimensionDef = encoding[dimensionChannel];
const dimensionField = isFieldDef(dimensionDef) ? vgField(dimensionDef, {}) : undefined;
const hasSameDimensionAndStackedField = dimensionField && dimensionField === stackedField;

if (dimensionField && dimensionField !== stackedField) {
// For polar coordinates, do not set a groupBy when working with quantitative fields.
const isPolar = isPolarPositionChannel(fieldChannel) || isPolarPositionChannel(dimensionChannel);
const shouldAddPolarGroupBy = !isUnbinnedQuantitative(dimensionDef);

if (isPolar ? shouldAddPolarGroupBy : !hasSameDimensionAndStackedField) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we really need isPolar ? shouldAddPolarGroupBy : clause? If we strictly check the field above, would that be sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By strictly check, do you mean we'd check if dimensionDef and stackedFieldDef have the same

  • field (the current check)
  • bin
  • aggregator
  • timeUnit

for both polar and cartesian graphs?

Currently if I just remove the isPolar ? shouldAddPolarGroupBy clause and use the existing check, we'd introduce this bug

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a PoC commit to see if this is what you had in mind

8b010a6

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd introduce this bug

can't find this link

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it interesting to see how many of the visual tests break if I removed the check that only applies this change to polar encodings.

#9557

// avoid grouping by the stacked field
groupbyChannels.push(dimensionChannel);
groupbyFields.add(dimensionField);
Expand Down Expand Up @@ -237,7 +242,6 @@ export function stack(m: Mark | MarkDef, encoding: Encoding<string>): StackPrope
if (!offset || !isStackOffset(offset)) {
return null;
}

if (isAggregate(encoding) && stackBy.length === 0) {
return null;
}
Expand Down
23 changes: 22 additions & 1 deletion test/stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ describe('stack', () => {
expect(_stack.stackBy[0].channel).toBe('color');
});

it('should be correct for radial chart', () => {
it('should be correct for radial chart with same radius and theta quantitative fields', () => {
const spec: TopLevel<NormalizedUnitSpec> = {
data: {url: 'data/barley.json'},
mark: 'arc',
Expand All @@ -463,6 +463,27 @@ describe('stack', () => {
};
const _stack = stack(spec.mark, spec.encoding);
expect(_stack.fieldChannel).toBe('theta');
expect(_stack.groupbyChannels).toHaveLength(0);
expect(_stack.groupbyFields.size).toBe(0);
});

it('should be correct for radial chart with different radius and theta quantitative fields', () => {
const spec: TopLevel<NormalizedUnitSpec> = {
data: {url: 'data/barley.json'},
mark: 'arc',
encoding: {
theta: {field: 'year', type: 'quantitative', stack: true},
radius: {
field: 'variety',
type: 'quantitative',
scale: {type: 'sqrt', zero: true, range: [20, 100]},
},
},
};
const _stack = stack(spec.mark, spec.encoding);
expect(_stack.fieldChannel).toBe('theta');
expect(_stack.groupbyChannels).toHaveLength(0);
expect(_stack.groupbyFields.size).toBe(0);
});
});

Expand Down