Java Code Examples for org.jfree.chart.text.TextUtilities#drawAlignedString()

The following examples show how to use org.jfree.chart.text.TextUtilities#drawAlignedString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShortTextTitle.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the title using the current font and paint.
 *
 * @param g2  the graphics target.
 * @param area  the title area.
 * @param params  optional parameters (ignored here).
 *
 * @return <code>null</code>.
 */
public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
    if (area.isEmpty()) {
        return null;
    }
    area = trimMargin(area);
    drawBorder(g2, area);
    area = trimBorder(area);
    area = trimPadding(area);
    g2.setFont(getFont());
    g2.setPaint(getPaint());
    TextUtilities.drawAlignedString(getText(), g2, (float) area.getMinX(),
            (float) area.getMinY(), TextAnchor.TOP_LEFT);

    return null;
}
 
Example 2
Source File: DialTextAnnotation.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been 
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted). 
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, 
            this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(this.label, g2, (float) pt.getX(), 
            (float) pt.getY(), this.anchor);
    
}
 
Example 3
Source File: jKali_000_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 4
Source File: jKali_0031_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 5
Source File: Chart_1_AbstractCategoryItemRenderer_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 6
Source File: Cardumen_00139_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 7
Source File: JGenProg2017_00124_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 8
Source File: jMutRepair_000_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 9
Source File: AbstractCategoryItemRenderer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 10
Source File: patch1-Chart-1-jMutRepair_patch1-Chart-1-jMutRepair_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 11
Source File: Cardumen_0075_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 12
Source File: StandardDialScale.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the scale on the dial plot.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not
 *     permitted).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.tickRadius, this.tickRadius);
    Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame,
            this.tickRadius - this.majorTickLength,
            this.tickRadius - this.majorTickLength);
    Rectangle2D arcRectMinor = arcRect;
    if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
        arcRectMinor = DialPlot.rectangleByRadius(frame,
                this.tickRadius - this.minorTickLength,
                this.tickRadius - this.minorTickLength);
    }
    Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame,
            this.tickRadius - this.tickLabelOffset,
            this.tickRadius - this.tickLabelOffset);

    boolean firstLabel = true;

    Arc2D arc = new Arc2D.Double();
    Line2D workingLine = new Line2D.Double();
    for (double v = this.lowerBound; v <= this.upperBound;
            v += this.majorTickIncrement) {
        arc.setArc(arcRect, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt0 = arc.getEndPoint();
        arc.setArc(arcRectMajor, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt1 = arc.getEndPoint();
        g2.setPaint(this.majorTickPaint);
        g2.setStroke(this.majorTickStroke);
        workingLine.setLine(pt0, pt1);
        g2.draw(workingLine);
        arc.setArc(arcRectForLabels, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt2 = arc.getEndPoint();

        if (this.tickLabelsVisible) {
            if (!firstLabel || this.firstTickLabelVisible) {
                g2.setFont(this.tickLabelFont);
                g2.setPaint(this.tickLabelPaint);
                TextUtilities.drawAlignedString(
                        this.tickLabelFormatter.format(v), g2,
                        (float) pt2.getX(), (float) pt2.getY(),
                        TextAnchor.CENTER);
            }
        }
        firstLabel = false;

        // now do the minor tick marks
        if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
            double minorTickIncrement = this.majorTickIncrement
                    / (this.minorTickCount + 1);
            for (int i = 0; i < this.minorTickCount; i++) {
                double vv = v + ((i + 1) * minorTickIncrement);
                if (vv >= this.upperBound) {
                    break;
                }
                double angle = valueToAngle(vv);

                arc.setArc(arcRect, this.startAngle, angle
                        - this.startAngle, Arc2D.OPEN);
                pt0 = arc.getEndPoint();
                arc.setArc(arcRectMinor, this.startAngle, angle
                        - this.startAngle, Arc2D.OPEN);
                Point2D pt3 = arc.getEndPoint();
                g2.setStroke(this.minorTickStroke);
                g2.setPaint(this.minorTickPaint);
                workingLine.setLine(pt0, pt3);
                g2.draw(workingLine);
            }
        }

    }
}
 
Example 13
Source File: DialValueIndicator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been 
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted). 
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, 
            this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();
    
    // calculate the bounds of the template value
    FontMetrics fm = g2.getFontMetrics(this.font);
    String s = this.formatter.format(this.templateValue);
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);

    // align this rectangle to the frameAnchor
    Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(
            tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), 
            this.frameAnchor);
    
    // add the insets
    Rectangle2D fb = this.insets.createOutsetRectangle(bounds);

    // draw the background
    g2.setPaint(this.backgroundPaint);
    g2.fill(fb);

    // draw the border
    g2.setStroke(this.outlineStroke);
    g2.setPaint(this.outlinePaint);
    g2.draw(fb);
    
    
    // now find the text anchor point
    double value = plot.getValue(this.datasetIndex);
    String valueStr = this.formatter.format(value);
    Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor);
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), 
            (float) pt2.getY(), this.textAnchor);
    
}
 
Example 14
Source File: DialValueIndicator.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius,
            this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();

    // the indicator bounds is calculated from the templateValue (which
    // determines the minimum size), the maxTemplateValue (which, if
    // specified, provides a maximum size) and the actual value
    FontMetrics fm = g2.getFontMetrics(this.font);
    double value = plot.getValue(this.datasetIndex);
    String valueStr = this.formatter.format(value);
    Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm);

    // calculate the bounds of the template value
    String s = this.formatter.format(this.templateValue);
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);
    double minW = tb.getWidth();
    double minH = tb.getHeight();

    double maxW = Double.MAX_VALUE;
    double maxH = Double.MAX_VALUE;
    if (this.maxTemplateValue != null) {
        s = this.formatter.format(this.maxTemplateValue);
        tb = TextUtilities.getTextBounds(s, g2, fm);
        maxW = Math.max(tb.getWidth(), minW);
        maxH = Math.max(tb.getHeight(), minH);
    }
    double w = fixToRange(valueBounds.getWidth(), minW, maxW);
    double h = fixToRange(valueBounds.getHeight(), minH, maxH);

    // align this rectangle to the frameAnchor
    Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(w, h),
            pt.getX(), pt.getY(), this.frameAnchor);

    // add the insets
    Rectangle2D fb = this.insets.createOutsetRectangle(bounds);

    // draw the background
    g2.setPaint(this.backgroundPaint);
    g2.fill(fb);

    // draw the border
    g2.setStroke(this.outlineStroke);
    g2.setPaint(this.outlinePaint);
    g2.draw(fb);

    // now find the text anchor point
    Shape savedClip = g2.getClip();
    g2.clip(fb);

    Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor);
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(),
            (float) pt2.getY(), this.textAnchor);
    g2.setClip(savedClip);

}
 
Example 15
Source File: CategoryPointerAnnotation.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 */
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea,
        CategoryAxis domainAxis, ValueAxis rangeAxis) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);
    CategoryDataset dataset = plot.getDataset();
    int catIndex = dataset.getColumnIndex(getCategory());
    int catCount = dataset.getColumnCount();
    double j2DX = domainAxis.getCategoryMiddle(catIndex, catCount, 
            dataArea, domainEdge);
    double j2DY = rangeAxis.valueToJava2D(getValue(), dataArea, rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        double temp = j2DX;
        j2DX = j2DY;
        j2DY = temp;
    }
    double startX = j2DX + Math.cos(this.angle) * this.baseRadius;
    double startY = j2DY + Math.sin(this.angle) * this.baseRadius;

    double endX = j2DX + Math.cos(this.angle) * this.tipRadius;
    double endY = j2DY + Math.sin(this.angle) * this.tipRadius;

    double arrowBaseX = endX + Math.cos(this.angle) * this.arrowLength;
    double arrowBaseY = endY + Math.sin(this.angle) * this.arrowLength;

    double arrowLeftX = arrowBaseX 
        + Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowLeftY = arrowBaseY 
        + Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;

    double arrowRightX = arrowBaseX 
        - Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowRightY = arrowBaseY 
        - Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;

    GeneralPath arrow = new GeneralPath();
    arrow.moveTo((float) endX, (float) endY);
    arrow.lineTo((float) arrowLeftX, (float) arrowLeftY);
    arrow.lineTo((float) arrowRightX, (float) arrowRightY);
    arrow.closePath();

    g2.setStroke(this.arrowStroke);
    g2.setPaint(this.arrowPaint);
    Line2D line = new Line2D.Double(startX, startY, endX, endY);
    g2.draw(line);
    g2.fill(arrow);

    // draw the label
    g2.setFont(getFont());
    g2.setPaint(getPaint());
    double labelX = j2DX 
        + Math.cos(this.angle) * (this.baseRadius + this.labelOffset);
    double labelY = j2DY 
        + Math.sin(this.angle) * (this.baseRadius + this.labelOffset);
    /* Rectangle2D hotspot = */ TextUtilities.drawAlignedString(getText(), 
            g2, (float) labelX, (float) labelY, getTextAnchor());
    // TODO: implement the entity for the annotation
    
}
 
Example 16
Source File: PiePlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 *
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys,
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea,
        PiePlotState state) {

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));

    Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle(
            pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include = true;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right,
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);

            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(),
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();

            PieSectionLabelGenerator labelGenerator = getLabelGenerator();
            if (labelGenerator == null) {
                continue;
            }
            String label = labelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out,
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null
                    && this.shadowGenerator == null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg,
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }

            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(getLabelGenerator()
                    .generateSectionLabel(getDataset(), key), g2, x, y,
                    TextAnchor.CENTER);

        }
    }

    g2.setComposite(originalComposite);

}
 
Example 17
Source File: jKali_0031_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 18
Source File: Arja_000_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 19
Source File: 1_AbstractCategoryItemRenderer.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 20
Source File: Chart_15_PiePlot_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws the pie section labels in the simple form.
 * 
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys, 
        double totalValue, Rectangle2D plotArea, Rectangle2D pieArea, 
        PiePlotState state) {
    
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
            1.0f));

    RectangleInsets labelInsets = new RectangleInsets(UnitType.RELATIVE, 
            0.18, 0.18, 0.18, 0.18);
    Rectangle2D labelsArea = labelInsets.createInsetRectangle(pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include = true;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        }
        else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }

        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right, 
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor()
                    * ((runningTotal - v / 2.0) * 360) / totalValue);
            
            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(), 
                    mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();
            
            PieSectionLabelGenerator labelGenerator = getLabelGenerator();
            if (labelGenerator == null) {
                continue;
            }
            String label = labelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(
                    bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out, 
                    x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg, 
                        this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null 
                    && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }
            
            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(getLabelGenerator()
                    .generateSectionLabel(getDataset(), key), g2, x, y, 
                    TextAnchor.CENTER);
            
        }
    }
   
    g2.setComposite(originalComposite);

}