use of org.jfree.chart.entity.AxisEntity in project mzmine2 by mzmine.
the class ChartGestureDragDiffHandler method getOrientation.
/**
* use default orientation or orientation of axis
*
* @param event
* @return
*/
public Orientation getOrientation(ChartGestureEvent event) {
ChartEntity ce = event.getEntity();
if (ce instanceof AxisEntity) {
JFreeChart chart = event.getChart();
PlotOrientation plotorient = PlotOrientation.HORIZONTAL;
if (chart.getXYPlot() != null)
plotorient = chart.getXYPlot().getOrientation();
else if (chart.getCategoryPlot() != null)
plotorient = chart.getCategoryPlot().getOrientation();
Entity entity = event.getGesture().getEntity();
if ((entity.equals(Entity.DOMAIN_AXIS) && plotorient.equals(PlotOrientation.VERTICAL)) || (entity.equals(Entity.RANGE_AXIS) && plotorient.equals(PlotOrientation.HORIZONTAL)))
orient = Orientation.HORIZONTAL;
else
orient = Orientation.VERTICAL;
}
return orient;
}
use of org.jfree.chart.entity.AxisEntity in project mzmine2 by mzmine.
the class ChartLogicsFX method mouseXYToPlotXY.
/**
* Translates mouse coordinates to chart coordinates (xy-axis)
*
* @param myChart
* @param mouseX
* @param mouseY
* @return Range as chart coordinates (never null)
*/
public static Point2D mouseXYToPlotXY(ChartViewer myChart, int mouseX, int mouseY) {
XYPlot plot = null;
// find plot as parent of axis
ChartEntity entity = findChartEntity(myChart.getCanvas(), mouseX, mouseY);
if (entity instanceof AxisEntity) {
Axis a = ((AxisEntity) entity).getAxis();
if (a.getPlot() instanceof XYPlot)
plot = (XYPlot) a.getPlot();
}
ChartRenderingInfo info = myChart.getRenderingInfo();
int subplot = info.getPlotInfo().getSubplotIndex(new Point2D.Double(mouseX, mouseY));
Rectangle2D dataArea = info.getPlotInfo().getDataArea();
if (subplot != -1)
dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea();
// find subplot or plot
if (plot == null)
plot = findXYSubplot(myChart.getChart(), info, mouseX, mouseY);
// coordinates
double cx = 0;
double cy = 0;
if (plot != null) {
// find axis
ValueAxis domainAxis = plot.getDomainAxis();
ValueAxis rangeAxis = plot.getRangeAxis();
RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
// parent?
if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
XYPlot pp = ((XYPlot) plot.getParent());
domainAxis = pp.getDomainAxis();
domainAxisEdge = pp.getDomainAxisEdge();
}
if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
XYPlot pp = ((XYPlot) plot.getParent());
rangeAxis = pp.getRangeAxis();
rangeAxisEdge = pp.getRangeAxisEdge();
}
if (domainAxis != null)
cx = domainAxis.java2DToValue(mouseX, dataArea, domainAxisEdge);
if (rangeAxis != null)
cy = rangeAxis.java2DToValue(mouseY, dataArea, rangeAxisEdge);
}
return new Point2D.Double(cx, cy);
}
use of org.jfree.chart.entity.AxisEntity in project mzmine2 by mzmine.
the class ChartLogics method mouseXYToPlotXY.
/**
* Translates mouse coordinates to chart coordinates (xy-axis)
*
* @param myChart
* @param mouseX
* @param mouseY
* @return Range as chart coordinates
* @throws Exception
*/
public static Point2D mouseXYToPlotXY(ChartPanel myChart, int mouseX, int mouseY) throws Exception {
Point2D p = myChart.translateScreenToJava2D(new Point(mouseX, mouseY));
XYPlot plot = null;
// find plot as parent of axis
ChartEntity entity = findChartEntity(myChart, mouseX, mouseY);
if (entity instanceof AxisEntity) {
Axis a = ((AxisEntity) entity).getAxis();
if (a.getPlot() instanceof XYPlot)
plot = (XYPlot) a.getPlot();
}
ChartRenderingInfo info = myChart.getChartRenderingInfo();
int subplot = info.getPlotInfo().getSubplotIndex(p);
Rectangle2D dataArea = info.getPlotInfo().getDataArea();
if (subplot != -1)
dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea();
if (plot == null)
plot = findXYSubplot(myChart.getChart(), info, p.getX(), p.getY());
// coordinates
double cx = 0;
double cy = 0;
if (plot != null) {
// find axis
ValueAxis domainAxis = plot.getDomainAxis();
ValueAxis rangeAxis = plot.getRangeAxis();
RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
// parent?
if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
XYPlot pp = ((XYPlot) plot.getParent());
domainAxis = pp.getDomainAxis();
domainAxisEdge = pp.getDomainAxisEdge();
}
if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
XYPlot pp = ((XYPlot) plot.getParent());
rangeAxis = pp.getRangeAxis();
rangeAxisEdge = pp.getRangeAxisEdge();
}
if (domainAxis != null)
cx = domainAxis.java2DToValue(p.getX(), dataArea, domainAxisEdge);
if (rangeAxis != null)
cy = rangeAxis.java2DToValue(p.getY(), dataArea, rangeAxisEdge);
} else {
throw new Exception("no xyplot found");
}
return new Point2D.Double(cx, cy);
}
use of org.jfree.chart.entity.AxisEntity in project SIMVA-SoS by SESoS.
the class Axis method createAndAddEntity.
/**
* Created an entity for the axis.
*
* @param cursor the initial cursor value.
* @param state the axis state after completion of the drawing with a
* possibly updated cursor position.
* @param dataArea the data area.
* @param edge the edge.
* @param plotState the PlotRenderingInfo from which a reference to the
* entity collection can be obtained.
*
* @since 1.0.13
*/
protected void createAndAddEntity(double cursor, AxisState state, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState) {
if (plotState == null || plotState.getOwner() == null) {
// no need to create entity if we can't save it anyways...
return;
}
Rectangle2D hotspot = null;
if (edge.equals(RectangleEdge.TOP)) {
hotspot = new Rectangle2D.Double(dataArea.getX(), state.getCursor(), dataArea.getWidth(), cursor - state.getCursor());
} else if (edge.equals(RectangleEdge.BOTTOM)) {
hotspot = new Rectangle2D.Double(dataArea.getX(), cursor, dataArea.getWidth(), state.getCursor() - cursor);
} else if (edge.equals(RectangleEdge.LEFT)) {
hotspot = new Rectangle2D.Double(state.getCursor(), dataArea.getY(), cursor - state.getCursor(), dataArea.getHeight());
} else if (edge.equals(RectangleEdge.RIGHT)) {
hotspot = new Rectangle2D.Double(cursor, dataArea.getY(), state.getCursor() - cursor, dataArea.getHeight());
}
EntityCollection e = plotState.getOwner().getEntityCollection();
if (e != null) {
e.add(new AxisEntity(hotspot, this));
}
}
Aggregations