Hi Dave, although we have ValueAxis.translateJava2DtoValue and ValueAxis.translateValueToJava2D, we have no way of going from screen co-ordinates to Java2D co-ordinates.
This is beacause there is no way to access the ChartPanel.scaleX and ChartPanel.scaleY fields.
ChartPanel frequently converts between screen and Java2D co-ordinates, maybe you could refactor this into two public methods on ChartPanel?
// BTW, I have no idea whether the choice of Point and Point2D below is
// right.
// Maybe everything should be Point2D (even though screen coords are
// always integer)?
public Point translateJava2DToScreen(Point2D java2DPoint){
Insets insets = getInsets();
int x = (int) (java2DPoint.getX() * scaleX + insets.left);
int y = (int) (java2DPoint.getY() * scaleY + insets.top);
return new Point(x,y);
}
public Point2D translateScreenToJava2D(Point2D screenPoint){
Insets insets = getInsets();
double x = (screenPoint.getX()-insets.left)/scaleX;
double y = (screenPoint.getY()-insets.top)/scaleY;
return new Point.Double(x,y);
}
Thanks
Dan
Translating between screen and graph co-ordinates
Re: Translating between screen and graph co-ordinates
Hi Dan,
Thanks for the suggestion, I will make the change now. I will start with Point for the screen coordinates and Point2D for the Java2D coordinates, and wait for any other feedback if someone thinks it should be different.
Regards,
DG.
Thanks for the suggestion, I will make the change now. I will start with Point for the screen coordinates and Point2D for the Java2D coordinates, and wait for any other feedback if someone thinks it should be different.
Regards,
DG.