예제 #1
0
    def test_server_basic_mulitselection(self, bokeh_server_page) -> None:
        data = {'x': [1, 2, 3, 4, 5, 6], 'y': [60, 50, 40, 30, 20, 10]}
        source = ColumnDataSource(data)

        def modify_doc(doc):

            plot = Plot(plot_height=400,
                        plot_width=400,
                        x_range=Range1d(0, 1),
                        y_range=Range1d(0, 1),
                        min_border=0)
            plot.add_tools(
                CustomAction(callback=CustomJS(
                    args=dict(s=source),
                    code=RECORD("indices", "s.selected.indices"))))

            table = DataTable(
                columns=[TableColumn(field="x"),
                         TableColumn(field="y")],
                source=source,
                editable=False)

            doc.add_root(column(plot, table))

        page = bokeh_server_page(modify_doc)

        page.click_custom_action()

        results = page.results
        assert results == {'indices': []}
        assert set(source.selected.indices) == set([])
        assert get_table_selected_rows(page.driver) == set([])

        # select the third row
        row = get_table_row(page.driver, 2)
        row.click()

        row = get_table_row(page.driver, 4)
        shift_click(page.driver, row)

        page.click_custom_action()

        results = page.results
        assert set(results['indices']) == set([1, 2, 3])
        assert set(source.selected.indices) == set([1, 2, 3])
        assert get_table_selected_rows(page.driver) == set([1, 2, 3])

        row = get_table_row(page.driver, 6)
        alt_click(page.driver, row)

        page.click_custom_action()

        results = page.results
        assert set(results['indices']) == set([1, 2, 3, 5])
        assert set(source.selected.indices) == set([1, 2, 3, 5])
        assert get_table_selected_rows(page.driver) == set([1, 2, 3, 5])
예제 #2
0
    def test_server_basic_mulitselection(
            self, bokeh_server_page: BokehServerPage) -> None:
        data = {'x': [1, 2, 3, 4, 5, 6], 'y': [60, 50, 40, 30, 20, 10]}
        source = ColumnDataSource(data)

        table = DataTable(
            columns=[TableColumn(field="x"),
                     TableColumn(field="y")],
            source=source,
            editable=False)

        def modify_doc(doc):
            plot = Plot(height=400,
                        width=400,
                        x_range=Range1d(0, 1),
                        y_range=Range1d(0, 1),
                        min_border=0)
            plot.tags.append(
                CustomJS(name="custom-action",
                         args=dict(s=source),
                         code=RECORD("indices", "s.selected.indices")))

            doc.add_root(column(plot, table))

        page = bokeh_server_page(modify_doc)

        page.eval_custom_action()

        results = page.results
        assert results == {'indices': []}
        assert set(source.selected.indices) == set()
        assert get_table_selected_rows(page.driver, table) == set()

        # select the third row
        row = get_table_row(page.driver, table, 2)
        row.click()

        row = get_table_row(page.driver, table, 4)
        shift_click(page.driver, row)

        page.eval_custom_action()

        results = page.results
        assert set(results["indices"]) == {1, 2, 3}
        assert set(source.selected.indices) == {1, 2, 3}
        assert get_table_selected_rows(page.driver, table) == {1, 2, 3}

        row = get_table_row(page.driver, table, 6)
        alt_click(page.driver, row)

        page.eval_custom_action()

        results = page.results
        assert set(results["indices"]) == {1, 2, 3, 5}
        assert set(source.selected.indices) == {1, 2, 3, 5}
        assert get_table_selected_rows(page.driver, table) == {1, 2, 3, 5}
예제 #3
0
    def test_server_basic_mulitselection(self, bokeh_server_page):
        data = {'x': [1,2,3,4,5,6], 'y': [60,50,40,30,20,10]}
        source = ColumnDataSource(data)

        def modify_doc(doc):

            plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
            plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("indices", "s.selected.indices"))))

            table = DataTable(columns=[
                TableColumn(field="x"),
                TableColumn(field="y")
            ], source=source, editable=False)

            doc.add_root(column(plot, table))

        page = bokeh_server_page(modify_doc)

        page.click_custom_action()

        results = page.results
        assert results ==  {'indices': []}
        assert set(source.selected.indices) == set([])
        assert get_table_selected_rows(page.driver) == set([])

        # select the third row
        row = get_table_row(page.driver, 2)
        row.click()

        row = get_table_row(page.driver, 4)
        shift_click(page.driver, row)

        page.click_custom_action()

        results = page.results
        assert set(results['indices']) ==  set([1, 2, 3])
        assert set(source.selected.indices) == set([1, 2, 3])
        assert get_table_selected_rows(page.driver) == set([1, 2, 3])

        row = get_table_row(page.driver, 6)
        alt_click(page.driver, row)

        page.click_custom_action()

        results = page.results
        assert set(results['indices']) ==  set([1, 2, 3, 5])
        assert set(source.selected.indices) == set([1, 2, 3, 5])
        assert get_table_selected_rows(page.driver) == set([1, 2, 3, 5])
예제 #4
0
    def test_glyph_selection_updates_table(self, single_plot_page) -> None:
        plot = Plot(height=800, width=1000)

        data = {'x': [1, 2, 3, 4], 'y': [1, 1, 1, 1]}
        source = ColumnDataSource(data)
        table = DataTable(columns=[
            TableColumn(field="x", title="x", sortable=True),
            TableColumn(field="y",
                        title="y",
                        sortable=True,
                        editor=NumberEditor())
        ],
                          source=source,
                          editable=True)

        plot.add_glyph(source, Rect(x='x', y='y', width=1.5, height=1))
        plot.add_tools(
            TapTool(callback=CustomJS(
                code=RECORD("indices", "cb_data.source.selected.indices"))))

        page = single_plot_page(column(plot, table))

        page.click_canvas_at_position(500, 400)
        assert set(page.results["indices"]) == {1, 2}

        assert get_table_selected_rows(page.driver) == {1, 2}

        assert page.has_no_console_errors()

        assert page.has_no_console_errors()
예제 #5
0
    def test_glyph_selection_updates_table(self, single_plot_page):
        plot = Plot(height=800, width=1000)

        data = {'x': [1,2,3,4], 'y': [1, 1, 1, 1]}
        source = ColumnDataSource(data)
        table = DataTable(columns=[
            TableColumn(field="x", title="x", sortable=True),
            TableColumn(field="y", title="y", sortable=True, editor=NumberEditor())
        ], source=source, editable=True)

        plot.add_glyph(source, Rect(x='x', y='y', width=1.5, height=1))
        plot.add_tools(TapTool(callback=CustomJS(code=RECORD("indices", "cb_data.source.selected.indices"))))

        page = single_plot_page(column(plot, table))

        page.click_canvas_at_position(500, 400)
        assert set(page.results["indices"]) == {1, 2}

        assert get_table_selected_rows(page.driver) == {1, 2}

        assert page.has_no_console_errors()

        assert page.has_no_console_errors()