Skip to content

Commit

Permalink
PCA reinstate basic dbl click selection score plot
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenz Gerber <[email protected]>
  • Loading branch information
lorenzgerber committed Nov 21, 2024
1 parent 08a1346 commit 92f16ec
Showing 1 changed file with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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<? extends IResultPCA, ? extends IVariable> resultsPCA = evaluationPCA.getResults();
List<? extends IResultPCA> resultList = resultsPCA.getPcaResultList();
List<ResultDelta> 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<ISample> 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
Expand Down

0 comments on commit 92f16ec

Please sign in to comment.