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: interactive aggregation threshold example #9123

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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/interactive_aggregation_threshold.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
272 changes: 272 additions & 0 deletions examples/compiled/interactive_aggregation_threshold.vg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"background": "white",
"padding": 5,
"width": 200,
"height": 200,
"style": "cell",
"data": [
{"name": "source_0", "url": "data/movies.json", "format": {"type": "json"}},
{"name": "source_1", "values": [{"start": 0, "stop": 100}]},
{
"name": "data_0",
"source": "source_0",
"transform": [
{"type": "filter", "expr": "datum['IMDB Rating'] > Threshold"},
{
"type": "filter",
"expr": "isValid(datum[\"IMDB Rating\"]) && isFinite(+datum[\"IMDB Rating\"]) && isValid(datum[\"Rotten Tomatoes Rating\"]) && isFinite(+datum[\"Rotten Tomatoes Rating\"])"
}
]
},
{
"name": "data_1",
"source": "source_0",
"transform": [
{
"type": "extent",
"field": "IMDB Rating",
"signal": "layer_1_bin_maxbins_10_IMDB_Rating_extent"
},
{
"type": "bin",
"field": "IMDB Rating",
"as": [
"bin_maxbins_10_IMDB Rating",
"bin_maxbins_10_IMDB Rating_end"
],
"signal": "layer_1_bin_maxbins_10_IMDB_Rating_bins",
"extent": {"signal": "layer_1_bin_maxbins_10_IMDB_Rating_extent"},
"maxbins": 10
},
{
"type": "extent",
"field": "Rotten Tomatoes Rating",
"signal": "layer_1_bin_maxbins_10_Rotten_Tomatoes_Rating_extent"
},
{
"type": "bin",
"field": "Rotten Tomatoes Rating",
"as": [
"bin_maxbins_10_Rotten Tomatoes Rating",
"bin_maxbins_10_Rotten Tomatoes Rating_end"
],
"signal": "layer_1_bin_maxbins_10_Rotten_Tomatoes_Rating_bins",
"extent": {
"signal": "layer_1_bin_maxbins_10_Rotten_Tomatoes_Rating_extent"
},
"maxbins": 10
},
{
"type": "aggregate",
"groupby": [
"bin_maxbins_10_IMDB Rating",
"bin_maxbins_10_IMDB Rating_end",
"bin_maxbins_10_Rotten Tomatoes Rating",
"bin_maxbins_10_Rotten Tomatoes Rating_end"
],
"ops": ["count"],
"fields": [null],
"as": ["__count"]
},
{
"type": "filter",
"expr": "isValid(datum[\"bin_maxbins_10_IMDB Rating\"]) && isFinite(+datum[\"bin_maxbins_10_IMDB Rating\"]) && isValid(datum[\"bin_maxbins_10_Rotten Tomatoes Rating\"]) && isFinite(+datum[\"bin_maxbins_10_Rotten Tomatoes Rating\"])"
}
]
},
{
"name": "data_2",
"source": "source_1",
"transform": [
{
"type": "filter",
"expr": "isValid(datum[\"start\"]) && isFinite(+datum[\"start\"])"
}
]
}
],
"signals": [
{
"name": "Threshold",
"value": 5,
"bind": {"input": "range", "min": 1, "max": 10, "step": 1}
}
],
"marks": [
{
"name": "layer_0_marks",
"type": "symbol",
"style": ["circle"],
"from": {"data": "data_0"},
"encode": {
"update": {
"opacity": {"value": 0.7},
"fill": {"value": "#4c78a8"},
"ariaRoleDescription": {"value": "circle"},
"description": {
"signal": "\"IMDB Rating: \" + (format(datum[\"IMDB Rating\"], \"\")) + \"; Rotten Tomatoes Rating: \" + (format(datum[\"Rotten Tomatoes Rating\"], \"\"))"
},
"x": {"scale": "x", "field": "IMDB Rating"},
"y": {"scale": "y", "field": "Rotten Tomatoes Rating"},
"shape": {"value": "circle"}
}
}
},
{
"name": "layer_1_marks",
"type": "symbol",
"style": ["circle"],
"from": {"data": "data_1"},
"encode": {
"update": {
"fill": {"value": "#4c78a8"},
"ariaRoleDescription": {"value": "circle"},
"description": {
"signal": "\"IMDB Rating (binned): \" + (!isValid(datum[\"bin_maxbins_10_IMDB Rating\"]) || !isFinite(+datum[\"bin_maxbins_10_IMDB Rating\"]) ? \"null\" : format(datum[\"bin_maxbins_10_IMDB Rating\"], \"\") + \" – \" + format(datum[\"bin_maxbins_10_IMDB Rating_end\"], \"\")) + \"; Rotten Tomatoes Rating (binned): \" + (!isValid(datum[\"bin_maxbins_10_Rotten Tomatoes Rating\"]) || !isFinite(+datum[\"bin_maxbins_10_Rotten Tomatoes Rating\"]) ? \"null\" : format(datum[\"bin_maxbins_10_Rotten Tomatoes Rating\"], \"\") + \" – \" + format(datum[\"bin_maxbins_10_Rotten Tomatoes Rating_end\"], \"\")) + \"; Count of Records: \" + (format(datum[\"__count\"], \"\"))"
},
"x": {
"signal": "scale(\"x\", 0.5 * datum[\"bin_maxbins_10_IMDB Rating\"] + 0.5 * datum[\"bin_maxbins_10_IMDB Rating_end\"])"
},
"y": {
"signal": "scale(\"y\", 0.5 * datum[\"bin_maxbins_10_Rotten Tomatoes Rating\"] + 0.5 * datum[\"bin_maxbins_10_Rotten Tomatoes Rating_end\"])"
},
"size": {"scale": "size", "field": "__count"},
"shape": {"value": "circle"}
}
}
},
{
"name": "layer_2_marks",
"type": "rule",
"style": ["rule"],
"from": {"data": "data_2"},
"encode": {
"update": {
"stroke": {"value": "gray"},
"strokeWidth": {"value": 3},
"description": {
"signal": "\"start: \" + (format(datum[\"start\"], \"\")) + \"; stop: \" + (format(datum[\"stop\"], \"\"))"
},
"x": {"scale": "x", "signal": "Threshold"},
"x2": {"scale": "x", "signal": "Threshold"},
"y": {"scale": "y", "field": "start"},
"y2": {"scale": "y", "field": "stop"}
}
}
}
],
"scales": [
{
"name": "x",
"type": "linear",
"domain": {
"fields": [
{"data": "data_0", "field": "IMDB Rating"},
{
"signal": "[layer_1_bin_maxbins_10_IMDB_Rating_bins.start, layer_1_bin_maxbins_10_IMDB_Rating_bins.stop]"
},
[{"expr": "Threshold"}]
]
},
"range": [0, {"signal": "width"}],
"bins": {"signal": "layer_1_bin_maxbins_10_IMDB_Rating_bins"},
"nice": true,
"zero": true
},
{
"name": "y",
"type": "linear",
"domain": {
"fields": [
{"data": "data_0", "field": "Rotten Tomatoes Rating"},
{
"signal": "[layer_1_bin_maxbins_10_Rotten_Tomatoes_Rating_bins.start, layer_1_bin_maxbins_10_Rotten_Tomatoes_Rating_bins.stop]"
},
{"data": "data_2", "field": "start"},
{"data": "data_2", "field": "stop"}
]
},
"range": [{"signal": "height"}, 0],
"bins": {"signal": "layer_1_bin_maxbins_10_Rotten_Tomatoes_Rating_bins"},
"nice": true,
"zero": true
},
{
"name": "size",
"type": "linear",
"domain": {"data": "data_1", "field": "__count"},
"range": [
0,
{
"signal": "pow(0.95 * min(width / ((layer_1_bin_maxbins_10_IMDB_Rating_bins.stop - layer_1_bin_maxbins_10_IMDB_Rating_bins.start) / layer_1_bin_maxbins_10_IMDB_Rating_bins.step), height / ((layer_1_bin_maxbins_10_Rotten_Tomatoes_Rating_bins.stop - layer_1_bin_maxbins_10_Rotten_Tomatoes_Rating_bins.start) / layer_1_bin_maxbins_10_Rotten_Tomatoes_Rating_bins.step)), 2)"
}
],
"zero": true
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"gridScale": "y",
"grid": true,
"tickCount": {"signal": "ceil(width/40)"},
"domain": false,
"labels": false,
"aria": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"gridScale": "x",
"grid": true,
"tickCount": {"signal": "ceil(height/40)"},
"domain": false,
"labels": false,
"aria": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "x",
"orient": "bottom",
"grid": false,
"title": "IMDB Rating",
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(width/40)"},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "Rotten Tomatoes Rating",
"labelOverlap": true,
"tickCount": {"signal": "ceil(height/40)"},
"zindex": 0
}
],
"legends": [
{
"size": "size",
"symbolType": "circle",
"title": "Count of Records",
"encode": {
"symbols": {
"update": {
"fill": {"value": "#4c78a8"},
"stroke": {"value": "transparent"}
}
}
}
}
]
}
49 changes: 49 additions & 0 deletions examples/specs/interactive_aggregation_threshold.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"params": [
{
"name": "Threshold",
"value": 5,
"bind": {"input": "range", "min": 1, "max": 10, "step": 1}
}
],
"layer": [
{
"data": {"url": "data/movies.json"},
"mark": "circle",
"transform": [{"filter": "datum['IMDB Rating'] > Threshold"}],
"encoding": {
"x": {
"field": "IMDB Rating",
"type": "quantitative",
"axis": {"title": "IMDB Rating"}
},
"y": {
"field": "Rotten Tomatoes Rating",
"type": "quantitative",
"axis": {"title": "Rotten Tomatoes Rating"}
}
}
},
{
"data": {"url": "data/movies.json"},
"mark": "circle",
"encoding": {
"x": {"bin": {"maxbins": 10}, "field": "IMDB Rating"},
"y": {"bin": {"maxbins": 10}, "field": "Rotten Tomatoes Rating"},
"size": {"aggregate": "count"}
}
},
{
"data": {"values": [{"start": 0, "stop": 100}]},
"mark": {"type": "rule", "color": "gray"},
"encoding": {
"strokeWidth": {"value": 3},
"x": {"datum": {"expr": "Threshold"}, "type": "quantitative"},
"y": {"field": "start", "type": "quantitative"},
"x2": {"datum": {"expr": "Threshold"}},
"y2": {"field": "stop"}
}
}
]
}
5 changes: 5 additions & 0 deletions site/_data/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,11 @@
"name": "param_search_input",
"description": "Search to highlight the relevant car models. Regexes are supported so you can type e.g. `mazda|ford`",
"title": "Search Input"
},
{
"name": "interactive_aggregation_threshold",
"description": "Dynamically specify the x threshold above which to bin your data",
"title": "Interactive Binning Threshold"
}
],
"Interactive Multi-View Displays": [
Expand Down