use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class BarLineChartBase method zoomToCenter.
/**
* Zooms to the center of the chart with the given scale factor.
*
* @param scaleX
* @param scaleY
*/
public void zoomToCenter(float scaleX, float scaleY) {
MPPointF center = getCenterOffsets();
Matrix save = mZoomMatrixBuffer;
mViewPortHandler.zoom(scaleX, scaleY, center.x, -center.y, save);
mViewPortHandler.refresh(save, this, false);
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class BarLineChartBase method zoomOut.
/**
* Zooms out by 0.7f, from the charts center.
*/
public void zoomOut() {
MPPointF center = mViewPortHandler.getContentCenter();
mViewPortHandler.zoomOut(center.x, -center.y, mZoomMatrixBuffer);
mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);
MPPointF.recycleInstance(center);
// Range might have changed, which means that Y-axis labels
// could have changed in size, affecting Y-axis size.
// So we need to recalculate offsets.
calculateOffsets();
postInvalidate();
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class Chart method onDraw.
@Override
protected void onDraw(Canvas canvas) {
if (mData == null) {
boolean hasText = !TextUtils.isEmpty(mNoDataText);
if (hasText) {
MPPointF c = getCenter();
canvas.drawText(mNoDataText, c.x, c.y, mInfoPaint);
}
return;
}
if (!mOffsetsCalculated) {
calculateOffsets();
mOffsetsCalculated = true;
}
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class Chart method drawDescription.
/**
* Draws the description text in the bottom right corner of the chart (per default)
*/
protected void drawDescription(Canvas c) {
// check if description should be drawn
if (mDescription != null && mDescription.isEnabled()) {
MPPointF position = mDescription.getPosition();
mDescPaint.setTypeface(mDescription.getTypeface());
mDescPaint.setTextSize(mDescription.getTextSize());
mDescPaint.setColor(mDescription.getTextColor());
mDescPaint.setTextAlign(mDescription.getTextAlign());
float x, y;
// if no position specified, draw on default position
if (position == null) {
x = getWidth() - mViewPortHandler.offsetRight() - mDescription.getXOffset();
y = getHeight() - mViewPortHandler.offsetBottom() - mDescription.getYOffset();
} else {
x = position.x;
y = position.y;
}
c.drawText(mDescription.getText(), x, y, mDescPaint);
}
}
use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.
the class BubbleChartRenderer method drawValues.
@Override
public void drawValues(Canvas c) {
BubbleData bubbleData = mChart.getBubbleData();
if (bubbleData == null)
return;
// if values are drawn
if (isDrawingValuesAllowed(mChart)) {
final List<IBubbleDataSet> dataSets = bubbleData.getDataSets();
float lineHeight = Utils.calcTextHeight(mValuePaint, "1");
for (int i = 0; i < dataSets.size(); i++) {
IBubbleDataSet dataSet = dataSets.get(i);
if (!shouldDrawValues(dataSet))
continue;
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
final float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
final float phaseY = mAnimator.getPhaseY();
mXBounds.set(mChart, dataSet);
final float[] positions = mChart.getTransformer(dataSet.getAxisDependency()).generateTransformedValuesBubble(dataSet, phaseY, mXBounds.min, mXBounds.max);
final float alpha = phaseX == 1 ? phaseY : phaseX;
MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
for (int j = 0; j < positions.length; j += 2) {
int valueTextColor = dataSet.getValueTextColor(j / 2 + mXBounds.min);
valueTextColor = Color.argb(Math.round(255.f * alpha), Color.red(valueTextColor), Color.green(valueTextColor), Color.blue(valueTextColor));
float x = positions[j];
float y = positions[j + 1];
if (!mViewPortHandler.isInBoundsRight(x))
break;
if ((!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y)))
continue;
BubbleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
if (dataSet.isDrawValuesEnabled()) {
drawValue(c, dataSet.getValueFormatter(), entry.getSize(), entry, i, x, y + (0.5f * lineHeight), valueTextColor);
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
Drawable icon = entry.getIcon();
Utils.drawImage(c, icon, (int) (x + iconsOffset.x), (int) (y + iconsOffset.y), icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
}
}
MPPointF.recycleInstance(iconsOffset);
}
}
}
Aggregations