def test_plot_pivot_column_float_type(self): model = _make_pivot_proxy_model() support = PivotTablePlottingHints() plot_widget = plot_pivot_column(model, 1, support) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 1) self.assertTrue(all(lines[0].get_ydata(orig=True) == [1.1, 1.2, 1.3]))
def test_plot_pivot_column_incompatible_data_types_on_existing_plot_raises(self): model = _make_pivot_proxy_model() support = PivotTablePlottingHints() plot_widget = plot_pivot_column(model, 3, support) self.assertEqual(plot_widget.plot_type, TimeSeries) with self.assertRaises(PlottingError): plot_pivot_column(model, 2, support, plot_widget)
def test_plot_pivot_column_with_row_filtering(self): model = _make_pivot_proxy_model() model.set_filter("rows", {"1", "3"}) support = PivotTablePlottingHints() plot_widget = plot_pivot_column(model, 1, support) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 1) self.assertTrue(all(lines[0].get_ydata(orig=True) == [1.1, 1.3]))
def test_plot_pivot_column_int_type(self): model = _make_pivot_proxy_model() support = PivotTablePlottingHints() plot_widget = plot_pivot_column(model, 1, support) self.assertEqual(plot_widget.plot_type, float) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 1) self.assertEqual(list(lines[0].get_ydata(orig=True)), [-3.0, -1.0, 2.0])
def test_plot_pivot_column_with_row_filtering(self): model = _make_pivot_proxy_model() model.set_filter("object", {"1", "3"}) support = PivotTablePlottingHints() plot_widget = plot_pivot_column(model, 2, support) self.assertEqual(plot_widget.plot_type, float) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 1) self.assertEqual(list(lines[0].get_ydata(orig=True)), [1.1, 1.3])
def test_plot_pivot_column_with_column_filtering(self): model = _make_pivot_proxy_model() model.set_filter("col_types", {"int_col"}) support = PivotTablePlottingHints() plot_widget = plot_pivot_column(model, 1, support) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 1) self.assertTrue( all(lines[0].get_ydata(orig=True) == [-3.0, -1.0, 2.0]))
def test_plot_pivot_column_time_series_type(self): model = _make_pivot_proxy_model() support = PivotTablePlottingHints() plot_widget = plot_pivot_column(model, 3, support) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 3) self.assertTrue(all(lines[0].get_ydata(orig=True) == [2.3, 5.0])) self.assertTrue(all(lines[1].get_ydata(orig=True) == [3.3, 4.0])) self.assertTrue(all(lines[2].get_ydata(orig=True) == [4.3, 3.0]))
def test_plot_simple_map(self): """Test that a selection containing a single plain number gets plotted.""" model = _make_pivot_proxy_model() support = PivotTablePlottingHints() plot_widget = plot_selection(model, [model.index(3, 4)], support) self.assertEqual(plot_widget.plot_type, Map) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 1) self.assertEqual(list(lines[0].get_ydata(orig=True)), [-1.1, -2.2])
def test_plot_pivot_column_with_x_column(self): model = _make_pivot_proxy_model() model.sourceModel().set_plot_x_column(1, True) support = PivotTablePlottingHints() plot_widget = plot_pivot_column(model, 2, support) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 1) self.assertTrue(all(lines[0].get_xdata(orig=True) == [1.1, 1.2, 1.3])) self.assertTrue( all(lines[0].get_ydata(orig=True) == [-3.0, -1.0, 2.0]))
def test_plot_pivot_column_when_x_column_hidden(self): model = _make_pivot_proxy_model() model.sourceModel().set_plot_x_column(1, True) model.set_filter("parameter", {(db, "int_col")}) support = PivotTablePlottingHints() plot_widget = plot_pivot_column(model, 1, support) self.assertEqual(plot_widget.plot_type, float) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 1) self.assertEqual(list(lines[0].get_xdata(orig=True)), [1.0, 2.0, 3.0]) self.assertEqual(list(lines[0].get_ydata(orig=True)), [-3.0, -1.0, 2.0])
def test_plot_nested_map_containing_time_series(self): """Test that a selection containing a single plain number gets plotted.""" model = _make_pivot_proxy_model() support = PivotTablePlottingHints() plot_widget = plot_selection(model, [model.index(5, 4)], support) self.assertEqual(plot_widget.plot_type, TimeSeries) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 4) self.assertEqual(list(lines[0].get_ydata(orig=True)), [-1.1, -2.2]) self.assertEqual(list(lines[1].get_ydata(orig=True)), [-3.3, -4.4]) self.assertEqual(list(lines[2].get_ydata(orig=True)), [-5.5, -6.6]) self.assertEqual(list(lines[3].get_ydata(orig=True)), [-7.7, -8.8])
def test_plot_pivot_selection(self): model = _make_pivot_proxy_model() selected_indexes = list() for row in range(2, 5): for column in range(1, 3): selected_indexes.append(model.index(row, column)) support = PivotTablePlottingHints() plot_widget = plot_selection(model, selected_indexes, support) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 2) self.assertTrue(all(lines[0].get_ydata(orig=True) == [1.1, 1.2, 1.3])) self.assertTrue( all(lines[1].get_ydata(orig=True) == [-3.0, -1.0, 2.0]))
def test_plot_pivot_column_on_existing_plot(self): model = _make_pivot_proxy_model() support = PivotTablePlottingHints() plot_widget = plot_pivot_column(model, 3, support) plot_pivot_column(model, 3, support, plot_widget) self.assertEqual(plot_widget.plot_type, TimeSeries) lines = plot_widget.canvas.axes.get_lines() self.assertEqual(len(lines), 6) self.assertEqual(list(lines[0].get_ydata(orig=True)), [2.3, 5.0]) self.assertEqual(list(lines[1].get_ydata(orig=True)), [3.3, 4.0]) self.assertEqual(list(lines[2].get_ydata(orig=True)), [4.3, 3.0]) self.assertEqual(list(lines[3].get_ydata(orig=True)), [2.3, 5.0]) self.assertEqual(list(lines[4].get_ydata(orig=True)), [3.3, 4.0]) self.assertEqual(list(lines[5].get_ydata(orig=True)), [4.3, 3.0])