Search in sources :

Example 1 with AxisEntity

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;
}
Also used : AxisEntity(org.jfree.chart.entity.AxisEntity) AxisEntity(org.jfree.chart.entity.AxisEntity) ChartEntity(org.jfree.chart.entity.ChartEntity) Entity(net.sf.mzmine.chartbasics.gestures.ChartGesture.Entity) PlotOrientation(org.jfree.chart.plot.PlotOrientation) ChartEntity(org.jfree.chart.entity.ChartEntity) JFreeChart(org.jfree.chart.JFreeChart)

Example 2 with AxisEntity

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);
}
Also used : AxisEntity(org.jfree.chart.entity.AxisEntity) Rectangle2D(java.awt.geom.Rectangle2D) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) CombinedRangeXYPlot(org.jfree.chart.plot.CombinedRangeXYPlot) Point2D(java.awt.geom.Point2D) ValueAxis(org.jfree.chart.axis.ValueAxis) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) ChartEntity(org.jfree.chart.entity.ChartEntity) ValueAxis(org.jfree.chart.axis.ValueAxis) Axis(org.jfree.chart.axis.Axis) RectangleEdge(org.jfree.chart.ui.RectangleEdge)

Example 3 with AxisEntity

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);
}
Also used : AxisEntity(org.jfree.chart.entity.AxisEntity) Rectangle2D(java.awt.geom.Rectangle2D) Point(java.awt.Point) Point(java.awt.Point) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) CombinedRangeXYPlot(org.jfree.chart.plot.CombinedRangeXYPlot) Point2D(java.awt.geom.Point2D) ValueAxis(org.jfree.chart.axis.ValueAxis) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) ChartEntity(org.jfree.chart.entity.ChartEntity) ValueAxis(org.jfree.chart.axis.ValueAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) Axis(org.jfree.chart.axis.Axis) RectangleEdge(org.jfree.chart.ui.RectangleEdge)

Example 4 with AxisEntity

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));
    }
}
Also used : AxisEntity(org.jfree.chart.entity.AxisEntity) EntityCollection(org.jfree.chart.entity.EntityCollection) Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

AxisEntity (org.jfree.chart.entity.AxisEntity)4 Rectangle2D (java.awt.geom.Rectangle2D)3 ChartEntity (org.jfree.chart.entity.ChartEntity)3 Point2D (java.awt.geom.Point2D)2 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)2 Axis (org.jfree.chart.axis.Axis)2 ValueAxis (org.jfree.chart.axis.ValueAxis)2 CombinedDomainXYPlot (org.jfree.chart.plot.CombinedDomainXYPlot)2 CombinedRangeXYPlot (org.jfree.chart.plot.CombinedRangeXYPlot)2 XYPlot (org.jfree.chart.plot.XYPlot)2 RectangleEdge (org.jfree.chart.ui.RectangleEdge)2 Point (java.awt.Point)1 Entity (net.sf.mzmine.chartbasics.gestures.ChartGesture.Entity)1 JFreeChart (org.jfree.chart.JFreeChart)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 EntityCollection (org.jfree.chart.entity.EntityCollection)1 PlotOrientation (org.jfree.chart.plot.PlotOrientation)1