Search in sources :

Example 1 with RadarChart

use of com.github.mikephil.charting.charts.RadarChart in project carat by amplab.

the class PieRadarChartTouchListener method onSingleTapUp.

@Override
public boolean onSingleTapUp(MotionEvent e) {
    OnChartGestureListener l = mChart.getOnChartGestureListener();
    if (l != null) {
        l.onChartSingleTapped(e);
    }
    float distance = mChart.distanceToCenter(e.getX(), e.getY());
    // check if a slice was touched
    if (distance > mChart.getRadius()) {
        // if no slice was touched, highlight nothing
        mChart.highlightValues(null);
        mLastHighlight = null;
    } else {
        float angle = mChart.getAngleForPoint(e.getX(), e.getY());
        int index = mChart.getIndexForAngle(angle);
        // check if the index could be found
        if (index < 0) {
            mChart.highlightValues(null);
            mLastHighlight = null;
        } else {
            ArrayList<SelInfo> valsAtIndex = mChart.getYValsAtIndex(index);
            int dataSetIndex = 0;
            // has one DataSet)
            if (mChart instanceof RadarChart) {
                dataSetIndex = Utils.getClosestDataSetIndex(valsAtIndex, distance / ((RadarChart) mChart).getFactor());
            }
            Highlight h = new Highlight(index, dataSetIndex);
            if (h.equalTo(mLastHighlight)) {
                mChart.highlightTouch(null);
                mLastHighlight = null;
            } else {
                mChart.highlightTouch(h);
                mLastHighlight = h;
            }
        }
    }
    return true;
}
Also used : Highlight(com.github.mikephil.charting.utils.Highlight) OnChartGestureListener(com.github.mikephil.charting.interfaces.OnChartGestureListener) RadarChart(com.github.mikephil.charting.charts.RadarChart) SelInfo(com.github.mikephil.charting.utils.SelInfo)

Aggregations

RadarChart (com.github.mikephil.charting.charts.RadarChart)1 OnChartGestureListener (com.github.mikephil.charting.interfaces.OnChartGestureListener)1 Highlight (com.github.mikephil.charting.utils.Highlight)1 SelInfo (com.github.mikephil.charting.utils.SelInfo)1