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

Correctly generate as for nested fields. Note that in Vega as cannot be nested so you have to provide a field name, not a field accessor. Fixes #3744 #4023

Merged
merged 4 commits into from
Jul 15, 2018

Conversation

kanitw
Copy link
Member

@kanitw kanitw commented Jul 15, 2018

No description provided.

…not be nested so you have to provide a field name, not a field accessor. Fixes #3744.
@kanitw kanitw changed the title Dom/nested aggregates Correctly generate as for nested fields. Note that in Vega as cannot be nested so you have to provide a field name, not a field accessor. Fixes #3744 Jul 15, 2018
Copy link
Member Author

@kanitw kanitw left a comment

Choose a reason for hiding this comment

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

Lucky we don't let it go.

These two names are super confusing: vgFieldName vgField. Both are field names. If one of them is transform output, better make that a parameter.

@domoritz
Copy link
Member

Updated the PR.

Copy link
Member Author

@kanitw kanitw left a comment

Choose a reason for hiding this comment

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

LGTM with a few minor knitpicks.

@@ -218,6 +218,7 @@ export class StackNode extends DataFlowNode {
// Impute
if (impute && dimensionFieldDef) {
const dimensionField = dimensionFieldDef ? vgField(dimensionFieldDef, {binSuffix: 'mid'}) : undefined;
const dimensionAs = dimensionFieldDef ? vgField(dimensionFieldDef, {binSuffix: 'mid', forAs: true}) : undefined;
Copy link
Member Author

Choose a reason for hiding this comment

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

Why should this be different from dimensionField?
especially given than you impute afterward.

Copy link
Member

Choose a reason for hiding this comment

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

The key is a field reference in Vega and we have to escape nesting.

Copy link
Member

Choose a reason for hiding this comment

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

I revides the code a bit since it's a bit superfluous to have a ternary with dimensionFieldDef if it is already required to pass the if.

export function facetSortFieldName(
fieldDef: FacetFieldDef<string>,
sort: EncodingSortField<string>,
expr?: 'datum',
Copy link
Member Author

Choose a reason for hiding this comment

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

Make {expr, forAs=true}: {expr?: datum, forAs:boolean}?

Copy link
Member

Choose a reason for hiding this comment

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

No, we want the default to be false.

Copy link
Member

Choose a reason for hiding this comment

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

Anyway, revised.

src/fielddef.ts Outdated
if (opt.forAs) {
// Don't need to mess with nested field names because Vega transform outputs are never nested.
return field;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

else if?

Copy link
Member

Choose a reason for hiding this comment

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

Done

@@ -297,7 +297,8 @@ export function accessPathWithDatum(path: string, datum = 'datum') {
}

/**
* Return access with datum to the falttened field.
* Return access with datum to the flattened field.
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI, the datum variable down there is a bit misleading as it can be parent too. (It confuses me for a bit)

Copy link
Member

Choose a reason for hiding this comment

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

Fixed

src/fielddef.ts Outdated
suffix?: string;
/** Use the field name for `as` in a transform. */
Copy link
Member Author

Choose a reason for hiding this comment

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

Add a comment how this affect the output.

Copy link
Member

Choose a reason for hiding this comment

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

Done

src/fielddef.ts Outdated
@@ -396,6 +401,11 @@ export function vgField(
field = `${prefix}_${field}`;
}

if (opt.forAs) {
// Don't need to mess with nested field names because Vega transform outputs are never nested.
Copy link
Member Author

Choose a reason for hiding this comment

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

"mess with" => escape

Copy link
Member

Choose a reason for hiding this comment

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

Done

@kanitw kanitw merged commit 2085ac0 into master Jul 15, 2018
@kanitw kanitw deleted the dom/nested-aggregates branch July 15, 2018 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants