コード例 #1
0
  /**
   * Performs all necessary operations needed for dragging.
   *
   * @param event
   */
  private void performDrag(MotionEvent event) {

    mMatrix.set(mSavedMatrix);

    OnChartGestureListener l = mChart.getOnChartGestureListener();

    float dX, dY;

    // check if axis is inverted
    if (mChart.isAnyAxisInverted()
        && mClosestDataSetToTouch != null
        && mChart.getAxis(mClosestDataSetToTouch.getAxisDependency()).isInverted()) {

      // if there is an inverted horizontalbarchart
      if (mChart instanceof HorizontalBarChart) {
        dX = -(event.getX() - mTouchStartPoint.x);
        dY = event.getY() - mTouchStartPoint.y;
      } else {
        dX = event.getX() - mTouchStartPoint.x;
        dY = -(event.getY() - mTouchStartPoint.y);
      }
    } else {
      dX = event.getX() - mTouchStartPoint.x;
      dY = event.getY() - mTouchStartPoint.y;
    }

    mMatrix.postTranslate(dX, dY);

    if (l != null) l.onChartTranslate(event, dX, dY);
  }
コード例 #2
0
  /**
   * returns the correct translation depending on the provided x and y touch points
   *
   * @param x
   * @param y
   * @return
   */
  public PointF getTrans(float x, float y) {

    ViewPortHandler vph = mChart.getViewPortHandler();

    float xTrans = x - vph.offsetLeft();
    float yTrans = 0f;

    // check if axis is inverted
    if (mChart.isAnyAxisInverted()
        && mClosestDataSetToTouch != null
        && mChart.isInverted(mClosestDataSetToTouch.getAxisDependency())) {
      yTrans = -(y - vph.offsetTop());
    } else {
      yTrans = -(mChart.getMeasuredHeight() - y - vph.offsetBottom());
    }

    return new PointF(xTrans, yTrans);
  }