コード例 #1
0
  private void drawLegend(Context2D context) {
    if (legend != null && drawLegend) {
      legend.setContext(context);
      double tX = 0;
      double tY = 0;
      double offsetTop = calculateOffsetCausedByTitleAndSubtitle(context);
      Legend.LegendPosition position = legend.getPosition();

      if (position.equals(Legend.LegendPosition.LEGEND_POSITION_LEFT)) {
        tX = paddingLeft;
        tY = offsetTop;
      } else if (position.equals(Legend.LegendPosition.LEGEND_POSITION_RIGHT)) {
        tX = width - paddingRight - legend.getWidth();
        tY = offsetTop;
      } else if (position.equals(Legend.LegendPosition.LEGEND_POSITION_TOP)) {
        tX = paddingLeft;
        tY = offsetTop;
      } else if (position.equals(Legend.LegendPosition.LEGEND_POSITION_BOTTOM)) {
        tX = paddingLeft;
        tY = height - paddingBottom - legend.getHeight();
      }
      context.save();
      context.translate(tX, tY);
      legend.draw();
      context.restore();
    }
  }
コード例 #2
0
 private void drawOuterBorder(
     Context2D context, Paint borderPaint, BasicStroke borderStroke, double width, double height) {
   float borderWidth = borderStroke.getLineWidth();
   context.setStroke(borderStroke);
   context.setPaint(borderPaint);
   context.draw(
       new Rectangle2D.Double(
           borderWidth / 2, borderWidth / 2, width - borderWidth, height - borderWidth));
 }
コード例 #3
0
  private void drawTitleAndSubtitle(Context2D context) {
    double widthWithoutPadding = width - paddingLeft - paddingRight;
    context.save();

    context.translate(0, paddingTop);

    // Draw title:
    if (title != null) {
      drawCenteredText(context, title, width, titleFont, titleColor, widthWithoutPadding);
      context.translate(0, context.getLineHeight(titleFont, title));
    }

    // Draw subtitle:
    if (subtitle != null) {
      context.translate(0, subtitleMargin);
      drawCenteredText(context, subtitle, width, subtitleFont, subtitleColor, widthWithoutPadding);
      context.translate(0, context.getLineHeight(subtitleFont, subtitle));
    }

    if (title != null || subtitle != null) {
      context.translate(0, titleMargin);
    }

    context.restore();
  }
コード例 #4
0
  private double calculateOffsetCausedByTitleAndSubtitle(Context2D context) {
    double offsetTop = paddingTop;
    if (title != null) {
      offsetTop += context.getLineHeight(titleFont, title);
    }
    if (subtitle != null) {
      offsetTop += context.getLineHeight(subtitleFont, subtitle) + subtitleMargin;
    }

    if (title != null || subtitle != null) {
      offsetTop += titleMargin;
    }
    return offsetTop;
  }
コード例 #5
0
 private void drawCenteredText(
     Context2D context,
     String text,
     double width,
     Font textFont,
     Color textColor,
     double maxWidth) {
   context.setFont(textFont);
   context.setPaint(textColor);
   context.drawText(
       text,
       width / 2,
       0,
       Context2D.HORIZONTAL_ALIGN_CENTER,
       Context2D.VERTICAL_ALIGN_TOP,
       maxWidth);
 }
コード例 #6
0
  private void drawChart(Context2D context) {
    if (renderer != null) {
      double offsetTop = calculateOffsetCausedByTitleAndSubtitle(context);
      double chartWidth = width - paddingLeft - paddingRight;
      double chartHeight = height - offsetTop - paddingBottom;

      context.save();
      context.translate(paddingLeft, offsetTop);

      if (drawLegend && legend != null) {
        Legend.LegendPosition position = legend.getPosition();
        if (position.equals(Legend.LegendPosition.LEGEND_POSITION_LEFT)
            || position.equals(Legend.LegendPosition.LEGEND_POSITION_RIGHT)) {

          chartWidth -= legend.getWidth() + legendMargin;

          if (position.equals(Legend.LegendPosition.LEGEND_POSITION_LEFT)) {
            context.translate(legend.getWidth() + legendMargin, 0);
          }

        } else {
          chartHeight -= legend.getHeight() + legendMargin;
          if (position.equals(Legend.LegendPosition.LEGEND_POSITION_TOP)) {
            context.translate(0, legend.getHeight() + legendMargin);
          }
        }
      }

      context.resize(chartWidth, chartHeight);
      renderer.draw(context, dataseries, labels);
      context.restore();
    }
  }
コード例 #7
0
 private void fillBackground(
     Context2D context, Paint backgroundPaint, double width, double height) {
   context.setPaint(backgroundPaint);
   context.fill(new Rectangle2D.Double(0, 0, width, height));
 }