-
Notifications
You must be signed in to change notification settings - Fork 590
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 joinaggregate. Fixes #4121 #4554
Merged
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8545768
Add joinaggregate. Fixes #4121
domoritz 5aa2ef6
Adjust docs
kanitw fcb9794
Update transform.ts
kanitw 71ef581
Simplify window examples with joinaggregates
domoritz a3d7057
Merge branch 'dom/joinaggregate' of github.com:vega/vega-lite into do…
domoritz b0a3590
[Travis] Update schema (build: 21186)
371e353
[Travis] Update examples (build: 21186)
090d5e8
Fix example
domoritz 4a682bd
Merge branch 'dom/joinaggregate' of github.com:vega/vega-lite into do…
domoritz 7b7d4c6
Fix frame check.
domoritz 0afc6cd
[Travis] Update examples (build: 21203)
e13cefa
Use joinaggregate in bar_diverging
domoritz d37431c
Merge branch 'dom/joinaggregate' of github.com:vega/vega-lite into do…
domoritz 79bf709
Fix waterfall chart
domoritz 1010ecb
Improve docs around aggregate and joinaggregate.
domoritz 5fa4bda
JoinAggregateDef -> JoinAggregateFieldDef
domoritz 610afa9
[Travis] Update examples (build: 21246)
4b3d935
[Travis] Update schema (build: 21250)
0489bc2
Update aggregate.md
kanitw File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
examples/specs/*.vl.json | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega-lite/v3.json", | ||
"data": {"url": "data/movies.json"}, | ||
"transform": [ | ||
{"filter": "datum.IMDB_Rating != null"}, | ||
{ | ||
"joinaggregate": [{ | ||
"op": "mean", | ||
"field": "IMDB_Rating", | ||
"as": "AverageRating" | ||
}] | ||
}, | ||
{"filter": "(datum.IMDB_Rating - datum.AverageRating) > 2.5"} | ||
], | ||
"layer": [ | ||
{ | ||
"mark": "bar", | ||
"encoding": { | ||
"x": { | ||
"field": "IMDB_Rating", "type": "quantitative", | ||
"axis": {"title": "IMDB Rating"} | ||
}, | ||
"y": {"field": "Title", "type": "ordinal"} | ||
} | ||
}, | ||
{ | ||
"mark": {"type": "rule", "color": "red"}, | ||
"encoding": { | ||
"x": { | ||
"aggregate": "average", | ||
"field": "AverageRating", | ||
"type": "quantitative" | ||
} | ||
} | ||
} | ||
] | ||
} |
56 changes: 56 additions & 0 deletions
56
examples/specs/joinaggregate_mean_difference_by_year.vl.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega-lite/v3.json", | ||
"description": "Bar graph showing the best films for the year they were produced, where best is defined by at least 2.5 points above average for that year. The red point shows the average rating for a film in that year, and the bar is the rating that the film recieved.", | ||
"data": { | ||
"url": "data/movies.json", | ||
"format": { | ||
"parse": {"Release_Date": "date:'%d-%b-%y'"} | ||
} | ||
}, | ||
"transform": [ | ||
{"filter": "datum.IMDB_Rating != null"}, | ||
{"timeUnit": "year", "field": "Release_Date", "as": "year"}, | ||
{ | ||
"joinaggregate": [{ | ||
"op": "mean", | ||
"field": "IMDB_Rating", | ||
"as": "AverageYearRating" | ||
}], | ||
"groupby": [ | ||
"year" | ||
] | ||
}, | ||
{ | ||
"filter": "(datum.IMDB_Rating - datum.AverageYearRating) > 2.5" | ||
} | ||
], | ||
"layer": [{ | ||
"mark": {"type": "bar", "clip": true}, | ||
"encoding": { | ||
"x": { | ||
"field": "IMDB_Rating", | ||
"type": "quantitative", | ||
"axis": {"title": "IMDB Rating"} | ||
}, | ||
"y": { | ||
"field": "Title", | ||
"type": "ordinal" | ||
} | ||
} | ||
}, | ||
{ | ||
"mark": "tick", | ||
"encoding": { | ||
"x": { | ||
"field": "AverageYearRating", | ||
"type": "quantitative" | ||
}, | ||
"y": { | ||
"field": "Title", | ||
"type": "ordinal" | ||
}, | ||
"color": {"value": "red"} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega-lite/v3.json", | ||
"description": "A bar graph showing what activites consume what percentage of the day.", | ||
"data": { | ||
"values": [ | ||
{"Activity": "Sleeping","Time": 8}, | ||
{"Activity": "Eating","Time": 2}, | ||
{"Activity": "TV","Time": 4}, | ||
{"Activity": "Work","Time": 8}, | ||
{"Activity": "Exercise","Time": 2} | ||
] | ||
}, | ||
"transform": [{ | ||
"joinaggregate": [{ | ||
"op": "sum", | ||
"field": "Time", | ||
"as": "TotalTime" | ||
}] | ||
}, | ||
{ | ||
"calculate": "datum.Time/datum.TotalTime * 100", | ||
"as": "PercentOfTotal" | ||
}], | ||
"mark": "bar", | ||
"encoding": { | ||
"x": { | ||
"field": "PercentOfTotal", | ||
"type": "quantitative", | ||
"axis": { | ||
"title": "% of total Time" | ||
} | ||
}, | ||
"y": { | ||
"field": "Activity", | ||
"type": "nominal", | ||
"scale": { | ||
"rangeStep": 12 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega-lite/v3.json", | ||
"description": "A dot plot showing each movie in the database, and the difference from the average movie rating. The display is sorted by year to visualize everything in sequential order. The graph is for all Movies before 2019.", | ||
"data": { | ||
"url": "data/movies.json", | ||
"format": { | ||
"parse": {"Release_Date": "date:'%d-%b-%y'"} | ||
} | ||
}, | ||
"transform": [ | ||
{"filter": "datum.IMDB_Rating != null"}, | ||
{"filter": {"timeUnit": "year", "field": "Release_Date", "range": [null, 2019]}}, | ||
{ | ||
"joinaggregate": [{ | ||
"op": "mean", | ||
"field": "IMDB_Rating", | ||
"as": "AverageRating" | ||
}] | ||
}, | ||
{ | ||
"calculate": "datum.IMDB_Rating - datum.AverageRating", | ||
"as": "RatingDelta" | ||
} | ||
], | ||
"mark": "point", | ||
"encoding": { | ||
"x": { | ||
"field": "Release_Date", | ||
"type": "temporal" | ||
}, | ||
"y": { | ||
"field": "RatingDelta", | ||
"type": "quantitative", | ||
"axis": {"title": "Rating Delta"} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
layout: docs | ||
menu: docs | ||
title: Join Aggregate | ||
permalink: /docs/joinaggregate.html | ||
--- | ||
|
||
The joinaggregate transform extends the input data objects with aggregate values. Aggregation is performed and the results are then joined with the input data. This transform can be helpful for creating derived values that combine both raw data and aggregate calculations, such as percentages of group totals. This transform is a special case of the [window](window.html) transform where the `frame` is always `[null, null]`. | ||
domoritz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Documentation Overview | ||
|
||
{:.no_toc} | ||
|
||
<!-- prettier-ignore --> | ||
- TOC | ||
{:toc} | ||
|
||
## Join Aggregate Field Definition | ||
|
||
{: .suppress-error} | ||
|
||
```json | ||
// A View Specification | ||
{ | ||
... | ||
"transform": [ | ||
{ | ||
// Join Aggregate Transform | ||
"joinaggregate": [{ | ||
"op": ..., | ||
"field": ..., | ||
"as": ... | ||
}], | ||
"groupby": [ | ||
"..." | ||
] | ||
} | ||
... | ||
], | ||
... | ||
} | ||
``` | ||
|
||
## Join Aggregate Transform Definition | ||
|
||
{% include table.html props="joinaggregate,frame,ignorePeers,groupby,sort" source="JoinAggregateTransform" %} | ||
|
||
{:#field-def} | ||
|
||
### Join Aggregate Transform Field Definition | ||
|
||
{% include table.html props="op,field,as" source="JoinAggregateFieldDef" %} | ||
|
||
{:#ops} | ||
|
||
## Examples | ||
|
||
Below are some common use cases for the join aggregate transform. | ||
|
||
### Percent of Total | ||
|
||
Here we use the join aggregate transform to derive the global sum so that we can calculate percentage. | ||
|
||
<div class="vl-example" data-name="joinaggregate_percent_of_total"></div> | ||
|
||
### Difference from Mean | ||
|
||
One example is to show the "exemplar" movies from a movie collection. Here "exemplar" is defined by having a score of 2.5 points higher than the global average. | ||
|
||
<div class="vl-example" data-name="joinaggregate_mean_difference"></div> | ||
|
||
Another example is to show the "exemplar" movies based on the release year average. Here "exemplar" is defined by having a score 2.5 points higher than the annual average for its release year (instead of the global average). | ||
|
||
<div class="vl-example" data-name="joinaggregate_mean_difference_by_year"></div> | ||
|
||
Rather than filtering the above two examples we can also calculate a residual by deriving the mean using the join aggregate transform first. | ||
|
||
<div class="vl-example" data-name="joinaggregate_residual_graph"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we put this rule in
.prettierrc.json
?If we can, probably better to consolidate them in one place.
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 don't think it works yet. prettier/prettier#3460