Skip to content

Commit

Permalink
docs: load all specs in widget example
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Sep 30, 2024
1 parent 9324986 commit efc55df
Showing 1 changed file with 74 additions and 44 deletions.
118 changes: 74 additions & 44 deletions dev/notebooks/specs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "93103597-996b-46ec-9804-63164b775896",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from pprint import pprint\n",
"from pathlib import Path\n",
"\n",
"import duckdb\n",
"import ipywidgets as widgets\n",
"import yaml\n",
"import json\n",
"\n",
"from mosaic_widget import MosaicWidget"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "ed9edb9e-4ed2-4e5e-b44c-81a2c7a73af4",
"metadata": {
"tags": []
Expand All @@ -35,18 +36,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "71be7064-deb8-4b5e-b86c-7c73c86220cf",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/dominik/Developer/mosaic\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/dominik/Library/Application Support/hatch/env/virtual/mosaic-widget/flBMdGv2/mosaic-widget/lib/python3.11/site-packages/IPython/core/magics/osm.py:417: UserWarning: This is now an optional IPython functionality, setting dhist requires you to install the `pickleshare` library.\n",
" self.shell.db['dhist'] = compress_dhist(dhist)[-100:]\n"
]
}
],
"source": [
"# Change working directory to mosaic root\n",
"%cd ../.."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "5f46684a-5a00-4db2-9a1e-7b394a84fc21",
"metadata": {
"tags": []
Expand All @@ -59,7 +76,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "4da7f0fd-ec48-4ca9-b927-cbf9b0a5d8b8",
"metadata": {
"tags": []
Expand All @@ -71,44 +88,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "72656409-7087-4394-bf73-24fe5353cea3",
"metadata": {},
"outputs": [],
"source": [
"def get_specs(folder_path):\n",
" folder = Path(folder_path)\n",
" for file_path in folder.glob(\"*.json\"):\n",
" data = json.loads(file_path.read_text())\n",
" meta = data.get(\"meta\")\n",
" if meta:\n",
" yield (meta.get(\"title\"), file_path)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "211e4826-c2c6-4af2-a46f-1786d4600c73",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"weather = Path(\"specs/json/weather.json\")\n",
"\n",
"dropdown = widgets.Dropdown(\n",
" options=[\n",
" (\"Athletes\", \"athletes\"),\n",
" (\"Bias Parameter\", \"bias\"),\n",
" (\"Contours\", \"contours\"),\n",
" (\"Density 1D\", \"density1d\"),\n",
" (\"Density 2D\", \"density2d\"),\n",
" (\"Axes & Gridlines\", \"axes\"),\n",
" (\"Earthquakes\", \"earthquakes\"),\n",
" (\"Flights Density\", \"flights-density\"),\n",
" (\"Flights\", \"flights\"),\n",
" (\"Flights 10M\", \"flights-10m\"),\n",
" (\"Gaia Star Catalog\", \"gaia\"),\n",
" (\"Hexbin\", \"hexbin\"),\n",
" (\"Images\", \"images\"),\n",
" (\"Links\", \"links\"),\n",
" (\"Line Density\", \"line-density\"),\n",
" (\"Mark Types\", \"marks\"),\n",
" (\"Moving Average\", \"moving-average\"),\n",
" (\"Normalize Stocks\", \"normalize\"),\n",
" (\"Overview + Detail\", \"overview-detail\"),\n",
" (\"Pan + Zoom\", \"pan-zoom\"),\n",
" (\"Regression\", \"regression\"),\n",
" (\"Scatter Plot Matrix\", \"splom\"),\n",
" (\"Seattle Weather\", \"weather\"),\n",
" (\"Symbols\", \"symbols\"),\n",
" (\"Table\", \"table\"),\n",
" (\"Voronoi\", \"voronoi\"),\n",
" (\"Wind Map\", \"wind-map\"),\n",
" ],\n",
" value=\"weather\",\n",
" options=get_specs(\"specs/json\"),\n",
" value=weather,\n",
" description=\"Example:\",\n",
")\n",
"\n",
Expand All @@ -118,13 +125,12 @@
"\n",
"\n",
"def open_spec(spec):\n",
" with open(f\"specs/yaml/{spec}.yaml\") as f:\n",
" mosaic.spec = yaml.safe_load(f)\n",
" mosaic.spec = json.loads(spec.read_text())\n",
"\n",
"\n",
"dropdown.observe(on_change, \"value\")\n",
"\n",
"open_spec(\"weather\")\n",
"open_spec(weather)\n",
"\n",
"output = widgets.Output()\n",
"\n",
Expand All @@ -139,15 +145,39 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "d192b9ff-2592-4683-b22d-b87994196379",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "54e3beb82b2c4abd8035d96c600f8b5a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Dropdown(description='Example:', index=20, options=(('Mark Types', PosixPath('specs/json/mark-t…"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"widgets.VBox([dropdown, mosaic, output])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "29babf14-24dc-4fc9-befb-ccda6eaa4781",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -166,7 +196,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit efc55df

Please sign in to comment.