Skip to content

Commit

Permalink
- Fixed error in calculation marker position after window resize
Browse files Browse the repository at this point in the history
  • Loading branch information
likhachev committed May 13, 2016
1 parent 62f15ae commit 00da21c
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/main/java/com/ivli/roim/controls/CurvePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.swing.JMenu;
Expand Down Expand Up @@ -119,15 +122,28 @@ private ChartEntity findEntity(MouseEvent e) {
private ValueMarker findMarker(MouseEvent e) {
final XYPlot plot = getChart().getXYPlot();

java.util.Collection mark = plot.getDomainMarkers(Layer.FOREGROUND);
Collection mark = plot.getDomainMarkers(Layer.FOREGROUND);

if (null == mark || mark.isEmpty())
return null;
//{

Point2D p = translateScreenToJava2D(e.getPoint());
Rectangle2D plotArea = getScreenDataArea();
///XYPlot plot = (XYPlot) chart.getPlot(); // your plot
double domainX = plot.getDomainAxis().java2DToValue(e.getX(), getScreenDataArea(), plot.getDomainAxisEdge());


//logger.info(String.format("domainX = %f, point(%f:%f), plotArea(%f:%f:%f:%f)", domainX, p.getX(), p.getY(), plotArea.getX(), plotArea.getY(), plotArea.getWidth(), plotArea.getHeight() ));
double domainY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());

// }
/*
final double domainX = plot.getDomainAxis().java2DToValue(e.getX(),
getChartRenderingInfo().getPlotInfo().getDataArea(),
plot.getDomainAxisEdge());
*/
final double Epsilon = plot.getDataRange(plot.getDomainAxis()).getLength() * .01d;

for (Object o : mark) {
Expand Down Expand Up @@ -237,22 +253,18 @@ final class Interpolation implements MarkerChangeListener {
fillIn();
((XYSeriesCollection)(getChart().getXYPlot().getDataset())).addSeries(iSrc);
aLhs.addChangeListener(this);
aRhs.addChangeListener(this);
}

void update() {
iSrc.clear();
fillIn();
aRhs.addChangeListener(this);
}

void fillIn() {
iSrc.add(iLhs.getValue(), iLhs.getLinkedMarker().getValue());
iSrc.add((iLhs.getValue() + iRhs.getValue())/2.0, (iLhs.getLinkedMarker().getValue() + iRhs.getLinkedMarker().getValue()) /2.0);
iSrc.add(iRhs.getValue(), iRhs.getLinkedMarker().getValue());
}

public void markerChanged(MarkerChangeEvent mce) {
update();
iSrc.clear();
fillIn();
}
}

Expand Down Expand Up @@ -331,9 +343,10 @@ public void mouseDragged(MouseEvent e) {
plot.getRangeAxisEdge()));
}
if (null != iMarker) {
iMarker.setValue(plot.getDomainAxis().java2DToValue(e.getX(),
getChartRenderingInfo().getPlotInfo().getDataArea(),
plot.getDomainAxisEdge()));
double domainX = plot.getDomainAxis().java2DToValue(e.getX(), getScreenDataArea(), plot.getDomainAxisEdge());
iMarker.setValue(domainX);//plot.getDomainAxis().java2DToValue(e.getX(),
//getChartRenderingInfo().getPlotInfo().getDataArea(),
// plot.getDomainAxisEdge()));
}
else
super.mouseDragged(e);
Expand Down

0 comments on commit 00da21c

Please # to comment.