Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use resolve "shared" instead of steps to fix artifacts in grouped density transform #9106

Merged
merged 3 commits into from
Sep 20, 2023
Merged
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
2 changes: 1 addition & 1 deletion examples/compiled/area_density_facet.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"groupby": ["Species"],
"extent": [2500, 6500],
"as": ["value", "density"],
"steps": 200
"resolve": "shared"
},
{
"type": "impute",
Expand Down
2 changes: 1 addition & 1 deletion examples/compiled/area_density_stacked.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"groupby": ["Species"],
"extent": [2500, 6500],
"as": ["value", "density"],
"steps": 200
"resolve": "shared"
},
{
"type": "impute",
Expand Down
3 changes: 2 additions & 1 deletion examples/compiled/area_density_stacked_fold.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"extent": [10, 500],
"counts": true,
"steps": 200,
"as": ["value", "density"]
"as": ["value", "density"],
"resolve": "shared"
Copy link
Member

Choose a reason for hiding this comment

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

Should this one change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the input Vega-Lite spec has:

    {
      "density": "value",
      "bandwidth": 10,
      "groupby": ["Measurement"],
      "extent": [10, 500],
      "counts": true,
      "steps": 200
    }

Since groupby is defined we get "resolve": "shared". "steps": 200 is still there because it's explicitly specified in the Vega-Lite transform.

},
{
"type": "impute",
Expand Down
8 changes: 3 additions & 5 deletions src/compile/data/density.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ export class DensityTransformNode extends DataFlowNode {
this.transform = duplicate(transform); // duplicate to prevent side effects
const specifiedAs = this.transform.as ?? [undefined, undefined];
this.transform.as = [specifiedAs[0] ?? 'value', specifiedAs[1] ?? 'density'];

// set steps when we are grouping so that we get consitent sampling points for imputing and grouping
if (transform.groupby && transform.minsteps == null && transform.maxsteps == null && transform.steps == null) {
this.transform.steps = 200;
}
}

public dependentFields() {
Expand All @@ -42,6 +37,9 @@ export class DensityTransformNode extends DataFlowNode {
field: density,
...rest
};
if (this.transform.groupby) {
result.resolve = 'shared';
}
return result;
}
}
5 changes: 3 additions & 2 deletions test/compile/data/density.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('compile/data/fold', () => {
extent: [0, 10],
minsteps: 25,
maxsteps: 200,
resolve: 'shared',
as: ['x', 'y']
});
});
Expand Down Expand Up @@ -57,7 +58,7 @@ describe('compile/data/fold', () => {
});
});

it('should add steps if we group', () => {
it('should add resolve shared if we group', () => {
const transform: Transform = {
density: 'v',
groupby: ['a']
Expand All @@ -67,7 +68,7 @@ describe('compile/data/fold', () => {
type: 'kde',
groupby: ['a'],
field: 'v',
steps: 200,
resolve: 'shared',
as: ['value', 'density']
});
});
Expand Down