From b3d98ca661fc619be6e9b14a1cfabdf1428664eb Mon Sep 17 00:00:00 2001 From: Bruce Johnson Date: Sat, 21 Mar 2026 10:49:55 -0400 Subject: [PATCH] Add mouse hit to show status --- .../org/nmrfx/analyst/gui/TablePlotGUI.java | 8 ++++ .../analyst/gui/molecule/PPMPlotGUI.java | 44 ++++++++++++++++--- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/nmrfx-analyst-gui/src/main/java/org/nmrfx/analyst/gui/TablePlotGUI.java b/nmrfx-analyst-gui/src/main/java/org/nmrfx/analyst/gui/TablePlotGUI.java index cbc7f04b7..e10bd5fa7 100644 --- a/nmrfx-analyst-gui/src/main/java/org/nmrfx/analyst/gui/TablePlotGUI.java +++ b/nmrfx-analyst-gui/src/main/java/org/nmrfx/analyst/gui/TablePlotGUI.java @@ -22,9 +22,11 @@ import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.control.*; +import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; import javafx.stage.FileChooser; @@ -97,6 +99,9 @@ public TablePlotGUI(TableView tableView, ExtraMode extraMod public record ParItem(String columnName, int group, String parName, double value, double error) { } + public void setBottom(Node node) { + borderPane.setBottom(node); + } /** * Creates and populates a new stage for the TablePlotGUI, if not already * created. The stage is displayed and raised to front. @@ -174,6 +179,7 @@ public void showPlotStage() { borderPane.setCenter(chartPane); borderPane.setRight(null); stage.setScene(stageScene); + activeChart.getCanvas().setOnMouseClicked(this::mouseClicked); } updateAxisChoices(); if (extraMode == ExtraMode.DIFFUSION) { @@ -185,6 +191,8 @@ public void showPlotStage() { updatePlot(); } + public void mouseClicked(MouseEvent e) { + } private void toggleFitPane(CheckBox showFitBox) { if (showFitBox.isSelected()) { diff --git a/nmrfx-analyst-gui/src/main/java/org/nmrfx/analyst/gui/molecule/PPMPlotGUI.java b/nmrfx-analyst-gui/src/main/java/org/nmrfx/analyst/gui/molecule/PPMPlotGUI.java index d1d5f4985..233d46191 100644 --- a/nmrfx-analyst-gui/src/main/java/org/nmrfx/analyst/gui/molecule/PPMPlotGUI.java +++ b/nmrfx-analyst-gui/src/main/java/org/nmrfx/analyst/gui/molecule/PPMPlotGUI.java @@ -1,6 +1,9 @@ package org.nmrfx.analyst.gui.molecule; +import javafx.scene.control.Label; import javafx.scene.control.TableView; +import javafx.scene.control.TextField; +import javafx.scene.input.MouseEvent; import org.nmrfx.analyst.gui.TablePlotGUI; import org.nmrfx.chart.*; import org.nmrfx.chemistry.Atom; @@ -10,17 +13,21 @@ public class PPMPlotGUI extends TablePlotGUI { + Label statusField = new Label(); public PPMPlotGUI(TableView atomTableView) { super(atomTableView, null, false); setChartTypeChoice(Arrays.asList("ScatterPlot", "BarChart", "BarChart-Euclidean")); skipColumns = Arrays.asList("Index", "Entity", "Res", "Atom"); + statusField.setPrefWidth(300); + setBottom(statusField); } -@Override + @Override protected DataSeries getBarChartData(List items, String yElem) { Map nameMap = getNameMap(); DataSeries series = new DataSeries(); series.clear(); + series.setName(yElem); String xElem = getXElem(); String firstAtomType = ((Atom) items.getFirst()).getName(); if (!items.stream().allMatch(item -> @@ -32,9 +39,11 @@ protected DataSeries getBarChartData(List items, String yElem) { Double yValue = item.getDouble(nameMap.get(yElem)); if (xValue != null && yValue != null) { if (item.getGroup() != 1) { - yValue /= 10.0; + yValue /= 5.0; } - series.add(new XYValue(xValue, yValue)); + XYValue xyValue = new XYValue(xValue, yValue); + xyValue.setExtraValue(item); + series.add(xyValue); } }); return series; @@ -46,19 +55,26 @@ protected DataSeries getEuclideanDistance(List items) { String yElem = getYElem().getFirst(); DataSeries series = new DataSeries(); series.clear(); + series.setName(yElem); HashMap values = new HashMap<>(); + HashMap plotItems = new HashMap<>(); items.forEach(item -> { int xValue = item.getDouble(nameMap.get(xElem)).intValue(); Double yValue = item.getDouble(nameMap.get(yElem)); if (yValue != null) { if (item.getGroup() != 1) { - yValue /= 10.0;} + yValue /= 10.0; + } values.put(xValue, values.getOrDefault(xValue, 0.0) + Math.pow(yValue, 2.0)); + plotItems.put(xValue, item); } }); - values.forEach((key, value) -> - series.add(new XYValue(key, Math.sqrt(value)))); + values.forEach((key, value) -> { + XYValue xyValue = new XYValue(key, Math.sqrt(value)); + xyValue.setExtraValue(plotItems.get(key)); + series.add(xyValue); + }); return series; } @@ -68,16 +84,30 @@ protected DataSeries getScatterPlotData(List items, String yElem) { String xElem = getXElem(); DataSeries series = new DataSeries(); series.clear(); + series.setName(yElem); items.forEach(item -> { Double ppm1 = item.getDouble(nameMap.get(xElem)); Double ppm2 = item.getDouble(nameMap.get(yElem)); if (ppm1 != null && ppm2 != null) { - series.add(new XYValue(ppm1, ppm2)); + XYValue xyValue = new XYValue(ppm1, ppm2); + xyValue.setExtraValue(item); + series.add(xyValue); } }); setYAxisLabel(yElem); return series; } + @Override + public void mouseClicked(MouseEvent e) { + Optional hitOpt = activeChart.pickChart(e.getX(), e.getY(), 5); + if (hitOpt.isPresent()) { + XYCanvasChart.Hit hit = hitOpt.get(); + Atom atom = (Atom) hit.getValue().getExtraValue(); + statusField.setText("HIT: " + hit + " " + atom); + } else { + statusField.setText(""); + } + } }