Skip to content

Commit 62870eb

Browse files
authored
Merge pull request #5 from jupytercon/layout_tutorial_updates
small enhancements to layout and styling tutorial
2 parents 7f87cca + afb6c0e commit 62870eb

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

notebooks/03.Layout-and-Styling/03.01-widget-layout-and-styling.ipynb

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
{
22
"cells": [
3-
{
4-
"cell_type": "markdown",
5-
"metadata": {},
6-
"source": [
7-
"<!--NAVIGATION-->\n",
8-
"< [Contents](03.00-layout-and-styling-overview.ipynb) | [*OPTIONAL* - Widget label styling](03.02-OPTIONAL-widget-label-styling.ipynb) >"
9-
]
10-
},
113
{
124
"cell_type": "markdown",
135
"metadata": {},
@@ -23,15 +15,13 @@
2315
"cell_type": "markdown",
2416
"metadata": {},
2517
"source": [
26-
"## The `layout` attribute.\n",
18+
"## The `layout` attribute\n",
2719
"\n",
2820
"Jupyter interactive widgets have a `layout` attribute exposing a number of CSS properties that impact how widgets are laid out.\n",
2921
"\n",
30-
"### Exposed CSS properties\n",
22+
"### CSS properties exposed with `layout` attribute\n",
3123
"\n",
32-
"<div class=\"alert alert-info\" style=\"margin: 20px\">\n",
3324
"The following properties map to the values of the CSS properties of the same name (underscores being replaced with dashes), applied to the top DOM elements of the corresponding widget.\n",
34-
"</div>\n",
3525
"\n",
3626
"\n",
3727
"#### Sizes\n",
@@ -64,7 +54,7 @@
6454
"- `bottom`\n",
6555
"- `right`\n",
6656
"\n",
67-
"#### Image/media\n",
57+
"#### Image / media\n",
6858
"\n",
6959
"- `object_fit`\n",
7060
"- `object_position`\n",
@@ -189,7 +179,7 @@
189179
"metadata": {},
190180
"outputs": [],
191181
"source": [
192-
"b2.style.button_color = 'yellow'"
182+
"b2.style.button_color = 'orange'"
193183
]
194184
},
195185
{
@@ -239,8 +229,8 @@
239229
"outputs": [],
240230
"source": [
241231
"from ipywidgets import IntSlider\n",
242-
"s1 = IntSlider(description='Blue handle')\n",
243-
"s1.style.handle_color = 'lightblue'\n",
232+
"s1 = IntSlider(description='Red handle')\n",
233+
"s1.style.handle_color = 'red'\n",
244234
"s1"
245235
]
246236
},
@@ -349,6 +339,7 @@
349339
" \"\"\"Displays multiple widgets horizontally using the flexible box model.\"\"\"\n",
350340
" box = Box(*pargs, **kwargs)\n",
351341
" box.layout.display = 'flex'\n",
342+
" box.layout.flex_flow = 'row'\n",
352343
" box.layout.align_items = 'stretch'\n",
353344
" return box\n",
354345
"```\n",
@@ -380,10 +371,10 @@
380371
"source": [
381372
"from ipywidgets import Layout, Button, Box\n",
382373
"\n",
383-
"items_layout = Layout(width='auto') # override the default width of the button to 'auto' to let the button grow\n",
374+
"items_layout = Layout(width='auto') # override the default width of the button to 'auto' to let the button grow\n",
384375
"\n",
385376
"box_layout = Layout(display='flex',\n",
386-
" flex_flow='column', \n",
377+
" flex_flow='column',\n",
387378
" align_items='stretch', \n",
388379
" border='solid',\n",
389380
" width='50%')\n",
@@ -410,9 +401,9 @@
410401
"from ipywidgets import Layout, Button, HBox\n",
411402
"\n",
412403
"items = [\n",
413-
" Button(description='weight=1; 0%', layout=Layout(flex='1 1 0%', width='auto'), button_style='danger'),\n",
414-
" Button(description='weight=3; 0%', layout=Layout(flex='3 1 0%', width='auto'), button_style='danger'),\n",
415-
" Button(description='weight=1; 0%', layout=Layout(flex='1 1 0%', width='auto'), button_style='danger'),\n",
404+
" Button(description='weight=1', layout=Layout(flex='1', width='auto'), button_style='danger'),\n",
405+
" Button(description='weight=3', layout=Layout(flex='3', width='auto'), button_style='danger'),\n",
406+
" Button(description='weight=1', layout=Layout(flex='1', width='auto'), button_style='danger'),\n",
416407
"]\n",
417408
"box_layout = Layout(align_items='stretch', width='70%')\n",
418409
"HBox(children=items, layout=box_layout)"
@@ -737,7 +728,7 @@
737728
"source": [
738729
"from ipywidgets import Layout, Button, Box\n",
739730
"\n",
740-
"items_layout = Layout(width='auto') # override the default width of the button to 'auto' to let the button grow\n",
731+
"items_layout = Layout(width='auto') # override the default width of the button to 'auto' to let the button grow\n",
741732
"\n",
742733
"box_layout = Layout(display='flex',\n",
743734
" flex_flow='column', \n",
@@ -877,7 +868,6 @@
877868
"metadata": {},
878869
"outputs": [],
879870
"source": [
880-
"# Utils widgets\n",
881871
"from ipywidgets import Button, Layout, jslink, IntText, IntSlider\n",
882872
"\n",
883873
"def create_expanded_button(description, button_style):\n",
@@ -1430,15 +1420,15 @@
14301420
" scatt = bq.Scatter(x=data[:, j], y=data[:, i], scales={'x': sc_x, 'y': sc_y})\n",
14311421
"\n",
14321422
" gs[i, j] = bq.Figure(marks=[scatt], layout=Layout(width='auto', height='auto'),\n",
1433-
" fig_margin=dict(top=5, bottom=5, left=5, right=5), background_style={'fill':'#f5f5ff'})\n",
1423+
" fig_margin=dict(top=5, bottom=5, left=5, right=5), background_style={'fill':'#e5e5ff'})\n",
14341424
" else:\n",
14351425
" sc_x = scales_x[j]\n",
14361426
" sc_y = bq.LinearScale()\n",
14371427
" \n",
14381428
" hist = bq.Hist(sample=data[:,i], scales={'sample': sc_x, 'count': sc_y})\n",
14391429
" \n",
14401430
" gs[i, j] = bq.Figure(marks=[hist], layout=Layout(width='auto', height='auto'),\n",
1441-
" fig_margin=dict(top=5, bottom=5, left=5, right=5), background_style={'fill':'#f5f5ff'})\n",
1431+
" fig_margin=dict(top=5, bottom=5, left=5, right=5), background_style={'fill':'#e5e5ff'})\n",
14421432
"gs"
14431433
]
14441434
},
@@ -1477,7 +1467,7 @@
14771467
" layout=Layout(\n",
14781468
" width='50%',\n",
14791469
" grid_template_columns='100px 50px 100px',\n",
1480-
" grid_template_rows='80px auto 80px', \n",
1470+
" grid_template_rows='80px auto 80px',\n",
14811471
" grid_gap='5px 10px')\n",
14821472
" )"
14831473
]
@@ -1534,13 +1524,13 @@
15341524
" style=ButtonStyle(button_color='lightblue'))\n",
15351525
"main = Button(description='Main',\n",
15361526
" layout=Layout(width='auto', height='auto', grid_area='main'),\n",
1537-
" style=ButtonStyle(button_color='moccasin'))\n",
1527+
" style=ButtonStyle(button_color='lightgray'))\n",
15381528
"sidebar = Button(description='Sidebar',\n",
15391529
" layout=Layout(width='auto', height='auto', grid_area='sidebar'),\n",
15401530
" style=ButtonStyle(button_color='salmon'))\n",
15411531
"footer = Button(description='Footer',\n",
15421532
" layout=Layout(width='auto', height='auto', grid_area='footer'),\n",
1543-
" style=ButtonStyle(button_color='olive'))\n",
1533+
" style=ButtonStyle(button_color='orange'))\n",
15441534
"\n",
15451535
"GridBox(children=[header, main, sidebar, footer],\n",
15461536
" layout=Layout(\n",
@@ -1577,7 +1567,7 @@
15771567
"metadata": {},
15781568
"source": [
15791569
"<!--NAVIGATION-->\n",
1580-
"< [Layout and Styling of Jupyter widgets](03.00-layout-and-styling-overview.ipynb) | [*OPTIONAL* - Widget label styling](03.02-OPTIONAL-widget-label-styling.ipynb) >"
1570+
"< [Contents](03.00-layout-and-styling-overview.ipynb) | [*OPTIONAL* - Widget Label Styling](03.02-OPTIONAL-widget-label-styling.ipynb) >"
15811571
]
15821572
}
15831573
],

0 commit comments

Comments
 (0)