예제 #1
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();
    }
  }
예제 #2
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();
    }
  }
예제 #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();
  }