ClusteringView¶
class ClusteringView()
Bases: MetaView
Subclass of MetaView for displaying and interacting with clustering analysis.
Handles plotting, user input, and signal exchanges.
Public Methods¶
- ClusteringView.get_current_view() str¶
Abstract method to get the name of the current view.
Subclasses must override this to return the current view name.
- Returns:
The name of the view currently displayed.
- Return type:
- Raises:
NotImplementedError – Always, unless overridden by a subclass.
- ClusteringView.get_save_filename() str¶
Opens a file dialog to select a location for saving a CSV file.
- Returns:
The selected file path.
- Return type:
- ClusteringView.get_walkthrough_steps() List[Tuple[str, str, str, Callable[[], QWidget | List[QWidget]]]]¶
Abstract method to retrieve the walkthrough steps for the current view.
Subclasses must override this to return a list of walkthrough steps, each a (title, description, view name, widget getter) tuple.
- Returns:
The ordered walkthrough steps for this view.
- Return type:
List[WalkthroughStep]
- Raises:
NotImplementedError – Always, unless overridden by a subclass.
- ClusteringView.handle_parameter_change(submodel_name: str, action_name: str, args: tuple) None¶
Handles actions triggered by the control panel.
- ClusteringView.notify_plugin_state_changed(metaclass: str, plugin_key: str, reason: str) None¶
Called when some other plugin instance’s state changed elsewhere in the app. Refreshes this tab’s column list only when the change concerns a MetaDatabaseLoader’s columns and the loader that changed is the one currently selected here; any other metaclass, reason, or a loader that isn’t currently selected in this tab is ignored.
- ClusteringView.on_cluster_column_checked(loader: str, existing_table: str | None) None¶
Confirm an overwrite if needed, then ask the Controller to commit.
The confirmation stays in the View - it is a modal dialog - which is why this is two round trips rather than one.
existing_tablebeing None means there is nothing to overwrite and the commit proceeds without asking.
- ClusteringView.on_clusters_committed(loader: str, status: bool) None¶
Refresh this tab and tell the rest of the app, once the write has landed.
- ClusteringView.on_metadata_loaded(config: Dict[str, Any], loader: str, plot_data: DataFrame) None¶
Parse the settings dialog, then ask for the rows to be clustered.
The second half of
_load_metadata_and_request_clustering(). The rows are a parameter now rather than something read back offself.plot_data, so the clear-before-emit guard that used to protect that read is gone with the read.The filtering itself is
ClusteringModel.build_clustering_frame()’s. What stays here is reading the settings dialog - the per-column flags and the method parameters are strings the user typed, so a bad one is this form’s problem to report.- Parameters:
- Returns:
None
- Return type:
None
- Raises:
ValueError – If the clustering method or its parameters are invalid or missing.
- ClusteringView.set_clustering_result(data: DataFrame, labels: Sequence[Any] | ndarray, confidence: Sequence[Any] | ndarray) None¶
Receive the Model’s clustering result and plot it.
The other half of cluster_requested: the clustering is ClusteringModel’s, so everything that depends on its result is drawn from here rather than inline after the call.
- Parameters:
data (pd.DataFrame) – the normalized frame the Model clustered
labels (Union[Sequence[Any], np.ndarray]) – cluster label per row
confidence (Union[Sequence[Any], np.ndarray]) – cluster confidence per row
- Returns:
None
- Return type:
None
- ClusteringView.set_query(query: str, table_name: str) None¶
Sets the SQL query and target table name.
- ClusteringView.update_available_columns(loader: str) None¶
Ask the Controller for the column names the given loader offers.
The answer arrives at
update_column_names. There is no try/except here: emitting a request does not raise, and the call that can fail is the Controller’s, which is where a failure can be reported.- Parameters:
loader (str) – Identifier for the loader plugin.
- ClusteringView.update_available_plugins(available_plugins: Dict[str, List[str]]) None¶
Called whenever a new plugin is instantiated elsewhere in the app, to keep an up-to-date list of possible data sources for use by this plugin.
- ClusteringView.update_column_names(column_names: List[str]) None¶
Updates the list of available column names.
- Parameters:
column_names (List[str]) – List of column names returned from the loader.
- ClusteringView.update_column_units(unit: str | None, column: str) None¶
Updates the unit for a specific column.
- ClusteringView.update_plot(data: DataFrame, labels: Sequence[Any] | ndarray, confidence: Sequence[Any] | ndarray, logs: Sequence[bool], normalized: Sequence[bool], units: Sequence[str | None], plot: Sequence[bool]) None¶
Updates the plot with clustered data and redraws it.
- Parameters:
data (pd.DataFrame) – DataFrame with clustering results.
labels (Union[Sequence[Any], np.ndarray]) – Cluster labels for each row.
confidence (Union[Sequence[Any], np.ndarray]) – Cluster confidence values.
logs (Sequence[bool]) – Flags indicating if each column is log-scaled.
normalized (Sequence[bool]) – Flags indicating if each column is normalized.
units (Sequence[Optional[str]]) – Units for each column.
plot (Sequence[bool]) – Flags indicating if a column should be plotted.
Private Methods¶
- ClusteringView._reset_actions(axis_type: str = '2d') None¶
Clears the figure and reinitializes axes. This will also add a flag to the tab action history if @register_action is being used to keep track of actions. Only actions applied after the most recent call to this function will be recreated if the related file is loaded.
- Parameters:
axis_type (str) – Either ‘2d’ or ‘3d’ to determine plot projection.