motile_plugin.data_views.views.tree_view.tree_widget
Classes
Bases: |
|
Re-implementation of QGraphicsView that removes scrollbars and allows unambiguous control of the |
|
pyqtgraph-based widget for lineage tree visualization and navigation |
Module Contents
- class motile_plugin.data_views.views.tree_view.tree_widget.CustomViewBox(*args, **kwds)
Bases:
pyqtgraph.ViewBox
Bases:
GraphicsWidget
Box that allows internal scaling/panning of children by mouse drag. This class is usually created automatically as part of a
PlotItem
or Canvas or withGraphicsLayout.addViewBox()
.Features:
Scaling contents by mouse or auto-scale when contents change
View linking–multiple views display the same data ranges
Configurable by context menu
Item coordinate mapping methods
- selected_rect
- mouseClickEvent(ev)
- showAxRect(ax, **kwargs)
Set the visible range to the given rectangle Emits sigRangeChangedManually without changing the range.
- mouseDragEvent(ev, axis=None)
Modified mouseDragEvent function to check which mouse mode to use and to submit rectangle coordinates for selecting multiple nodes if necessary
- class motile_plugin.data_views.views.tree_view.tree_widget.TreePlot
Bases:
pyqtgraph.PlotWidget
Re-implementation of QGraphicsView that removes scrollbars and allows unambiguous control of the viewed coordinate range. Also automatically creates a GraphicsScene and a central QGraphicsWidget that is automatically scaled to the full view geometry.
This widget is the basis for
PlotWidget
,GraphicsLayoutWidget
, and the view widget inImageView
.By default, the view coordinate system matches the widget’s pixel coordinates and automatically updates when the view is resized. This can be overridden by setting autoPixelRange=False. The exact visible range can be set with setRange().
The view can be panned using the middle mouse button and scaled using the right mouse button if enabled via enableMouse() (but ordinarily, we use ViewBox for this functionality).
- node_clicked
- nodes_selected
- _pos = []
- adj = []
- symbolBrush = []
- symbols = []
- pen = []
- outline_pen = []
- node_ids = []
- sizes = []
- view_direction = None
- feature = None
- g
- select_points_in_rect(rect: pyqtgraph.Qt.QtCore.QRectF)
Select all nodes in given rectangle
- update(track_df: pandas.DataFrame, view_direction: str, feature: str, selected_nodes: list[Any], reset_view: bool | None = False)
Update the entire view, including the data, view direction, and selected nodes
- Args:
track_df (pd.DataFrame): The dataframe containing the graph data view_direction (str): The view direction feature (str): The feature to be plotted (‘tree’ or ‘area’) selected_nodes (list[Any]): The currently selected nodes to be highlighted
- set_view(view_direction: str, feature: str, reset_view: bool | None = False)
Set the view direction, saving the new value as an attribute and changing the axes labels. Shortcuts if the view direction is already correct. Does not actually update the rendered graph (need to call _update_viewed_data).
- Args:
view_direction (str): “horizontal” or “vertical” feature (str): the feature being displayed, it can be ‘tree’ or ‘area’
- _on_click(_, points: numpy.ndarray, ev: qtpy.QtGui.QMouseEvent) None
Adds the selected point to the selected_nodes list. Called when the user clicks on the TreeWidget to select nodes.
- Args:
points (np.ndarray): _description_ ev (QMouseEvent): _description_
- set_data(track_df: pandas.DataFrame, feature: str) None
Updates the stored pyqtgraph content based on the given dataframe. Does not render the new information (need to call _update_viewed_data).
- Args:
- track_df (pd.DataFrame): The tracks df to compute the pyqtgraph
content for. Can be all lineages or any subset of them.
feature (str): The feature to be plotted. Can either be ‘tree’, or ‘area’.
- _update_viewed_data(view_direction: str)
Set the data according to the view direction Args:
view_direction (str): direction to plot the data, either ‘horizontal’ or ‘vertical’
- _create_pyqtgraph_content(track_df: pandas.DataFrame, feature: str) None
Parse the given track_df into the format that pyqtgraph expects and save the information as attributes.
- Args:
- track_df (pd.DataFrame): The dataframe containing the graph to be
rendered in the tree view. Can be all lineages or a subset.
feature (str): The feature to be plotted. Can either be ‘tree’ or ‘area’.
- set_selection(selected_nodes: list[Any], feature: str) None
Set the provided list of nodes to be selected. Increases the size and highlights the outline with blue. Also centers the view if the first selected node is not visible in the current canvas.
- Args:
selected_nodes (list[Any]): A list of node ids to be selected. feature (str): the feature that is being plotted, either ‘tree’ or ‘area’
- _center_range(min_x: int, max_x: int, min_t: int, max_t: int)
Check whether viewbox contains current range and adjust if not
- _center_view(center_x: int, center_y: int)
Center the Viewbox on given coordinates
- class motile_plugin.data_views.views.tree_view.tree_widget.TreeWidget(viewer: napari.Viewer)
Bases:
qtpy.QtWidgets.QWidget
pyqtgraph-based widget for lineage tree visualization and navigation
- track_df
- lineage_df
- graph = None
- mode = 'all'
- feature = 'tree'
- view_direction = 'vertical'
- tracks_viewer
- selected_nodes
- mode_widget
- feature_widget
- keyPressEvent(event: qtpy.QtGui.QKeyEvent) None
Handle key press events.
- delete_node()
Delete a node.
- create_edge()
Create an edge.
- delete_edge()
Delete an edge.
- undo()
Undo action.
- redo()
Redo action.
- toggle_display_mode()
Toggle display mode.
- toggle_feature_mode()
Toggle feature mode.
- set_mouse_enabled(x: bool, y: bool)
Enable or disable mouse zoom scrolling in X or Y direction.
- keyReleaseEvent(ev)
Reset the mouse scrolling when releasing the X/Y key
- _update_selected()
Called whenever the selection list is updated. Only re-computes the full graph information when the new selection is not in the lineage df (and in lineage mode)
- _update_track_data(reset_view: bool | None = None) None
Called when the TracksViewer emits the tracks_updated signal, indicating that a new set of tracks should be viewed.
- _set_mode(mode: str) None
Set the display mode to all or lineage view. Currently, linage view is always horizontal and all view is always vertical.
- Args:
mode (str): The mode to set the view to. Options are “all” or “lineage”
- _set_feature(feature: str) None
Set the feature mode to ‘tree’ or ‘area’. For this the view is always horizontal.
- Args:
feature (str): The feature to plot. Options are “tree” or “area”
- _update_lineage_df() None
Subset dataframe to include only nodes belonging to the current lineage