Search in sources :

Example 6 with XYItemLabelGenerator

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);
}
Also used : Point2D(java.awt.geom.Point2D) FontMetrics(java.awt.FontMetrics) XYItemLabelGenerator(org.jfree.chart.labels.XYItemLabelGenerator) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) Font(java.awt.Font)

Aggregations

XYItemLabelGenerator (org.jfree.chart.labels.XYItemLabelGenerator)6 Paint (java.awt.Paint)3 Rectangle2D (java.awt.geom.Rectangle2D)3 EntityCollection (org.jfree.chart.entity.EntityCollection)3 PlotOrientation (org.jfree.chart.plot.PlotOrientation)3 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)3 RectangleEdge (org.jfree.ui.RectangleEdge)3 Font (java.awt.Font)2 Point2D (java.awt.geom.Point2D)2 ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)2 FontMetrics (java.awt.FontMetrics)1 GradientPaint (java.awt.GradientPaint)1 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)1 TableXYDataset (org.jfree.data.xy.TableXYDataset)1 XYDataset (org.jfree.data.xy.XYDataset)1