org.jfree.chart.ChartRenderingInfo Java Examples

The following examples show how to use org.jfree.chart.ChartRenderingInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BoxAndWhiskerRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws a chart where the dataset contains a null mean value.
 */
public void testDrawWithNullMean() {
    boolean success = false;
    try {
        DefaultBoxAndWhiskerCategoryDataset dataset 
                = new DefaultBoxAndWhiskerCategoryDataset();
        dataset.add(new BoxAndWhiskerItem(null, new Double(2.0),
                new Double(0.0), new Double(4.0), new Double(0.5), 
                new Double(4.5), new Double(-0.5), 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);
}
 
Example #2
Source File: BoxAndWhiskerRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws a chart where the dataset contains a null median value.
 */
@Test
public void testDrawWithNullMedian() {
    boolean success;
    try {
        DefaultBoxAndWhiskerCategoryDataset dataset
                = new DefaultBoxAndWhiskerCategoryDataset();
        dataset.add(new BoxAndWhiskerItem(new Double(1.0), null,
                new Double(0.0), new Double(4.0), new Double(0.5),
                new Double(4.5), new Double(-0.5), 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);
}
 
Example #3
Source File: TaScrollHandlerFX.java    From TAcharting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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(TaChartCanvas canvas, Zoomable zoomable,
                            ScrollEvent e) {
    // don't zoom unless the mouse pointer is in the plot's org.sjwimmer.tacharting.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 (canvas.isDomainZoomable()) {
            zoomable.zoomDomainAxes(zf, pinfo, p, true);
        }
        if (canvas.isRangeZoomable()) {
            zoomable.zoomRangeAxes(zf, pinfo, p, true);
        }
        plot.setNotify(notifyState);  // this generates the change event too
    }
}
 
Example #4
Source File: ChartGestureMouseAdapterFX.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * 
 * @param chartPanel
 * @param x
 * @param y
 * @return
 */
private ChartEntity findChartEntity(MouseEventWrapper e) {
  // TODO check if insets were needed
  // coordinates to find chart entities
  int x = (int) ((e.getX()) / chartViewer.getCanvas().getScaleX());
  int y = (int) ((e.getY()) / chartViewer.getCanvas().getScaleY());

  if (lastEntity != null && x == lastEntityX && y == lastEntityY)
    return lastEntity;
  else {
    ChartRenderingInfo info = chartViewer.getCanvas().getRenderingInfo();
    ChartEntity entity = null;
    if (info != null) {
      EntityCollection entities = info.getEntityCollection();
      if (entities != null) {
        entity = entities.getEntity(x, y);
      }
    }
    return entity;
  }
}
 
Example #5
Source File: PlotRenderingInfoTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    PlotRenderingInfo p1 = new PlotRenderingInfo(new ChartRenderingInfo());
    p1.setPlotArea(new Rectangle2D.Double());
    PlotRenderingInfo p2 = (PlotRenderingInfo) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // check independence
    p1.getPlotArea().setRect(1.0, 2.0, 3.0, 4.0);
    assertFalse(p1.equals(p2));
    p2.getPlotArea().setRect(1.0, 2.0, 3.0, 4.0);
    assertTrue(p1.equals(p2));

    p1.getDataArea().setRect(4.0, 3.0, 2.0, 1.0);
    assertFalse(p1.equals(p2));
    p2.getDataArea().setRect(4.0, 3.0, 2.0, 1.0);
    assertTrue(p1.equals(p2));
}
 
Example #6
Source File: BoxAndWhiskerRendererTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a chart where the dataset contains a null min regular value.
 */
@Test
public void testDrawWithNullMinRegular() {
    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), null,
                new Double(4.5), new Double(-0.5), 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);
}
 
Example #7
Source File: TooltipHandlerFX.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #8
Source File: BoxAndWhiskerRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a chart where the dataset contains a null max regular value.
 */
@Test
public void testDrawWithNullMaxRegular() {
    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),
                null, new Double(-0.5), 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);
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #9
Source File: BoxAndWhiskerRendererTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a chart where the dataset contains a null median value.
 */
@Test
public void testDrawWithNullMedian() {
    boolean success;
    try {
        DefaultBoxAndWhiskerCategoryDataset dataset
                = new DefaultBoxAndWhiskerCategoryDataset();
        dataset.add(new BoxAndWhiskerItem(new Double(1.0), null,
                new Double(0.0), new Double(4.0), new Double(0.5),
                new Double(4.5), new Double(-0.5), 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);
}
 
Example #10
Source File: TooltipHandlerFX.java    From jfreechart-fx with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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}).
  */
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();
}
 
Example #11
Source File: ChartLogics.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * 
 * @param chart
 * @param mx mouse coordinates
 * @param my mouse coordinates
 * @return
 */
public static ChartEntity findChartEntity(ChartPanel chart, double mx, double my) {
  // TODO check if insets were needed
  // coordinates to find chart entities
  Insets insets = chart.getInsets();
  int x = (int) ((mx - insets.left) / chart.getScaleX());
  int y = (int) ((my - insets.top) / chart.getScaleY());

  ChartRenderingInfo info = chart.getChartRenderingInfo();
  ChartEntity entity = null;
  if (info != null) {
    EntityCollection entities = info.getEntityCollection();
    if (entities != null) {
      entity = entities.getEntity(x, y);
    }
  }
  return entity;
}
 
Example #12
Source File: EESGenerator.java    From SensorWebClient with GNU General Public License v2.0 6 votes vote down vote up
@Override
public RepresentationResponse producePresentation(DesignOptions options) throws GeneratorException {
    ChartRenderingInfo renderingInfo = new ChartRenderingInfo(new StandardEntityCollection());
    String chartUrl = createChart(options, renderingInfo);
    
    Rectangle2D plotArea = renderingInfo.getPlotInfo().getDataArea();
    for (Axis axis : renderer.getAxisMapping().values()) {
        axis.setMaxY(plotArea.getMaxY());
        axis.setMinY(plotArea.getMinY());
    }

    ImageEntity[] entities = {};
    if (!this.isOverview) {
        LOGGER.debug("Produced EES diagram " + chartUrl);
        entities = createImageEntities(renderingInfo.getEntityCollection());
    } else {
        LOGGER.debug("Produced EES Overview diagram " + chartUrl);
    }

    Bounds chartArea = new Bounds(plotArea.getMinX(), plotArea.getMaxX(), plotArea.getMinY(), plotArea.getMaxY());
    return new EESDataResponse(chartUrl, options, chartArea, entities, renderer.getAxisMapping());
}
 
Example #13
Source File: Generator.java    From SensorWebClient with GNU General Public License v2.0 6 votes vote down vote up
protected String createAndSaveImage(DesignOptions options, JFreeChart chart, ChartRenderingInfo renderingInfo) throws GeneratorException {
    int width = options.getWidth();
    int height = options.getHeight();
    BufferedImage image = chart.createBufferedImage(width, height, renderingInfo);
    Graphics2D chartGraphics = image.createGraphics();
    chartGraphics.setColor(Color.white);
    chartGraphics.fillRect(0, 0, width, height);
    chart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height));

    try {
        return ServletUtilities.saveChartAsPNG(chart, width, height, renderingInfo, null);
    }
    catch (IOException e) {
        throw new GeneratorException("Could not save PNG!", e);
    }
}
 
Example #14
Source File: BoxAndWhiskerRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws a chart where the dataset contains a null max regular value.
 */
public void testDrawWithNullMaxRegular() {
    boolean success = false;
    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),
                null, new Double(-0.5), 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);
}
 
Example #15
Source File: BoxAndWhiskerRendererTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws a chart where the dataset contains a null median value.
 */
@Test
public void testDrawWithNullMedian() {
    boolean success;
    try {
        DefaultBoxAndWhiskerCategoryDataset dataset
                = new DefaultBoxAndWhiskerCategoryDataset();
        dataset.add(new BoxAndWhiskerItem(new Double(1.0), null,
                new Double(0.0), new Double(4.0), new Double(0.5),
                new Double(4.5), new Double(-0.5), 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);
}
 
Example #16
Source File: BoxAndWhiskerRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws a chart where the dataset contains a null Q3 value.
 */
public void testDrawWithNullQ3() {
    boolean success = false;
    try {
        DefaultBoxAndWhiskerCategoryDataset dataset 
                = new DefaultBoxAndWhiskerCategoryDataset();
        dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0),
                new Double(3.0), null, new Double(0.5), 
                new Double(4.5), new Double(-0.5), 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);
}
 
Example #17
Source File: ScrollHandlerFX.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
        }
        plot.setNotify(notifyState);  // this generates the change event too
    } 
}
 
Example #18
Source File: TooltipHandlerFX.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #19
Source File: BoxAndWhiskerRendererTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a chart where the dataset contains a null mean value.
 */
@Test
public void testDrawWithNullMean() {
    boolean success;
    try {
        DefaultBoxAndWhiskerCategoryDataset dataset
                = new DefaultBoxAndWhiskerCategoryDataset();
        dataset.add(new BoxAndWhiskerItem(null, new Double(2.0),
                new Double(0.0), new Double(4.0), new Double(0.5),
                new Double(4.5), new Double(-0.5), 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);
}
 
Example #20
Source File: BoxAndWhiskerRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a chart where the dataset contains a null Q3 value.
 */
@Test
public void testDrawWithNullQ3() {
    boolean success;
    try {
        DefaultBoxAndWhiskerCategoryDataset dataset
                = new DefaultBoxAndWhiskerCategoryDataset();
        dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0),
                new Double(3.0), null, new Double(0.5),
                new Double(4.5), new Double(-0.5), 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);
}
 
Example #21
Source File: ImageMapUtilities.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Writes an image map to an output stream.
 *
 * @param writer  the writer (<code>null</code> not permitted).
 * @param name  the map name (<code>null</code> not permitted).
 * @param info  the chart rendering info (<code>null</code> not permitted).
 * @param useOverLibForToolTips  whether to use OverLIB for tooltips
 *                               (http://www.bosrup.com/web/overlib/).
 *
 * @throws java.io.IOException if there are any I/O errors.
 */
public static void writeImageMap(PrintWriter writer,
        String name, ChartRenderingInfo info,
        boolean useOverLibForToolTips) throws IOException {

    ToolTipTagFragmentGenerator toolTipTagFragmentGenerator;
    if (useOverLibForToolTips) {
        toolTipTagFragmentGenerator
                = new OverLIBToolTipTagFragmentGenerator();
    }
    else {
        toolTipTagFragmentGenerator
                = new StandardToolTipTagFragmentGenerator();
    }
    ImageMapUtilities.writeImageMap(writer, name, info,
            toolTipTagFragmentGenerator,
            new StandardURLTagFragmentGenerator());

}
 
Example #22
Source File: ImageMapUtilities.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Writes an image map to an output stream.
 *
 * @param writer  the writer (<code>null</code> not permitted).
 * @param name  the map name (<code>null</code> not permitted).
 * @param info  the chart rendering info (<code>null</code> not permitted).
 * @param useOverLibForToolTips  whether to use OverLIB for tooltips
 *                               (http://www.bosrup.com/web/overlib/).
 *
 * @throws java.io.IOException if there are any I/O errors.
 */
public static void writeImageMap(PrintWriter writer,
        String name, ChartRenderingInfo info,
        boolean useOverLibForToolTips) throws IOException {

    ToolTipTagFragmentGenerator toolTipTagFragmentGenerator;
    if (useOverLibForToolTips) {
        toolTipTagFragmentGenerator
                = new OverLIBToolTipTagFragmentGenerator();
    }
    else {
        toolTipTagFragmentGenerator
                = new StandardToolTipTagFragmentGenerator();
    }
    ImageMapUtilities.writeImageMap(writer, name, info,
            toolTipTagFragmentGenerator,
            new StandardURLTagFragmentGenerator());

}
 
Example #23
Source File: ImageMapUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Writes an image map to an output stream.
 *
 * @param writer  the writer (<code>null</code> not permitted).
 * @param name  the map name (<code>null</code> not permitted).
 * @param info  the chart rendering info (<code>null</code> not permitted).
 * @param useOverLibForToolTips  whether to use OverLIB for tooltips
 *                               (http://www.bosrup.com/web/overlib/).
 *
 * @throws java.io.IOException if there are any I/O errors.
 */
public static void writeImageMap(PrintWriter writer,
                                 String name,
                                 ChartRenderingInfo info,
                                 boolean useOverLibForToolTips) 
    throws IOException {

    ToolTipTagFragmentGenerator toolTipTagFragmentGenerator = null;
    if (useOverLibForToolTips) {
        toolTipTagFragmentGenerator 
                = new OverLIBToolTipTagFragmentGenerator();
    }
    else {
        toolTipTagFragmentGenerator 
                = new StandardToolTipTagFragmentGenerator();
    }
    ImageMapUtilities.writeImageMap(writer, name, info, 
            toolTipTagFragmentGenerator, 
            new StandardURLTagFragmentGenerator());

}
 
Example #24
Source File: ScrollHandlerFX.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
        }
        plot.setNotify(notifyState);  // this generates the change event too
    } 
}
 
Example #25
Source File: StandardXYItemRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check to ensure that an item that falls outside the plot's data area
 * does NOT generate an item entity.
 */
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));
}
 
Example #26
Source File: TooltipHandlerFX.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #27
Source File: StandardXYItemRendererTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
}
 
Example #28
Source File: ServletUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Saves the chart as a PNG format file in the temporary directory and
 * populates the {@link ChartRenderingInfo} object which can be used to 
 * generate an HTML image map.
 *
 * @param chart  the chart to be saved (<code>null</code> not permitted).
 * @param width  the width of the chart.
 * @param height  the height of the chart.
 * @param info  the ChartRenderingInfo object to be populated 
 *              (<code>null</code> permitted).
 * @param session  the HttpSession of the client (if <code>null</code>, the
 *                 temporary file is marked as "one-time" and deleted by 
 *                 the {@link DisplayChart} servlet right after it is
 *                 streamed to the client).
 *
 * @return The filename of the chart saved in the temporary directory.
 *
 * @throws IOException if there is a problem saving the file.
 */
public static String saveChartAsPNG(JFreeChart chart, int width, int height,
        ChartRenderingInfo info, HttpSession session) throws IOException {

    if (chart == null) {
        throw new IllegalArgumentException("Null 'chart' argument.");   
    }
    ServletUtilities.createTempDir();
    String prefix = ServletUtilities.tempFilePrefix;
    if (session == null) {
        prefix = ServletUtilities.tempOneTimeFilePrefix;
    }
    File tempFile = File.createTempFile(prefix, ".png", 
            new File(System.getProperty("java.io.tmpdir")));
    ChartUtilities.saveChartAsPNG(tempFile, chart, width, height, info);
    if (session != null) {
        ServletUtilities.registerChartForDeletion(tempFile, session);
    }
    return tempFile.getName();

}
 
Example #29
Source File: ChartLogics.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * 
 * @param chart
 * @param mx mouse coordinates
 * @param my mouse coordinates
 * @return
 */
public static ChartEntity findChartEntity(ChartPanel chart, double mx, double my) {
  // TODO check if insets were needed
  // coordinates to find chart entities
  Insets insets = chart.getInsets();
  int x = (int) ((mx - insets.left) / chart.getScaleX());
  int y = (int) ((my - insets.top) / chart.getScaleY());

  ChartRenderingInfo info = chart.getChartRenderingInfo();
  ChartEntity entity = null;
  if (info != null) {
    EntityCollection entities = info.getEntityCollection();
    if (entities != null) {
      entity = entities.getEntity(x, y);
    }
  }
  return entity;
}
 
Example #30
Source File: ChartLogicsFX.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * 
 * @param chart
 * @return
 */
public static ChartEntity findChartEntity(ChartCanvas chart, double mx, double my) {
  // TODO check if insets were needed
  // coordinates to find chart entities
  int x = (int) (mx / chart.getScaleX());
  int y = (int) (my / chart.getScaleY());

  ChartRenderingInfo info = chart.getRenderingInfo();
  ChartEntity entity = null;
  if (info != null) {
    EntityCollection entities = info.getEntityCollection();
    if (entities != null) {
      entity = entities.getEntity(x, y);
    }
  }
  return entity;
}