示例#1
0
    def test_get_selection_geometry_callback(self):
        bg = BaseGraph()

        df = cudf.DataFrame({"a": [1, 2, 2], "b": [3, 4, 5]})
        dashboard = DashBoard(dataframe=DataFrame.from_dataframe(df))

        assert (bg.get_selection_geometry_callback(dashboard).__name__ ==
                "selection_callback")
        assert callable(type(bg.get_selection_geometry_callback(dashboard)))
示例#2
0
    def test_box_selection_callback(self, inspect_neighbors, result):
        nodes = cudf.DataFrame({
            "vertex": [0, 1, 2, 3],
            "x": [0, 1, 1, 2],
            "y": [0, 1, 2, 0]
        })
        edges = cudf.DataFrame({
            "source": [1, 1, 1, 1],
            "target": [0, 1, 2, 3]
        })
        dashboard = DashBoard(dataframe=DataFrame.load_graph((nodes, edges)))

        bg = BaseGraph()
        bg.chart_type = "temp"
        bg.nodes = nodes
        bg.edges = edges
        bg.inspect_neighbors = inspect_neighbors
        self.result = None

        def t_function(nodes, edges=None, patch_update=False):
            self.result = nodes.reset_index(drop=True)

        bg.reload_chart = t_function

        dashboard._active_view = bg.name

        class evt:
            geometry = dict(x0=1, x1=3, y0=0, y1=1, type="rect")

        t = bg.get_selection_geometry_callback(dashboard)
        t(evt)
        assert self.result.equals(result)
示例#3
0
    def test_lasso_election_callback(self):
        nodes = cudf.DataFrame({
            "vertex": [0, 1, 2, 3],
            "x": [0, 1, 1, 2],
            "y": [0, 1, 2, 0]
        })
        edges = cudf.DataFrame({
            "source": [1, 1, 1, 1],
            "target": [0, 1, 2, 3]
        })
        dashboard = DashBoard(dataframe=DataFrame.load_graph((nodes, edges)))

        bg = BaseGraph()
        bg.chart_type = "temp"
        bg.nodes = nodes
        bg.edges = edges
        bg.inspect_neighbors = CustomInspectTool(_active=False)

        def t_function(nodes, edges=None, patch_update=False):
            pass

        bg.reload_chart = t_function

        class evt:
            geometry = dict(x=[1, 1, 2], y=[1, 2, 1], type="poly")
            final = True

        t = bg.get_selection_geometry_callback(dashboard)
        with mock.patch("cuspatial.point_in_polygon") as pip:

            pip.return_value = cudf.DataFrame(
                {"selection": [True, False, True, False]})
            t(evt)
            assert pip.called