Quinn-Curtis Forums
Quinn-Curtis Forums
Home | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Tools for Java
 QCChart2D for Java
 DataToolTip positionning

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
   

T O P I C    R E V I E W
rixmith Posted - 01 Feb 2010 : 10:06:46

The DataToolTip object does not seem to check its postion before drawing itself. For data points that are located close to the top or right edge of the ChartView the tooltip gets clipped.

By default the tooltip seems to be displayed above, and to the right of, the cursor (mouse click) position. Is it possible to set the location to be below, and to the left of the cursor? I'm using a plot area that fills most of the ChartView and I'm most interested in the max and rightmost data.

Ideally this object would draw itself in such a way that the tooltip information is never clipped.



Rick
4   L A T E S T    R E P L I E S    (Newest First)
rixmith Posted - 07 Feb 2010 : 20:39:08
Here's the code. I reference a custom class called LblMultiLine that is not included. Replace this reference with a JLabel to get rid
of any compile errors.

Also, the tooltip attributes (i.e color, font, date format) are hardcoded to the values I want. Ideally the attributes set via the superclass setters would be used.

package myproject.ui.util;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;

import com.quinncurtis.chart2djava.ChartView;
import com.quinncurtis.chart2djava.DataToolTip;
import com.quinncurtis.chart2djava.TimeGroupDataset;
import com.quinncurtis.chart2djava.TimeSimpleDataset;


public class MyDataTooltip extends DataToolTip {
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
private JPopupMenu popMenu = new JPopupMenu();
//replace LbLMultiLine (a custom class)with a JLabel
//to get rid of the compile errors!
private LblMultiLine lblToolTipPrice = new LblMultiLine();
private JLabel lblToolTipTime = new JLabel();
private JComponent parent = null;
private SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MMM yy HH:mm") ;
private DecimalFormat decimalFormatter = new DecimalFormat("0.00");
private Point mouseClickScreenLocation;


public MyDataTooltip(ChartView chart) {
super(chart);

this.parent = (JComponent)chart;
this.popMenu.add(this.lblToolTipTime);
this.popMenu.add(this.lblToolTipPrice);

this.lblToolTipPrice.setOpaque(true);
this.lblToolTipPrice.setBackground(Color.yellow);
this.lblToolTipTime.setOpaque(true);
this.lblToolTipTime.setBackground(Color.yellow);
this.lblToolTipTime.setFont(new Font("SansSerif", Font.BOLD,11));
}

@Override
public void mousePressed(MouseEvent event) {
this.mouseClickScreenLocation = event.getLocationOnScreen();
super.mousePressed(event);


}
@Override
public void mouseReleased(MouseEvent event) {
this.popMenu.setVisible(false);
super.mouseReleased(event);
this.parent.repaint();

}

@Override
public void draw(Graphics2D g2) {

if (this.selectedDataset != null) {

StringBuilder sb = new StringBuilder();
int idx = getNearestPoint().getNearestPointIndex();


if (this.selectedDataset instanceof TimeSimpleDataset) {
lblToolTipTime.setText(" " + dateFormatter.format( ((TimeSimpleDataset)this.selectedDataset).getTimeXDataValue(idx).getTime()) + " " +LINE_SEPARATOR);
sb.append(" Price: " + decimalFormatter.format(((TimeSimpleDataset)this.selectedDataset).getYDataValue(idx)) + " " );
}
else {
lblToolTipTime.setText(" " + dateFormatter.format( ((TimeGroupDataset)this.selectedDataset).getTimeXDataValue(idx).getTime()) + " " + LINE_SEPARATOR);
sb.append(" Open: " + decimalFormatter.format(((TimeGroupDataset)this.selectedDataset).getYDataValue(0, idx)) + " " + LINE_SEPARATOR);
sb.append(" High: " + decimalFormatter.format(((TimeGroupDataset)this.selectedDataset).getYDataValue(1, idx)) + " " +LINE_SEPARATOR);
sb.append(" Low: " + decimalFormatter.format(((TimeGroupDataset)this.selectedDataset).getYDataValue(2, idx)) + " " + LINE_SEPARATOR);
sb.append(" Close: " + decimalFormatter.format(((TimeGroupDataset)this.selectedDataset).getYDataValue(3, idx) ) + " " );
}



lblToolTipPrice.setText(sb.toString());

SwingUtilities.convertPointFromScreen(mouseClickScreenLocation, this.parent);

this.popMenu.show(this.parent, this.mouseClickScreenLocation.x - this.popMenu.getWidth(), this.mouseClickScreenLocation.y );
}
}

}


Rick
quinncurtis Posted - 04 Feb 2010 : 15:23:13
You should post your code. Others would be interested.
rixmith Posted - 04 Feb 2010 : 13:04:09
Thanks for the info.

I subclassed the DataToolTip class and overridded its draw() method.
Instead of writing the tooltip as ChartText on the Chartview, I load the the tooltip text into my own component and place it exactly where I want. This approach seems to work.

Rick
quinncurtis Posted - 01 Feb 2010 : 14:08:24
Sorry, but we not have a variant of the tool tips which auto-justify themselves based on the tool tip location. It sticks to the justification values which have been set. You will have to leave a large enough border around the plotting area to display the tool tip.

Quinn-Curtis Forums © 2000-2018 Quinn-Curtis, Inc. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.07