Skip to content

Commit ebe064c

Browse files
committed
Update ipydatagrid notebook
Signed-off-by: Itay Dafna <[email protected]>
1 parent ccee49c commit ebe064c

File tree

1 file changed

+43
-32
lines changed

1 file changed

+43
-32
lines changed

notebooks/07.03-ipydatagrid.ipynb

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@
371371
" \"Signal\": signal_column_formatting,\n",
372372
" \"Return\": TextRenderer(background_color='seashell',\n",
373373
" text_color=VegaExpr('cell.value > 0 ? \"green\" : \"firebrick\"')\n",
374-
" ),\n",
375-
" \"Stock\": TextRenderer(background_color='seashell')\n",
374+
" )\n",
376375
"}\n",
377376
"\n",
378377
"conditional_grid = DataGrid(\n",
@@ -416,15 +415,15 @@
416415
"outputs": [],
417416
"source": [
418417
"columns_renderer = TextRenderer(\n",
419-
" background_color='honeydew',\n",
418+
" background_color='dimgray',\n",
420419
" horizontal_alignment='center')\n",
421420
"\n",
422421
"renderers= {\n",
423-
" \"('Ticker', '')\": TextRenderer(background_color='honeydew')\n",
422+
" \"('Ticker', '')\": TextRenderer(background_color='dimgray')\n",
424423
"}\n",
425424
"\n",
426425
"default_renderer = TextRenderer(\n",
427-
" background_color=VegaExpr('cell.value > 0 ? \"azure\" : \"lavenderblush\"')\n",
426+
" background_color=VegaExpr('cell.value > 0 ? \"steelblue\" : \"seagreen\"')\n",
428427
")\n",
429428
"\n",
430429
"nested_grid = DataGrid(nested_df,\n",
@@ -657,7 +656,7 @@
657656
"small_grid = DataGrid(small_df, \n",
658657
" editable=True, \n",
659658
" default_renderer=TextRenderer(\n",
660-
" background_color=VegaExpr(\"cell.value === 1 ? 'limegreen' : 'moccasin'\")\n",
659+
" background_color=VegaExpr(\"cell.value === 1 ? 'limegreen' : 'hotpink'\")\n",
661660
" ),\n",
662661
" layout={'height': '250px'})\n",
663662
"small_grid"
@@ -741,7 +740,9 @@
741740
"id": "8c454fb8",
742741
"metadata": {},
743742
"source": [
744-
"#### An example with the BarRenderer"
743+
"#### An example with the BarRenderer\n",
744+
"\n",
745+
"Renders cell values as horizontal bars based on a scale. `ipydatagrid` has two renderers - `TextRenderer`, which is the default one we've seen, and `BarRenderer`, which we will use now."
745746
]
746747
},
747748
{
@@ -795,6 +796,16 @@
795796
"slider"
796797
]
797798
},
799+
{
800+
"cell_type": "code",
801+
"execution_count": null,
802+
"id": "6ab2857d-60be-46e2-8402-6f6b8edb7c33",
803+
"metadata": {},
804+
"outputs": [],
805+
"source": [
806+
"color_scale.min"
807+
]
808+
},
798809
{
799810
"cell_type": "markdown",
800811
"id": "b78005c8",
@@ -824,25 +835,18 @@
824835
"source": [
825836
"from bqplot import LinearScale, Axis, Figure, Lines, CATEGORY10\n",
826837
"from ipywidgets import HBox, Layout\n",
827-
"\n",
828-
"def plot_stock(e):\n",
829-
" line.y = stock_grid.selected_cell_values\n",
830-
" line.x = range(len(line.y))\n",
831-
" line.labels = [e['column']]\n",
832-
" line.colors = [CATEGORY10[np.random.randint(0, len(CATEGORY10)) % len(CATEGORY10)]]\n",
833838
" \n",
839+
"# Setting up the data grid\n",
834840
"stock_grid = DataGrid(stock_df, selection_mode='column')\n",
835841
"\n",
836-
"# Event listener for cell click\n",
837-
"stock_grid.on_cell_click(plot_stock)"
838-
]
839-
},
840-
{
841-
"cell_type": "markdown",
842-
"id": "65ae20ea",
843-
"metadata": {},
844-
"source": [
845-
"Setting up bqplot and ipywidgets objects"
842+
"# Creating the bqplot chart objects\n",
843+
"sc_x = LinearScale()\n",
844+
"sc_y = LinearScale()\n",
845+
"line = Lines(x=[], y=[], labels=['Fake stock price'], display_legend=True,\n",
846+
" scales={'x': sc_x, 'y': sc_y})\n",
847+
"ax_x = Axis(scale=sc_x, label='Index')\n",
848+
"ax_y = Axis(scale=sc_y, orientation='vertical', label='y-value')\n",
849+
"fig = Figure(marks=[line], axes=[ax_x, ax_y], title='Line Chart', layout=Layout(flex='1 1 auto', width='100%'))"
846850
]
847851
},
848852
{
@@ -852,15 +856,14 @@
852856
"metadata": {},
853857
"outputs": [],
854858
"source": [
855-
"\n",
856-
"# Creating the bqplot chart objects\n",
857-
"sc_x = LinearScale()\n",
858-
"sc_y = LinearScale()\n",
859-
"line = Lines(x=[], y=[], labels=['Fake stock price'], display_legend=True,\n",
860-
" scales={'x': sc_x, 'y': sc_y})\n",
861-
"ax_x = Axis(scale=sc_x, label='Index')\n",
862-
"ax_y = Axis(scale=sc_y, orientation='vertical', label='y-value')\n",
863-
"fig = Figure(marks=[line], axes=[ax_x, ax_y], title='Line Chart', layout=Layout(flex='1 1 auto', width='100%'))"
859+
"def plot_stock(e=None):\n",
860+
" line.y = stock_grid.selected_cell_values\n",
861+
" line.x = range(len(line.y))\n",
862+
" line.labels = [e['column']]\n",
863+
" line.colors = [CATEGORY10[np.random.randint(0, len(CATEGORY10)) % len(CATEGORY10)]]\n",
864+
" \n",
865+
"# Event listener for cell click\n",
866+
"stock_grid.on_cell_click(plot_stock)"
864867
]
865868
},
866869
{
@@ -874,6 +877,14 @@
874877
" [stock_grid, fig]\n",
875878
")"
876879
]
880+
},
881+
{
882+
"cell_type": "code",
883+
"execution_count": null,
884+
"id": "100aec93-89b1-48d8-9077-0cc0d5fc48ac",
885+
"metadata": {},
886+
"outputs": [],
887+
"source": []
877888
}
878889
],
879890
"metadata": {

0 commit comments

Comments
 (0)