Search in sources :

Example 26 with MPPointF

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);
}
Also used : Matrix(android.graphics.Matrix) MPPointF(com.github.mikephil.charting.utils.MPPointF)

Example 27 with MPPointF

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();
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF)

Example 28 with MPPointF

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;
    }
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF)

Example 29 with MPPointF

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);
    }
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF)

Example 30 with MPPointF

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);
        }
    }
}
Also used : BubbleData(com.github.mikephil.charting.data.BubbleData) IBubbleDataSet(com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet) BubbleEntry(com.github.mikephil.charting.data.BubbleEntry) MPPointF(com.github.mikephil.charting.utils.MPPointF) Drawable(android.graphics.drawable.Drawable)

Aggregations

MPPointF (com.github.mikephil.charting.utils.MPPointF)43 Paint (android.graphics.Paint)13 Drawable (android.graphics.drawable.Drawable)9 RectF (android.graphics.RectF)5 TextPaint (android.text.TextPaint)5 Entry (com.github.mikephil.charting.data.Entry)5 PieEntry (com.github.mikephil.charting.data.PieEntry)4 Transformer (com.github.mikephil.charting.utils.Transformer)4 Path (android.graphics.Path)3 RadarEntry (com.github.mikephil.charting.data.RadarEntry)3 IPieDataSet (com.github.mikephil.charting.interfaces.datasets.IPieDataSet)3 SuppressLint (android.annotation.SuppressLint)2 BarBuffer (com.github.mikephil.charting.buffer.BarBuffer)2 Chart (com.github.mikephil.charting.charts.Chart)2 BarEntry (com.github.mikephil.charting.data.BarEntry)2 BubbleData (com.github.mikephil.charting.data.BubbleData)2 BubbleEntry (com.github.mikephil.charting.data.BubbleEntry)2 PieData (com.github.mikephil.charting.data.PieData)2 PieDataSet (com.github.mikephil.charting.data.PieDataSet)2 IValueFormatter (com.github.mikephil.charting.formatter.IValueFormatter)2