Java Code Examples for com.github.mikephil.charting.highlight.Highlight#getXIndex()
The following examples show how to use
com.github.mikephil.charting.highlight.Highlight#getXIndex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Chart.java From iMoney with Apache License 2.0 | 5 votes |
/** * Highlights the value selected by touch gesture. Unlike * highlightValues(...), this generates a callback to the * OnChartValueSelectedListener. * * @param high */ public void highlightTouch(Highlight high) { Entry e = null; if (high == null) mIndicesToHightlight = null; else { if (mLogEnabled) Log.i(LOG_TAG, "Highlighted: " + high.toString()); e = mData.getEntryForHighlight(high); if (e == null || e.getXIndex() != high.getXIndex()) { mIndicesToHightlight = null; high = null; } else { // set the indices to highlight mIndicesToHightlight = new Highlight[] { high }; } } // redraw the chart invalidate(); if (mSelectionListener != null) { if (!valuesToHighlight()) mSelectionListener.onNothingSelected(); else { // notify the listener mSelectionListener.onValueSelected(e, high.getDataSetIndex(), high); } } }
Example 2
Source File: Chart.java From Stayfit with Apache License 2.0 | 5 votes |
/** * Highlights the value selected by touch gesture. Unlike * highlightValues(...), this generates a callback to the * OnChartValueSelectedListener. * * @param high - the highlight object * @param callListener - call the listener */ public void highlightValue(Highlight high, boolean callListener) { Entry e = null; if (high == null) mIndicesToHighlight = null; else { if (mLogEnabled) Log.i(LOG_TAG, "Highlighted: " + high.toString()); e = mData.getEntryForHighlight(high); if (e == null || e.getXIndex() != high.getXIndex()) { mIndicesToHighlight = null; high = null; } else { // set the indices to highlight mIndicesToHighlight = new Highlight[]{ high }; } } if (callListener && mSelectionListener != null) { if (!valuesToHighlight()) mSelectionListener.onNothingSelected(); else { // notify the listener mSelectionListener.onValueSelected(e, high.getDataSetIndex(), high); } } // redraw the chart invalidate(); }
Example 3
Source File: Results.java From NoiseCapture with GNU General Public License v3.0 | 5 votes |
@Override public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { if(!sChart.valuesToHighlight()) { return ""; } Highlight[] highlights = sChart.getHighlighted(); for (final Highlight highlight : highlights) { int xIndex = highlight.getXIndex(); if (xIndex == entry.getXIndex()) { return String.format(Locale.getDefault(), "%.1f dB(A)", value); } } return ""; }
Example 4
Source File: Chart.java From iMoney with Apache License 2.0 | 4 votes |
/** * draws all MarkerViews on the highlighted positions */ protected void drawMarkers(Canvas canvas) { // if there is no marker view or drawing marker is disabled if (mMarkerView == null || !mDrawMarkerViews || !valuesToHighlight()) return; for (int i = 0; i < mIndicesToHightlight.length; i++) { Highlight highlight = mIndicesToHightlight[i]; int xIndex = highlight.getXIndex(); int dataSetIndex = highlight.getDataSetIndex(); if (xIndex <= mDeltaX && xIndex <= mDeltaX * mAnimator.getPhaseX()) { Entry e = mData.getEntryForHighlight(mIndicesToHightlight[i]); // make sure entry not null if (e == null || e.getXIndex() != mIndicesToHightlight[i].getXIndex()) continue; float[] pos = getMarkerPosition(e, highlight); // check bounds if (!mViewPortHandler.isInBounds(pos[0], pos[1])) continue; // callbacks to update the content mMarkerView.refreshContent(e, highlight); // mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, // MeasureSpec.UNSPECIFIED), // MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); // mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), // mMarkerView.getMeasuredHeight()); // mMarkerView.draw(mDrawCanvas, pos[0], pos[1]); mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), mMarkerView.getMeasuredHeight()); if (pos[1] - mMarkerView.getHeight() <= 0) { float y = mMarkerView.getHeight() - pos[1]; mMarkerView.draw(canvas, pos[0], pos[1] + y); } else { mMarkerView.draw(canvas, pos[0], pos[1]); } } } }
Example 5
Source File: BubbleChartRenderer.java From iMoney with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { BubbleData bubbleData = mChart.getBubbleData(); float phaseX = mAnimator.getPhaseX(); float phaseY = mAnimator.getPhaseY(); for (Highlight indice : indices) { BubbleDataSet dataSet = bubbleData.getDataSetByIndex(indice.getDataSetIndex()); if (dataSet == null || !dataSet.isHighlightEnabled()) continue; Entry entryFrom = dataSet.getEntryForXIndex(mMinX); Entry entryTo = dataSet.getEntryForXIndex(mMaxX); int minx = dataSet.getEntryPosition(entryFrom); int maxx = Math.min(dataSet.getEntryPosition(entryTo) + 1, dataSet.getEntryCount()); final BubbleEntry entry = (BubbleEntry) bubbleData.getEntryForHighlight(indice); if (entry == null || entry.getXIndex() != indice.getXIndex()) continue; Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); sizeBuffer[0] = 0f; sizeBuffer[2] = 1f; trans.pointValuesToPixel(sizeBuffer); // calcualte the full width of 1 step on the x-axis final float maxBubbleWidth = Math.abs(sizeBuffer[2] - sizeBuffer[0]); final float maxBubbleHeight = Math.abs(mViewPortHandler.contentBottom() - mViewPortHandler.contentTop()); final float referenceSize = Math.min(maxBubbleHeight, maxBubbleWidth); pointBuffer[0] = (float) (entry.getXIndex() - minx) * phaseX + (float) minx; pointBuffer[1] = (float) (entry.getVal()) * phaseY; trans.pointValuesToPixel(pointBuffer); float shapeHalf = getShapeSize(entry.getSize(), dataSet.getMaxSize(), referenceSize) / 2f; if (!mViewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf) || !mViewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf)) continue; if (!mViewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf)) continue; if (!mViewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf)) break; if (indice.getXIndex() < minx || indice.getXIndex() >= maxx) continue; final int originalColor = dataSet.getColor(entry.getXIndex()); Color.RGBToHSV(Color.red(originalColor), Color.green(originalColor), Color.blue(originalColor), _hsvBuffer); _hsvBuffer[2] *= 0.5f; final int color = Color.HSVToColor(Color.alpha(originalColor), _hsvBuffer); mHighlightPaint.setColor(color); mHighlightPaint.setStrokeWidth(dataSet.getHighlightCircleWidth()); c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint); } }
Example 6
Source File: BarChartRenderer.java From iMoney with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { int setCount = mChart.getBarData().getDataSetCount(); for (int i = 0; i < indices.length; i++) { Highlight h = indices[i]; int index = h.getXIndex(); int dataSetIndex = h.getDataSetIndex(); BarDataSet set = mChart.getBarData().getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; float barspaceHalf = set.getBarSpace() / 2f; Transformer trans = mChart.getTransformer(set.getAxisDependency()); mHighlightPaint.setColor(set.getHighLightColor()); mHighlightPaint.setAlpha(set.getHighLightAlpha()); // check outofbounds if (index >= 0 && index < (mChart.getXChartMax() * mAnimator.getPhaseX()) / setCount) { BarEntry e = set.getEntryForXIndex(index); if (e == null || e.getXIndex() != index) continue; float groupspace = mChart.getBarData().getGroupSpace(); boolean isStack = h.getStackIndex() < 0 ? false : true; // calculate the correct x-position float x = index * setCount + dataSetIndex + groupspace / 2f + groupspace * index; final float y1; final float y2; if (isStack) { y1 = h.getRange().from; y2 = h.getRange().to; } else { y1 = e.getVal(); y2 = 0.f; } prepareBarHighlight(x, y1, y2, barspaceHalf, trans); c.drawRect(mBarRect, mHighlightPaint); if (mChart.isDrawHighlightArrowEnabled()) { mHighlightPaint.setAlpha(255); // distance between highlight arrow and bar float offsetY = mAnimator.getPhaseY() * 0.07f; float[] values = new float[9]; trans.getPixelToValueMatrix().getValues(values); final float xToYRel = Math.abs(values[Matrix.MSCALE_Y] / values[Matrix.MSCALE_X]); final float arrowWidth = set.getBarSpace() / 2.f; final float arrowHeight = arrowWidth * xToYRel; final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY(); Path arrow = new Path(); arrow.moveTo(x + 0.4f, yArrow + offsetY); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY - arrowHeight); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY + arrowHeight); trans.pathValueToPixel(arrow); c.drawPath(arrow, mHighlightPaint); } } } }
Example 7
Source File: Chart.java From Stayfit with Apache License 2.0 | 4 votes |
/** * draws all MarkerViews on the highlighted positions */ protected void drawMarkers(Canvas canvas) { // if there is no marker view or drawing marker is disabled if (mMarkerView == null || !mDrawMarkerViews || !valuesToHighlight()) return; for (int i = 0; i < mIndicesToHighlight.length; i++) { Highlight highlight = mIndicesToHighlight[i]; int xIndex = highlight.getXIndex(); int dataSetIndex = highlight.getDataSetIndex(); if (xIndex <= mDeltaX && xIndex <= mDeltaX * mAnimator.getPhaseX()) { Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]); // make sure entry not null if (e == null || e.getXIndex() != mIndicesToHighlight[i].getXIndex()) continue; float[] pos = getMarkerPosition(e, highlight); // check bounds if (!mViewPortHandler.isInBounds(pos[0], pos[1])) continue; // callbacks to update the content mMarkerView.refreshContent(e, highlight); // mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, // MeasureSpec.UNSPECIFIED), // MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); // mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), // mMarkerView.getMeasuredHeight()); // mMarkerView.draw(mDrawCanvas, pos[0], pos[1]); mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), mMarkerView.getMeasuredHeight()); if (pos[1] - mMarkerView.getHeight() <= 0) { float y = mMarkerView.getHeight() - pos[1]; mMarkerView.draw(canvas, pos[0], pos[1] + y); } else { mMarkerView.draw(canvas, pos[0], pos[1]); } } } }
Example 8
Source File: BubbleChartRenderer.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { BubbleData bubbleData = mChart.getBubbleData(); float phaseX = mAnimator.getPhaseX(); float phaseY = mAnimator.getPhaseY(); for (Highlight indice : indices) { IBubbleDataSet dataSet = bubbleData.getDataSetByIndex(indice.getDataSetIndex()); if (dataSet == null || !dataSet.isHighlightEnabled()) continue; BubbleEntry entryFrom = dataSet.getEntryForXIndex(mMinX); BubbleEntry entryTo = dataSet.getEntryForXIndex(mMaxX); int minx = dataSet.getEntryIndex(entryFrom); int maxx = Math.min(dataSet.getEntryIndex(entryTo) + 1, dataSet.getEntryCount()); final BubbleEntry entry = (BubbleEntry) bubbleData.getEntryForHighlight(indice); if (entry == null || entry.getXIndex() != indice.getXIndex()) continue; Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); sizeBuffer[0] = 0f; sizeBuffer[2] = 1f; trans.pointValuesToPixel(sizeBuffer); // calcualte the full width of 1 step on the x-axis final float maxBubbleWidth = Math.abs(sizeBuffer[2] - sizeBuffer[0]); final float maxBubbleHeight = Math.abs(mViewPortHandler.contentBottom() - mViewPortHandler.contentTop()); final float referenceSize = Math.min(maxBubbleHeight, maxBubbleWidth); pointBuffer[0] = (float) (entry.getXIndex() - minx) * phaseX + (float) minx; pointBuffer[1] = (float) (entry.getVal()) * phaseY; trans.pointValuesToPixel(pointBuffer); float shapeHalf = getShapeSize(entry.getSize(), dataSet.getMaxSize(), referenceSize) / 2f; if (!mViewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf) || !mViewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf)) continue; if (!mViewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf)) continue; if (!mViewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf)) break; if (indice.getXIndex() < minx || indice.getXIndex() >= maxx) continue; final int originalColor = dataSet.getColor(entry.getXIndex()); Color.RGBToHSV(Color.red(originalColor), Color.green(originalColor), Color.blue(originalColor), _hsvBuffer); _hsvBuffer[2] *= 0.5f; final int color = Color.HSVToColor(Color.alpha(originalColor), _hsvBuffer); mHighlightPaint.setColor(color); mHighlightPaint.setStrokeWidth(dataSet.getHighlightCircleWidth()); c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint); } }
Example 9
Source File: BarChartRenderer.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { int setCount = mChart.getBarData().getDataSetCount(); for (int i = 0; i < indices.length; i++) { Highlight h = indices[i]; int index = h.getXIndex(); int dataSetIndex = h.getDataSetIndex(); IBarDataSet set = mChart.getBarData().getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; float barspaceHalf = set.getBarSpace() / 2f; Transformer trans = mChart.getTransformer(set.getAxisDependency()); mHighlightPaint.setColor(set.getHighLightColor()); mHighlightPaint.setAlpha(set.getHighLightAlpha()); // check outofbounds if (index >= 0 && index < (mChart.getXChartMax() * mAnimator.getPhaseX()) / setCount) { BarEntry e = set.getEntryForXIndex(index); if (e == null || e.getXIndex() != index) continue; float groupspace = mChart.getBarData().getGroupSpace(); boolean isStack = h.getStackIndex() < 0 ? false : true; // calculate the correct x-position float x = index * setCount + dataSetIndex + groupspace / 2f + groupspace * index; final float y1; final float y2; if (isStack) { y1 = h.getRange().from; y2 = h.getRange().to; } else { y1 = e.getVal(); y2 = 0.f; } prepareBarHighlight(x, y1, y2, barspaceHalf, trans); c.drawRect(mBarRect, mHighlightPaint); if (mChart.isDrawHighlightArrowEnabled()) { mHighlightPaint.setAlpha(255); // distance between highlight arrow and bar float offsetY = mAnimator.getPhaseY() * 0.07f; float[] values = new float[9]; trans.getPixelToValueMatrix().getValues(values); final float xToYRel = Math.abs(values[Matrix.MSCALE_Y] / values[Matrix.MSCALE_X]); final float arrowWidth = set.getBarSpace() / 2.f; final float arrowHeight = arrowWidth * xToYRel; final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY(); Path arrow = new Path(); arrow.moveTo(x + 0.4f, yArrow + offsetY); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY - arrowHeight); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY + arrowHeight); trans.pathValueToPixel(arrow); c.drawPath(arrow, mHighlightPaint); } } } }
Example 10
Source File: Chart.java From NetKnight with Apache License 2.0 | 4 votes |
/** * draws all MarkerViews on the highlighted positions */ protected void drawMarkers(Canvas canvas) { // if there is no marker view or drawing marker is disabled if (mMarkerView == null || !mDrawMarkerViews || !valuesToHighlight()) return; for (int i = 0; i < mIndicesToHighlight.length; i++) { Highlight highlight = mIndicesToHighlight[i]; int xIndex = highlight.getXIndex(); int dataSetIndex = highlight.getDataSetIndex(); float deltaX = mXAxis != null ? mXAxis.mAxisRange : ((mData == null ? 0.f : mData.getXValCount()) - 1.f); if (xIndex <= deltaX && xIndex <= deltaX * mAnimator.getPhaseX()) { Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]); // make sure entry not null if (e == null || e.getXIndex() != mIndicesToHighlight[i].getXIndex()) continue; float[] pos = getMarkerPosition(e, highlight); // check bounds if (!mViewPortHandler.isInBounds(pos[0], pos[1])) continue; // callbacks to update the content mMarkerView.refreshContent(e, highlight); // mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, // MeasureSpec.UNSPECIFIED), // MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); // mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), // mMarkerView.getMeasuredHeight()); // mMarkerView.draw(mDrawCanvas, pos[0], pos[1]); mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), mMarkerView.getMeasuredHeight()); if (pos[1] - mMarkerView.getHeight() <= 0) { float y = mMarkerView.getHeight() - pos[1]; mMarkerView.draw(canvas, pos[0], pos[1] + y); } else { mMarkerView.draw(canvas, pos[0], pos[1]); } } } }
Example 11
Source File: BubbleChartRenderer.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { BubbleData bubbleData = mChart.getBubbleData(); float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX())); float phaseY = mAnimator.getPhaseY(); for (Highlight high : indices) { final int minDataSetIndex = high.getDataSetIndex() == -1 ? 0 : high.getDataSetIndex(); final int maxDataSetIndex = high.getDataSetIndex() == -1 ? bubbleData.getDataSetCount() : (high.getDataSetIndex() + 1); if (maxDataSetIndex - minDataSetIndex < 1) continue; for (int dataSetIndex = minDataSetIndex; dataSetIndex < maxDataSetIndex; dataSetIndex++) { IBubbleDataSet dataSet = bubbleData.getDataSetByIndex(dataSetIndex); if (dataSet == null || !dataSet.isHighlightEnabled()) continue; final BubbleEntry entry = (BubbleEntry) bubbleData.getEntryForHighlight(high); if (entry == null || entry.getXIndex() != high.getXIndex()) continue; BubbleEntry entryFrom = dataSet.getEntryForXIndex(mMinX); BubbleEntry entryTo = dataSet.getEntryForXIndex(mMaxX); int minx = dataSet.getEntryIndex(entryFrom); int maxx = Math.min(dataSet.getEntryIndex(entryTo) + 1, dataSet.getEntryCount()); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); sizeBuffer[0] = 0f; sizeBuffer[2] = 1f; trans.pointValuesToPixel(sizeBuffer); boolean normalizeSize = dataSet.isNormalizeSizeEnabled(); // calcualte the full width of 1 step on the x-axis final float maxBubbleWidth = Math.abs(sizeBuffer[2] - sizeBuffer[0]); final float maxBubbleHeight = Math.abs( mViewPortHandler.contentBottom() - mViewPortHandler.contentTop()); final float referenceSize = Math.min(maxBubbleHeight, maxBubbleWidth); pointBuffer[0] = (float) (entry.getXIndex() - minx) * phaseX + (float) minx; pointBuffer[1] = (float) (entry.getVal()) * phaseY; trans.pointValuesToPixel(pointBuffer); float shapeHalf = getShapeSize(entry.getSize(), dataSet.getMaxSize(), referenceSize, normalizeSize) / 2f; if (!mViewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf) || !mViewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf)) continue; if (!mViewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf)) continue; if (!mViewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf)) break; if (high.getXIndex() < minx || high.getXIndex() >= maxx) continue; final int originalColor = dataSet.getColor(entry.getXIndex()); Color.RGBToHSV(Color.red(originalColor), Color.green(originalColor), Color.blue(originalColor), _hsvBuffer); _hsvBuffer[2] *= 0.5f; final int color = Color.HSVToColor(Color.alpha(originalColor), _hsvBuffer); mHighlightPaint.setColor(color); mHighlightPaint.setStrokeWidth(dataSet.getHighlightCircleWidth()); c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint); } } }
Example 12
Source File: LineChartRenderer.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { LineData lineData = mChart.getLineData(); for (Highlight high : indices) { final int minDataSetIndex = high.getDataSetIndex() == -1 ? 0 : high.getDataSetIndex(); final int maxDataSetIndex = high.getDataSetIndex() == -1 ? lineData.getDataSetCount() : (high.getDataSetIndex() + 1); if (maxDataSetIndex - minDataSetIndex < 1) continue; for (int dataSetIndex = minDataSetIndex; dataSetIndex < maxDataSetIndex; dataSetIndex++) { ILineDataSet set = lineData.getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; int xIndex = high.getXIndex(); // get the // x-position if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX()) continue; final float yVal = set.getYValForXIndex(xIndex); if (Float.isNaN(yVal)) continue; float y = yVal * mAnimator.getPhaseY(); // get // the // y-position float[] pts = new float[]{ xIndex, y }; mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts); // draw the lines drawHighlightLines(c, pts, set); } } }
Example 13
Source File: BarChartRenderer.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { BarData barData = mChart.getBarData(); int setCount = barData.getDataSetCount(); for (Highlight high : indices) { final int minDataSetIndex = high.getDataSetIndex() == -1 ? 0 : high.getDataSetIndex(); final int maxDataSetIndex = high.getDataSetIndex() == -1 ? barData.getDataSetCount() : (high.getDataSetIndex() + 1); if (maxDataSetIndex - minDataSetIndex < 1) continue; for (int dataSetIndex = minDataSetIndex; dataSetIndex < maxDataSetIndex; dataSetIndex++) { IBarDataSet set = barData.getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; float barspaceHalf = set.getBarSpace() / 2f; Transformer trans = mChart.getTransformer(set.getAxisDependency()); mHighlightPaint.setColor(set.getHighLightColor()); mHighlightPaint.setAlpha(set.getHighLightAlpha()); int index = high.getXIndex(); // check outofbounds if (index >= 0 && index < (mChart.getXChartMax() * mAnimator.getPhaseX()) / setCount) { BarEntry e = set.getEntryForXIndex(index); if (e == null || e.getXIndex() != index) continue; float groupspace = barData.getGroupSpace(); boolean isStack = high.getStackIndex() < 0 ? false : true; // calculate the correct x-position float x = index * setCount + dataSetIndex + groupspace / 2f + groupspace * index; final float y1; final float y2; if (isStack) { y1 = high.getRange().from; y2 = high.getRange().to; } else { y1 = e.getVal(); y2 = 0.f; } prepareBarHighlight(x, y1, y2, barspaceHalf, trans); c.drawRect(mBarRect, mHighlightPaint); if (mChart.isDrawHighlightArrowEnabled()) { mHighlightPaint.setAlpha(255); // distance between highlight arrow and bar float offsetY = mAnimator.getPhaseY() * 0.07f; float[] values = new float[9]; trans.getPixelToValueMatrix().getValues(values); final float xToYRel = Math.abs( values[Matrix.MSCALE_Y] / values[Matrix.MSCALE_X]); final float arrowWidth = set.getBarSpace() / 2.f; final float arrowHeight = arrowWidth * xToYRel; final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY(); Path arrow = new Path(); arrow.moveTo(x + 0.4f, yArrow + offsetY); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY - arrowHeight); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY + arrowHeight); trans.pathValueToPixel(arrow); c.drawPath(arrow, mHighlightPaint); } } } } }
Example 14
Source File: CandleStickChartRenderer.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { CandleData candleData = mChart.getCandleData(); for (Highlight high : indices) { final int minDataSetIndex = high.getDataSetIndex() == -1 ? 0 : high.getDataSetIndex(); final int maxDataSetIndex = high.getDataSetIndex() == -1 ? candleData.getDataSetCount() : (high.getDataSetIndex() + 1); if (maxDataSetIndex - minDataSetIndex < 1) continue; for (int dataSetIndex = minDataSetIndex; dataSetIndex < maxDataSetIndex; dataSetIndex++) { int xIndex = high.getXIndex(); // get the // x-position ICandleDataSet set = mChart.getCandleData().getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; CandleEntry e = set.getEntryForXIndex(xIndex); if (e == null || e.getXIndex() != xIndex) continue; float lowValue = e.getLow() * mAnimator.getPhaseY(); float highValue = e.getHigh() * mAnimator.getPhaseY(); float y = (lowValue + highValue) / 2f; float[] pts = new float[]{ xIndex, y }; mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts); // draw the lines drawHighlightLines(c, pts, set); } } }
Example 15
Source File: ScatterChartRenderer.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { ScatterData scatterData = mChart.getScatterData(); for (Highlight high : indices) { final int minDataSetIndex = high.getDataSetIndex() == -1 ? 0 : high.getDataSetIndex(); final int maxDataSetIndex = high.getDataSetIndex() == -1 ? scatterData.getDataSetCount() : (high.getDataSetIndex() + 1); if (maxDataSetIndex - minDataSetIndex < 1) continue; for (int dataSetIndex = minDataSetIndex; dataSetIndex < maxDataSetIndex; dataSetIndex++) { IScatterDataSet set = scatterData.getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; int xIndex = high.getXIndex(); // get the // x-position if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX()) continue; final float yVal = set.getYValForXIndex(xIndex); if (Float.isNaN(yVal)) continue; float y = yVal * mAnimator.getPhaseY(); float[] pts = new float[]{ xIndex, y }; mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts); // draw the lines drawHighlightLines(c, pts, set); } } }