-
Notifications
You must be signed in to change notification settings - Fork 629
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
[WIP] Revise window
transform + Add Docs / Examples
#3199
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great start. I have some styling / docs
comments.
@domoritz please feel free to add more comments if you have time. (I'm pretty swamped too so only got a chance to quickly look at this.)
src/compile/data/window.ts
Outdated
|
||
export class WindowTransformNode extends DataFlowNode { | ||
public clone(): WindowTransformNode { | ||
return new WindowTransformNode(duplicate(this.transform)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
de-tab
src/compile/data/window.ts
Outdated
const result: VgWindowTransform = { | ||
type: 'window', | ||
params: params, | ||
as: as, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just do as
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved.
src/compile/data/window.ts
Outdated
|
||
const result: VgWindowTransform = { | ||
type: 'window', | ||
params: params, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just do
params,
as,
ops, // rename operations to ops
fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved.
src/transform.ts
Outdated
@@ -97,6 +98,57 @@ export interface AggregatedFieldDef { | |||
as: string; | |||
} | |||
|
|||
export interface WindowFieldDef { | |||
/** | |||
* The operations supported for the window aggregation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to link to the table that lists all supported operations in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved.
src/transform.ts
Outdated
op: AggregateOp | WindowOnlyOp; | ||
|
||
/** | ||
* The optional parameters for the operation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add full stop.
Explain a bit more that look at the operator table to see parameter for each operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved.
src/transform.ts
Outdated
field?: string; | ||
|
||
/** | ||
* The name for the new field in the window transform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
full stop.. can you add it all for the rest of the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved.
src/transform.ts
Outdated
window: WindowFieldDef[]; | ||
|
||
/** | ||
* The frame for the window, if none is set the default is [null, 0] everything before the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use back tick around code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved.
src/transform.ts
Outdated
frame?: Number[]; | ||
|
||
/** | ||
* Whether to ignoreThePeers during the comparison in the window |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why camelcase for ignoreThePeers
?
src/transform.ts
Outdated
@@ -139,10 +191,26 @@ export interface LookupTransform { | |||
default?: string; | |||
} | |||
|
|||
export interface Comparator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if naming this SortField or WindowSortField make more sense?
(But not sure if there is another thing already called SortField -- but this is definitely slightly different from sort
's SortField(Def?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a couple changes and this should be reflective of the Comparator defined here now: https://vega.github.io/vega/docs/types/#Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um, I haven't looked how you do it -- but seeing that you mention that you make it like "Compare" in Vega. I would like to mention that it might be more important to make it more consistent with rest of Vega-Lite language than the underlying Vega.
src/compile/data/window.ts
Outdated
import {WindowOnlyOp} from '../../window'; | ||
import {AggregateOp} from '../../aggregate'; | ||
|
||
export class WindowTransformNode extends DataFlowNode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WindowNode?
src/vega.schema.ts
Outdated
|
||
export interface VgComparator { | ||
field?: string | string[]; | ||
order?: VgComparatorOrder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this allow array too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming this is referring to the field parameter, it is resolved.
src/compile/data/window.ts
Outdated
sort: this.transform.sort | ||
}; | ||
|
||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor -- but I guess you can just return the line above
ad3d465
to
7b0c01f
Compare
examples/examples.test.ts
Outdated
@@ -33,7 +33,7 @@ function validateVL(spec: TopLevelExtendedSpec) { | |||
} | |||
|
|||
function validateVega(spec: TopLevelExtendedSpec) { | |||
const vegaSpec = compile(spec).spec; | |||
const vegaSpec = JSON.parse(JSON.stringify(compile(spec).spec)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@domoritz -- any idea why this makes some validation passes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AkshatSh -- this commit should be separated from other changes as it's a controversial change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removes undefines and is not something we should do in tests. I am strongly against this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, what happens when you stringify something that is undefined?
I'll look into the tests more than and try to fix them without using this change.
f5bf7f8
to
1c7abee
Compare
2dc5f98
to
2e8dd98
Compare
bc51406
to
7ac5053
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. This is a good progress!
I have just rebased and re-compile an example so hopefully the test will pass now.
I think we're in the last mile for this PR.
Please address my comments and add a doc page for window. I think once you try to write a documentation. You might want to modify your examples so you can embed them to show diversity in your PR.
src/transform.ts
Outdated
frame?: (null | number)[]; | ||
|
||
/** | ||
* Whether to ignoreThePeers during the comparison in the window. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description here reads quite confusing. I don't understand what is "Whether to ignoreThePeers during the comparison in the window."
For each of the window transform property, please copy the more detailed description from Vega docs and edit them so they are sensible with Vega-Lite.
src/transform.ts
Outdated
/** | ||
* The comparator to use to determine the window. | ||
*/ | ||
sort?: Comparator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just ComparatorField[]
?
The nested "compare" seems unnecessary.
{
...
sort: { compare: [...] }
}
src/transform.ts
Outdated
order?: ('ascending' | 'descending'); | ||
} | ||
|
||
export interface Comparator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
src/transform.ts
Outdated
/** | ||
* A comparator fields | ||
*/ | ||
export interface ComparatorField { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WindowSortField
?
src/transform.ts
Outdated
op: AggregateOp | WindowOnlyOp; | ||
|
||
/** | ||
* The optional parameters for the operation. For example the window operator (nth_value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, (missing ,)
Also point to the window operation table for specific parameter for each operation?
src/transform.ts
Outdated
export interface WindowFieldDef { | ||
/** | ||
* The operations supported for the window aggregation. See the list of supported operations here: | ||
* https://vega.github.io/vega/docs/transforms/window/#ops |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not link to Vega docs.
Instead write a Vega-Lite docs for window (and you can copy the listed operations to this new page.)
"height": 50, | ||
"data": { | ||
"values": [ | ||
{ "x": 1, "y": 28 }, { "x": 2, "y": 55 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do the data need "x" here at all?
Also, maybe rename this file to window_row_number
?
@@ -0,0 +1,44 @@ | |||
{ | |||
"$schema": "https://vega.github.io/schema/vega-lite/v2.json", | |||
"description": "Bar graph showing how each film differs from the average rating for that year", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this example is quite confusing.
I took me a while to get that "Good" "Bad" "Average" are movie names. Maybe better put actual movie names in there?
Also, it's kinda weird that you calculate average ratings for one movie in 2015.
Perhaps, try to re-create examples using the movies data instead? (Feel free to play with it in Voyager a bit.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked this example because it could group by year. I changed the movie names to be Move One etc. I also added another example to use the movies.json file and do something similar there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add another movie for 2015 to make it less weird. Also, looks like the bar is acting weird here. (Why isn't it starting from zero?) -- Use point for now and file a bug?
[@AkshatSh]: If the bug is that the part start's from -10, it is because I defined the domain to be [-10,10]
. This was because I wanted to be able to see how each movie was below and above average for that year.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, this example seems redundant with window_transform_movie_mean_difference.vl.json?
An improved window_transform_movie_mean_difference.vl.json would be way more interesting, so remove this one?
(Still, please file a bug that bar for this one is wrong.)
@@ -0,0 +1,53 @@ | |||
{ | |||
"$schema": "https://vega.github.io/schema/vega-lite/v2.json", | |||
"description": "Bar graph showing how each film differs from the average rating for that year", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outdated description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not sure what this plot try to communicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to make a more complicated window transform example. The purpose was to show how long each student has been in class until the current class. So if student A and B both show up to a class, the graph will show that class along with the total time each student has been at school, to show how tired (or the fatigue) of a student during that class. For example, something like this could be used to see the affects of taking an exam after a lot of other classes vs taking an exam at the beginning of the day or when there are a few classes before hand.
I changed the name of the axis to be Time Spent in Class
instead to hopefully make this more clear. I have also updated the description.
"y": { | ||
"field": "TimeInClass", | ||
"type": "quantitative", | ||
"axis": { "title": "Fatigue", "grid": false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"fatigue" as a title axis is quite confusing to me.
Btw, please make sure to demonstrate these cases in your doc page:
|
window
transform
7ac5053
to
ebe93d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! We're getting really close!
I have some comments.
Please squash all existing commits into 3 commits
- One for all the code changes. (I might just cherry pick and merge this first so we will unblock @mattwchun to add outliers to boxplot)
- One for just the new documentation file.
- Another for just examples.
(If this is hard we can also just make all of them one commit too.)
Then please add new commits to address my changes.
For the examples, I think some of the examples still need improvement. You may choose to just remove some of them (e.g., window_transform_time_spent_in_class.vl.json) and focus on adding full examples for common use cases that you currently listed in the documentation.
site/docs/transform/window.md
Outdated
|
||
| Property | Type | Description | | ||
| :----------- | :-------: | :------------| | ||
| window | WindowFieldDef[] | The definition of the fields in the window, and what calculations to use. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a special tag and make sure that you have the JSDocs in the code include comments for all of these
{% include table.html props="window,frame,ignorePeers,groupBy,sort" source="WindowTransform" %}
(Window Only Operation Reference can't use this table thing though as it's a list of valid values, not property table.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh thats pretty cool. I didn't know about that tag. Just updated it to use that for the 3 object definitions (WindowTransform, WindowSortField, WIndowFieldDef).
site/docs/transform/window.md
Outdated
|
||
### Percent of Total | ||
|
||
```json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add actual Vega-Lite specs for all of these? Also make sure to include other good examples that you're adding.
<div class="vl-example" data-name="example-file-name-without-extension"></div>
src/compile/data/window.ts
Outdated
ops, | ||
fields, | ||
sort, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird... What's the error?
src/transform.ts
Outdated
*/ | ||
export interface WindowSortField { | ||
field: string; | ||
order?: ('ascending' | 'descending'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for parentheses?
src/transform.ts
Outdated
op: AggregateOp | WindowOnlyOp; | ||
|
||
/** | ||
* Parameter values for the window functions. Parameter value can be null for operations that do not accept a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"See the list of operations for each operation's supported parameter."?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, for operations that do not accept a parameter -- should param really be null
? Why not undefined
(omitted)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my mistake. I copied the definition from the vega docs, but here it can just be omitted. Updated to remove that.
@@ -0,0 +1,44 @@ | |||
{ | |||
"$schema": "https://vega.github.io/schema/vega-lite/v2.json", | |||
"description": "Bar graph showing how each film differs from the average rating for that year", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add another movie for 2015 to make it less weird. Also, looks like the bar is acting weird here. (Why isn't it starting from zero?) -- Use point for now and file a bug?
[@AkshatSh]: If the bug is that the part start's from -10, it is because I defined the domain to be [-10,10]
. This was because I wanted to be able to see how each movie was below and above average for that year.
"layer": [{ | ||
"transform": [{ | ||
"calculate": "datum.y - 50", | ||
"as": "ny" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this ny for?
@@ -0,0 +1,46 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this example important?
(Is it important for explaining any concept in the documentation?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say rank chart as in https://stats.stackexchange.com/a/178344 is a more compelling use case of row_number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dropped this file, and added a new one which compares the ranks of the top 5 students on an exam.
@@ -0,0 +1,53 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the discussion here: #3199 (comment)
I'm still not convinced that this is a good example.
If you can explain a specific analysis question that this plot can answer well, I can be more convinced. (Why would you want to stack the time spent in school for the two students?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped this example.
site/docs/transform/window.md
Outdated
``` | ||
|
||
|
||
### Difference from Total |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An improved window_transform_movie_mean_difference.vl.json is a fair game for this one. (Difference from mean)
I'd put this one as the first example in the docs, as it seems the most common.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also make sure that window is listed on the menu on the left. (See docs.html
).
Here are some more comments after seeing which commits are new :)
src/compile/data/window.ts
Outdated
constructor(private transform: WindowTransform) { | ||
super(); | ||
constructor(parent: DataFlowNode, private transform: WindowTransform) { | ||
super(parent); | ||
} | ||
|
||
public producedFields() { | ||
const out = {}; | ||
this.transform.window.forEach(element => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
element => windowFieldDef?
src/compile/data/window.ts
Outdated
}); | ||
|
||
return out; | ||
} | ||
|
||
private getDefaultName(window: WindowFieldDef): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window => windowFieldDef
src/compile/data/window.ts
Outdated
@@ -43,7 +47,7 @@ export class WindowTransformNode extends DataFlowNode { | |||
const sortFields: string[] = []; | |||
const sortOrder: VgComparatorOrder[] = []; | |||
if (this.transform.sort !== undefined) { | |||
for (const compField of this.transform.sort.compare) { | |||
for (const compField of this.transform.sort) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compField => sortField
3d63cac
to
8d90ba0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working so hard, I made another pass over the new commit and have some more comments.
src/transform.ts
Outdated
*/ | ||
param?: number; | ||
|
||
/** | ||
* The data fields for which to compute aggregate or window functions. Field can be omitted for operations that do not | ||
* operate over a specific data field, including count, rank, and dense_rank. | ||
* The data field for which to compute the aggregate or window function. This can be null for functions that do not operate over a field such as `count`, `rank`, `dense_rank`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null => omitted
src/transform.ts
Outdated
*/ | ||
field?: string; | ||
|
||
/** | ||
* The output name for each field. If none is defined will use the format op_field. For example, count_field for count, | ||
* and sum_field for sum. | ||
* The output name for each field. If non specified will use the format `window_op_field` for example, `count_field` for count and `sum_field` for sum. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make as required by removing question mark below? (Yes -- we should still autogenerate it if as
is missing, but JSON schema to enforce people to specify it, so that people write better specs.)
src/transform.ts
Outdated
@@ -146,12 +143,12 @@ export interface WindowTransform { | |||
ignorePeers?: boolean; | |||
|
|||
/** | |||
* The fields to group by. | |||
* The names of the data fields to partioin the objects into seprate windows. If not specified, everything will be in a single group. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data fields for partitioning the data objects into separate windows. If unspecified, all data points will be a single group.
src/transform.ts
Outdated
*/ | ||
groupby?: string[]; | ||
|
||
/** | ||
* The definitions of how to sort each of the fields in the window. | ||
* A definition for sorting the objects within the window. Equivalent objects are considered a peer (Look at ignorePeers). If left undefined, the order of items in the window is undefined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A definition for sorting the data objects (add data)
if left undefined => If undefined
src/transform.ts
Outdated
@@ -110,20 +111,17 @@ export interface WindowFieldDef { | |||
op: AggregateOp | WindowOnlyOp; | |||
|
|||
/** | |||
* Parameter values for the window functions. Parameter value can be null for operations that do not accept a | |||
* parameter. | |||
* Parameter values for the window functions. Parameter value can be omitted for operations that do not accept a parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refer to the operation / parameter table.
Also, I want to be able to read this and know if it is ever required.
- For ones that don't have param, then obviously this property will be "ignored" -- not just "can be omitted"
- For ones that do have param, are they ever required, or are they always optional?
Please make this clear (Note that Vega docs isn't very clear in this aspect too, please experiment and help jeff fix Vega docs :p)
src/transform.ts
Outdated
|
||
export type WindowOnlyOp = 'row_number' | 'rank' | 'dense_rank' | 'percent_rank' | 'cume_dist' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this right above WindowTransform
?
src/transform.ts
Outdated
@@ -135,8 +133,7 @@ export interface WindowTransform { | |||
window: WindowFieldDef[]; | |||
|
|||
/** | |||
* The frame for the window, if none is set the default is `[null, 0]` everything before the | |||
* current item. | |||
* A two element specification about how large the sliding window is. The first element indicates the start and the second element indicates the end. If `null` is specified for the start, it will include everything before the current point. If `null` is specified for the end, it will include everything after the endpoint. For example a frame of `[-5,5]` says the window should include 5 previous objects and 5 after objects. The default is `[null, 0]`, which means include everything in the window. `[null, null]` would mean include everything in the window. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is
[null, 0]
, which means include everything in the window.[null, null]
would mean include everything in the window.
This is inaccurate. Your text basically says that [null, 0]
and [null,null]
are the same. Why not just copy text from Vega docs https://vega.github.io/vega/docs/transforms/window/.
- Maybe use "data objects" over just "objects" though
- Another thing to change is that we always use the following format for default values:
__Default value:__: `[null, 0]` (includes the current object and all preceding objects)
(Please make sure that you use this format for all properties.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I thought the default was [null, null]
realized it was [null, 0]
so I quickly changed it, but forgot to update the description. I'll update this.
site/docs/transform/window.md
Outdated
|
||
## <a name="ops"></a> Window Only Operation Reference | ||
|
||
The valid operations include all [valid aggregate operations](../aggregate/#ops) plus the following window operations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
broken link -- I think aggregate.html#ops
is the right one, but please run yarn run site
to check.
window
transformwindow
transform + Add Docs / Examples
Note that I change merge target to a new feature branch, but some comments (like [this one]) got collapsed, but still need to be addressed. |
Resolved all the comments. I also added a couple examples that will hopefully show case this transform better. I have also displayed all the examples, and their vega-lite specs in the window.md documentation file. Let me know your thoughts! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think we should be ready to merge in 1-2 more revisions.
The examples are clearly improved, but still need to be revised.
-[ ] Please only use layer
when you really have layers.
-
For description of each property, could you please compare them with Vega docs and make sure you have equal amount of information? -- I'm not sure why you have to totally rewrite a lot of them. As a result, some important information are accidentally dropped. (We use slightly different format so it shouldn't be all copy and paste. Plus, we have our own default value format. However, we shouldn't lose important bit of information for each of those too.)
-
This comment is not fully addressed. (I still think the example should be removed though -- but please file a bug about it.)
Please take your time to polish this PR. (The latest revision seems a bit rushed.)
Note that you're no longer 100% blocking people as I have merged the implementation into a feature branch so people can already use window. (Yes, having docs will help them, but it's not like they can't do work anymore.)
Thank you so much for helping. I'm sure we can get this merged very soon!
"type": "quantitative", | ||
"scale": { "domain": [-5, 5] }, | ||
"axis": { "title": "Rating Delta" } | ||
"scale": { "domain": [7, 10] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using "bar" with scale not starting from zero is misleading as the ratio between bar length do not reflect their true ratio.
Please use domain: [0, 10]
site/docs/transform/window.md
Outdated
"op": "sum", | ||
"field": "x", | ||
"as": "total" | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the div example already include source code -- why do you have to include the code again?
site/docs/transform/window.md
Outdated
## Other examples | ||
|
||
Here is an example where the window_transform can be used to get the average rating for a film during different years. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window_transform => window transform
src/transform.ts
Outdated
@@ -103,6 +100,20 @@ export interface AggregatedFieldDef { | |||
as: string; | |||
} | |||
|
|||
|
|||
export type WindowOnlyOp = | |||
|'row_number' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why starting with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following the example for aggregate op in transform.d.ts, to make the style more consistent.
export type AggregateOp =
| 'argmax'
| 'argmin'
| 'average'
| 'count'
| 'distinct'
| 'max'
| 'mean'
| 'median'
| 'min'
| 'missing'
| 'q1'
| 'q3'
| 'ci0'
| 'ci1'
| 'stderr'
| 'stdev'
| 'stdevp'
| 'sum'
| 'valid'
| 'values'
| 'variance'
| 'variancep';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I don't know what's the rationale for transform.d.ts
though.
I'd argue that this is a bad style, so we shouldn't follow it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the style in vega-typings. It might be automatically generated by prettier over there. You can ignore the style for Vega-Lite.
src/transform.ts
Outdated
@@ -111,19 +122,19 @@ export interface WindowFieldDef { | |||
op: AggregateOp | WindowOnlyOp; | |||
|
|||
/** | |||
* Parameter values for the window functions. Parameter value can be omitted for operations that do not accept a parameter. | |||
* Please refer to the operation/parameter table. Parameter values for the window functions. Parameter value can be omitted for operations that do not accept a parameter. The spec will be invalid if any function that requires a parameter is unspecified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refer to the operation/parameter table.
It's weird description to say refer first. Better describe what it is first and say this later.
The spec will be invalid if any function that requires a parameter is unspecified.
This seems too extreme. It should just be ignored without failing.
src/transform.ts
Outdated
*/ | ||
ignorePeers?: boolean; | ||
|
||
/** | ||
* The names of the data fields to partioin the objects into seprate windows. If not specified, everything will be in a single group. | ||
* The data fields for partitioning the data objects into separate windows. If unspecified, all data points will be a single group. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If unspecified, a single group containing all data objects will be used.
@@ -7,7 +7,8 @@ | |||
"values": [ | |||
{ "name": "Movie 1", "Rating": 9, "Year": 2016 }, | |||
{ "name": "Movie 2", "Rating": 3, "Year": 2016 }, | |||
{ "name": "Movie 3", "Rating": 5, "Year": 2015 } | |||
{ "name": "Movie 3", "Rating": 5, "Year": 2015 }, | |||
{ "name": "Movie 4", "Rating": 2, "Year": 2015 } | |||
] | |||
}, | |||
"layer": [{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you use layer
and only have one layer.
That said, a better plot would be overlaying it with ticks showing AverageYearRating
.
@@ -1,6 +1,6 @@ | |||
{ | |||
"$schema": "https://vega.github.io/schema/vega-lite/v2.json", | |||
"description": "Bar graph showing how each movie is different from the average movie rating", | |||
"description": "Bar graph showing how each of the 'really good' movies is different from the average movie rating. Really good is defined to differ from the average movie rating by more than 2.5 points.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This plot would benefit from another layer of rule that show global average rating (and perhaps another layer of text to label the average)
site/docs/transform/window.md
Outdated
}], | ||
"frame": [null, null] | ||
}, | ||
{ | ||
"calculate": "(datum.total - datum.x)/dataum.total", | ||
"as": "Percent difference from total" | ||
"calculate": "(datum.total - datum.x)/dataum.average * 100", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"dataum"
also the example above doesn't have field "x"
Please make sure to organize sections in a sensible way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not addressed yet...
site/docs/transform/window.md
Outdated
## Other examples | ||
|
||
Here is an example where the window_transform can be used to get the average rating for a film during different years. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this "other example"? This is another example of difference from mean. Seems like the DIV tag is also pointing to the same example as above.
I'd say group this in the ### Difference from mean
section.
In fact, I'd say that remove the "Movie 1, Movie 2, Movie 3, Movie 4" example as it's as interesting as the real one.
If your point is to show that you can group by year, you can create multiple variations of the same example like:
- no group by and use the value to filter
- group by year and use the value to filter
- no group by, but visualize residual (rating - mean_rating) instead of just filtering.
This way users can easily see the changes without having to totally learn about a totally different example.
modified: build/vega-lite-schema.json modified: site/docs/transform/window.md modified: src/compile/data/window.ts modified: src/transform.ts modified: src/vega.schema.ts deleted: src/window.ts
(It exists in Vega, but not Vega-Lite)
8687adb
to
2634c56
Compare
Implemented Window Transform for Vega Lite
Issue #2488