Quinn-Curtis Forums
Quinn-Curtis Forums
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Tools for Java
 QCChart2D for Java
 DataToolTip customization
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rixmith

33 Posts

Posted - 29 Jul 2011 :  12:00:57  Show Profile  Reply with Quote
Hi,

Is there a suggested method to use to hook into the DataToolTip so that I can execute my own code when DataToolTip fails to select a ChartDataset (because the click point is too far from any plot)?

In other words, is there a way of knowning when the threshold distance test fails?




Rick

quinncurtis

1555 Posts

Posted - 29 Jul 2011 :  14:51:35  Show Profile  Reply with Quote
Not really. You can change the hit testing threshold to be whatever you want though.

datatooltip.setHitTestThreshold(50);

The default is 15 pixels.

What is it that you want to do if the hit testing threshold fails?
Go to Top of Page

rixmith

33 Posts

Posted - 30 Jul 2011 :  07:19:40  Show Profile  Reply with Quote
I need the tooltip to appear every time the user clicks on the chart. When the user clicks on the chart and the tooltip threshold test fails I would determine the location on the x-axis that corresponds to the location of the mouse click and display "There is no datapoint for Monday June 23, 1985".

If I have to write my own MouseListener to handle tooltips, what is the best way to convert the x location of the mouse click to a value on the x-axis?

Rick
Go to Top of Page

quinncurtis

1555 Posts

Posted - 30 Jul 2011 :  09:24:03  Show Profile  Reply with Quote
Seems like an inefficient user interface. Having someone click around on a line plot, using the tool tip to find out whether or not there is a data point present. Why not just use a SimpleLineMarkerPlot, instead of a line plot. In a SimpleLineMarkerPlot, a symbol is displayed at every data point, so the user know by simple inspection whether or not a data point is present. He can click on the symbol to get the associated tooltip. No wasted clicks.
Go to Top of Page

rixmith

33 Posts

Posted - 30 Jul 2011 :  10:31:08  Show Profile  Reply with Quote
The interface is not up for debate: the user requires certain tooltip feedback when he clicks the chart, even when there is no datapoint nearby.

I understand from your response that I must roll my own tooltip
to accomplish this behaviour - and that's ok.

Can you assist with a related question: what's the best way to determine the value on the x-axis that corresponds to the mouse click location on the chart?

thanks,

Rick
Go to Top of Page

quinncurtis

1555 Posts

Posted - 30 Jul 2011 :  13:35:09  Show Profile  Reply with Quote
You can subclass the DataTooltip and override the mousePressed method, calling the base method. If the selectedDataset is null, it didn't find a point. It then gets the GregorianCalendar value of the mouse position. Hope this helps.

<Removed Code>
Go to Top of Page

quinncurtis

1555 Posts

Posted - 30 Jul 2011 :  14:09:15  Show Profile  Reply with Quote
That probably wouldn't work, because the actual data point is only calculated after a plot object is found.

So, to do the coordinate conversion you will need to do something like this, using the coordinate system you used for your plot objects.

class CustomToolTip extends DataToolTip {

   public CustomToolTip(ChartView component) {
		super(component);
	}

   public void mousePressed(MouseEvent event) {
       super.mousePressed(event);
       if (this.getSelectedDataset() == null)
       {
      	      ChartPoint2D mousepos = new ChartPoint2D();
       	      mousepos.setLocation(event.getX(), event.getY());

	      ChartPoint2D xvalue =    pTransform1.convertCoord(ChartConstants.PHYS_POS,mousepos , 
       		ChartConstants.DEV_POS);  
	      GregorianCalendar timevalue = xvalue.getCalendarX();
	}
    }		
}
Go to Top of Page

rixmith

33 Posts

Posted - 01 Aug 2011 :  08:45:03  Show Profile  Reply with Quote
Thanks for your help. My DataTooltip subclass is now working as required.

Rick
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Quinn-Curtis Forums © 2000-2018 Quinn-Curtis, Inc. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.07