コード例 #1
0
ファイル: LegendPainter.java プロジェクト: jdddog/Lablet
  private LayoutInfo layout() {
    LayoutInfo info = new LayoutInfo();

    info.labelHeight = labelPaint.descent() - labelPaint.ascent();

    float maxMarkerSize = Float.MIN_VALUE;
    float maxLength = Float.MIN_VALUE;
    for (Entry entry : entryList) {
      float length = labelPaint.measureText(entry.label);
      if (maxLength < length) maxLength = length;
      float markerSize = entry.painter.getDrawConfig().getMarkerSize();
      if (markerSize > maxMarkerSize) maxMarkerSize = markerSize;
    }

    info.markerWidth = maxMarkerSize;

    info.frame.left = 0;
    info.frame.top = 0;
    info.frame.right =
        2 * info.margin
            + info.markerWidth
            + info.markerXSpacing
            + maxLength
            + 2 * info.markerLineSpace;
    info.frame.bottom = 2 * info.margin + entryList.size() * (info.labelHeight + info.labelSpacing);

    return info;
  }
コード例 #2
0
ファイル: LegendPainter.java プロジェクト: jdddog/Lablet
  @Override
  public void onDraw(Canvas canvas) {
    if (layoutInfo == null) layoutInfo = layout();

    float width = containerView.getWidth();
    float margin = 10f;

    canvas.save();
    canvas.translate(width - layoutInfo.frame.width() - margin, margin);
    // draw background
    canvas.drawRect(layoutInfo.frame, backgroundPaint);
    canvas.drawRect(layoutInfo.frame, borderPaint);

    // draw markers
    float x = layoutInfo.getMarkerX();
    float lineLeft = layoutInfo.getMarkerLineLeft();
    float lineRight = layoutInfo.getMarkerLineRight();
    for (int i = 0; i < entryList.size(); i++) {
      Entry entry = entryList.get(i);
      float y = layoutInfo.margin + (layoutInfo.labelHeight + layoutInfo.labelSpacing) * (0.5f + i);
      canvas.drawLine(lineLeft, y, lineRight, y, entry.getPainter().getDrawConfig().getLinePaint());
      tempPoint.set(x, y);
      IPointRenderer pointRenderer = entry.painter.getPointRenderer();
      pointRenderer.drawPoint(canvas, tempPoint, entry.painter.getDrawConfig());
    }

    // draw labels
    x = layoutInfo.getLabelStartX();
    for (int i = 0; i < entryList.size(); i++) {
      Entry entry = entryList.get(i);
      float y =
          layoutInfo.margin
              + (layoutInfo.labelHeight + layoutInfo.labelSpacing) * i
              + layoutInfo.labelHeight;
      canvas.drawText(entry.getLabel(), x, y, labelPaint);
    }

    canvas.restore();
  }