protected void drawDataSet(Canvas c, PieDataSet dataSet) {

    float angle = mChart.getRotationAngle();

    List<Entry> entries = dataSet.getYVals();
    float[] drawAngles = mChart.getDrawAngles();

    for (int j = 0; j < entries.size(); j++) {

      float newangle = drawAngles[j];
      float sliceSpace = dataSet.getSliceSpace();

      Entry e = entries.get(j);

      // draw only if the value is greater than zero
      if ((Math.abs(e.getVal()) > 0.000001)) {

        if (!mChart.needsHighlight(e.getXIndex(), mChart.getData().getIndexOfDataSet(dataSet))) {

          mRenderPaint.setColor(dataSet.getColor(j));
          mBitmapCanvas.drawArc(
              mChart.getCircleBox(),
              (angle + sliceSpace / 2f) * mAnimator.getPhaseY(),
              (newangle - sliceSpace / 2f) * mAnimator.getPhaseY(),
              true,
              mRenderPaint);
        }
      }

      angle += newangle * mAnimator.getPhaseX();
    }
  }
  protected void drawRoundedSlices(Canvas c) {

    if (!mChart.isDrawRoundedSlicesEnabled()) return;

    PieDataSet dataSet = mChart.getData().getDataSet();

    if (!dataSet.isVisible()) return;

    PointF center = mChart.getCenterCircleBox();
    float r = mChart.getRadius();

    // calculate the radius of the "slice-circle"
    float circleRadius = (r - (r * mChart.getHoleRadius() / 100f)) / 2f;

    List<Entry> entries = dataSet.getYVals();
    float[] drawAngles = mChart.getDrawAngles();
    float angle = mChart.getRotationAngle();

    for (int j = 0; j < entries.size(); j++) {

      float newangle = drawAngles[j];

      Entry e = entries.get(j);

      // draw only if the value is greater than zero
      if ((Math.abs(e.getVal()) > 0.000001)) {

        float x =
            (float)
                ((r - circleRadius)
                        * Math.cos(Math.toRadians((angle + newangle) * mAnimator.getPhaseY()))
                    + center.x);
        float y =
            (float)
                ((r - circleRadius)
                        * Math.sin(Math.toRadians((angle + newangle) * mAnimator.getPhaseY()))
                    + center.y);

        mRenderPaint.setColor(dataSet.getColor(j));
        mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint);
      }

      angle += newangle * mAnimator.getPhaseX();
    }
  }
Ejemplo n.º 3
0
  /**
   * This method takes in a scrollable pane, and populates it with entries from a linked list Each
   * entry fills up a JTextArea
   *
   * @param financesTransactionList_SCP
   * @param transactionList
   */
  private void renderList(JPanel ListPane, LinkedList<Entry> transactionList) {
    int size = transactionList.size();
    for (int i = 0; i < size; ++i) {
      JPanel tempPanel = new JPanel(new MigLayout("flowy", "5[280]5", "[]"));
      tempPanel.setBackground(new Color(255, 255, 255));
      JTextArea entry = new JTextArea();
      String entryText = new String();
      Entry tempEntry = transactionList.get(i);
      entryText += "ID:\t" + Integer.toString(tempEntry.getId()) + "\n";
      switch (tempEntry.getTransactionType()) {
        case 0:
          entryText += "Income\t";
          break;
        case 1:
        case 2:
          entryText += "Expense\t";
          break;
        case 3:
          entryText += "Repay Loan\t";
          break;
        case 4:
          entryText += "Take Loan\t";
          break;
        case 5:
          entryText += "Asset Transfer\t";
          break;
        case 6:
          entryText += "Liability Transfer\t";
          break;
        default:
          entryText += "Unspecified Type!";
          break;
      }
      entryText += Double.toString(tempEntry.getAmount()) + "\n";
      entryText += "From:\t" + tempEntry.getCategory1() + "\n";
      entryText += "To:\t" + tempEntry.getCategory2() + "\n";
      entry.setText(entryText);
      tempPanel.add(entry);
      JLabel financesDescription_LBL =
          new JLabel("<html>" + tempEntry.getDescription() + "</html>");
      financesDescription_LBL.setFont(new Font("SanSerif", Font.ITALIC, 12));
      tempPanel.add(financesDescription_LBL);

      ListPane.add(tempPanel, "alignx left, gapx 2px 5px, gapy 2px 2px, top");
      ListPane.validate();
    }
  }
  @Override
  public void drawValues(Canvas c) {

    PointF center = mChart.getCenterCircleBox();

    // get whole the radius
    float r = mChart.getRadius();
    float rotationAngle = mChart.getRotationAngle();
    float[] drawAngles = mChart.getDrawAngles();
    float[] absoluteAngles = mChart.getAbsoluteAngles();

    float off = r / 10f * 3.6f;

    if (mChart.isDrawHoleEnabled()) {
      off = (r - (r / 100f * mChart.getHoleRadius())) / 2f;
    }

    r -= off; // offset to keep things inside the chart

    PieData data = mChart.getData();
    List<PieDataSet> dataSets = data.getDataSets();
    boolean drawXVals = mChart.isDrawSliceTextEnabled();

    int cnt = 0;

    for (int i = 0; i < dataSets.size(); i++) {

      PieDataSet dataSet = dataSets.get(i);

      if (!dataSet.isDrawValuesEnabled() && !drawXVals) continue;

      // apply the text-styling defined by the DataSet
      applyValueTextStyle(dataSet);

      float lineHeight = Utils.calcTextHeight(mValuePaint, "Q") + Utils.convertDpToPixel(4f);

      List<Entry> entries = dataSet.getYVals();

      for (int j = 0,
              maxEntry =
                  Math.min((int) Math.ceil(entries.size() * mAnimator.getPhaseX()), entries.size());
          j < maxEntry;
          j++) {

        Entry entry = entries.get(j);

        // offset needed to center the drawn text in the slice
        float offset = drawAngles[cnt] / 2;

        // calculate the text position
        float x =
            (float)
                (r
                        * Math.cos(
                            Math.toRadians(
                                (rotationAngle + absoluteAngles[cnt] - offset)
                                    * mAnimator.getPhaseY()))
                    + center.x);
        float y =
            (float)
                (r
                        * Math.sin(
                            Math.toRadians(
                                (rotationAngle + absoluteAngles[cnt] - offset)
                                    * mAnimator.getPhaseY()))
                    + center.y);

        float value =
            mChart.isUsePercentValuesEnabled()
                ? entry.getVal() / data.getYValueSum() * 100f
                : entry.getVal();

        ValueFormatter formatter = dataSet.getValueFormatter();

        boolean drawYVals = dataSet.isDrawValuesEnabled();

        // draw everything, depending on settings
        if (drawXVals && drawYVals) {

          drawValue(c, formatter, value, entry, 0, x, y);

          if (j < data.getXValCount())
            c.drawText(data.getXVals().get(j), x, y + lineHeight, mValuePaint);

        } else if (drawXVals && !drawYVals) {
          if (j < data.getXValCount())
            c.drawText(data.getXVals().get(j), x, y + lineHeight / 2f, mValuePaint);
        } else if (!drawXVals && drawYVals) {

          drawValue(c, formatter, value, entry, 0, x, y + lineHeight / 2f);
        }

        cnt++;
      }
    }
  }