Skip to content

Commit

Permalink
feat!: supporting channel name string for sorting by another encoding…
Browse files Browse the repository at this point in the history
… (e.g., `sort: "x"`, `sort: "-x"`) (#5134)

Fixes #4933
  • Loading branch information
kanitw committed Jul 20, 2019
1 parent e566e42 commit 3a813df
Show file tree
Hide file tree
Showing 113 changed files with 231 additions and 8,304 deletions.
2 changes: 2 additions & 0 deletions _data/link.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ SingleDefChannel:
SingleDefUnitChannel:
name: "Channel"
link: "encoding.html#channels"
AllSortString:
name: "String"

# Channel Definitions
NumericFieldDefWithCondition:
Expand Down
68 changes: 57 additions & 11 deletions build/vega-lite-schema.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/compiled/bar_aggregate_sort_by_encoding.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/compiled/bar_aggregate_sort_by_encoding.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"domain": {
"data": "source_0",
"field": "age",
"sort": {"op": "sum", "field": "people"}
"sort": {"op": "sum", "field": "people", "order": "descending"}
},
"range": {"step": {"signal": "y_step"}},
"paddingInner": 0.1,
Expand Down
1 change: 0 additions & 1 deletion examples/compiled/trellis_barley.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
237 changes: 0 additions & 237 deletions examples/compiled/trellis_barley.vg.json
Original file line number Diff line number Diff line change
@@ -1,237 +0,0 @@
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "The Trellis display by Becker et al. helped establish small multiples as a “powerful mechanism for understanding interactions in studies of how a response depends on explanatory variables”. Here we reproduce a trellis of Barley yields from the 1930s, complete with main-effects ordering to facilitate comparison.",
"autosize": "pad",
"padding": 5,
"data": [
{"name": "source_0", "url": "data/barley.json", "format": {"type": "json"}},
{
"name": "trellis_barley_facet_domain",
"source": "source_0",
"transform": [
{
"type": "aggregate",
"groupby": ["site"],
"fields": ["yield"],
"ops": ["median"],
"as": ["median_yield"]
}
]
},
{
"name": "trellis_barley_facet_domain_row",
"transform": [
{
"type": "sequence",
"start": 0,
"stop": {
"signal": "ceil(length(data(\"trellis_barley_facet_domain\")) / 2)"
}
}
]
},
{
"name": "trellis_barley_facet_domain_column",
"transform": [
{
"type": "sequence",
"start": 0,
"stop": {
"signal": "min(length(data(\"trellis_barley_facet_domain\")), 2)"
}
}
]
},
{
"name": "data_2",
"source": "source_0",
"transform": [
{
"type": "aggregate",
"groupby": ["variety", "year", "site"],
"ops": ["median"],
"fields": ["yield"],
"as": ["median_yield"]
}
]
}
],
"signals": [
{"name": "trellis_barley_child_width", "value": 200},
{"name": "trellis_barley_y_step", "value": 12},
{
"name": "trellis_barley_child_height",
"update": "bandspace(domain('trellis_barley_y').length, 1, 0.5) * trellis_barley_y_step"
}
],
"layout": {"padding": 20, "bounds": "full", "align": "all", "columns": 2},
"marks": [
{
"name": "facet-title",
"type": "group",
"role": "column-title",
"title": {"text": "site", "style": "guide-title", "offset": 10}
},
{
"name": "trellis_barley_row_header",
"type": "group",
"role": "row-header",
"from": {"data": "trellis_barley_facet_domain_row"},
"encode": {
"update": {"height": {"signal": "trellis_barley_child_height"}}
},
"axes": [
{
"scale": "trellis_barley_y",
"orient": "left",
"grid": false,
"title": "variety",
"labelOverlap": true,
"zindex": 1
}
]
},
{
"name": "trellis_barley_column_footer",
"type": "group",
"role": "column-footer",
"from": {"data": "trellis_barley_facet_domain_column"},
"encode": {"update": {"width": {"signal": "trellis_barley_child_width"}}},
"axes": [
{
"scale": "trellis_barley_x",
"orient": "bottom",
"grid": false,
"title": "Median of yield",
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(trellis_barley_child_width/40)"},
"zindex": 1
}
]
},
{
"name": "trellis_barley_cell",
"type": "group",
"title": {
"text": {"signal": "''+parent[\"site\"]"},
"style": "guide-label",
"frame": "group",
"offset": 10
},
"style": "cell",
"from": {
"facet": {
"name": "trellis_barley_facet",
"data": "source_0",
"groupby": ["site"],
"aggregate": {
"fields": ["yield"],
"ops": ["median"],
"as": ["median_yield_by_site"]
}
}
},
"sort": {
"field": ["datum[\"median_yield_by_site\"]"],
"order": ["ascending"]
},
"data": [
{
"source": "trellis_barley_facet",
"name": "data_0",
"transform": [
{
"type": "aggregate",
"groupby": ["variety", "year"],
"ops": ["median"],
"fields": ["yield"],
"as": ["median_yield"]
}
]
}
],
"encode": {
"update": {
"width": {"signal": "trellis_barley_child_width"},
"height": {"signal": "trellis_barley_child_height"}
}
},
"marks": [
{
"name": "trellis_barley_child_marks",
"type": "symbol",
"style": ["point"],
"from": {"data": "data_0"},
"encode": {
"update": {
"fill": {"value": "transparent"},
"stroke": {"scale": "trellis_barley_color", "field": "year"},
"x": [
{
"test": "datum[\"median_yield\"] === null || isNaN(datum[\"median_yield\"])",
"value": 0
},
{"scale": "trellis_barley_x", "field": "median_yield"}
],
"y": {"scale": "trellis_barley_y", "field": "variety"}
}
}
}
],
"axes": [
{
"scale": "trellis_barley_x",
"orient": "bottom",
"gridScale": "trellis_barley_y",
"grid": true,
"tickCount": {"signal": "ceil(trellis_barley_child_width/40)"},
"domain": false,
"labels": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
}
]
}
],
"scales": [
{
"name": "trellis_barley_x",
"type": "linear",
"domain": {"data": "data_2", "field": "median_yield"},
"range": [0, {"signal": "trellis_barley_child_width"}],
"zero": false,
"nice": true
},
{
"name": "trellis_barley_y",
"type": "point",
"domain": {
"data": "source_0",
"field": "variety",
"sort": {"op": "median", "field": "yield", "order": "descending"}
},
"range": {"step": {"signal": "trellis_barley_y_step"}},
"padding": 0.5
},
{
"name": "trellis_barley_color",
"type": "ordinal",
"domain": {"data": "data_2", "field": "year", "sort": true},
"range": "category"
}
],
"legends": [
{
"stroke": "trellis_barley_color",
"gradientLength": {
"signal": "clamp(trellis_barley_child_height, 64, 200)"
},
"symbolType": "circle",
"title": "year",
"encode": {"symbols": {"update": {"fill": {"value": "transparent"}}}}
}
]
}
1 change: 0 additions & 1 deletion examples/compiled/trellis_barley_independent.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3a813df

Please sign in to comment.