Ejemplo n.º 1
0
    def test_server_on_change_round_trip(self, bokeh_server_page) -> None:

        def modify_doc(doc):
            source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"]))
            plot = Plot(height=400, width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
            plot.add_glyph(source, Circle(x='x', y='y', size=20))
            plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data"))))
            slider = DateSlider(start=start, end=end, value=value, css_classes=["foo"], width=300, step=24*3600*1000)

            def cb(attr, old, new):
                source.data['val'] = [slider.value_as_date.isoformat()]

            slider.on_change('value', cb)
            doc.add_root(column(slider, plot))

        page = bokeh_server_page(modify_doc)

        drag_slider(page.driver, ".foo", 50)

        page.click_custom_action()
        results = page.results
        new = results['data']['val']
        assert new[0] > '2017-08-04'

        drag_slider(page.driver, ".foo", -70)

        page.click_custom_action()
        results = page.results
        new = results['data']['val']
        assert new[0] == '2017-08-03'
Ejemplo n.º 2
0
    def test_server_title_updates(self, bokeh_server_page) -> None:
        def modify_doc(doc):
            plot = Plot(height=400,
                        width=400,
                        x_range=Range1d(0, 1),
                        y_range=Range1d(0, 1),
                        min_border=0)
            slider = DateSlider(start=start,
                                end=end,
                                value=value,
                                css_classes=["foo"],
                                width=300)

            def cb(attr, old, new):
                slider.title = "baz"

            slider.on_change('value', cb)
            doc.add_root(column(slider, plot))

        page = bokeh_server_page(modify_doc)

        drag_slider(page.driver, ".foo", 150)

        sleep(1)  # noUiSlider does a transition that takes some time

        assert get_slider_title_text(page.driver, ".foo") > "04 Aug 2017"
Ejemplo n.º 3
0
    def test_server_bar_color_updates(
            self, bokeh_server_page: BokehServerPage) -> None:
        slider = DateSlider(start=start,
                            end=end,
                            value=value,
                            width=300,
                            bar_color="red")

        def modify_doc(doc):
            plot = Plot(height=400,
                        width=400,
                        x_range=Range1d(0, 1),
                        y_range=Range1d(0, 1),
                        min_border=0)

            def cb(attr, old, new):
                slider.bar_color = "rgba(255, 255, 0, 1)"

            slider.on_change('value', cb)
            doc.add_root(column(slider, plot))

        page = bokeh_server_page(modify_doc)

        drag_slider(page.driver, slider, 150)

        sleep(1)  # noUiSlider does a transition that takes some time

        assert get_slider_bar_color(page.driver,
                                    slider) == "rgba(255, 255, 0, 1)"
Ejemplo n.º 4
0
    def test_server_bar_color_updates(self, bokeh_server_page) -> None:
        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)
            slider = Slider(start=0,
                            end=10,
                            value=1,
                            title="bar",
                            css_classes=["foo"],
                            width=300)

            def cb(attr, old, new):
                slider.bar_color = "rgba(255, 255, 0, 1)"

            slider.on_change('value', cb)
            doc.add_root(column(slider, plot))

        page = bokeh_server_page(modify_doc)

        drag_slider(page.driver, ".foo", 150)

        sleep(1)  # noUiSlider does a transition that takes some time

        assert get_slider_bar_color(page.driver,
                                    ".foo") == "rgba(255, 255, 0, 1)"
Ejemplo n.º 5
0
    def test_js_on_change_executes(self, bokeh_model_page) -> None:
        slider = Slider(start=0, end=10, value=1, title="bar", css_classes=["foo"], width=300)
        slider.js_on_change('value', CustomJS(code=RECORD("value", "cb_obj.value")))

        page = bokeh_model_page(slider)

        drag_slider(page.driver, ".foo", 150)

        results = page.results
        assert float(results['value']) > 1

        assert page.has_no_console_errors()
Ejemplo n.º 6
0
    def test_js_on_change_executes(self, bokeh_model_page) -> None:
        slider = DateSlider(start=start, end=end, value=value, css_classes=["foo"], width=300)
        slider.js_on_change('value', CustomJS(code=RECORD("value", "cb_obj.value")))

        page = bokeh_model_page(slider)

        drag_slider(page.driver, ".foo", 150)

        results = page.results
        assert datetime.fromtimestamp(results['value']/1000) > datetime(*date.fromisoformat("2017-08-04").timetuple()[:3])

        assert page.has_no_console_errors()
Ejemplo n.º 7
0
    def test_title_updates(self, bokeh_model_page: BokehModelPage) -> None:
        slider = DateSlider(start=start, end=end, value=value, width=300)

        page = bokeh_model_page(slider)

        assert get_slider_title_value(page.driver, slider) == "04 Aug 2017"

        drag_slider(page.driver, slider, 50)
        assert get_slider_title_value(page.driver, slider) > "04 Aug 2017"

        drag_slider(page.driver, slider, -70)
        assert get_slider_title_value(page.driver, slider) == "03 Aug 2017"

        assert page.has_no_console_errors()
Ejemplo n.º 8
0
    def test_server_callback_value_vs_value_throttled(self, bokeh_server_page) -> None:
        junk = dict(v=0, vt=0)

        def modify_doc(doc):
            plot = Plot(height=400, width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
            slider = Slider(start=0, end=10, value=1, title="bar", css_classes=["foo"], width=300)

            def cbv(attr, old, new): junk['v'] += 1
            def cbvt(attr, old, new): junk['vt'] += 1

            slider.on_change('value', cbv)
            slider.on_change('value_throttled', cbvt)
            doc.add_root(column(slider, plot))

        page = bokeh_server_page(modify_doc)

        drag_slider(page.driver, ".foo", 30, release=False)
        sleep(1) # noUiSlider does a transition that takes some time

        drag_slider(page.driver, ".foo", 30, release=False)
        sleep(1) # noUiSlider does a transition that takes some time

        drag_slider(page.driver, ".foo", 30, release=False)
        sleep(1) # noUiSlider does a transition that takes some time

        drag_slider(page.driver, ".foo", 30, release=True)
        sleep(1) # noUiSlider does a transition that takes some time

        assert junk['v'] == 4
        assert junk['vt'] == 1
Ejemplo n.º 9
0
    def test_server_on_change_round_trip(
            self, bokeh_server_page: BokehServerPage) -> None:
        slider = DateSlider(start=start,
                            end=end,
                            value=value,
                            width=300,
                            step=24 * 3600 * 1000)

        def modify_doc(doc):
            source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"]))
            plot = Plot(height=400,
                        width=400,
                        x_range=Range1d(0, 1),
                        y_range=Range1d(0, 1),
                        min_border=0)
            plot.add_glyph(source, Circle(x='x', y='y', size=20))
            plot.tags.append(
                CustomJS(name="custom-action",
                         args=dict(s=source),
                         code=RECORD("data", "s.data")))

            def cb(attr, old, new):
                iso_date = slider.value_as_date.isoformat()
                source.data['val'] = [iso_date, iso_date]

            slider.on_change('value', cb)
            doc.add_root(column(slider, plot))

        page = bokeh_server_page(modify_doc)

        drag_slider(page.driver, slider, 50)

        page.eval_custom_action()
        results = page.results
        new = results['data']['val']
        assert new[0] > '2017-08-04'

        drag_slider(page.driver, slider, -70)

        page.eval_custom_action()
        results = page.results
        new = results['data']['val']
        assert new[0] == '2017-08-03'
Ejemplo n.º 10
0
    def test_server_title_updates(self,
                                  bokeh_server_page: BokehServerPage) -> None:
        slider = Slider(start=0, end=10, value=1, title="bar", width=300)

        def modify_doc(doc):
            plot = Plot(height=400,
                        width=400,
                        x_range=Range1d(0, 1),
                        y_range=Range1d(0, 1),
                        min_border=0)

            def cb(attr, old, new):
                slider.title = "baz"

            slider.on_change('value', cb)
            doc.add_root(column(slider, plot))

        page = bokeh_server_page(modify_doc)

        drag_slider(page.driver, slider, 150)

        sleep(1)  # noUiSlider does a transition that takes some time

        assert get_slider_title_text(page.driver, slider) == "baz: 6"
Ejemplo n.º 11
0
    def test_server_on_change_round_trip(self, bokeh_server_page) -> None:
        def modify_doc(doc):
            source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"]))
            plot = Plot(plot_height=400,
                        plot_width=400,
                        x_range=Range1d(0, 1),
                        y_range=Range1d(0, 1),
                        min_border=0)
            plot.add_glyph(source, Circle(x='x', y='y', size=20))
            plot.add_tools(
                CustomAction(callback=CustomJS(args=dict(s=source),
                                               code=RECORD("data", "s.data"))))
            slider = Slider(start=0,
                            end=10,
                            value=1,
                            title="bar",
                            css_classes=["foo"],
                            width=300)

            def cb(attr, old, new):
                source.data['val'] = [old, new]

            slider.on_change('value', cb)
            doc.add_root(column(slider, plot))

        page = bokeh_server_page(modify_doc)

        drag_slider(page.driver, ".foo", 50)

        page.click_custom_action()
        results = page.results
        old, new = results['data']['val']
        assert float(old) == 1
        assert float(new) > 1

        drag_slider(page.driver, ".foo", 50)

        page.click_custom_action()
        results = page.results
        old, new = results['data']['val']
        assert float(new) > 2

        drag_slider(page.driver, ".foo", -135)

        page.click_custom_action()
        results = page.results
        old, new = results['data']['val']
        assert float(new) == 0
Ejemplo n.º 12
0
    def test_server_on_change_round_trip(
            self, bokeh_server_page: BokehServerPage) -> None:
        slider = Slider(start=0, end=10, value=1, title="bar", width=300)

        def modify_doc(doc):
            source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"]))
            plot = Plot(height=400,
                        width=400,
                        x_range=Range1d(0, 1),
                        y_range=Range1d(0, 1),
                        min_border=0)
            plot.add_glyph(source, Circle(x='x', y='y', size=20))
            plot.tags.append(
                CustomJS(name="custom-action",
                         args=dict(s=source),
                         code=RECORD("data", "s.data")))

            def cb(attr, old, new):
                source.data['val'] = [old, new]

            slider.on_change('value', cb)
            doc.add_root(column(slider, plot))

        page = bokeh_server_page(modify_doc)

        drag_slider(page.driver, slider, 50)

        page.eval_custom_action()
        results = page.results
        old, new = results['data']['val']
        assert float(old) == 1
        assert float(new) > 1

        drag_slider(page.driver, slider, 50)

        page.eval_custom_action()
        results = page.results
        old, new = results['data']['val']
        assert float(new) > 2

        drag_slider(page.driver, slider, -135)

        page.eval_custom_action()
        results = page.results
        old, new = results['data']['val']
        assert float(new) == 0
Ejemplo n.º 13
0
    def test_title_updates(self, bokeh_model_page) -> None:
        slider = Slider(start=0, end=10, value=1, title="bar", css_classes=["foo"], width=300)

        page = bokeh_model_page(slider)

        assert float(get_slider_title_value(page.driver, ".foo")) == 1

        drag_slider(page.driver, ".foo", 50)
        value = get_slider_title_value(page.driver, ".foo")
        assert float(value) > 1
        assert float(value) == int(value) # integral step size

        drag_slider(page.driver, ".foo", 50)
        assert float(get_slider_title_value(page.driver, ".foo")) > 2

        drag_slider(page.driver, ".foo", -135)
        assert float(get_slider_title_value(page.driver, ".foo")) == 0

        assert page.has_no_console_errors()