use of org.jfree.chart.labels.XYItemLabelGenerator in project mzmine2 by mzmine.
the class ScatterPlotRenderer method drawItemLabel.
/**
* Draws an item label.
*
* @param g2 the graphics device.
* @param orientation the orientation.
* @param dataset the dataset.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param x the x coordinate (in Java2D space).
* @param y the y coordinate (in Java2D space).
* @param negative indicates a negative value (which affects the item label position).
*/
protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) {
XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
Font labelFont = getItemLabelFont(series, item);
g2.setFont(labelFont);
String label = generator.generateLabel(dataset, series, item);
if ((label == null) || (label.length() == 0))
return;
// get the label position..
ItemLabelPosition position = null;
if (!negative) {
position = getPositiveItemLabelPosition(series, item);
} else {
position = getNegativeItemLabelPosition(series, item);
}
// work out the label anchor point...
Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation);
FontMetrics metrics = g2.getFontMetrics(labelFont);
int width = SwingUtilities.computeStringWidth(metrics, label) + 2;
int height = metrics.getHeight();
int X = (int) (anchorPoint.getX() - (width / 2));
int Y = (int) (anchorPoint.getY() - (height));
g2.setPaint(searchColor);
g2.fillRect(X, Y, width, height);
super.drawItemLabel(g2, orientation, dataset, series, item, x, y, negative);
}
Aggregations