Ejemplo n.º 1
0
    def test_chart_tools_linear(self, mock_warn):
        base_args = dict(
            title="title", xlabel="xlabel", ylabel="ylabel",
            legend="top_left", xscale="linear", yscale="linear", xgrid=True, ygrid=True,
            width=800, height=600, filename=False, server=False, notebook=False
        )
        expected = [
            [PanTool,  WheelZoomTool, BoxZoomTool, PreviewSaveTool, ResizeTool, ResetTool],
            [],
            [ResizeTool, PanTool,  BoxZoomTool, ResetTool, LassoSelectTool],
        ]
        scenarios = zip(
            [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected
        )

        self.check_tools_scenario(base_args, scenarios)

        self.check_tools_scenario(base_args, scenarios, categorical=True)

        msg_repeat = "LassoSelectTool are being repeated"
        expected_tools = [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool, LassoSelectTool]
        mock_warn.reset_mock()

        # Finally check repeated tools
        base_args['tools'] = "resize,pan,box_zoom,reset,lasso_select,lasso_select"

        chart = Chart(**base_args)
        chart.x_range = FactorRange()
        chart.tools = []
        chart.create_tools(chart._options.tools)

        self.compare_tools(chart.tools, expected_tools)
        mock_warn.assert_any_call(msg_repeat)
Ejemplo n.º 2
0
    def test_chart_tools_linear(self, mock_warn):
        base_args = dict(
            title="title", xlabel="xlabel", ylabel="ylabel",
            legend="top_left", xscale="linear", yscale="linear", xgrid=True, ygrid=True,
            width=800, height=600,
        )
        expected = [
            [PanTool,  WheelZoomTool, BoxZoomTool, PreviewSaveTool, ResizeTool, ResetTool, HelpTool],
            [],
            [ResizeTool, PanTool,  BoxZoomTool, ResetTool, LassoSelectTool],
        ]
        scenarios = zip(
            [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected
        )

        self.check_tools_scenario(base_args, scenarios)

        self.check_tools_scenario(base_args, scenarios, categorical=True)

        msg_repeat = "LassoSelectTool are being repeated"
        expected_tools = [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool, LassoSelectTool]
        mock_warn.reset_mock()

        # Finally check removing tools
        base_args['tools'] = "resize,pan,box_zoom,reset,lasso_select,lasso_select"

        chart = Chart(**base_args)
        chart.x_range = FactorRange()

        self.compare_tools(chart.tools, expected_tools)
        mock_warn.assert_any_call(msg_repeat)
Ejemplo n.º 3
0
def test_defaults():
    c1 = Chart()
    defaults.height = 1000
    defaults.tools = False
    c2 = Chart()
    c3 = Chart()

    assert c1.height == 400
    assert c2.height == c3.height == 1000

    assert c1.tools
    assert c2.tools == c3.tools == []
Ejemplo n.º 4
0
 def setUp(self):
     self.source = ColumnDataSource()
     self.xdr = Range1d()
     self.ydr = Range1d()
     self.glyph = GlyphRenderer()
     self._groups = [self.glyph] * 3
     self.chart = Chart(
         title="title", xlabel="xlabel", ylabel="ylabel",
         legend="top_left", xscale="linear", yscale="linear",
         width=800, height=600, tools=True,
         responsive=True,
         xgrid=True, ygrid=False
     )
Ejemplo n.º 5
0
def test_defaults():
    c1 = Chart()
    defaults.plot_height = 1000
    defaults.plot_width = 1000
    defaults.tools = False
    c2 = Chart()
    c3 = Chart()

    assert c1.plot_height == 600
    assert c2.plot_height == c3.plot_height == 1000

    assert c1.plot_width == 600
    assert c2.plot_width == c3.plot_width == 1000

    assert c1.tools
    assert c2.tools == c3.tools == []
Ejemplo n.º 6
0
 def setUp(self):
     self.source = ColumnDataSource()
     self.xdr = Range1d()
     self.ydr = Range1d()
     self.glyph = GlyphRenderer()
     self._groups = [self.glyph] * 3
     self.chart = Chart(
         title="title", xlabel="xlabel", ylabel="ylabel",
         legend="top_left", xscale="linear", yscale="linear",
         width=800, height=600, tools=True,
         filename=False, server=False, notebook=False,
         xgrid=True, ygrid=False
     )
Ejemplo n.º 7
0
    def test_chart_tools_linear(self, mock_warn):
        base_args = dict(title="title",
                         xlabel="xlabel",
                         ylabel="ylabel",
                         legend="top_left",
                         xscale="linear",
                         yscale="linear",
                         xgrid=True,
                         ygrid=True,
                         width=800,
                         height=600,
                         filename=False,
                         server=False,
                         notebook=False)
        expected = [
            [
                PanTool, WheelZoomTool, BoxZoomTool, PreviewSaveTool,
                ResizeTool, ResetTool
            ],
            [],
            [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool],
        ]
        scenarios = zip(
            [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected)

        self.check_tools_scenario(base_args, scenarios)

        # need to change the expected tools because categorical scales
        # automatically removes pan and zoom tools
        expected = [
            [PreviewSaveTool, ResizeTool, ResetTool],
            [],
            [ResizeTool, ResetTool, LassoSelectTool],
        ]
        scenarios = zip(
            [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected)
        self.check_tools_scenario(base_args, scenarios, categorical=True)

        msg_repeat = "LassoSelectTool are being repeated"
        msg_removed = "categorical plots do not support pan and zoom operations.\n" \
                      "Removing tool(s): pan, box_zoom"
        expected_tools = [
            ResizeTool, ResetTool, LassoSelectTool, LassoSelectTool
        ]
        mock_warn.reset_mock()

        # Finally check repeated tools
        base_args[
            'tools'] = "resize,pan,box_zoom,reset,lasso_select,lasso_select"

        chart = Chart(**base_args)
        chart.x_range = FactorRange()
        chart.tools = []
        chart.create_tools(chart._options.tools)

        self.compare_tools(chart.tools, expected_tools)
        mock_warn.assert_any_call(msg_repeat)
        mock_warn.assert_any_call(msg_removed)
Ejemplo n.º 8
0
class TestChart(unittest.TestCase):
    def setUp(self):
        self.source = ColumnDataSource()
        self.xdr = Range1d()
        self.ydr = Range1d()
        self.glyph = GlyphRenderer()
        self._groups = [self.glyph] * 3
        self.chart = Chart(
            title="title", xlabel="xlabel", ylabel="ylabel",
            legend="top_left", xscale="linear", yscale="linear",
            width=800, height=600, tools=True,
            filename=False, server=False, notebook=False,
            xgrid=True, ygrid=False
        )

    def test_title(self):
        self.chart.title = "new_title"
        self.assertEqual(self.chart.title, "new_title")

    def test_xlabel(self):
        self.chart.xlabel("new_xlabel")
        self.assertEqual(self.chart._options.xlabel, "new_xlabel")

    def test_ylabel(self):
        self.chart.ylabel("new_ylabel")
        self.assertEqual(self.chart._options.ylabel, "new_ylabel")

    def test_legend(self):
        self.chart.legend("bottom_right")
        self.assertEqual(self.chart._options.legend, "bottom_right")
        self.chart.legend(True)
        self.assertTrue(self.chart._options.legend)

    def test_xscale(self):
        self.chart.xscale("datetime")
        self.assertEqual(self.chart._options.xscale, "datetime")

    def test_yscale(self):
        self.chart.yscale("datetime")
        self.assertEqual(self.chart._options.yscale, "datetime")

    def test_width(self):
        self.chart.width(400)
        self.assertEqual(self.chart._options.width, 400)

    def test_height(self):
        self.chart.height(400)
        self.assertEqual(self.chart._options.height, 400)

    def test_filename(self):
        self.chart.filename("bar.html")
        self.assertEqual(self.chart._options.filename, "bar.html")
        self.chart.filename(True)
        self.assertTrue(self.chart._options.filename)

    def test_server(self):
        self.chart.server("baz")
        self.assertEqual(self.chart._options.server, "baz")
        self.chart.server(True)
        self.assertTrue(self.chart._options.server)

    def test_notebook(self):
        self.chart.notebook(True)
        self.assertTrue(self.chart._options.notebook)
        self.chart.notebook(False)
        self.assertFalse(self.chart._options.notebook)

    def check_chart_elements(self, expected_tools):
        self.assertIsInstance(self.chart.left[0], LinearAxis)
        self.assertIsInstance(self.chart.renderers[0], LinearAxis)
        self.assertIsInstance(self.chart.below[0], LinearAxis)
        self.assertIsInstance(self.chart.renderers[1], LinearAxis)
        self.assertIsInstance(self.chart.renderers[2], Grid)
        self.assertIsInstance(self.chart.renderers[3], Grid)
        for i, type_ in enumerate(expected_tools):
            self.assertIsInstance(self.chart.tools[i], type_)

    def test_ranges(self):
        """
        Test ranges are not created buy the chart
        """
        self.assertEqual(self.chart.x_range, None)
        self.assertEqual(self.chart.y_range, None)

    def test_make_axis(self):
        axis = self.chart.make_axis("left", "datetime", "foo")
        self.assertEqual(axis.location, "auto")
        self.assertEqual(axis.scale, "time")
        self.assertEqual(axis.axis_label, "foo")

        axis = self.chart.make_axis("left", "categorical", "bar")
        self.assertEqual(axis.location, "auto")
        self.assertEqual(axis.axis_label, "bar")
        self.assertEqual(axis.major_label_orientation, np.pi/4)

        axis = self.chart.make_axis("left", "linear", "foobar")
        self.assertEqual(axis.location, "auto")
        self.assertEqual(axis.axis_label, "foobar")

    def test_make_grid(self):
        axis = self.chart.make_axis("left", "datetime", "foo")
        grid = self.chart.make_grid(0, axis.ticker)
        self.assertEqual(grid.dimension, 0)
        self.assertIsInstance(grid.ticker, Ticker)

    def check_tools_scenario(self, base_args, scenarios, categorical=False):
        for tools, expected_tools in scenarios:
            base_args['tools'] = tools
            chart = Chart(**base_args)
            self.compare_tools(chart.tools, expected_tools)

    def compare_tools(self, tools, expected_tools):
        self.assertEqual(len(tools), len(expected_tools))
        for i, _type in enumerate(expected_tools):
            self.assertIsInstance(tools[i], _type)

    @patch('bokeh.plotting_helpers.warnings.warn')
    def test_chart_tools_linear(self, mock_warn):
        base_args = dict(
            title="title", xlabel="xlabel", ylabel="ylabel",
            legend="top_left", xscale="linear", yscale="linear", xgrid=True, ygrid=True,
            width=800, height=600, filename=False, server=False, notebook=False
        )
        expected = [
            [PanTool,  WheelZoomTool, BoxZoomTool, PreviewSaveTool, ResizeTool, ResetTool],
            [],
            [ResizeTool, PanTool,  BoxZoomTool, ResetTool, LassoSelectTool],
        ]
        scenarios = zip(
            [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected
        )

        self.check_tools_scenario(base_args, scenarios)

        self.check_tools_scenario(base_args, scenarios, categorical=True)

        msg_repeat = "LassoSelectTool are being repeated"
        expected_tools = [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool, LassoSelectTool]
        mock_warn.reset_mock()

        # Finally check repeated tools
        base_args['tools'] = "resize,pan,box_zoom,reset,lasso_select,lasso_select"

        chart = Chart(**base_args)
        chart.x_range = FactorRange()
        chart.tools = []
        chart.create_tools(chart._options.tools)

        self.compare_tools(chart.tools, expected_tools)
        mock_warn.assert_any_call(msg_repeat)
Ejemplo n.º 9
0
class TestChart(unittest.TestCase):
    def setUp(self):
        self.source = ColumnDataSource()
        self.xdr = Range1d()
        self.ydr = Range1d()
        self.glyph = GlyphRenderer()
        self._groups = [self.glyph] * 3
        self.chart = Chart(
            title="title", xlabel="xlabel", ylabel="ylabel",
            legend="top_left", xscale="linear", yscale="linear",
            width=800, height=600, tools=True,
            responsive=True,
            xgrid=True, ygrid=False
        )

    def test_title(self):
        self.chart.title = "new_title"
        self.assertEqual(self.chart.title.text, "new_title")

    def test_responsive(self):
        self.assertEqual(self.chart.responsive, 'scale_width')

    def check_chart_elements(self, expected_tools):
        self.assertIsInstance(self.chart.left[0], LinearAxis)
        self.assertIsInstance(self.chart.renderers[0], LinearAxis)
        self.assertIsInstance(self.chart.below[0], LinearAxis)
        self.assertIsInstance(self.chart.renderers[1], LinearAxis)
        self.assertIsInstance(self.chart.renderers[2], Grid)
        self.assertIsInstance(self.chart.renderers[3], Grid)
        for i, type_ in enumerate(expected_tools):
            self.assertIsInstance(self.chart.tools[i], type_)

    def test_ranges(self):
        """Test ranges are not created buy the chart."""
        self.assertEqual(self.chart.x_range, None)
        self.assertEqual(self.chart.y_range, None)

    def test_axis_requires_range(self):

        # the axis creation depends on ranges
        with pytest.raises(ValueError):
            self.chart.make_axis("x", "left", "datetime", "foo")

    def test_make_axis(self):

        self.chart.add_ranges('x', Range1d())

        axis = self.chart.make_axis("x", "left", "datetime", "foo")
        self.assertEqual(axis.axis_label, "foo")

        axis = self.chart.make_axis("x", "left", "categorical", "bar")
        self.assertEqual(axis.axis_label, "bar")
        self.assertEqual(axis.major_label_orientation, np.pi/4)

        axis = self.chart.make_axis("x", "left", "linear", "foobar")
        self.assertEqual(axis.axis_label, "foobar")

    def test_make_grid(self):
        self.chart.add_ranges('x', Range1d())
        axis = self.chart.make_axis("x", "left", "datetime", "foo")
        grid = self.chart.make_grid(0, axis.ticker)
        self.assertEqual(grid.dimension, 0)
        self.assertIsInstance(grid.ticker, Ticker)

    def check_tools_scenario(self, base_args, scenarios, categorical=False):
        for tools, expected_tools in scenarios:
            base_args['tools'] = tools
            chart = Chart(**base_args)
            self.compare_tools(chart.tools, expected_tools)

    def compare_tools(self, tools, expected_tools):
        self.assertEqual(len(tools), len(expected_tools))
        for i, _type in enumerate(expected_tools):
            self.assertIsInstance(tools[i], _type)

    @patch('bokeh.plotting.helpers.warnings.warn')
    def test_chart_tools_linear(self, mock_warn):
        base_args = dict(
            title="title", xlabel="xlabel", ylabel="ylabel",
            legend="top_left", xscale="linear", yscale="linear", xgrid=True, ygrid=True,
            width=800, height=600,
        )
        expected = [
            [PanTool,  WheelZoomTool, BoxZoomTool, SaveTool, ResizeTool, ResetTool, HelpTool],
            [],
            [ResizeTool, PanTool,  BoxZoomTool, ResetTool, LassoSelectTool],
        ]
        scenarios = zip(
            [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected
        )

        self.check_tools_scenario(base_args, scenarios)

        self.check_tools_scenario(base_args, scenarios, categorical=True)

        msg_repeat = "LassoSelectTool are being repeated"
        expected_tools = [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool, LassoSelectTool]
        mock_warn.reset_mock()

        # Finally check removing tools
        base_args['tools'] = "resize,pan,box_zoom,reset,lasso_select,lasso_select"

        chart = Chart(**base_args)
        chart.x_range = FactorRange()

        self.compare_tools(chart.tools, expected_tools)
        mock_warn.assert_any_call(msg_repeat)
Ejemplo n.º 10
0
class TestChart(unittest.TestCase):
    def setUp(self):
        self.source = ColumnDataSource()
        self.xdr = Range1d()
        self.ydr = Range1d()
        self.glyph = GlyphRenderer()
        self._groups = [self.glyph] * 3
        self.chart = Chart(
            title="title", xlabel="xlabel", ylabel="ylabel",
            legend="top_left", xscale="linear", yscale="linear",
            width=800, height=600, tools=True,
            responsive=True,
            xgrid=True, ygrid=False
        )

    def test_title(self):
        self.chart.title = "new_title"
        self.assertEqual(self.chart.title, "new_title")

    def test_responsive(self):
        self.assertEqual(self.chart.responsive, True)

    def check_chart_elements(self, expected_tools):
        self.assertIsInstance(self.chart.left[0], LinearAxis)
        self.assertIsInstance(self.chart.renderers[0], LinearAxis)
        self.assertIsInstance(self.chart.below[0], LinearAxis)
        self.assertIsInstance(self.chart.renderers[1], LinearAxis)
        self.assertIsInstance(self.chart.renderers[2], Grid)
        self.assertIsInstance(self.chart.renderers[3], Grid)
        for i, type_ in enumerate(expected_tools):
            self.assertIsInstance(self.chart.tools[i], type_)

    def test_ranges(self):
        """Test ranges are not created buy the chart."""
        self.assertEqual(self.chart.x_range, None)
        self.assertEqual(self.chart.y_range, None)

    def test_axis_requires_range(self):

        # the axis creation depends on ranges
        with pytest.raises(ValueError):
            self.chart.make_axis("x", "left", "datetime", "foo")

    def test_make_axis(self):

        self.chart.add_ranges('x', Range1d())

        axis = self.chart.make_axis("x", "left", "datetime", "foo")
        self.assertEqual(axis.location, "auto")
        self.assertEqual(axis.axis_label, "foo")

        axis = self.chart.make_axis("x", "left", "categorical", "bar")
        self.assertEqual(axis.location, "auto")
        self.assertEqual(axis.axis_label, "bar")
        self.assertEqual(axis.major_label_orientation, np.pi/4)

        axis = self.chart.make_axis("x", "left", "linear", "foobar")
        self.assertEqual(axis.location, "auto")
        self.assertEqual(axis.axis_label, "foobar")

    def test_make_grid(self):
        self.chart.add_ranges('x', Range1d())
        axis = self.chart.make_axis("x", "left", "datetime", "foo")
        grid = self.chart.make_grid(0, axis.ticker)
        self.assertEqual(grid.dimension, 0)
        self.assertIsInstance(grid.ticker, Ticker)

    def check_tools_scenario(self, base_args, scenarios, categorical=False):
        for tools, expected_tools in scenarios:
            base_args['tools'] = tools
            chart = Chart(**base_args)
            self.compare_tools(chart.tools, expected_tools)

    def compare_tools(self, tools, expected_tools):
        self.assertEqual(len(tools), len(expected_tools))
        for i, _type in enumerate(expected_tools):
            self.assertIsInstance(tools[i], _type)

    @patch('bokeh.plotting.helpers.warnings.warn')
    def test_chart_tools_linear(self, mock_warn):
        base_args = dict(
            title="title", xlabel="xlabel", ylabel="ylabel",
            legend="top_left", xscale="linear", yscale="linear", xgrid=True, ygrid=True,
            width=800, height=600,
        )
        expected = [
            [PanTool,  WheelZoomTool, BoxZoomTool, PreviewSaveTool, ResizeTool, ResetTool, HelpTool],
            [],
            [ResizeTool, PanTool,  BoxZoomTool, ResetTool, LassoSelectTool],
        ]
        scenarios = zip(
            [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected
        )

        self.check_tools_scenario(base_args, scenarios)

        self.check_tools_scenario(base_args, scenarios, categorical=True)

        msg_repeat = "LassoSelectTool are being repeated"
        expected_tools = [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool, LassoSelectTool]
        mock_warn.reset_mock()

        # Finally check removing tools
        base_args['tools'] = "resize,pan,box_zoom,reset,lasso_select,lasso_select"

        chart = Chart(**base_args)
        chart.x_range = FactorRange()

        self.compare_tools(chart.tools, expected_tools)
        mock_warn.assert_any_call(msg_repeat)
Ejemplo n.º 11
0
def test_chart_id():
    chart = Chart(id='1234', title="title")
    assert chart._id == '1234'
Ejemplo n.º 12
0
 def check_tools_scenario(self, base_args, scenarios, categorical=False):
     for tools, expected_tools in scenarios:
         base_args['tools'] = tools
         chart = Chart(**base_args)
         self.compare_tools(chart.tools, expected_tools)
Ejemplo n.º 13
0
def test_title_kwarg_no_warning(recwarn):
    Chart(title="title")
    assert len(recwarn) == 0
Ejemplo n.º 14
0
class TestChart(unittest.TestCase):
    def setUp(self):
        self.source = ColumnDataSource()
        self.xdr = Range1d()
        self.ydr = Range1d()
        self.glyph = GlyphRenderer()
        self._groups = [self.glyph] * 3
        self.chart = Chart(title="title",
                           xlabel="xlabel",
                           ylabel="ylabel",
                           legend="top_left",
                           xscale="linear",
                           yscale="linear",
                           width=800,
                           height=600,
                           tools=True,
                           filename=False,
                           server=False,
                           notebook=False,
                           xgrid=True,
                           ygrid=False)

    def test_title(self):
        self.chart.title = "new_title"
        self.assertEqual(self.chart.title, "new_title")

    def test_xlabel(self):
        self.chart.xlabel("new_xlabel")
        self.assertEqual(self.chart._options.xlabel, "new_xlabel")

    def test_ylabel(self):
        self.chart.ylabel("new_ylabel")
        self.assertEqual(self.chart._options.ylabel, "new_ylabel")

    def test_legend(self):
        self.chart.legend("bottom_right")
        self.assertEqual(self.chart._options.legend, "bottom_right")
        self.chart.legend(True)
        self.assertTrue(self.chart._options.legend)

    def test_xscale(self):
        self.chart.xscale("datetime")
        self.assertEqual(self.chart._options.xscale, "datetime")

    def test_yscale(self):
        self.chart.yscale("datetime")
        self.assertEqual(self.chart._options.yscale, "datetime")

    def test_width(self):
        self.chart.width(400)
        self.assertEqual(self.chart._options.width, 400)

    def test_height(self):
        self.chart.height(400)
        self.assertEqual(self.chart._options.height, 400)

    def test_filename(self):
        self.chart.filename("bar.html")
        self.assertEqual(self.chart._options.filename, "bar.html")
        self.chart.filename(True)
        self.assertTrue(self.chart._options.filename)

    def test_server(self):
        self.chart.server("baz")
        self.assertEqual(self.chart._options.server, "baz")
        self.chart.server(True)
        self.assertTrue(self.chart._options.server)

    def test_notebook(self):
        self.chart.notebook(True)
        self.assertTrue(self.chart._options.notebook)
        self.chart.notebook(False)
        self.assertFalse(self.chart._options.notebook)

    def check_chart_elements(self, expected_tools):
        self.assertIsInstance(self.chart.left[0], LinearAxis)
        self.assertIsInstance(self.chart.renderers[0], LinearAxis)
        self.assertIsInstance(self.chart.below[0], LinearAxis)
        self.assertIsInstance(self.chart.renderers[1], LinearAxis)
        self.assertIsInstance(self.chart.renderers[2], Grid)
        self.assertIsInstance(self.chart.renderers[3], Grid)
        for i, type_ in enumerate(expected_tools):
            self.assertIsInstance(self.chart.tools[i], type_)

    def test_ranges(self):
        """
        Test ranges are not created buy the chart
        """
        self.assertEqual(self.chart.x_range, None)
        self.assertEqual(self.chart.y_range, None)

    def test_make_axis(self):
        axis = self.chart.make_axis("left", "datetime", "foo")
        self.assertEqual(axis.location, "auto")
        self.assertEqual(axis.scale, "time")
        self.assertEqual(axis.axis_label, "foo")

        axis = self.chart.make_axis("left", "categorical", "bar")
        self.assertEqual(axis.location, "auto")
        self.assertEqual(axis.axis_label, "bar")
        self.assertEqual(axis.major_label_orientation, np.pi / 4)

        axis = self.chart.make_axis("left", "linear", "foobar")
        self.assertEqual(axis.location, "auto")
        self.assertEqual(axis.axis_label, "foobar")

    def test_make_grid(self):
        axis = self.chart.make_axis("left", "datetime", "foo")
        grid = self.chart.make_grid(0, axis.ticker)
        self.assertEqual(grid.dimension, 0)
        self.assertIsInstance(grid.ticker, Ticker)

    def check_tools_scenario(self, base_args, scenarios, categorical=False):
        for tools, expected_tools in scenarios:
            base_args['tools'] = tools
            chart = Chart(**base_args)
            self.compare_tools(chart.tools, expected_tools)

    def compare_tools(self, tools, expected_tools):
        self.assertEqual(len(tools), len(expected_tools))
        for i, _type in enumerate(expected_tools):
            self.assertIsInstance(tools[i], _type)

    @patch('bokeh.plotting_helpers.warnings.warn')
    def test_chart_tools_linear(self, mock_warn):
        base_args = dict(title="title",
                         xlabel="xlabel",
                         ylabel="ylabel",
                         legend="top_left",
                         xscale="linear",
                         yscale="linear",
                         xgrid=True,
                         ygrid=True,
                         width=800,
                         height=600,
                         filename=False,
                         server=False,
                         notebook=False)
        expected = [
            [
                PanTool, WheelZoomTool, BoxZoomTool, PreviewSaveTool,
                ResizeTool, ResetTool
            ],
            [],
            [ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool],
        ]
        scenarios = zip(
            [True, False, "resize,pan,box_zoom,reset,lasso_select"], expected)

        self.check_tools_scenario(base_args, scenarios)

        self.check_tools_scenario(base_args, scenarios, categorical=True)

        msg_repeat = "LassoSelectTool are being repeated"
        expected_tools = [
            ResizeTool, PanTool, BoxZoomTool, ResetTool, LassoSelectTool,
            LassoSelectTool
        ]
        mock_warn.reset_mock()

        # Finally check repeated tools
        base_args[
            'tools'] = "resize,pan,box_zoom,reset,lasso_select,lasso_select"

        chart = Chart(**base_args)
        chart.x_range = FactorRange()
        chart.tools = []
        chart.create_tools(chart._options.tools)

        self.compare_tools(chart.tools, expected_tools)
        mock_warn.assert_any_call(msg_repeat)
Ejemplo n.º 15
0
    def check_tools_scenario(self, base_args, scenarios, categorical=False):
        for tools, expected_tools in scenarios:
            base_args['tools'] = tools
            chart = Chart(**base_args)

            if categorical:
                chart.x_range = FactorRange()
                chart.tools = []
                chart.create_tools(chart._options.tools)
                self.compare_tools(chart.tools, expected_tools)

                chart = Chart(**base_args)
                chart.y_range = FactorRange()
                chart.tools = []
                chart.create_tools(chart._options.tools)
                self.compare_tools(chart.tools, expected_tools)

            else:
                self.compare_tools(chart.tools, expected_tools)
Ejemplo n.º 16
0
#bokeh serve --show crossfilter

import pandas as pd

from bokeh.charts import Chart, color, marker
from classes import RUN
import ast
#getting the data
data=RUN('MATCH (ctd:Instrument)<-[r:TAKEN_WITH]-(s:Sample)-[:TAKEN_IN]->(i:Site) where s.number < 4 return s.code as code, s.site as site, s.number as number, s.pressure as depth, s.runs as runs, s.temperature as temperature, s.salinity as salinity, s.conductivity as conductivity, i.region as region')
dd={}
dcodes={}
bins=list(range(0,101,1))
for row in data:
    df=pd.DataFrame()
    code=row['code']
    df['temperature']=ast.literal_eval(row['temperature'])
    df['salinity']=ast.literal_eval(row['salinity'])
    df['conductivity']=ast.literal_eval(row['conductivity'])
    df['depth']=ast.literal_eval(row['depth'])
    df=df.loc[df['depth']>=0]
    df['depthCat'] = pd.cut(df['depth'], bins, labels=bins[1:])
    dd[code]=df
    dcodes[code]={"site":row['site'],"region":row['region'],"runs":row['runs'],"number":row['number']}
colors=[["#2ca25f","#99d8c9","#e5f5f9"],["#8856a7","#9ebcda","#e0ecf4"],["#43a2ca","#a8ddb5","#e0f3db"],["#e34a33","#fdbb84","#fee8c8"],["#2b8cbe","#a6bddb","#ece7f2"],["#dd1c77","#c994c7","#e7e1ef"],["#636363","#bdbdbd","#f0f0f0"]]

for key in dd.keys():
    df=dd[key]
    Chart(df, color=colors[int(dcodes[key]['site'])%7][int(dcodes[key]['number'])])