datasette-vega 0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: datasette-vega
3
+ Version: 0.7
4
+ Summary: A Datasette plugin that provides tools for generating charts using Vega
5
+ Author: Simon Willison
6
+ License-Expression: Apache-2.0
7
+ Requires-Dist: datasette
8
+ Requires-Dist: pytest ; extra == 'test'
9
+ Requires-Dist: pytest-asyncio ; extra == 'test'
10
+ Requires-Dist: httpx ; extra == 'test'
11
+ Requires-Python: >=3.11
12
+ Project-URL: Homepage, https://github.com/simonw/datasette-vega
13
+ Project-URL: Issues, https://github.com/simonw/datasette-vega/issues
14
+ Project-URL: CI, https://github.com/simonw/datasette-vega/actions
15
+ Project-URL: Changelog, https://github.com/simonw/datasette-vega/releases
16
+ Provides-Extra: test
17
+ Description-Content-Type: text/markdown
18
+
19
+ # datasette-vega
20
+
21
+ [![PyPI](https://img.shields.io/pypi/v/datasette-vega.svg)](https://pypi.org/project/datasette-vega/)
22
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/datasette-vega/blob/main/LICENSE)
23
+
24
+ A [Datasette](https://github.com/simonw/datasette) plugin that provides tools
25
+ for generating charts using [Vega](https://vega.github.io/).
26
+
27
+ ![Datasette Vega interface](https://raw.githubusercontent.com/simonw/datasette-vega/main/datasette-vega.png)
28
+
29
+ Try it out in your browser using [Datasette Lite](https://lite.datasette.io/?install=datasette-vega&csv=https%3A%2F%2Fraw.githubusercontent.com%2Ffivethirtyeight%2Fdata%2Fmaster%2Fairline-safety%2Fairline-safety.csv#/data/airline-safety?_size=max#g.mark=bar&g.x_column=airline&g.x_type=ordinal&g.y_column=fatalities_00_14&g.y_type=quantitative), which installs the latest release of this plugin and charts fatalities per airline from 2000 to 2014, using [FiveThirtyEight's airline safety data](https://github.com/fivethirtyeight/data/tree/master/airline-safety).
30
+
31
+ To add this to your Datasette installation, install the plugin like so:
32
+
33
+ pip install datasette-vega
34
+
35
+ The plugin will then add a "Show charting options" button to every Datasette table and SQL query page.
36
+
37
+ If you are publishing data using the `datasette publish` command, you can
38
+ include this plugin like so:
39
+
40
+ datasette publish cloudrun mydatabase.db --service=my-service --install=datasette-vega
41
+
42
+ ## Development
43
+
44
+ The JavaScript is bundled using [esbuild](https://esbuild.github.io/). Install the dependencies and build the plugin's static assets into `datasette_vega/static/` like this:
45
+
46
+ npm install
47
+ npm run build
48
+
49
+ This needs to run before building the Python package, since the bundled assets are not checked into the repository.
50
+
51
+ To work on the charting interface against the demo page in `public/index.html`, with automatic rebuilds:
52
+
53
+ npm run dev
54
+
55
+ Then open `http://localhost:3000/`.
56
+
57
+ To run the Python tests (after `npm run build`):
58
+
59
+ uv run pytest
@@ -0,0 +1,41 @@
1
+ # datasette-vega
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/datasette-vega.svg)](https://pypi.org/project/datasette-vega/)
4
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/datasette-vega/blob/main/LICENSE)
5
+
6
+ A [Datasette](https://github.com/simonw/datasette) plugin that provides tools
7
+ for generating charts using [Vega](https://vega.github.io/).
8
+
9
+ ![Datasette Vega interface](https://raw.githubusercontent.com/simonw/datasette-vega/main/datasette-vega.png)
10
+
11
+ Try it out in your browser using [Datasette Lite](https://lite.datasette.io/?install=datasette-vega&csv=https%3A%2F%2Fraw.githubusercontent.com%2Ffivethirtyeight%2Fdata%2Fmaster%2Fairline-safety%2Fairline-safety.csv#/data/airline-safety?_size=max#g.mark=bar&g.x_column=airline&g.x_type=ordinal&g.y_column=fatalities_00_14&g.y_type=quantitative), which installs the latest release of this plugin and charts fatalities per airline from 2000 to 2014, using [FiveThirtyEight's airline safety data](https://github.com/fivethirtyeight/data/tree/master/airline-safety).
12
+
13
+ To add this to your Datasette installation, install the plugin like so:
14
+
15
+ pip install datasette-vega
16
+
17
+ The plugin will then add a "Show charting options" button to every Datasette table and SQL query page.
18
+
19
+ If you are publishing data using the `datasette publish` command, you can
20
+ include this plugin like so:
21
+
22
+ datasette publish cloudrun mydatabase.db --service=my-service --install=datasette-vega
23
+
24
+ ## Development
25
+
26
+ The JavaScript is bundled using [esbuild](https://esbuild.github.io/). Install the dependencies and build the plugin's static assets into `datasette_vega/static/` like this:
27
+
28
+ npm install
29
+ npm run build
30
+
31
+ This needs to run before building the Python package, since the bundled assets are not checked into the repository.
32
+
33
+ To work on the charting interface against the demo page in `public/index.html`, with automatic rebuilds:
34
+
35
+ npm run dev
36
+
37
+ Then open `http://localhost:3000/`.
38
+
39
+ To run the Python tests (after `npm run build`):
40
+
41
+ uv run pytest
@@ -0,0 +1,34 @@
1
+ from datasette import hookimpl
2
+ import glob
3
+ import os
4
+
5
+ cache = {}
6
+ static_dir = os.path.join(os.path.dirname(__file__), "static")
7
+
8
+
9
+ def cached_filepaths_for_extension(extension):
10
+ pattern = os.path.join(static_dir, "*.{}".format(extension))
11
+ if pattern not in cache:
12
+ cache[pattern] = [
13
+ "/-/static-plugins/datasette_vega/{}".format(os.path.basename(g))
14
+ for g in glob.glob(pattern)
15
+ ]
16
+ return cache[pattern]
17
+
18
+
19
+ def should_include_assets(template, view_name):
20
+ # Table pages, plus SQL query pages - those report view_name="database"
21
+ # but render query.html (or a custom query-*.html template)
22
+ return view_name == "table" or (template or "").startswith("query")
23
+
24
+
25
+ @hookimpl
26
+ def extra_css_urls(template, view_name):
27
+ if should_include_assets(template, view_name):
28
+ return cached_filepaths_for_extension("css")
29
+
30
+
31
+ @hookimpl
32
+ def extra_js_urls(template, view_name):
33
+ if should_include_assets(template, view_name):
34
+ return cached_filepaths_for_extension("js")
@@ -0,0 +1 @@
1
+ body.datasette-vega-demo{margin:0;padding:1em;font-family:sans-serif}body.datasette-vega-demo form div{margin-bottom:.5em}body.datasette-vega-demo label{padding-right:.5em}.vega-embed{position:relative;display:inline-block;padding-right:38px}.vega-embed .vega-actions-wrapper{display:inline-flex;position:absolute;top:0;right:0;padding:6px;z-index:1000;opacity:.2;background:#fff;box-shadow:1px 1px 3px #0000001a;color:#1b1e23;border:1px solid #aaa;border-radius:999px;transition:opacity .4s ease-in}.vega-embed:hover .vega-actions-wrapper{transition:opacity .2s ease;opacity:1}.vega-embed .vega-actions{position:absolute;top:0;right:0;display:none;flex-direction:column;padding-bottom:8px;padding-top:8px;border-radius:4px;box-shadow:0 2px 8px #0003;border:1px solid #d9d9d9;background:#fff}.vega-embed .vega-actions-wrapper:hover{background:transparent;color:transparent;border:none;box-shadow:none}.vega-embed .vega-actions-wrapper:hover .vega-actions{display:flex}.vega-embed .vega-actions a{padding:8px 16px;font-family:sans-serif;font-size:14px;font-weight:600;white-space:nowrap;color:#434a56;text-decoration:none}.vega-embed .vega-actions a:hover{background-color:#f7f7f9;color:#1b1e23}.datasette-vega{margin:1em 0;padding:1em;width:auto;display:inline-block;font-size:.8em;box-shadow:1px 2px 8px 2px #00000014}.datasette-vega h3{margin-top:0}.datasette-vega .swap-x-y{text-align:center;margin-bottom:.6em}.datasette-vega button,.datasette-vega-inactive button{background-color:#fafafa;border:1px solid #ccc;font-weight:400;cursor:pointer;text-align:center;vertical-align:middle;padding:.5em .8em;line-height:1;border-radius:.25rem;-webkit-appearance:button;font-size:.7em}.datasette-vega-chart,.datasette-vega-inactive{margin-bottom:1em}form.datasette-vega label{font-weight:700;display:inline;width:auto;padding-right:.3em}form.datasette-vega div{margin-bottom:.3em}.datasette-vega .radio-buttons label{margin-right:2em;display:inline-block}.datasette-vega .radio-buttons{margin-bottom:1em}