Skip to content

Commit

Permalink
docs: add example with custom tick label strings (#7049)
Browse files Browse the repository at this point in the history
Co-authored-by: Joel Ostblom <joel.ostblom@gmail.com>
Co-authored-by: GitHub Actions Bot <vega-actions-bot@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 17, 2020
1 parent 0e7e3f7 commit fb12778
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
Binary file added examples/compiled/circle_custom_tick_labels.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/compiled/circle_custom_tick_labels.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions examples/compiled/circle_custom_tick_labels.vg.json
@@ -0,0 +1,111 @@
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"background": "white",
"padding": 5,
"width": 200,
"style": "cell",
"data": [
{"name": "source_0", "url": "data/movies.json", "format": {"type": "json"}},
{
"name": "data_0",
"source": "source_0",
"transform": [
{
"type": "aggregate",
"groupby": ["Major Genre"],
"ops": ["mean"],
"fields": ["IMDB Rating"],
"as": ["mean_IMDB Rating"]
},
{
"type": "filter",
"expr": "isValid(datum[\"mean_IMDB Rating\"]) && isFinite(+datum[\"mean_IMDB Rating\"])"
}
]
}
],
"signals": [
{"name": "y_step", "value": 20},
{
"name": "height",
"update": "bandspace(domain('y').length, 1, 0.5) * y_step"
}
],
"marks": [
{
"name": "marks",
"type": "symbol",
"style": ["circle"],
"from": {"data": "data_0"},
"encode": {
"update": {
"size": {"value": 80},
"fill": {"value": "#4c78a8"},
"ariaRoleDescription": {"value": "circle"},
"description": {
"signal": "\"Mean of IMDB Rating: \" + (format(datum[\"mean_IMDB Rating\"], \"\")) + \"; Major Genre: \" + (isValid(datum[\"Major Genre\"]) ? datum[\"Major Genre\"] : \"\"+datum[\"Major Genre\"])"
},
"x": {"scale": "x", "field": "mean_IMDB Rating"},
"y": {"scale": "y", "field": "Major Genre"},
"shape": {"value": "circle"}
}
}
}
],
"scales": [
{
"name": "x",
"type": "linear",
"domain": [0, 10],
"range": [0, {"signal": "width"}],
"nice": true,
"zero": true
},
{
"name": "y",
"type": "point",
"domain": {
"data": "source_0",
"field": "Major Genre",
"sort": {"op": "mean", "field": "IMDB Rating"}
},
"range": {"step": {"signal": "y_step"}},
"padding": 0.5
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"values": [0, 5, 10],
"gridScale": "y",
"grid": true,
"domain": false,
"labels": false,
"aria": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "x",
"orient": "bottom",
"grid": false,
"labelFlush": false,
"values": [0, 5, 10],
"labelOverlap": true,
"encode": {
"labels": {
"update": {
"text": {
"signal": "datum.label == 0 ? 'Poor' : datum.label == 5 ? 'Neutral' : 'Great'"
}
}
}
},
"zindex": 0
},
{"scale": "y", "orient": "left", "grid": false, "zindex": 0}
]
}
21 changes: 21 additions & 0 deletions examples/specs/circle_custom_tick_labels.vl.json
@@ -0,0 +1,21 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {
"url": "data/movies.json"
},
"mark": {"size": 80, "type": "circle"},
"encoding": {
"x": {
"aggregate": "mean",
"axis": {
"labelExpr": "datum.label == 0 ? 'Poor' : datum.label == 5 ? 'Neutral' : 'Great'",
"labelFlush": false,
"values": [0, 5, 10]
},
"field": "IMDB Rating",
"scale": {"domain": [0, 10]},
"title": null
},
"y": {"field": "Major Genre", "sort": "x", "title": null}
}
}
5 changes: 5 additions & 0 deletions site/_data/examples.json
Expand Up @@ -199,6 +199,11 @@
{
"name": "scatter_image",
"title": "Image-based Scatter Plot"
},
{
"name": "circle_custom_tick_labels",
"description": "After using the numerical values to calculate the average rating, they are replaced by string labels.",
"title": "Strip plot with custom axis tick labels"
}
],
"Line Charts": [
Expand Down

0 comments on commit fb12778

Please sign in to comment.