fixed mz-mobility's mobility picking issue
@@ -52,9 +52,8 @@ import org.jfree.chart.ui.RectangleInsets;
import org.jfree.data.xy.XYZDataset;
import java.awt.*;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
+import java.awt.geom.Point2D;
+import java.util.*;
import java.util.logging.Logger;
public class MzMobilityHeatMapPlot extends EChartViewer {
@@ -69,7 +68,9 @@ public class MzMobilityHeatMapPlot extends EChartViewer {
private Scan selectedMobilityScan;
private Scan scans[];
private RawDataFile dataFiles[];
- public MzMobilityHeatMapPlot(XYZDataset dataset, String paintScaleStyle, ParameterSet parameters ) {
+
+ public MzMobilityHeatMapPlot(
+ XYZDataset dataset, String paintScaleStyle, ParameterSet parameters) {
super(
ChartFactory.createScatterPlot(
@@ -204,6 +205,29 @@ public class MzMobilityHeatMapPlot extends EChartViewer {
@Override
public void chartMouseClicked(ChartMouseEventFX event) {
ChartEntity chartEntity = event.getEntity();
+
+ // if chartintity is not selected any valid point find it's nearest.
+ if (chartEntity == null || !(chartEntity instanceof XYItemEntity)) {
+ int x = (int) ((event.getTrigger().getX() - getInsets().getLeft()) / getScaleX());
+ int y = (int) ((event.getTrigger().getY() - getInsets().getRight()) / getScaleY());
+ Point2D point2d = new Point2D.Double(x, y);
+ double minDistance = Integer.MAX_VALUE;
+ Collection entities = getRenderingInfo().getEntityCollection().getEntities();
+ for (Iterator iter = entities.iterator(); iter.hasNext(); ) {
+ ChartEntity element = (ChartEntity) iter.next();
+
+ if (element instanceof XYItemEntity) {
+ Rectangle rect = element.getArea().getBounds();
+ Point2D centerPoint = new Point2D.Double(rect.getCenterX(), rect.getCenterY());
+
+ if (point2d.distance(centerPoint) < minDistance) {
+ minDistance = point2d.distance(centerPoint);
+ chartEntity = element;
+ }
+ }
+ }
+ }
+
if (chartEntity instanceof XYItemEntity) {
XYItemEntity entity = (XYItemEntity) chartEntity;
int serindex = entity.getSeriesIndex();
@@ -223,7 +247,6 @@ public class MzMobilityHeatMapPlot extends EChartViewer {
@Override
public void chartMouseMoved(ChartMouseEventFX event) {}
});
-
}
void updateChart() {
