-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "get column usage" section to docs
- Loading branch information
Showing
15 changed files
with
542 additions
and
3,524 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Get Column Usage | ||
VegaFusion provides a function for introspecting a Vega specification and determining which columns are referenced from each root dataset. A root dataset is one defined at the top-level of the spec that includes a `url` or `values` properties. This is useful in contexts where it's more efficient to minimize the number of columns provided to the Vega specification. For example, the Python library uses this function to determine how to downsample the input DataFrame columns prior to converting to Arrow. | ||
|
||
When VegaFusion cannot precisely determine which columns are referenced from each root dataset, this function returns `None` or `null` for the corresponding dataset. | ||
|
||
## Python | ||
```{eval-rst} | ||
.. autofunction:: vegafusion.get_column_usage | ||
``` | ||
|
||
See [column_usage.py](https://github.com/vega/vegafusion/tree/v2/examples/python-examples/column_usage.py) for a complete example. | ||
|
||
## Rust | ||
See [column_usage.rs](https://github.com/vega/vegafusion/tree/v2/examples/rust-examples/examples/column_usage.rs) for a complete example. | ||
|
||
## JavaScript | ||
See the [Editor Demo](https://github.com/vega/vegafusion/tree/v2/examples/editor-demo/src/index.js) for example usage of the `getColumnUsage` function in the `vegafusion-wasm` package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import json | ||
from typing import Any | ||
|
||
from vegafusion import get_column_usage | ||
|
||
|
||
def main(): | ||
spec = get_spec() | ||
column_usage = get_column_usage(spec) | ||
print(json.dumps(column_usage, indent=2)) | ||
|
||
assert column_usage == { | ||
"source": ["Acceleration", "Horsepower", "Miles_per_Gallon"] | ||
} | ||
|
||
|
||
def get_spec() -> dict[str, Any]: | ||
spec_str = """ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega/v5.json", | ||
"description": "A basic scatter plot example depicting automobile statistics.", | ||
"width": 200, | ||
"height": 200, | ||
"padding": 5, | ||
"data": [ | ||
{ | ||
"name": "source", | ||
"url": "data/cars.json", | ||
"transform": [ | ||
{ | ||
"type": "filter", | ||
"expr": "datum['Horsepower'] != null && datum['Miles_per_Gallon'] != null && datum['Acceleration'] != null" | ||
} | ||
] | ||
} | ||
], | ||
"scales": [ | ||
{ | ||
"name": "x", | ||
"type": "linear", | ||
"round": true, | ||
"nice": true, | ||
"zero": true, | ||
"domain": {"data": "source", "field": "Horsepower"}, | ||
"range": "width" | ||
}, | ||
{ | ||
"name": "y", | ||
"type": "linear", | ||
"round": true, | ||
"nice": true, | ||
"zero": true, | ||
"domain": {"data": "source", "field": "Miles_per_Gallon"}, | ||
"range": "height" | ||
}, | ||
{ | ||
"name": "size", | ||
"type": "linear", | ||
"round": true, | ||
"nice": false, | ||
"zero": true, | ||
"domain": {"data": "source", "field": "Acceleration"}, | ||
"range": [4,361] | ||
} | ||
], | ||
"axes": [ | ||
{ | ||
"scale": "x", | ||
"grid": true, | ||
"domain": false, | ||
"orient": "bottom", | ||
"tickCount": 5, | ||
"title": "Horsepower" | ||
}, | ||
{ | ||
"scale": "y", | ||
"grid": true, | ||
"domain": false, | ||
"orient": "left", | ||
"titlePadding": 5, | ||
"title": "Miles_per_Gallon" | ||
} | ||
], | ||
"legends": [ | ||
{ | ||
"size": "size", | ||
"title": "Acceleration", | ||
"format": "s", | ||
"symbolStrokeColor": "#4682b4", | ||
"symbolStrokeWidth": 2, | ||
"symbolOpacity": 0.5, | ||
"symbolType": "circle" | ||
} | ||
], | ||
"marks": [ | ||
{ | ||
"name": "marks", | ||
"type": "symbol", | ||
"from": {"data": "source"}, | ||
"encode": { | ||
"update": { | ||
"x": {"scale": "x", "field": "Horsepower"}, | ||
"y": {"scale": "y", "field": "Miles_per_Gallon"}, | ||
"size": {"scale": "size", "field": "Acceleration"}, | ||
"shape": {"value": "circle"}, | ||
"strokeWidth": {"value": 2}, | ||
"opacity": {"value": 0.5}, | ||
"stroke": {"value": "#4682b4"}, | ||
"fill": {"value": "transparent"} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
""" | ||
return json.loads(spec_str) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "rust-examples" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dev-dependencies] | ||
serde_json = { workspace = true } | ||
vegafusion-core = { path = "../../vegafusion-core" } |
Oops, something went wrong.