use of android.graphics.PointF in project carat by amplab.
the class BarLineChartTouchListener method performDrag.
/**
* Performs all necessary operations needed for dragging.
*
* @param event
*/
private void performDrag(MotionEvent event) {
mMatrix.set(mSavedMatrix);
PointF dragPoint = new PointF(event.getX(), event.getY());
// check if axis is inverted
if (!mChart.isInvertYAxisEnabled()) {
mMatrix.postTranslate(dragPoint.x - mTouchStartPoint.x, dragPoint.y - mTouchStartPoint.y);
} else {
mMatrix.postTranslate(dragPoint.x - mTouchStartPoint.x, -(dragPoint.y - mTouchStartPoint.y));
}
}
use of android.graphics.PointF in project carat by amplab.
the class Chart method getMarkerPosition.
/**
* Returns the actual position in pixels of the MarkerView for the given
* Entry in the given DataSet.
*
* @param xIndex
* @param dataSetIndex
* @return
*/
private float[] getMarkerPosition(Entry e, int dataSetIndex) {
float xPos = e.getXIndex();
// CandleStickChart
if (this instanceof CandleStickChart)
xPos += 0.5f;
else if (this instanceof BarChart) {
BarData bd = (BarData) mData;
float space = bd.getGroupSpace();
float j = mData.getDataSetByIndex(dataSetIndex).getEntryPosition(e);
float x = (j * (mData.getDataSetCount() - 1)) + dataSetIndex + space * j + space / 2f + 0.5f;
xPos += x;
} else if (this instanceof RadarChart) {
RadarChart rc = (RadarChart) this;
float angle = rc.getSliceAngle() * e.getXIndex() + rc.getRotationAngle();
float val = e.getVal() * rc.getFactor();
PointF c = getCenterOffsets();
PointF p = new PointF((float) (c.x + val * Math.cos(Math.toRadians(angle))), (float) (c.y + val * Math.sin(Math.toRadians(angle))));
return new float[] { p.x, p.y };
}
// position of the marker depends on selected value index and value
float[] pts = new float[] { xPos, e.getVal() * mPhaseY };
mTrans.pointValuesToPixel(pts);
return pts;
}
use of android.graphics.PointF in project carat by amplab.
the class RadarChart method drawWeb.
/**
* Draws the spider web.
*/
private void drawWeb() {
if (!mDrawWeb)
return;
float sliceangle = getSliceAngle();
// calculate the factor that is needed for transforming the value to
// pixels
float factor = getFactor();
PointF c = getCenterOffsets();
// draw the web lines that come from the center
mWebPaint.setStrokeWidth(mWebLineWidth);
mWebPaint.setColor(mWebColor);
mWebPaint.setAlpha(mWebAlpha);
for (int i = 0; i < mData.getXValCount(); i++) {
PointF p = getPosition(c, mYChartMax * factor, sliceangle * i + mRotationAngle);
mDrawCanvas.drawLine(c.x, c.y, p.x, p.y, mWebPaint);
}
// draw the inner-web
mWebPaint.setStrokeWidth(mInnerWebLineWidth);
mWebPaint.setColor(mWebColorInner);
mWebPaint.setAlpha(mWebAlpha);
int labelCount = mYLabels.mEntryCount;
for (int j = 0; j < labelCount; j++) {
for (int i = 0; i < mData.getXValCount(); i++) {
float r = ((mYChartMax / labelCount) * (j + 1)) * factor;
PointF p1 = getPosition(c, r, sliceangle * i + mRotationAngle);
PointF p2 = getPosition(c, r, sliceangle * (i + 1) + mRotationAngle);
mDrawCanvas.drawLine(p1.x, p1.y, p2.x, p2.y, mWebPaint);
}
}
}
use of android.graphics.PointF in project carat by amplab.
the class RadarChart method drawYLabels.
/**
* Draws the y-labels of the RadarChart.
*/
private void drawYLabels() {
if (!mDrawYLabels)
return;
mYLabelPaint.setTypeface(mYLabels.getTypeface());
mYLabelPaint.setTextSize(mYLabels.getTextSize());
mYLabelPaint.setColor(mYLabels.getTextColor());
PointF c = getCenterOffsets();
float factor = getFactor();
int labelCount = mYLabels.mEntryCount;
for (int j = 0; j < labelCount; j++) {
if (j == labelCount - 1 && mYLabels.isDrawTopYLabelEntryEnabled() == false)
break;
float r = ((mYChartMax / labelCount) * j) * factor;
PointF p = getPosition(c, r, mRotationAngle);
float val = r / factor;
String label = Utils.formatNumber(val, mYLabels.mDecimals, mYLabels.isSeparateThousandsEnabled());
if (mYLabels.isDrawUnitsInYLabelEnabled())
mDrawCanvas.drawText(label + mUnit, p.x + 10, p.y - 5, mYLabelPaint);
else {
mDrawCanvas.drawText(label, p.x + 10, p.y - 5, mYLabelPaint);
}
}
}
use of android.graphics.PointF in project carat by amplab.
the class RadarChart method drawXLabels.
/**
* Draws the x-labels of the chart.
*/
private void drawXLabels() {
if (!mDrawXLabels)
return;
mXLabelPaint.setTypeface(mXLabels.getTypeface());
mXLabelPaint.setTextSize(mXLabels.getTextSize());
mXLabelPaint.setColor(mXLabels.getTextColor());
float sliceangle = getSliceAngle();
// calculate the factor that is needed for transforming the value to
// pixels
float factor = getFactor();
PointF c = getCenterOffsets();
for (int i = 0; i < mData.getXValCount(); i++) {
String text = mData.getXVals().get(i);
float angle = (sliceangle * i + mRotationAngle) % 360f;
PointF p = getPosition(c, mYChartMax * factor + mXLabels.mLabelWidth / 2f, angle);
mDrawCanvas.drawText(text, p.x, p.y + mXLabels.mLabelHeight / 2f, mXLabelPaint);
}
}
Aggregations