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 3942e6aa8..ee8f15734 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 @@ -23,9 +23,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; @@ -100,6 +102,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. @@ -177,6 +182,7 @@ public void showPlotStage() { borderPane.setCenter(chartPane); borderPane.setRight(null); stage.setScene(stageScene); + activeChart.getCanvas().setOnMouseClicked(this::mouseClicked); } updateAxisChoices(); if (extraMode == ExtraMode.DIFFUSION) { @@ -188,6 +194,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 0382977d1..414959668 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,19 +13,23 @@ 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); xZeroIncluded(false); yZeroIncluded(false); } -@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 -> @@ -34,9 +41,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; @@ -48,19 +57,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; } @@ -70,16 +86,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(""); + } + } }