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

Add Flatten transform #3812

Merged
merged 26 commits into from May 30, 2018
Merged

Add Flatten transform #3812

merged 26 commits into from May 30, 2018

Conversation

invokesus
Copy link
Member

@invokesus invokesus commented May 25, 2018

TODO:

  • Use vega-typings
  • Docs
  • Example
  • Add docstrings in transform.ts

private getDefaultName(field: string): string {
const index = this.transform.flatten.indexOf(field);
// Returns the "as" entry corresponding to field if it exists else returns field
return (this.transform.as === undefined || this.transform.as[index] === undefined) ? field : this.transform.as[index];
Copy link
Member Author

Choose a reason for hiding this comment

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

Right now this follows Vega Defaults. Not sure whether to change this and introduce different behavior when as is not specified.

Copy link
Member

Choose a reason for hiding this comment

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

Can't we just pass nothing and let Vega handle the default case?

Copy link
Member Author

Choose a reason for hiding this comment

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

@kanitw mentioned in slack that we need to set as, so that producedFields gives the correct output. But here, since the default is the field value, I think passing nothing might be ok.

Copy link
Member

Choose a reason for hiding this comment

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

Try it out and I'd always prefer to output less.

Copy link
Member

Choose a reason for hiding this comment

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

You can output as=undefined if you modify producedFields to output field name instead if as is undefined

Copy link
Member

Choose a reason for hiding this comment

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

I think this method is pretty unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

Try it out and I'd always prefer to output less.

I just check the rest of transform are all explicit though, so doing so would be quite inconsistent. So let's make them explicit for consistency for now.

If @domoritz doesn't like it, he can refactor all of the transforms later.

Copy link
Member

@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.

Great start. Please see comments. :)

const fields: string[] = [];
const as = [];
for (const field of this.transform.flatten) {
fields.push(field === undefined ? null : field);
Copy link
Member

Choose a reason for hiding this comment

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

why converting undefined to null?

}

private getDefaultName(field: string): string {
const index = this.transform.flatten.indexOf(field);
Copy link
Member

Choose a reason for hiding this comment

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

  1. The use of indexOf here is a bit unnecessary complex. Why don't you pass index in as a parameter. Your producedFields method can use the index in the reducer.

  2. when referring to properties of an object multiple times, always use destructure syntax.

const {flatten, as} = this.transform

}

public producedFields() {
const out = {};
Copy link
Member

Choose a reason for hiding this comment

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

Better just use reduce

return this.transform.flatten.reduce((index, field, i) => {
  out[as[i] || field] = true;
  return out
}, {});

private getDefaultName(field: string): string {
const index = this.transform.flatten.indexOf(field);
// Returns the "as" entry corresponding to field if it exists else returns field
return (this.transform.as === undefined || this.transform.as[index] === undefined) ? field : this.transform.as[index];
Copy link
Member

Choose a reason for hiding this comment

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

I think this method is pretty unnecessary.

private getDefaultName(field: string): string {
const index = this.transform.flatten.indexOf(field);
// Returns the "as" entry corresponding to field if it exists else returns field
return (this.transform.as === undefined || this.transform.as[index] === undefined) ? field : this.transform.as[index];
Copy link
Member

Choose a reason for hiding this comment

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

Try it out and I'd always prefer to output less.

I just check the rest of transform are all explicit though, so doing so would be quite inconsistent. So let's make them explicit for consistency for now.

If @domoritz doesn't like it, he can refactor all of the transforms later.

Copy link
Member

@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. Please make last minor fix and make the test pass and we can merge this to feature/transform. (Let's do docs separately so it's easier to review.)

}, {});
}

private getNames() {
Copy link
Member

Choose a reason for hiding this comment

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

Remove this method and move the logic above?

@invokesus invokesus changed the title Add flatten transform Add Flatten transform May 26, 2018
Copy link
Member

@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.

Cool. We're almost done there. Here are some comments.

"data": {
"values": [
{ "id": "001",
"ra": "243.35",
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to put these numbers as strings? Same for "time".

}
]
},
"transform": [
Copy link
Member

Choose a reason for hiding this comment

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

Why transforming it up here? Doing so require you to apply aggregate to basically unflatten it for the upper plot.

"width": 300,
"height": 200,
"title": "Sky position",
"transform": [{"aggregate": [], "groupby": ["ra", "dec", "id"]}],
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't have to aggregate here.

},
"size": {"value": 100}
},
"mark": "circle"
Copy link
Member

Choose a reason for hiding this comment

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

We always put mark before encoding in our examples.

"color": {"value": "steelblue"},
"detail": {"field": "id", "type": "nominal"}
},
"mark": "line"
Copy link
Member

Choose a reason for hiding this comment

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

We always put mark before encoding in our examples.

<div class="vl-example" data-name="circle_flatten"></div>


### Concat Circle and Line Marks with Nested Data
Copy link
Member

@kanitw kanitw May 29, 2018

Choose a reason for hiding this comment

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

### Advanced Example: Coordinated View with Nested Time Series


{% include table.html props="flatten,as" source="FlattenTransform" %}


Copy link
Member

Choose a reason for hiding this comment

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

Having a usage section without specs like Vega does is helpful.

The visual example is good additions, but having explicit examples how data is reshaped is useful.

@kanitw kanitw changed the base branch from master to feature/transform May 30, 2018 17:40
"mark": "circle",
"encoding": {
"x": {

Copy link
Member

Choose a reason for hiding this comment

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

  1. Why line breaks here.

  2. I think you can fit field and type in one online for each of x, y, and color

@kanitw kanitw merged commit 271b7bc into feature/transform May 30, 2018
@kanitw kanitw deleted the inv/flatten branch May 30, 2018 19:41
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.

None yet

3 participants