CategoryLabelEntity vs AxisEntity

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Ted Hill
Posts: 54
Joined: Mon Jun 12, 2006 7:39 pm

CategoryLabelEntity vs AxisEntity

Post by Ted Hill » Fri Aug 14, 2009 7:24 pm

Hello,

I have a ChartMouseListener attached to a ChartPanel.

The mouse listener is used to detect clicks on the x-axis labels.

I developed the code using freechart-1.0.10

In that environment the following code would assign the x-axis label that the user clicked on to 'selectedKey' in the snippet below.

Code: Select all

        public void chartMouseClicked(ChartMouseEvent event)
        {
            ChartEntity entity = event.getEntity();

            // if user has clicked on an x-axis label
            if (entity instanceof CategoryLabelEntity)
            {
                selectedKey = ((CategoryLabelEntity)entity).getKey();
            }
Now, using jfreechart-1.0.13 this no longer works.

event.getEntity() now returns an AxisEntity instead of a CategoryLabelEntity

Does anyone know how to get the label that the user clicked on from the AxisEntity?

For example, if the lables along the x-axis are " 1 2 3 4 5 6 "

and the user clicks on 3, how can I get that?

There is no getKey() method on AxisEntity.

Thanks.
Ted Hill

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: CategoryLabelEntity vs AxisEntity

Post by paradoxoff » Fri Aug 14, 2009 8:07 pm

That is a bug which was introduced with the AxisEntities. The hot spot for the axis entity of a CategoryAxis is placed on top of the entities for the category labels and thus "hides" them.
In order to fix it, you need to exchange the following lines in the draw() method of the CategoryAxis class

Code: Select all

// draw the category labels and axis label
state = drawCategoryLabels(g2, plotArea, dataArea, edge, state,plotState);
state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state);
createAndAddEntity(cursor, state, dataArea, edge, plotState);
with the following

Code: Select all

createAndAddEntity(cursor, state, dataArea, edge, plotState);
// draw the category labels and axis label
state = drawCategoryLabels(g2, plotArea, dataArea, edge, state,plotState);
state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state);
This fix will be included in the next release.

Ted Hill
Posts: 54
Joined: Mon Jun 12, 2006 7:39 pm

Re: CategoryLabelEntity vs AxisEntity

Post by Ted Hill » Fri Aug 14, 2009 8:17 pm

Thanks for the quick response.

Do you know when the next release with the fix will be available?

Thanks again.
Ted Hill

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: CategoryLabelEntity vs AxisEntity

Post by paradoxoff » Sat Aug 15, 2009 10:14 am

Sorry, no idea.
If David maintains the update cycle of 3-4 month between releases, it probably won´t take long.

Ted Hill
Posts: 54
Joined: Mon Jun 12, 2006 7:39 pm

Re: CategoryLabelEntity vs AxisEntity

Post by Ted Hill » Fri Oct 02, 2009 2:52 pm

Any idea as to when 1.0.14 will be realeased and if it will fix the bug described above?

Thanks.
Ted Hill

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

Re: CategoryLabelEntity vs AxisEntity

Post by david.gilbert » Mon Oct 05, 2009 10:12 pm

I'm pretty sure this fix is in Subversion. JFreeChart 1.0.14 is late because I've started a new job, I am sadly no longer able to afford to work on JFreeChart full time. I hope I will get a release done this month, but it depends on a lot of things that aren't under my control.
David Gilbert
JFreeChart Project Leader

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

Locked