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)
def test_add_reset_event(self): bg = BaseGraph() bg.edges = None bg.chart_type = "test" bg.x = "a" bg.x_range = (0, 2) bg.y_range = (3, 5) df = cudf.DataFrame({"a": [1, 2, 2], "b": [3, 4, 5]}) dashboard = DashBoard(dataframe=DataFrame.from_dataframe(df)) dashboard._active_view = "a_test" def t_func1(event, fn): fn("event") def reload_fn(nodes, edges=None, patch_update=False): pass bg.add_event = t_func1 bg.reload_chart = reload_fn bg.add_reset_event(dashboard) assert bg.x_range is None assert bg.y_range is None assert dashboard._active_view == "a_test"
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
def test_add_reset_event(self, df_type): bg = BaseGraph() bg.edges = None bg.chart_type = "test" bg.x = "a" bg.x_range = (0, 2) bg.y_range = (3, 5) bg.chart = hv.InteractiveDatashader() df = initialize_df(df_type, {"a": [1, 2, 2], "b": [3, 4, 5]}) dashboard = DashBoard(dataframe=DataFrame.from_dataframe(df)) dashboard._active_view = bg def t_func1(event, fn): fn("event") def reload_fn(data, edges=None, patch_update=False): pass bg.add_event = t_func1 bg.reload_chart = reload_fn bg.add_reset_event(dashboard) assert bg.selected_indices is None
def test_lasso_selection_callback(self, df_type): nodes = initialize_df( df_type, {"vertex": [0, 1, 2, 3], "x": [0, 1, 1, 2], "y": [0, 1, 2, 0]}, ) edges = initialize_df( df_type, {"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(data, edges=None, patch_update=False): self.result = data bg.reload_chart = t_function geometry = np.array([[1, 1, 2], [1, 2, 1]]) t = bg.get_lasso_select_callback(dashboard) with mock.patch("cuspatial.point_in_polygon") as pip: if isinstance(nodes, dask_cudf.DataFrame): # point in polygon is called per partition, # in this case 2 partitions of length 2 each pip.return_value = cudf.DataFrame({"selection": [True, False]}) else: pip.return_value = cudf.DataFrame( {"selection": [True, False, True, False]} ) t(geometry) assert pip.called assert isinstance(self.result, df_type)
def test_box_selection_callback( self, df_type, inspect_neighbors, result, index ): nodes = initialize_df( df_type, {"vertex": [0, 1, 2, 3], "x": [0, 1, 1, 2], "y": [0, 1, 2, 0]}, ) edges = initialize_df( df_type, {"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(data, edges=None, patch_update=False): self.result = data.reset_index(drop=True) bg.reload_chart = t_function dashboard._active_view = bg class evt: bounds = (1, 3, 0, 1) x_selection = (1, 3) y_selection = (0, 1) t = bg.get_box_select_callback(dashboard) t(evt.bounds, evt.x_selection, evt.y_selection) result = initialize_df(df_type, result, index) assert df_equals(self.result, result)