-
Notifications
You must be signed in to change notification settings - Fork 33
howto pixel coordinates of points
Erich Seifert edited this page Apr 6, 2016
·
3 revisions
In GRAL the screen coordinates of the data points are calculated by querying the AxisRenderer of each axis.
For a two-dimensional x-y plot GRAL queries the renderer of x axis for the horizontal position and the renderer of the y axis for the vertical position. Given the data point values x and y, it would as follows:
double pixelX = plot.getAxisRenderer(XYPlot.AXIS_X).worldToView(axisX, x, true);
double pixelY = plot.getAxisRenderer(XYPlot.AXIS_Y).worldToView(axisY, y, true);The axes are positioned inside a plot area (PlotArea). In order to get the absolute position in the plot area, we have to translate the pixel coordinates:
double pixelX = plot.getAxisRenderer(XYPlot.AXIS_X).worldToView(axisX, x, true);
double pixelY = plot.getAxisRenderer(XYPlot.AXIS_Y).worldToView(axisY, y, true);
double plotAreaHeight = plot.getPlotArea().getHeight();
double plotAreaX = plot.getPlotArea().getX();
double plotAreaY = plot.getPlotArea().getY();
pixelX = plotAreaX + pixelX;
pixelY = plotAreaY + plotAreaHeight - pixelY;