Skip to content

Commit

Permalink
feat: support repeat layer (#6142)
Browse files Browse the repository at this point in the history
* feat: support repeat layer

part of #1274

Note that repeat layer isn't very useful yet until we have `datum` support (#1601)

* chore: update schema [CI]

* chore: update examples [CI]

* fix: fix comment

* chore: update schema [CI]

Co-authored-by: GitHub Actions Bot <vega-actions-bot@users.noreply.github.com>
  • Loading branch information
kanitw and GitHub Actions Bot authored Mar 23, 2020
1 parent 8dca856 commit 43ec4a2
Show file tree
Hide file tree
Showing 17 changed files with 1,544 additions and 932 deletions.
787 changes: 545 additions & 242 deletions build/vega-lite-schema.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/compiled/repeat_child_layer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
596 changes: 596 additions & 0 deletions examples/compiled/repeat_child_layer.vg.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/compiled/repeat_layer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
638 changes: 93 additions & 545 deletions examples/compiled/repeat_layer.vg.json

Large diffs are not rendered by default.

94 changes: 94 additions & 0 deletions examples/specs/normalized/repeat_child_layer_normalized.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"data": {"url": "data/weather.csv"},
"align": "all",
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Summarized and per year weather information for Seatle and New York.",
"columns": 3,
"concat": [
{
"layer": [
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": "temp_max",
"type": "quantitative"
},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"detail": {"timeUnit": "year", "type": "temporal", "field": "date"},
"color": {"type": "nominal", "field": "location"},
"opacity": {"value": 0.2}
}
},
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": "temp_max",
"type": "quantitative"
},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"color": {"type": "nominal", "field": "location"}
}
}
],
"name": "child__column_temp_max"
},
{
"layer": [
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": "precipitation",
"type": "quantitative"
},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"detail": {"timeUnit": "year", "type": "temporal", "field": "date"},
"color": {"type": "nominal", "field": "location"},
"opacity": {"value": 0.2}
}
},
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": "precipitation",
"type": "quantitative"
},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"color": {"type": "nominal", "field": "location"}
}
}
],
"name": "child__column_precipitation"
},
{
"layer": [
{
"mark": "line",
"encoding": {
"y": {"aggregate": "mean", "field": "wind", "type": "quantitative"},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"detail": {"timeUnit": "year", "type": "temporal", "field": "date"},
"color": {"type": "nominal", "field": "location"},
"opacity": {"value": 0.2}
}
},
{
"mark": "line",
"encoding": {
"y": {"aggregate": "mean", "field": "wind", "type": "quantitative"},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"color": {"type": "nominal", "field": "location"}
}
}
],
"name": "child__column_wind"
}
]
}
102 changes: 17 additions & 85 deletions examples/specs/normalized/repeat_layer_normalized.vl.json
Original file line number Diff line number Diff line change
@@ -1,94 +1,26 @@
{
"data": {"url": "data/weather.csv"},
"align": "all",
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Summarized and per year weather information for Seatle and New York.",
"columns": 3,
"concat": [
"data": {"url": "data/movies.json"},
"layer": [
{
"layer": [
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": "temp_max",
"type": "quantitative"
},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"detail": {"timeUnit": "year", "type": "temporal", "field": "date"},
"color": {"type": "nominal", "field": "location"},
"opacity": {"value": 0.2}
}
},
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": "temp_max",
"type": "quantitative"
},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"color": {"type": "nominal", "field": "location"}
}
}
],
"name": "child__column_temp_max"
},
{
"layer": [
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": "precipitation",
"type": "quantitative"
},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"detail": {"timeUnit": "year", "type": "temporal", "field": "date"},
"color": {"type": "nominal", "field": "location"},
"opacity": {"value": 0.2}
}
},
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": "precipitation",
"type": "quantitative"
},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"color": {"type": "nominal", "field": "location"}
}
}
],
"name": "child__column_precipitation"
"mark": "line",
"encoding": {
"x": {"bin": true, "field": "IMDB_Rating", "type": "quantitative"},
"y": {"aggregate": "mean", "field": "US_Gross", "type": "quantitative"}
},
"name": "child__layer_US_Gross"
},
{
"layer": [
{
"mark": "line",
"encoding": {
"y": {"aggregate": "mean", "field": "wind", "type": "quantitative"},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"detail": {"timeUnit": "year", "type": "temporal", "field": "date"},
"color": {"type": "nominal", "field": "location"},
"opacity": {"value": 0.2}
}
},
{
"mark": "line",
"encoding": {
"y": {"aggregate": "mean", "field": "wind", "type": "quantitative"},
"x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
"color": {"type": "nominal", "field": "location"}
}
"mark": "line",
"encoding": {
"x": {"bin": true, "field": "IMDB_Rating", "type": "quantitative"},
"y": {
"aggregate": "mean",
"field": "Worldwide_Gross",
"type": "quantitative"
}
],
"name": "child__column_wind"
},
"name": "child__layer_Worldwide_Gross"
}
]
}
48 changes: 48 additions & 0 deletions examples/specs/repeat_child_layer.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Summarized and per year weather information for Seatle and New York.",
"data": {"url": "data/weather.csv"},
"repeat": {"column": ["temp_max", "precipitation", "wind"]},
"spec": {
"layer": [
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": {"repeat": "column"},
"type": "quantitative"
},
"x": {
"timeUnit": "month",
"field": "date",
"type": "ordinal"
},
"detail": {
"timeUnit": "year",
"type": "temporal",
"field": "date"
},
"color": {"type": "nominal", "field": "location"},
"opacity": {"value": 0.2}
}
},
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": {"repeat": "column"},
"type": "quantitative"
},
"x": {
"timeUnit": "month",
"field": "date",
"type": "ordinal"
},
"color": {"type": "nominal", "field": "location"}
}
}
]
}
}
58 changes: 17 additions & 41 deletions examples/specs/repeat_layer.vl.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,24 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Summarized and per year weather information for Seatle and New York.",
"data": {"url": "data/weather.csv"},
"repeat": {"column": ["temp_max", "precipitation", "wind"]},
"data": {
"url": "data/movies.json"
},
"repeat": {
"layer": ["US_Gross", "Worldwide_Gross"]
},
"spec": {
"layer": [
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": {"repeat": "column"},
"type": "quantitative"
},
"x": {
"timeUnit": "month",
"field": "date",
"type": "ordinal"
},
"detail": {
"timeUnit": "year",
"type": "temporal",
"field": "date"
},
"color": {"type": "nominal", "field": "location"},
"opacity": {"value": 0.2}
}
"mark": "line",
"encoding": {
"x": {
"bin": true,
"field": "IMDB_Rating",
"type": "quantitative"
},
{
"mark": "line",
"encoding": {
"y": {
"aggregate": "mean",
"field": {"repeat": "column"},
"type": "quantitative"
},
"x": {
"timeUnit": "month",
"field": "date",
"type": "ordinal"
},
"color": {"type": "nominal", "field": "location"}
}
"y": {
"aggregate": "mean",
"field": {"repeat": "layer"},
"type": "quantitative"
}
]
}
}
}
2 changes: 1 addition & 1 deletion site/_includes/docs_toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
- [Repeat]({{site.baseurl}}/docs/repeat.html)
- [Documentation Overview]({{site.baseurl}}/docs/repeat.html#documentation-overview)
- [Repeat Operator]({{site.baseurl}}/docs/repeat.html#repeat-operator)
- [Row/Column Repeat Mapping]({{site.baseurl}}/docs/repeat.html#repeat-mapping)
- [Row/Column/Layer Repeat Mapping]({{site.baseurl}}/docs/repeat.html#repeat-mapping)
- [Examples]({{site.baseurl}}/docs/repeat.html#examples)
- [Resolve]({{site.baseurl}}/docs/repeat.html#resolve)
- [Repeat Configuration]({{site.baseurl}}/docs/repeat.html#config)
Expand Down
4 changes: 2 additions & 2 deletions site/docs/composition/repeat.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ In addition to [common properties of a view specification](spec.html#common), a

{: #repeat-mapping}

## Row/Column Repeat Mapping
## Row/Column/Layer Repeat Mapping

The `repeat` property can be an object with two optional properties (`"row"` and `"column"`), which define the list of fields that should be repeated into a row or column.
The `repeat` property can be an object with at least one of `"row"`, `"column"` and `"layer"` properties, which define the list of fields that should be repeated into a row, a column, or a layer.

{% include table.html props="row,column" source="RepeatMapping" %}

Expand Down
2 changes: 1 addition & 1 deletion src/channeldef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export type StringFieldDefWithCondition<F extends Field> = FieldDefWithCondition
* Reference to a repeated value.
*/
export interface RepeatRef {
repeat: 'row' | 'column' | 'repeat';
repeat: 'row' | 'column' | 'repeat' | 'layer';
}

export type FieldName = string;
Expand Down
Loading

0 comments on commit 43ec4a2

Please sign in to comment.