Ejemplo n.º 1
0
    /** draw graph without animation */
    private void drawGraphWithoutAnimation(GraphCanvasWrapper graphCanvas) {

      for (int i = 0; i < mLineGraphVO.getArrGraph().size(); i++) {
        GraphPath linePath =
            new GraphPath(
                width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
        GraphPath regionPath =
            new GraphPath(
                width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
        boolean firstSet = false;
        float x = 0;
        float y = 0;
        p.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        pCircle.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        float xGap = xLength / (mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length - 1);

        Bitmap icon = arrIcon.get(i);

        for (int j = 0; j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length; j++) {
          if (j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length) {

            if (!firstSet) {

              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              linePath.moveTo(x, y);

              firstSet = true;
            } else {
              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              linePath.lineTo(x, y);
            }

            if (icon == null) {
              graphCanvas.drawCircle(x, y, 4, pCircle);
            } else {
              graphCanvas.drawBitmapIcon(icon, x, y, null);
            }
          }
        }

        graphCanvas.getCanvas().drawPath(linePath, p);
      }
    }
Ejemplo n.º 2
0
    /** draw graph with animation */
    private void drawGraphWithAnimation(GraphCanvasWrapper graphCanvas) {
      // for draw animation
      float prev_x = 0;
      float prev_y = 0;

      float next_x = 0;
      float next_y = 0;

      float value = 0;
      float mode = 0;

      for (int i = 0; i < mLineGraphVO.getArrGraph().size(); i++) {
        GraphPath linePath =
            new GraphPath(
                width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
        GraphPath regionPath =
            new GraphPath(
                width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
        boolean firstSet = false;
        float x = 0;
        float y = 0;
        p.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        pCircle.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        float xGap = xLength / (mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length - 1);

        Bitmap icon = arrIcon.get(i);
        value = anim / 1;
        mode = anim % 1;

        for (int j = 0; j < value + 1; j++) {
          if (j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length) {

            if (!firstSet) {

              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              linePath.moveTo(x, y);

              firstSet = true;
            } else {
              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              if (j > value && mode != 0) {
                next_x = x - prev_x;
                next_y = y - prev_y;

                linePath.lineTo(prev_x + next_x * mode, prev_y + next_y * mode);
              } else {
                linePath.lineTo(x, y);
              }
            }

            if (icon == null) {
              graphCanvas.drawCircle(x, y, 4, pCircle);
            } else {
              graphCanvas.drawBitmapIcon(icon, x, y, null);
            }
            prev_x = x;
            prev_y = y;
          }
        }

        graphCanvas.getCanvas().drawPath(linePath, p);
      }
    }