use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class BarLineChartTouchListener method performZoom.
/**
* Performs the all operations necessary for pinch and axis zoom.
*
* @param event
*/
private void performZoom(MotionEvent event) {
if (event.getPointerCount() >= 2) {
// two finger zoom
OnChartGestureListener l = mChart.getOnChartGestureListener();
// get the distance between the pointers of the touch event
float totalDist = spacing(event);
if (totalDist > mMinScalePointerDistance) {
// get the translation
MPPointF t = getTrans(mTouchPointCenter.x, mTouchPointCenter.y);
ViewPortHandler h = mChart.getViewPortHandler();
// take actions depending on the activated touch mode
if (mTouchMode == PINCH_ZOOM) {
mLastGesture = ChartGesture.PINCH_ZOOM;
// total scale
float scale = totalDist / mSavedDist;
boolean isZoomingOut = (scale < 1);
boolean canZoomMoreX = isZoomingOut ? h.canZoomOutMoreX() : h.canZoomInMoreX();
boolean canZoomMoreY = isZoomingOut ? h.canZoomOutMoreY() : h.canZoomInMoreY();
float scaleX = (mChart.isScaleXEnabled()) ? scale : 1f;
float scaleY = (mChart.isScaleYEnabled()) ? scale : 1f;
if (canZoomMoreY || canZoomMoreX) {
mMatrix.set(mSavedMatrix);
mMatrix.postScale(scaleX, scaleY, t.x, t.y);
if (l != null)
l.onChartScale(event, scaleX, scaleY);
}
} else if (mTouchMode == X_ZOOM && mChart.isScaleXEnabled()) {
mLastGesture = ChartGesture.X_ZOOM;
float xDist = getXDist(event);
// x-axis scale
float scaleX = xDist / mSavedXDist;
boolean isZoomingOut = (scaleX < 1);
boolean canZoomMoreX = isZoomingOut ? h.canZoomOutMoreX() : h.canZoomInMoreX();
if (canZoomMoreX) {
mMatrix.set(mSavedMatrix);
mMatrix.postScale(scaleX, 1f, t.x, t.y);
if (l != null)
l.onChartScale(event, scaleX, 1f);
}
} else if (mTouchMode == Y_ZOOM && mChart.isScaleYEnabled()) {
mLastGesture = ChartGesture.Y_ZOOM;
float yDist = getYDist(event);
// y-axis scale
float scaleY = yDist / mSavedYDist;
boolean isZoomingOut = (scaleY < 1);
boolean canZoomMoreY = isZoomingOut ? h.canZoomOutMoreY() : h.canZoomInMoreY();
if (canZoomMoreY) {
mMatrix.set(mSavedMatrix);
mMatrix.postScale(1f, scaleY, t.x, t.y);
if (l != null)
l.onChartScale(event, 1f, scaleY);
}
}
MPPointF.recycleInstance(t);
}
}
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class PieRadarChartBase method calculateOffsets.
@Override
public void calculateOffsets() {
float legendLeft = 0f, legendRight = 0f, legendBottom = 0f, legendTop = 0f;
if (mLegend != null && mLegend.isEnabled() && !mLegend.isDrawInsideEnabled()) {
float fullLegendWidth = Math.min(mLegend.mNeededWidth, mViewPortHandler.getChartWidth() * mLegend.getMaxSizePercent());
switch(mLegend.getOrientation()) {
case VERTICAL:
{
float xLegendOffset = 0.f;
if (mLegend.getHorizontalAlignment() == Legend.LegendHorizontalAlignment.LEFT || mLegend.getHorizontalAlignment() == Legend.LegendHorizontalAlignment.RIGHT) {
if (mLegend.getVerticalAlignment() == Legend.LegendVerticalAlignment.CENTER) {
// this is the space between the legend and the chart
final float spacing = Utils.convertDpToPixel(13f);
xLegendOffset = fullLegendWidth + spacing;
} else {
// this is the space between the legend and the chart
float spacing = Utils.convertDpToPixel(8f);
float legendWidth = fullLegendWidth + spacing;
float legendHeight = mLegend.mNeededHeight + mLegend.mTextHeightMax;
MPPointF center = getCenter();
float bottomX = mLegend.getHorizontalAlignment() == Legend.LegendHorizontalAlignment.RIGHT ? getWidth() - legendWidth + 15.f : legendWidth - 15.f;
float bottomY = legendHeight + 15.f;
float distLegend = distanceToCenter(bottomX, bottomY);
MPPointF reference = getPosition(center, getRadius(), getAngleForPoint(bottomX, bottomY));
float distReference = distanceToCenter(reference.x, reference.y);
float minOffset = Utils.convertDpToPixel(5f);
if (bottomY >= center.y && getHeight() - legendWidth > getWidth()) {
xLegendOffset = legendWidth;
} else if (distLegend < distReference) {
float diff = distReference - distLegend;
xLegendOffset = minOffset + diff;
}
MPPointF.recycleInstance(center);
MPPointF.recycleInstance(reference);
}
}
switch(mLegend.getHorizontalAlignment()) {
case LEFT:
legendLeft = xLegendOffset;
break;
case RIGHT:
legendRight = xLegendOffset;
break;
case CENTER:
switch(mLegend.getVerticalAlignment()) {
case TOP:
legendTop = Math.min(mLegend.mNeededHeight, mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
break;
case BOTTOM:
legendBottom = Math.min(mLegend.mNeededHeight, mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
break;
}
break;
}
}
break;
case HORIZONTAL:
float yLegendOffset = 0.f;
if (mLegend.getVerticalAlignment() == Legend.LegendVerticalAlignment.TOP || mLegend.getVerticalAlignment() == Legend.LegendVerticalAlignment.BOTTOM) {
// It's possible that we do not need this offset anymore as it
// is available through the extraOffsets, but changing it can mean
// changing default visibility for existing apps.
float yOffset = getRequiredLegendOffset();
yLegendOffset = Math.min(mLegend.mNeededHeight + yOffset, mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
switch(mLegend.getVerticalAlignment()) {
case TOP:
legendTop = yLegendOffset;
break;
case BOTTOM:
legendBottom = yLegendOffset;
break;
}
}
break;
}
legendLeft += getRequiredBaseOffset();
legendRight += getRequiredBaseOffset();
legendTop += getRequiredBaseOffset();
legendBottom += getRequiredBaseOffset();
}
float minOffset = Utils.convertDpToPixel(mMinOffset);
if (this instanceof RadarChart) {
XAxis x = this.getXAxis();
if (x.isEnabled() && x.isDrawLabelsEnabled()) {
minOffset = Math.max(minOffset, x.mLabelRotatedWidth);
}
}
legendTop += getExtraTopOffset();
legendRight += getExtraRightOffset();
legendBottom += getExtraBottomOffset();
legendLeft += getExtraLeftOffset();
float offsetLeft = Math.max(minOffset, legendLeft);
float offsetTop = Math.max(minOffset, legendTop);
float offsetRight = Math.max(minOffset, legendRight);
float offsetBottom = Math.max(minOffset, Math.max(getRequiredBaseOffset(), legendBottom));
mViewPortHandler.restrainViewPort(offsetLeft, offsetTop, offsetRight, offsetBottom);
if (mLogEnabled)
Log.i(LOG_TAG, "offsetLeft: " + offsetLeft + ", offsetTop: " + offsetTop + ", offsetRight: " + offsetRight + ", offsetBottom: " + offsetBottom);
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class YAxisRendererRadarChart method renderLimitLines.
@Override
public void renderLimitLines(Canvas c) {
List<LimitLine> limitLines = mYAxis.getLimitLines();
if (limitLines == null)
return;
float sliceangle = mChart.getSliceAngle();
// calculate the factor that is needed for transforming the value to
// pixels
float factor = mChart.getFactor();
MPPointF center = mChart.getCenterOffsets();
MPPointF pOut = MPPointF.getInstance(0, 0);
for (int i = 0; i < limitLines.size(); i++) {
LimitLine l = limitLines.get(i);
if (!l.isEnabled())
continue;
mLimitLinePaint.setColor(l.getLineColor());
mLimitLinePaint.setPathEffect(l.getDashPathEffect());
mLimitLinePaint.setStrokeWidth(l.getLineWidth());
float r = (l.getLimit() - mChart.getYChartMin()) * factor;
Path limitPath = mRenderLimitLinesPathBuffer;
limitPath.reset();
for (int j = 0; j < mChart.getData().getMaxEntryCountSet().getEntryCount(); j++) {
Utils.getPosition(center, r, sliceangle * j + mChart.getRotationAngle(), pOut);
if (j == 0)
limitPath.moveTo(pOut.x, pOut.y);
else
limitPath.lineTo(pOut.x, pOut.y);
}
limitPath.close();
c.drawPath(limitPath, mLimitLinePaint);
}
MPPointF.recycleInstance(center);
MPPointF.recycleInstance(pOut);
}
Aggregations