High Performance Apps

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
gumshoe
Posts: 80
Joined: Mon Jul 12, 2004 6:06 pm

Post by gumshoe » Wed Jul 06, 2005 3:28 pm

I have put the changes into the code posting.

nclemeur
Posts: 7
Joined: Mon Feb 14, 2005 12:35 pm

Tooltip not displayed when Shapes only are shown

Post by nclemeur » Thu Jul 21, 2005 2:00 pm

I have try this XYRenderer and found to work almost correctly, I am still having some problems to display the tooltips on the when the lines are not displayed. It is working when the shapes and lines are drawn or when the lines only are plotted, but not when the shapes are plotted by themself. Does anyone would know how to fix this? This problem does not happen when the native XYLinesAndShapesRenderer is used.

BTW, I have added the two methods below for completness:
public void setToolTipGenerator(XYToolTipGenerator toolTipGenerator) {
super.setToolTipGenerator(toolTipGenerator);
}

public void setURLGenerator(XYURLGenerator urlGenerator) {
super.setURLGenerator(urlGenerator);
}
[/code][/code]

BigWillyStyle42
Posts: 58
Joined: Wed Jun 02, 2004 1:37 pm

Re: Tooltip not displayed when Shapes only are shown

Post by BigWillyStyle42 » Thu Jul 21, 2005 2:49 pm

nclemeur wrote:BTW, I have added the two methods below for completness:

Code: Select all

public void setToolTipGenerator(XYToolTipGenerator toolTipGenerator) {
        super.setToolTipGenerator(toolTipGenerator);
    }
    
    public void setURLGenerator(XYURLGenerator urlGenerator) {
        super.setURLGenerator(urlGenerator);
    }
That does nothing but generate useless code bloat. A function that does nothing but call the its super implementation might as well not be there.

nclemeur
Posts: 7
Joined: Mon Feb 14, 2005 12:35 pm

Post by nclemeur » Fri Jul 22, 2005 2:05 am

Yes you are completeluy right, it was probably a bit too late a night yesterday (I actually tried several things with these methods, but forgot to remove them when realising that the problem was not there).

But, it does not solve the problem of the tooltip not showing up on Shapes only curves. :cry:

nclemeur
Posts: 7
Joined: Mon Feb 14, 2005 12:35 pm

Post by nclemeur » Sat Jul 23, 2005 3:27 am

I think I have found the reason why the tooltip are not generated when only the Shapes are drawn. The bAddEntity is never set to true when only shapes are drawn. So modifying the code like below solves the problem:

Code: Select all

 if (getPlotShapes()) {
            ...
            if (shape.intersects(dataArea)) {
                bAddEntity = true;//<------------------------------Added
                if (getItemShapeFilled(series, item)) {
                    g2.fill(shape);
                }
                else {
                    g2.draw(shape);
                }
            }
            entityArea = shape;
        }

gumshoe
Posts: 80
Joined: Mon Jul 12, 2004 6:06 pm

Post by gumshoe » Mon Jul 25, 2005 3:50 pm

I have edited the code posting to include your fix. Thanks.

gumshoe
Posts: 80
Joined: Mon Jul 12, 2004 6:06 pm

Post by gumshoe » Fri Aug 19, 2005 8:24 pm

Additional bug fix; series containing null Y values would sometimes have lines drawn spanning the null values instead of leaving a gap. This has been fixed and the code posting updated.

gumshoe
Posts: 80
Joined: Mon Jul 12, 2004 6:06 pm

Post by gumshoe » Fri Dec 02, 2005 5:38 pm

Code sample updated to reflect changes in 1.0.0.

uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Post by uvoigt » Tue Dec 06, 2005 12:24 pm

Hi gumshoe,

thanx for updating the changes for 1.0.0. Unfortunately I doesn't run. The renderer is now inherited from StandardXYItemRendererProtected which I cannot find.

Am I missing something?

gumshoe
Posts: 80
Joined: Mon Jul 12, 2004 6:06 pm

Post by gumshoe » Tue Dec 06, 2005 3:17 pm

Oops; my instructions failed to make it clear that you have to make a copy of StandardXYItemRenderer called StandardXYItemRendererProtected which has a number of its private members changed to protected (you can let the IDE figure out which ones are needed or just make them all protected). The optimzed class derives from this and overloads just one method. I figured this was cleaner than posting the whole class again plus it should be easier to update in the future if changes are made to StandardXYItemRenderer.

uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Post by uvoigt » Thu Dec 08, 2005 9:13 am

Yeah, seems to be a reasonable solution. Good work!

uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Post by uvoigt » Wed Dec 14, 2005 4:02 pm

Theres is a remaining bug, which is also located in StandardXYItemRenderer.
Try to render a dataseries containing at least one Double.NaN (not at the border) with drawSeriesLineAsPath=true. The chart is empty.

I have posted the bug (#1380480) including a fix. I hope that David will integrate the fix in 1.0.1.

Testprogramm:

Code: Select all

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
 * A simple demo showing a dataset created using the {@link XYSeriesCollection} class.
 */
public class XYRendererNaNValuesTest
    extends ApplicationFrame
{

    /**
     * A demonstration application showing an XY series containing a null value.
     * 
     * @param title the frame title.
     */
    public XYRendererNaNValuesTest(String title)
    {

        super(title);
        XYDataset dataset = createDataset();
        JFreeChart chart = createChart(dataset);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    }

    private static JFreeChart createChart(XYDataset dataset)
    {
        JFreeChart chart = ChartFactory.createXYLineChart("XY Series Demo", "X", "Y", dataset,
            PlotOrientation.VERTICAL, true, true, false);
        StandardXYItemRenderer renderer = new StandardXYItemRenderer();
        renderer.setDrawSeriesLineAsPath(true);
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
        chart.getXYPlot().setRenderer(renderer);
        return chart;
    }

    private static XYDataset createDataset()
    {
        XYSeries series = new XYSeries("Random Data");
        double t = 0.0;
        double x = 0.0;

        for (int i = 0; i < 10; i++)
        {
            t += Math.random();
            series.add(t, Double.NaN);
        }
        for (int i = 0; i < 200; i++)
        {
            t += Math.random();
            if (i == 120)
            {
                series.add(t, Double.NaN);
                continue;
            }
            double r = Math.random();
            if (r < 0.33)
            {
                x += Math.random();
            }
            else if (r < 0.66)
            {
                x -= Math.random();
            }
            series.add(t, x);
        }

        t += Math.random();
        series.add(t, Double.NaN);
        return new XYSeriesCollection(series);
    }

    public static JPanel createDemoPanel()
    {
        JFreeChart chart = createChart(createDataset());
        return new ChartPanel(chart);
    }

    public static void main(String[] args)
    {
        XYRendererNaNValuesTest demo = new XYRendererNaNValuesTest("XY Series Demo");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);

    }

}

gumshoe
Posts: 80
Joined: Mon Jul 12, 2004 6:06 pm

Post by gumshoe » Wed Jun 14, 2006 5:08 pm

I edited my code posting to include a bug fix. It was possible to get an array index out of bounds exception in certain cases. It came up in my app with large datasets updating live combined with users resizing the chart. I am really looking forward to these mods being merged in.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Jun 15, 2006 12:02 pm

uvoigt wrote:I have posted the bug (#1380480) including a fix. I hope that David will integrate the fix in 1.0.1.
Too late! But I've just committed a fix for this bug which will be included in 1.0.2.

Now to rescan the rest of this thread...
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked