Skip to content
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

docs: add example with custom tick label strings #7049

Merged
merged 2 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/compiled/circle_custom_tick_labels.png
Loading
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
Loading
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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