|
371 | 371 | " \"Signal\": signal_column_formatting,\n",
|
372 | 372 | " \"Return\": TextRenderer(background_color='seashell',\n",
|
373 | 373 | " text_color=VegaExpr('cell.value > 0 ? \"green\" : \"firebrick\"')\n",
|
374 |
| - " ),\n", |
375 |
| - " \"Stock\": TextRenderer(background_color='seashell')\n", |
| 374 | + " )\n", |
376 | 375 | "}\n",
|
377 | 376 | "\n",
|
378 | 377 | "conditional_grid = DataGrid(\n",
|
|
416 | 415 | "outputs": [],
|
417 | 416 | "source": [
|
418 | 417 | "columns_renderer = TextRenderer(\n",
|
419 |
| - " background_color='honeydew',\n", |
| 418 | + " background_color='dimgray',\n", |
420 | 419 | " horizontal_alignment='center')\n",
|
421 | 420 | "\n",
|
422 | 421 | "renderers= {\n",
|
423 |
| - " \"('Ticker', '')\": TextRenderer(background_color='honeydew')\n", |
| 422 | + " \"('Ticker', '')\": TextRenderer(background_color='dimgray')\n", |
424 | 423 | "}\n",
|
425 | 424 | "\n",
|
426 | 425 | "default_renderer = TextRenderer(\n",
|
427 |
| - " background_color=VegaExpr('cell.value > 0 ? \"azure\" : \"lavenderblush\"')\n", |
| 426 | + " background_color=VegaExpr('cell.value > 0 ? \"steelblue\" : \"seagreen\"')\n", |
428 | 427 | ")\n",
|
429 | 428 | "\n",
|
430 | 429 | "nested_grid = DataGrid(nested_df,\n",
|
|
657 | 656 | "small_grid = DataGrid(small_df, \n",
|
658 | 657 | " editable=True, \n",
|
659 | 658 | " default_renderer=TextRenderer(\n",
|
660 |
| - " background_color=VegaExpr(\"cell.value === 1 ? 'limegreen' : 'moccasin'\")\n", |
| 659 | + " background_color=VegaExpr(\"cell.value === 1 ? 'limegreen' : 'hotpink'\")\n", |
661 | 660 | " ),\n",
|
662 | 661 | " layout={'height': '250px'})\n",
|
663 | 662 | "small_grid"
|
|
741 | 740 | "id": "8c454fb8",
|
742 | 741 | "metadata": {},
|
743 | 742 | "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." |
745 | 746 | ]
|
746 | 747 | },
|
747 | 748 | {
|
|
795 | 796 | "slider"
|
796 | 797 | ]
|
797 | 798 | },
|
| 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 | + }, |
798 | 809 | {
|
799 | 810 | "cell_type": "markdown",
|
800 | 811 | "id": "b78005c8",
|
|
824 | 835 | "source": [
|
825 | 836 | "from bqplot import LinearScale, Axis, Figure, Lines, CATEGORY10\n",
|
826 | 837 | "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", |
833 | 838 | " \n",
|
| 839 | + "# Setting up the data grid\n", |
834 | 840 | "stock_grid = DataGrid(stock_df, selection_mode='column')\n",
|
835 | 841 | "\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%'))" |
846 | 850 | ]
|
847 | 851 | },
|
848 | 852 | {
|
|
852 | 856 | "metadata": {},
|
853 | 857 | "outputs": [],
|
854 | 858 | "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)" |
864 | 867 | ]
|
865 | 868 | },
|
866 | 869 | {
|
|
874 | 877 | " [stock_grid, fig]\n",
|
875 | 878 | ")"
|
876 | 879 | ]
|
| 880 | + }, |
| 881 | + { |
| 882 | + "cell_type": "code", |
| 883 | + "execution_count": null, |
| 884 | + "id": "100aec93-89b1-48d8-9077-0cc0d5fc48ac", |
| 885 | + "metadata": {}, |
| 886 | + "outputs": [], |
| 887 | + "source": [] |
877 | 888 | }
|
878 | 889 | ],
|
879 | 890 | "metadata": {
|
|
0 commit comments