예제 #1
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}
예제 #2
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])
예제 #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])