Example usage for org.jfree.chart.title TextTitle getPosition

List of usage examples for org.jfree.chart.title TextTitle getPosition

Introduction

In this page you can find the example usage for org.jfree.chart.title TextTitle getPosition.

Prototype

public RectangleEdge getPosition() 

Source Link

Document

Returns the position of the title.

Usage

From source file:net.sf.dynamicreports.test.jasper.chart.ChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);// w ww.  j a  v  a  2s .  c  om

    chartCountTest("summary.chart1", 1);
    JFreeChart chart = getChart("summary.chart1", 0);

    TextTitle title = chart.getTitle();
    Assert.assertEquals("title", "title", title.getText());
    Assert.assertEquals("title color", Color.BLUE, title.getPaint());
    Assert.assertEquals("title font", new Font("Arial", Font.BOLD, 10), title.getFont());
    Assert.assertEquals("title position", RectangleEdge.RIGHT, title.getPosition());

    TextTitle subtitle = (TextTitle) chart.getSubtitle(1);
    Assert.assertEquals("subtitle", "subtitle", subtitle.getText());
    Assert.assertEquals("subtitle color", Color.CYAN, subtitle.getPaint());
    Assert.assertEquals("subtitle font", new Font("Arial", Font.PLAIN, 10), subtitle.getFont());

    LegendTitle legend = (LegendTitle) chart.getSubtitle(0);
    Assert.assertEquals("legend color", Color.BLUE, legend.getItemPaint());
    Assert.assertEquals("legend backgroundcolor", Color.LIGHT_GRAY, legend.getBackgroundPaint());
    Assert.assertEquals("legend font", new Font("Courier New", Font.PLAIN, 10), legend.getItemFont());
    Assert.assertEquals("legend position", RectangleEdge.LEFT, legend.getPosition());

    chartCountTest("summary.chart2", 1);
    chart = getChart("summary.chart2", 0);
    Assert.assertNull("legend", chart.getLegend());
    Assert.assertEquals("plot orientation", PlotOrientation.HORIZONTAL,
            chart.getCategoryPlot().getOrientation());
    Assert.assertEquals("plot series colors", Color.BLUE, chart.getPlot().getDrawingSupplier().getNextPaint());
    Assert.assertEquals("plot series colors", Color.GREEN, chart.getPlot().getDrawingSupplier().getNextPaint());
    Assert.assertEquals("plot series colors", Color.RED, chart.getPlot().getDrawingSupplier().getNextPaint());
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, double shiftX, double shiftY) {
    //       g2.setPaint(Color.white);
    //      g2.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
    //      if (getChart() != null) {
    ////         Image chartImage = getChart().createBufferedImage((int) area.getWidth(),
    ////               (int) area.getHeight());
    ////         g2.drawImage(chartImage, (int) area.getMinX(), (int) area.getMinY(), 
    ////               this);
    //         getChart().draw(g2, area, getAnchor(), null);
    //         ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), maskList, 
    //               null, getChart());
    //      }//from ww w.  j a v a  2 s . co m
    double widthRatio = area.getWidth() / getWidth();
    double heightRatio = area.getHeight() / getHeight();
    double overallRatio = 1;
    overallRatio = widthRatio < heightRatio ? widthRatio : heightRatio;

    XYPlot plot = (XYPlot) getChart().getPlot();
    Font domainFont = plot.getDomainAxis().getLabelFont();
    int domainSize = domainFont.getSize();
    Font rangeFont = plot.getRangeAxis().getLabelFont();
    int rangeSize = rangeFont.getSize();
    TextTitle titleBlock = getChart().getTitle();
    Font titleFont = null;
    int titleSize = 0;
    if (titleBlock != null) {
        titleFont = titleBlock.getFont();
        titleSize = titleFont.getSize();
        getChart().getTitle().setFont(titleFont.deriveFont((float) (titleSize * overallRatio)));
    }
    Font domainScaleFont = plot.getDomainAxis().getTickLabelFont();
    int domainScaleSize = domainScaleFont.getSize();
    Font rangeScaleFont = plot.getRangeAxis().getTickLabelFont();
    int rangeScaleSize = rangeScaleFont.getSize();
    plot.getDomainAxis().setLabelFont(domainFont.deriveFont((float) (domainSize * overallRatio)));
    plot.getRangeAxis().setLabelFont(rangeFont.deriveFont((float) (rangeSize * overallRatio)));
    plot.getDomainAxis().setTickLabelFont(domainScaleFont.deriveFont((float) (domainScaleSize * overallRatio)));
    plot.getRangeAxis().setTickLabelFont(rangeScaleFont.deriveFont((float) (rangeScaleSize * overallRatio)));
    LegendTitle legend = getChart().getLegend();
    Font legendFont = null;
    int legendFontSize = 0;
    if (legend != null) {
        legendFont = legend.getItemFont();
        legendFontSize = legendFont.getSize();
        legend.setItemFont(legendFont.deriveFont((float) (legendFontSize * overallRatio)));
    }

    Rectangle2D chartArea = (Rectangle2D) area.clone();
    getChart().getPadding().trim(chartArea);
    if (titleBlock != null) {
        AxisUtilities.trimTitle(chartArea, g2, titleBlock, titleBlock.getPosition());
    }

    Axis scaleAxis = null;
    Font scaleAxisFont = null;
    int scaleAxisFontSize = 0;
    for (Object object : getChart().getSubtitles()) {
        Title title = (Title) object;
        if (title instanceof PaintScaleLegend) {
            scaleAxis = ((PaintScaleLegend) title).getAxis();
            scaleAxisFont = scaleAxis.getTickLabelFont();
            scaleAxisFontSize = scaleAxisFont.getSize();
            scaleAxis.setTickLabelFont(scaleAxisFont.deriveFont((float) (scaleAxisFontSize * overallRatio)));
        }
        AxisUtilities.trimTitle(chartArea, g2, title, title.getPosition());
    }
    AxisSpace axisSpace = AxisUtilities.calculateAxisSpace(getChart().getXYPlot(), g2, chartArea);
    Rectangle2D dataArea = axisSpace.shrink(chartArea, null);
    getChart().getXYPlot().getInsets().trim(dataArea);
    getChart().getXYPlot().getAxisOffset().trim(dataArea);

    //        Rectangle2D screenArea = getScreenDataArea();
    //        Rectangle2D visibleArea = getVisibleRect();
    //        Rectangle2D printScreenArea = new Rectangle2D.Double(screenArea.getMinX() * overallRatio + x, 
    //              screenArea.getMinY() * overallRatio + y, 
    //              printArea.getWidth() - visibleArea.getWidth() + screenArea.getWidth(), 
    //              printArea.getHeight() - visibleArea.getHeight() + screenArea.getHeight());

    getChart().draw(g2, area, getAnchor(), null);
    ChartMaskingUtilities.drawMasks(g2, dataArea, maskList, null, getChart(), overallRatio);
    ChartMaskingUtilities.drawShapes(g2, dataArea, shapeMap, getChart());
    ChartMaskingUtilities.drawText(g2, dataArea, textContentMap, getChart());
    plot.getDomainAxis().setLabelFont(domainFont);
    plot.getRangeAxis().setLabelFont(rangeFont);
    if (titleBlock != null) {
        titleBlock.setFont(titleFont);
    }
    if (legend != null) {
        legend.setItemFont(legendFont);
    }
    plot.getDomainAxis().setTickLabelFont(domainScaleFont);
    plot.getRangeAxis().setTickLabelFont(rangeScaleFont);
    if (scaleAxis != null) {
        scaleAxis.setTickLabelFont(scaleAxisFont);
    }
    //        System.out.println("print " + titleBlock.getText() + 
    //              " at [" + area.getX() + ", " + area.getY() + ", " + 
    //              area.getWidth() + ", " + area.getHeight() + "]");
}