/** * 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); }
/** * Returns an array of SelInfo objects for the given x-index. The SelInfo objects give information * about the value at the selected index and the DataSet it belongs to. INFORMATION: This method * does calculations at runtime. Do not over-use in performance critical situations. * * @return */ public List<SelInfo> getYValsAtIndex(int xIndex) { List<SelInfo> vals = new ArrayList<SelInfo>(); for (int i = 0; i < mData.getDataSetCount(); i++) { DataSet<?> dataSet = mData.getDataSetByIndex(i); // extract all y-values from all DataSets at the given x-index float yVal = dataSet.getYValForXIndex(xIndex); if (!Float.isNaN(yVal)) { vals.add(new SelInfo(yVal, i, dataSet)); } } return vals; }
/** * 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); }