use of com.github.mikephil.charting.utils.MPPointD in project MPAndroidChart by PhilJay.
the class AxisRenderer method computeAxis.
/**
* Computes the axis values.
*
* @param min - the minimum value in the data object for this axis
* @param max - the maximum value in the data object for this axis
*/
public void computeAxis(float min, float max, boolean inverted) {
// zoom / contentrect bounds)
if (mViewPortHandler != null && mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutY()) {
MPPointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());
MPPointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom());
if (!inverted) {
min = (float) p2.y;
max = (float) p1.y;
} else {
min = (float) p1.y;
max = (float) p2.y;
}
MPPointD.recycleInstance(p1);
MPPointD.recycleInstance(p2);
}
computeAxisValues(min, max);
}
use of com.github.mikephil.charting.utils.MPPointD in project MPAndroidChart by PhilJay.
the class LineChartRenderer method drawHighlighted.
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
LineData lineData = mChart.getLineData();
for (Highlight high : indices) {
ILineDataSet set = lineData.getDataSetByIndex(high.getDataSetIndex());
if (set == null || !set.isHighlightEnabled())
continue;
Entry e = set.getEntryForXValue(high.getX(), high.getY());
if (!isInBoundsX(e, set))
continue;
MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator.getPhaseY());
high.setDraw((float) pix.x, (float) pix.y);
// draw the lines
drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
}
}
use of com.github.mikephil.charting.utils.MPPointD in project MPAndroidChart by PhilJay.
the class BarHighlighter method getHighlight.
@Override
public Highlight getHighlight(float x, float y) {
Highlight high = super.getHighlight(x, y);
if (high == null) {
return null;
}
MPPointD pos = getValsForTouch(x, y);
BarData barData = mChart.getBarData();
IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
if (set.isStacked()) {
return getStackedHighlight(high, set, (float) pos.x, (float) pos.y);
}
MPPointD.recycleInstance(pos);
return high;
}
use of com.github.mikephil.charting.utils.MPPointD in project MPAndroidChart by PhilJay.
the class ChartHighlighter method buildHighlights.
/**
* An array of `Highlight` objects corresponding to the selected xValue and dataSetIndex.
*
* @param set
* @param dataSetIndex
* @param xVal
* @param rounding
* @return
*/
protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {
ArrayList<Highlight> highlights = new ArrayList<>();
//noinspection unchecked
List<Entry> entries = set.getEntriesForXValue(xVal);
if (entries.size() == 0) {
// Try to find closest x-value and take all entries for that x-value
final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding);
if (closest != null) {
//noinspection unchecked
entries = set.getEntriesForXValue(closest.getX());
}
}
if (entries.size() == 0)
return highlights;
for (Entry e : entries) {
MPPointD pixels = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY());
highlights.add(new Highlight(e.getX(), e.getY(), (float) pixels.x, (float) pixels.y, dataSetIndex, set.getAxisDependency()));
}
return highlights;
}
Aggregations