コード例 #1
0
ファイル: XYChart.java プロジェクト: erdincay/chartdroid
  // ========================================================================
  float measureSecondaryYaxisTickLabels(Paint hash_mark_label_paint) {

    MinMax y_secondary_span = mRenderer.getYSecondaryAxisSpan();

    Rect text_bounds_holder = new Rect();

    List<Integer> y_secondary_label_widths = new ArrayList<Integer>();
    for (Double ylabel : MathHelper.getLabels(y_secondary_span, mRenderer.getSecondaryYLabels())) {
      String y_label = getLabel(ylabel, Axis.Y_AXIS_SECONDARY);
      hash_mark_label_paint.getTextBounds(y_label, 0, y_label.length(), text_bounds_holder);

      int label_width = text_bounds_holder.width();
      y_secondary_label_widths.add(label_width);
    }
    float max_label_width = Collections.max(y_secondary_label_widths);

    return max_label_width + VERTICAL_AXIS_LINE_LABEL_CLEARANCE;
  }
コード例 #2
0
ファイル: XYChart.java プロジェクト: erdincay/chartdroid
  protected void drawVerticalAxisLabels(
      Canvas canvas,
      Rect frame,
      Paint hash_mark_label_paint,
      double yPixelsPerUnit,
      double ySecondaryPixelsPerUnit,
      float vertical_axis_hash_mark_width,
      float vertical_secondary_axis_hash_mark_width) {

    MinMax y_span = mRenderer.getYPrimaryAxisSpan();

    List<Double> yLabels = MathHelper.getLabels(y_span, mRenderer.getYLabels());

    List<List<Double>> vertical_axis_datasets = new ArrayList<List<Double>>();
    List<MinMax> vertical_axis_spans = new ArrayList<MinMax>();
    vertical_axis_datasets.add(yLabels);
    vertical_axis_spans.add(y_span);
    if (mRenderer.hasSecondaryYAxis()) {
      MinMax secondary_span = mRenderer.getYSecondaryAxisSpan();
      vertical_axis_datasets.add(
          MathHelper.getLabels(secondary_span, mRenderer.getSecondaryYLabels()));
      vertical_axis_spans.add(secondary_span);
    }

    double[] vertical_pixels_per_unit = new double[] {yPixelsPerUnit, ySecondaryPixelsPerUnit};
    for (int vertical_axis_index = 0;
        vertical_axis_index < vertical_axis_datasets.size();
        vertical_axis_index++) {
      //			List<Double> vertical_labels = vertical_axis_datasets.get(0);
      List<Double> vertical_labels = vertical_axis_datasets.get(vertical_axis_index);

      MinMax label_span = vertical_axis_spans.get(vertical_axis_index);

      hash_mark_label_paint.setTextAlign(label_alignments[vertical_axis_index]);
      for (int i = 0; i < vertical_labels.size(); i++) {
        double label = vertical_labels.get(i);
        float label_value =
            (float)
                (frame.bottom
                    - vertical_pixels_per_unit[vertical_axis_index]
                        * (label - label_span.min.doubleValue()));

        float grid_line_startx, grid_line_stopx, hash_mark_startx, hash_mark_stopx;
        float label_x_offset;

        if (vertical_axis_index == 0) {

          grid_line_startx = frame.left;
          grid_line_stopx = frame.right;
          hash_mark_startx = grid_line_startx - vertical_axis_hash_mark_width;
          hash_mark_stopx = grid_line_startx;

          label_x_offset = frame.left - VERTICAL_AXIS_LINE_LABEL_CLEARANCE;

        } else {

          grid_line_startx = frame.left;
          grid_line_stopx = frame.right;
          hash_mark_startx = grid_line_stopx;
          hash_mark_stopx = grid_line_stopx + vertical_secondary_axis_hash_mark_width;

          label_x_offset = frame.right + VERTICAL_AXIS_LINE_LABEL_CLEARANCE;
        }

        if (mRenderer.isShowLabels()) {
          hash_mark_label_paint.setColor(grid_line_colors[vertical_axis_index]);
          //					hash_mark_label_paint.setColor(mRenderer.getLabelsColor());	// XXX
          canvas.drawLine(
              hash_mark_startx, label_value, hash_mark_stopx, label_value, hash_mark_label_paint);

          String label_string = getLabel(label, vertical_axis_enums[vertical_axis_index]);
          hash_mark_label_paint.measureText(label_string);
          drawText(
              canvas,
              getLabel(label, vertical_axis_enums[vertical_axis_index]),
              label_x_offset,
              label_value - VERTICAL_AXIS_LABEL_HASH_MARK_CLEARANCE,
              hash_mark_label_paint,
              0);
        }

        if (mRenderer.isShowGrid() && mRenderer.isShowGridHorizontalLines()) {
          hash_mark_label_paint.setColor(grid_line_colors[vertical_axis_index]);
          hash_mark_label_paint.setPathEffect(grid_line_path_effects[vertical_axis_index]);
          canvas.drawLine(
              grid_line_startx, label_value, grid_line_stopx, label_value, hash_mark_label_paint);

          hash_mark_label_paint.setPathEffect(null);
        }
      }
    }
  }