Search in sources :

Example 26 with ChartRenderingInfo

use of org.jfree.chart.ChartRenderingInfo in project SIMVA-SoS by SESoS.

the class ScrollHandlerFX method handleZoomable.

/**
 * Handle the case where a plot implements the {@link Zoomable} interface.
 *
 * @param zoomable  the zoomable plot.
 * @param e  the mouse wheel event.
 */
private void handleZoomable(ChartCanvas canvas, Zoomable zoomable, ScrollEvent e) {
    // don't zoom unless the mouse pointer is in the plot's data area
    ChartRenderingInfo info = canvas.getRenderingInfo();
    PlotRenderingInfo pinfo = info.getPlotInfo();
    Point2D p = new Point2D.Double(e.getX(), e.getY());
    if (pinfo.getDataArea().contains(p)) {
        Plot plot = (Plot) zoomable;
        // do not notify while zooming each axis
        boolean notifyState = plot.isNotify();
        plot.setNotify(false);
        int clicks = (int) e.getDeltaY();
        double zf = 1.0 + this.zoomFactor;
        if (clicks < 0) {
            zf = 1.0 / zf;
        }
        if (true) {
            // this.chartPanel.isDomainZoomable()) {
            zoomable.zoomDomainAxes(zf, pinfo, p, true);
        }
        if (true) {
            // this.chartPanel.isRangeZoomable()) {
            zoomable.zoomRangeAxes(zf, pinfo, p, true);
        }
        // this generates the change event too
        plot.setNotify(notifyState);
    }
}
Also used : PlotRenderingInfo(org.jfree.chart.plot.PlotRenderingInfo) Point2D(java.awt.geom.Point2D) Plot(org.jfree.chart.plot.Plot) PiePlot(org.jfree.chart.plot.PiePlot) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo)

Example 27 with ChartRenderingInfo

use of org.jfree.chart.ChartRenderingInfo in project SIMVA-SoS by SESoS.

the class TooltipHandlerFX method getTooltipText.

/**
 * Returns the tooltip text.
 *
 * @param canvas  the canvas that is displaying the chart.
 * @param x  the x-coordinate of the mouse pointer.
 * @param y  the y-coordinate of the mouse pointer.
 *
 * @return String The tooltip text (possibly <code>null</code>).
 */
private String getTooltipText(ChartCanvas canvas, double x, double y) {
    ChartRenderingInfo info = canvas.getRenderingInfo();
    if (info == null) {
        return null;
    }
    EntityCollection entities = info.getEntityCollection();
    if (entities == null) {
        return null;
    }
    ChartEntity entity = entities.getEntity(x, y);
    if (entity == null) {
        return null;
    }
    return entity.getToolTipText();
}
Also used : EntityCollection(org.jfree.chart.entity.EntityCollection) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) ChartEntity(org.jfree.chart.entity.ChartEntity)

Example 28 with ChartRenderingInfo

use of org.jfree.chart.ChartRenderingInfo in project SIMVA-SoS by SESoS.

the class StandardXYItemRendererTest method testNoDisplayedItem.

/**
 * A check to ensure that an item that falls outside the plot's data area
 * does NOT generate an item entity.
 */
@Test
public void testNoDisplayedItem() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(10.0, 10.0);
    dataset.addSeries(s1);
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", dataset, PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StandardXYItemRenderer());
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setRange(0.0, 5.0);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setRange(0.0, 5.0);
    BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, info);
    g2.dispose();
    EntityCollection ec = info.getEntityCollection();
    assertFalse(TestUtilities.containsInstanceOf(ec.getEntities(), XYItemEntity.class));
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) Rectangle2D(java.awt.geom.Rectangle2D) JFreeChart(org.jfree.chart.JFreeChart) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) XYItemEntity(org.jfree.chart.entity.XYItemEntity) XYPlot(org.jfree.chart.plot.XYPlot) EntityCollection(org.jfree.chart.entity.EntityCollection) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) Test(org.junit.Test)

Example 29 with ChartRenderingInfo

use of org.jfree.chart.ChartRenderingInfo in project SIMVA-SoS by SESoS.

the class BoxAndWhiskerRendererTest method testBug1572478Vertical.

/**
 * A check for bug 1572478 (for the vertical orientation).
 */
@Test
public void testBug1572478Vertical() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset() {

        @Override
        public Number getQ1Value(int row, int column) {
            return null;
        }

        @Override
        public Number getQ1Value(Comparable rowKey, Comparable columnKey) {
            return null;
        }
    };
    List values = new ArrayList();
    values.add(new Double(1.0));
    values.add(new Double(10.0));
    values.add(new Double(100.0));
    dataset.add(values, "row", "column");
    CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("x"), new NumberAxis("y"), new BoxAndWhiskerRenderer());
    JFreeChart chart = new JFreeChart(plot);
    boolean success;
    try {
        BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, new ChartRenderingInfo());
        g2.dispose();
        success = true;
    } catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) ArrayList(java.util.ArrayList) Rectangle2D(java.awt.geom.Rectangle2D) DefaultBoxAndWhiskerCategoryDataset(org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 30 with ChartRenderingInfo

use of org.jfree.chart.ChartRenderingInfo in project SIMVA-SoS by SESoS.

the class BoxAndWhiskerRendererTest method testDrawWithNullMinOutlier.

/**
 * Draws a chart where the dataset contains a null min outlier value.
 */
@Test
public void testDrawWithNullMinOutlier() {
    boolean success;
    try {
        DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
        dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0), new Double(0.5), new Double(4.5), null, new Double(5.5), null), "S1", "C1");
        CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer());
        ChartRenderingInfo info = new ChartRenderingInfo();
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */
        chart.createBufferedImage(300, 200, info);
        success = true;
    } catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) DefaultBoxAndWhiskerCategoryDataset(org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset) BoxAndWhiskerItem(org.jfree.data.statistics.BoxAndWhiskerItem) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Aggregations

ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)36 Test (org.junit.Test)15 JFreeChart (org.jfree.chart.JFreeChart)14 CategoryAxis (org.jfree.chart.axis.CategoryAxis)11 NumberAxis (org.jfree.chart.axis.NumberAxis)11 CategoryPlot (org.jfree.chart.plot.CategoryPlot)11 DefaultBoxAndWhiskerCategoryDataset (org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset)10 StandardEntityCollection (org.jfree.chart.entity.StandardEntityCollection)8 BoxAndWhiskerItem (org.jfree.data.statistics.BoxAndWhiskerItem)8 BufferedImage (java.awt.image.BufferedImage)7 PrintWriter (java.io.PrintWriter)7 StringWriter (java.io.StringWriter)7 Element (org.dom4j.Element)7 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)7 Rectangle2D (java.awt.geom.Rectangle2D)6 Document (org.dom4j.Document)6 Graphics2D (java.awt.Graphics2D)5 Rectangle (java.awt.Rectangle)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ChartEntity (org.jfree.chart.entity.ChartEntity)4