Skip to content

Commit

Permalink
Make %browse work in VSCode, update font
Browse files Browse the repository at this point in the history
  • Loading branch information
hugetim committed Oct 22, 2024
1 parent a346469 commit eeb0264
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
67 changes: 50 additions & 17 deletions nbs/07_browse.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1280,9 +1280,9 @@
"#| export\n",
"def display_df_as_ipydatagrid(df):\n",
" from ipydatagrid import DataGrid, TextRenderer\n",
" i_renderer = TextRenderer(horizontal_alignment=\"right\", font=\"11px monospace\", background_color=\"rgb(243, 243, 243)\")\n",
" d_renderer = TextRenderer(horizontal_alignment=\"right\", font=\"11px monospace\")\n",
" h_renderer = TextRenderer(horizontal_alignment=\"center\", font=\"11px monospace\")\n",
" i_renderer = TextRenderer(horizontal_alignment=\"right\", background_color=\"rgb(243, 243, 243)\")\n",
" d_renderer = TextRenderer(horizontal_alignment=\"right\")\n",
" h_renderer = TextRenderer(horizontal_alignment=\"center\")\n",
" column_widths = {}\n",
" temp_head = df.head(20)\n",
" char_px_width = 6.05\n",
Expand Down Expand Up @@ -1310,7 +1310,7 @@
" header_renderer=h_renderer,\n",
" renderers={\" \": i_renderer},\n",
" column_widths=column_widths,\n",
" layout={\"height\": \"100%\"},\n",
" #layout={\"height\": \"100%\"},\n",
" )\n",
" g.grid_style = {\n",
" \"background_color\": \"rgb(255, 255, 255)\",\n",
Expand All @@ -1324,41 +1324,74 @@
" \"header_selection_border_color\": \"rgb(229, 229, 229)\",\n",
" \"cursor_fill_color\": \"rgb(255, 255, 255, 0)\",\n",
" \"cursor_border_color\": \"rgb(40, 40, 40)\",\n",
" \"scroll_shadow\": {'size': 0},\n",
" \"scroll_shadow\": {'size': 0, 'color1': \"white\", 'color2': \"white\", 'color3': \"white\"},\n",
" }\n",
" display(g)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(41 missing values generated)\n"
]
}
],
"source": [
"#| eval: False\n",
"#set_ipydatagrid_height()\n",
"run_single('gen long_name_1234567 = \"\"')\n",
"run_single('gen long_str = \"10000000000200000000003000000000040000000000500000000006000000000070000000000800000000009000000000010000000000\"')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>div.jp-Notebook .datagrid-container {min-height: 448px; }</style>"
],
"application/vnd.jupyter.widget-view+json": {
"model_id": "274edd0ade744e8ab7a3f81d5cca57f2",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"<IPython.core.display.HTML object>"
"DataGrid(auto_fit_params={'area': 'all', 'padding': 30, 'numCols': None}, base_row_size=21, column_widths={'ye…"
]
},
"metadata": {},
"output_type": "display_data"
},
}
],
"source": [
"#| eval: False\n",
"df = get_df(*browse_df_params(', noformat', obs_count(), '.'))\n",
"display_df_as_ipydatagrid(df)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(41 missing values generated)\n"
"(1978 automobile data)\n"
]
}
],
"source": [
"#| eval: False\n",
"set_ipydatagrid_height()\n",
"run_single('gen long_name_1234567 = \"\"')\n",
"run_single('gen long_str = \"10000000000200000000003000000000040000000000500000000006000000000070000000000800000000009000000000010000000000\"')"
"#set_ipydatagrid_height()\n",
"run_single('sysuse auto, clear')"
]
},
{
Expand All @@ -1369,12 +1402,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c8c7bee37b5a47f7b526676d2cb4c610",
"model_id": "ee1e980f753042c895ed0306a4ae0b64",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"DataGrid(auto_fit_params={'area': 'all', 'padding': 30, 'numCols': None}, base_row_size=21, column_widths={'ye"
"DataGrid(auto_fit_params={'area': 'all', 'padding': 30, 'numCols': None}, base_row_size=21, column_widths={'ma"
]
},
"metadata": {},
Expand All @@ -1383,7 +1416,7 @@
],
"source": [
"#| eval: False\n",
"df = get_df(*browse_df_params(', noformat', obs_count(), '.'))\n",
"df = get_df(*browse_df_params('', obs_count(), '.'))\n",
"display_df_as_ipydatagrid(df)"
]
},
Expand Down
10 changes: 5 additions & 5 deletions nbstata/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ def set_ipydatagrid_height():
# %% ../nbs/07_browse.ipynb 53
def display_df_as_ipydatagrid(df):
from ipydatagrid import DataGrid, TextRenderer
i_renderer = TextRenderer(horizontal_alignment="right", font="11px monospace", background_color="rgb(243, 243, 243)")
d_renderer = TextRenderer(horizontal_alignment="right", font="11px monospace")
h_renderer = TextRenderer(horizontal_alignment="center", font="11px monospace")
i_renderer = TextRenderer(horizontal_alignment="right", background_color="rgb(243, 243, 243)")
d_renderer = TextRenderer(horizontal_alignment="right")
h_renderer = TextRenderer(horizontal_alignment="center")
column_widths = {}
temp_head = df.head(20)
char_px_width = 6.05
Expand Down Expand Up @@ -235,7 +235,7 @@ def name_width(name_len):
header_renderer=h_renderer,
renderers={" ": i_renderer},
column_widths=column_widths,
layout={"height": "100%"},
#layout={"height": "100%"},
)
g.grid_style = {
"background_color": "rgb(255, 255, 255)",
Expand All @@ -249,6 +249,6 @@ def name_width(name_len):
"header_selection_border_color": "rgb(229, 229, 229)",
"cursor_fill_color": "rgb(255, 255, 255, 0)",
"cursor_border_color": "rgb(40, 40, 40)",
"scroll_shadow": {'size': 0},
"scroll_shadow": {'size': 0, 'color1': "white", 'color2': "white", 'color3': "white"},
}
display(g)

0 comments on commit eeb0264

Please sign in to comment.