From 92f16ec85e97b9c28147677f39951ebd4e8e8aa3 Mon Sep 17 00:00:00 2001 From: Lorenz Gerber Date: Thu, 21 Nov 2024 16:07:18 +0800 Subject: [PATCH] PCA reinstate basic dbl click selection score plot Signed-off-by: Lorenz Gerber --- .../pca/ui/swt/ExtendedScorePlot2D.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/chemclipse/plugins/org.eclipse.chemclipse.xxd.process.supplier.pca.ui/src/org/eclipse/chemclipse/xxd/process/supplier/pca/ui/swt/ExtendedScorePlot2D.java b/chemclipse/plugins/org.eclipse.chemclipse.xxd.process.supplier.pca.ui/src/org/eclipse/chemclipse/xxd/process/supplier/pca/ui/swt/ExtendedScorePlot2D.java index 2e0c1dd99a..f60e416f35 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.xxd.process.supplier.pca.ui/src/org/eclipse/chemclipse/xxd/process/supplier/pca/ui/swt/ExtendedScorePlot2D.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.xxd.process.supplier.pca.ui/src/org/eclipse/chemclipse/xxd/process/supplier/pca/ui/swt/ExtendedScorePlot2D.java @@ -14,6 +14,8 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.concurrent.atomic.AtomicReference; @@ -34,6 +36,7 @@ import org.eclipse.chemclipse.xxd.process.supplier.pca.model.IAnalysisSettings; import org.eclipse.chemclipse.xxd.process.supplier.pca.model.IResultPCA; import org.eclipse.chemclipse.xxd.process.supplier.pca.model.IResultsPCA; +import org.eclipse.chemclipse.xxd.process.supplier.pca.model.ResultDelta; import org.eclipse.chemclipse.xxd.process.supplier.pca.ui.Activator; import org.eclipse.chemclipse.xxd.process.supplier.pca.ui.chart2d.ScorePlot; import org.eclipse.chemclipse.xxd.process.supplier.pca.ui.help.HelpContext; @@ -297,6 +300,75 @@ public void handleEvent(BaseChart baseChart, Event event) { } } }); + chartSettings.addHandledEventProcessor(new IHandledEventProcessor() { + + @Override + public int getEvent() { + + return IMouseSupport.EVENT_MOUSE_DOUBLE_CLICK; + } + + @Override + public int getButton() { + + return IMouseSupport.MOUSE_BUTTON_LEFT; + } + + @Override + public int getStateMask() { + + return SWT.NONE; + } + + @Override + public void handleEvent(BaseChart baseChart, Event event) { + + if(evaluationPCA != null) { + /* + * Determine the x|y coordinates. + */ + Rectangle rectangle = baseChart.getPlotArea().getBounds(); + int x = event.x; + int y = event.y; + int width = rectangle.width; + int height = rectangle.height; + /* + * Calculate the selected point. + */ + Range rangeX = baseChart.getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS).getRange(); + Range rangeY = baseChart.getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS).getRange(); + double pX = rangeX.lower + (rangeX.upper - rangeX.lower) * ((1.0d / width) * x); + double pY = rangeY.lower + (rangeY.upper - rangeY.lower) * ((1.0d / height) * y); + /* + * Map the result deltas. + */ + PrincipalComponentUI principalComponentUI = principalComponentControl.get(); + int pcX = principalComponentUI.getPCX(); + int pcY = principalComponentUI.getPCY(); + IResultsPCA resultsPCA = evaluationPCA.getResults(); + List resultList = resultsPCA.getPcaResultList(); + List resultDeltas = new ArrayList<>(); + // + for(int i = 0; i < resultList.size(); i++) { + IResultPCA pcaResult = resultList.get(i); + IPoint pointResult = getPoint(pcaResult, pcX, pcY, i); + double deltaX = Math.abs(pointResult.getX() - pX); + double deltaY = Math.abs(pointResult.getY() - pY); + resultDeltas.add(new ResultDelta(pcaResult, deltaX, deltaY)); + } + /* + * Get the closest result. + */ + if(!resultDeltas.isEmpty()) { + Collections.sort(resultDeltas, Comparator.comparing(ResultDelta::getDeltaX).thenComparing(ResultDelta::getDeltaY)); + ResultDelta resultDelta = resultDeltas.get(0); + List highlightedSamples = new ArrayList<>(); + highlightedSamples.add(resultDelta.getResultPCA().getSample()); + UpdateNotifierUI.update(event.display, IChemClipseEvents.TOPIC_PCA_UPDATE_HIGHLIGHT_SAMPLE, highlightedSamples.toArray()); + } + } + } + }); scorePlot.applySettings(chartSettings); /* * Paint Listener