Bug [ 746512 ] closed but not fixed?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
pietschy
Posts: 2
Joined: Mon Jun 02, 2003 8:39 am

Bug [ 746512 ] closed but not fixed?

Post by pietschy » Tue Jul 15, 2003 1:05 am

Howdy, I noticed that bug 746512 ChartRenderingInfo incorrect after chart resized has been closed. I eagerly downloaded 0.9.9 and tried it out, but I'm still seeing the same problem.

Is there a recommended way to determine the category from a mouse click (ie should I be calling a translatePoint(p) style method?).

Cheers
Andrew

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 » Tue Jul 15, 2003 9:31 am

Here is the code from the mouseClicked(...) method in the ChartPanel:

Code: Select all

    public void mouseClicked(MouseEvent event) {

        Insets insets = getInsets();
        int x = (int) ((event.getX() - insets.left) / scaleX);
        int y = (int) ((event.getY() - insets.top) / scaleY);

        // old 'handle click' code...
        chart.handleClick(x, y, this.info);

        // new entity code...
        if (this.chartMouseListeners.isEmpty()) {
            return;
        }

        ChartEntity entity = this.info.getEntityCollection().getEntity(x, y);
        ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event, entity);

        Iterator iterator = chartMouseListeners.iterator();
        while (iterator.hasNext()) {
            ChartMouseListener listener = (ChartMouseListener) iterator.next();
            listener.chartMouseClicked(chartEvent);
        }

    }
Notice how the x and y values are transformed before they are used to determine the entity at that location on the chart. That's important, because sometimes the chart is drawn at a larger size than the panel, then scaled down to fit, OR the chart is drawn at a smaller size than the panel and scaled up to fit.
David Gilbert
JFreeChart Project Leader

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

pietschy
Posts: 2
Joined: Mon Jun 02, 2003 8:39 am

Post by pietschy » Tue Jul 15, 2003 10:49 am

Thanks for that, I also discovered your translateScreenToJava2D(p) that does just what you mentioned (I couldn't do it as you demonstrated since the scaleX/Y and insets members are private). So now when I override the display I do the following...

Code: Select all

public displayPopupMenu(int x, int y)
{
  
    Point2D p2d = translateScreenToJava2D(new Point(x, y));
     
    doStuffWithThePoint(p2d); 

     // now display the menu...
    ...

}
Which works like a charm. Thanks for your help.
(c:

Cheers
Andrew

Irv Thomae

Post by Irv Thomae » Tue Jul 15, 2003 8:53 pm

I'm really glad Andrew mentioned that, because it's been bothering me too that ChartPanel's scale{X,Y} and insets are private, without getxxx() methods.
When I started experimenting with Entities in 0.9.8, I made my own version of the ChartPanel class, identical to the "real thing" except with getters added for those members. Obviously that's not a sustainable approach as time and jFeeChart march forward.
Does translateScreenToJava2D(p) really do all that is required?

And on another topic which in my mind is quite closely related, is there any way we can "freeze" the dimensions of the actual plot area so that it won't change as the ValueLabels change in size with autoscaling?
It's a real problem in customized multiple plots, where the horizontal axes _should_ all match up.

Irv

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 Jul 17, 2003 11:09 pm

Hi Irv,

The translateScreenToJava2D(...) method covers all the requirements I can think of, but let me know what you are trying to do and I'll look at it.

The "dynamic" nature of the plot area is a difficult problem to solve, because JFreeChart has been designed that way around. You could try experimenting with the setFixedDimension(...) method in the Axis class...it is used with combined charts to align the axes, the problem is to determine the appropriate dimension.
David Gilbert
JFreeChart Project Leader

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

notme
Posts: 4
Joined: Tue Mar 07, 2006 1:29 am

Post by notme » Thu Mar 16, 2006 11:31 pm

[quote="pietschy"]Thanks for that, I also discovered your translateScreenToJava2D(p) that does just what you mentioned (I couldn't do it as you demonstrated since the scaleX/Y and insets members are private). So now when I override the display I do the following...

[code]
public displayPopupMenu(int x, int y)
{

Point2D p2d = translateScreenToJava2D(new Point(x, y));

doStuffWithThePoint(p2d);

// now display the menu...
...

}
[/code]

Which works like a charm. Thanks for your help.
(c:

Cheers
Andrew[/quote]

Locked