Java Code Examples for com.github.mikephil.charting.interfaces.datasets.ILineDataSet#getEntryForIndex()
The following examples show how to use
com.github.mikephil.charting.interfaces.datasets.ILineDataSet#getEntryForIndex() .
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: LineChartRenderer.java From NetKnight with Apache License 2.0 | 5 votes |
protected void drawCubicFill(Canvas c, ILineDataSet dataSet, Path spline, Transformer trans, int from, int to) { if (to - from <= 1) return; float fillMin = dataSet.getFillFormatter() .getFillLinePosition(dataSet, mChart); // Take the from/to xIndex from the entries themselves, // so missing entries won't screw up the filling. // What we need to draw is line from points of the xIndexes - not arbitrary entry indexes! final Entry toEntry = dataSet.getEntryForIndex(to - 1); final Entry fromEntry = dataSet.getEntryForIndex(from); final float xTo = toEntry == null ? 0 : toEntry.getXIndex(); final float xFrom = fromEntry == null ? 0 : fromEntry.getXIndex(); spline.lineTo(xTo, fillMin); spline.lineTo(xFrom, fillMin); spline.close(); trans.pathValueToPixel(spline); final Drawable drawable = dataSet.getFillDrawable(); if (drawable != null) { drawFilledPath(c, spline, drawable); } else { drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha()); } }
Example 2
Source File: LineBuffer.java From Stayfit with Apache License 2.0 | 5 votes |
@Override public void feed(ILineDataSet data) { moveTo(data.getEntryForIndex(mFrom).getXIndex(), data.getEntryForIndex(mFrom).getVal() * phaseY); int size = (int) Math.ceil((mTo - mFrom) * phaseX + mFrom); int from = mFrom + 1; for (int i = from; i < size; i++) { Entry e = data.getEntryForIndex(i); lineTo(e.getXIndex(), e.getVal() * phaseY); } reset(); }
Example 3
Source File: LineChartRenderer.java From android-kline with Apache License 2.0 | 5 votes |
/** * Generates a path that is used for filled drawing. * * @param dataSet The dataset from which to read the entries. * @param startIndex The index from which to start reading the dataset * @param endIndex The index from which to stop reading the dataset * @param outputPath The path object that will be assigned the chart data. * @return */ private void generateFilledPath(final ILineDataSet dataSet, final int startIndex, final int endIndex, final Path outputPath) { final float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart); final float phaseY = mAnimator.getPhaseY(); final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED; final Path filled = outputPath; filled.reset(); final Entry entry = dataSet.getEntryForIndex(startIndex); filled.moveTo(entry.getX(), fillMin); filled.lineTo(entry.getX(), entry.getY() * phaseY); // create a new path Entry currentEntry = null; Entry previousEntry = null; for (int x = startIndex + 1; x <= endIndex; x++) { currentEntry = dataSet.getEntryForIndex(x); if (isDrawSteppedEnabled && previousEntry != null) { filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY); } filled.lineTo(currentEntry.getX(), currentEntry.getY() * phaseY); previousEntry = currentEntry; } // close up if (currentEntry != null) { filled.lineTo(currentEntry.getX(), fillMin); } filled.close(); }
Example 4
Source File: LineChartRenderer.java From Stayfit with Apache License 2.0 | 5 votes |
protected void drawCubicFill(Canvas c, ILineDataSet dataSet, Path spline, Transformer trans, int from, int to) { if (to - from <= 1) return; float fillMin = dataSet.getFillFormatter() .getFillLinePosition(dataSet, mChart); // Take the from/to xIndex from the entries themselves, // so missing entries won't screw up the filling. // What we need to draw is line from points of the xIndexes - not arbitrary entry indexes! final Entry toEntry = dataSet.getEntryForIndex(to - 1); final Entry fromEntry = dataSet.getEntryForIndex(from); final float xTo = toEntry == null ? 0 : toEntry.getXIndex(); final float xFrom = fromEntry == null ? 0 : fromEntry.getXIndex(); spline.lineTo(xTo, fillMin); spline.lineTo(xFrom, fillMin); spline.close(); trans.pathValueToPixel(spline); final Drawable drawable = dataSet.getFillDrawable(); if (drawable != null) { drawFilledPath(c, spline, drawable); } else { drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha()); } }
Example 5
Source File: LineChartRenderer.java From Stayfit with Apache License 2.0 | 5 votes |
/** * Generates the path that is used for filled drawing. * * @param dataSet * @return */ private Path generateFilledPath(ILineDataSet dataSet, int from, int to) { float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart); float phaseX = mAnimator.getPhaseX(); float phaseY = mAnimator.getPhaseY(); Path filled = new Path(); Entry entry = dataSet.getEntryForIndex(from); filled.moveTo(entry.getXIndex(), fillMin); filled.lineTo(entry.getXIndex(), entry.getVal() * phaseY); // create a new path for (int x = from + 1, count = (int) Math.ceil((to - from) * phaseX + from); x < count; x++) { Entry e = dataSet.getEntryForIndex(x); filled.lineTo(e.getXIndex(), e.getVal() * phaseY); } // close up filled.lineTo( dataSet.getEntryForIndex( Math.max( Math.min((int) Math.ceil((to - from) * phaseX + from) - 1, dataSet.getEntryCount() - 1), 0)).getXIndex(), fillMin); filled.close(); return filled; }
Example 6
Source File: LineChartRenderer.java From Ticket-Analysis with MIT License | 5 votes |
/** * Generates a path that is used for filled drawing. * * @param dataSet The dataset from which to read the entries. * @param startIndex The index from which to start reading the dataset * @param endIndex The index from which to stop reading the dataset * @param outputPath The path object that will be assigned the chart data. * @return */ private void generateFilledPath(final ILineDataSet dataSet, final int startIndex, final int endIndex, final Path outputPath) { final float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart); final float phaseY = mAnimator.getPhaseY(); final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED; final Path filled = outputPath; filled.reset(); final Entry entry = dataSet.getEntryForIndex(startIndex); filled.moveTo(entry.getX(), fillMin); filled.lineTo(entry.getX(), entry.getY() * phaseY); // create a new path Entry currentEntry = null; Entry previousEntry = null; for (int x = startIndex + 1; x <= endIndex; x++) { currentEntry = dataSet.getEntryForIndex(x); if (isDrawSteppedEnabled && previousEntry != null) { filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY); } filled.lineTo(currentEntry.getX(), currentEntry.getY() * phaseY); previousEntry = currentEntry; } // close up if (currentEntry != null) { filled.lineTo(currentEntry.getX(), fillMin); } filled.close(); }
Example 7
Source File: OneDayChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 动态更新最后一点数据 * @param timeDatamodel * @param length */ public void dynamicsUpdateOne(TimeDataModel timeDatamodel, int length) { int index = length - 1; LineData lineData = lineChart.getData(); ILineDataSet d1 = lineData.getDataSetByIndex(0); Entry e = d1.getEntryForIndex(index); d1.removeEntry(e); d1.addEntry(new Entry(index, (float) timeDatamodel.getNowPrice())); ILineDataSet d2 = lineData.getDataSetByIndex(1); Entry e2 = d2.getEntryForIndex(index); d2.removeEntry(e2); d2.addEntry(new Entry(index, (float) timeDatamodel.getAveragePrice())); BarData barData = barChart.getData(); IBarDataSet barDataSet = barData.getDataSetByIndex(0); barDataSet.removeEntry(index); float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f; barDataSet.addEntry(new BarEntry(index, timeDatamodel.getVolume(),color)); lineData.notifyDataChanged(); lineChart.notifyDataSetChanged(); lineChart.moveViewToX(index); barData.notifyDataChanged(); barChart.notifyDataSetChanged(); barChart.moveViewToX(index); }
Example 8
Source File: LineChartRenderer.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * Generates a path that is used for filled drawing. * * @param dataSet The dataset from which to read the entries. * @param startIndex The index from which to start reading the dataset * @param endIndex The index from which to stop reading the dataset * @param outputPath The path object that will be assigned the chart data. * @return */ private void generateFilledPath(final ILineDataSet dataSet, final int startIndex, final int endIndex, final Path outputPath) { final float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart); final float phaseY = mAnimator.getPhaseY(); final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED; final Path filled = outputPath; filled.reset(); final Entry entry = dataSet.getEntryForIndex(startIndex); filled.moveTo(entry.getX(), fillMin); filled.lineTo(entry.getX(), entry.getY() * phaseY); // create a new path Entry currentEntry = null; Entry previousEntry = entry; for (int x = startIndex + 1; x <= endIndex; x++) { currentEntry = dataSet.getEntryForIndex(x); if (isDrawSteppedEnabled) { filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY); } filled.lineTo(currentEntry.getX(), currentEntry.getY() * phaseY); previousEntry = currentEntry; } // close up if (currentEntry != null) { filled.lineTo(currentEntry.getX(), fillMin); } filled.close(); }
Example 9
Source File: AppLineChartRenderer.java From android-kline with Apache License 2.0 | 4 votes |
protected void drawLastPointCircle(Canvas c) { mRenderPaint.setStyle(Paint.Style.FILL); float phaseY = mAnimator.getPhaseY(); mCirclesBuffer[0] = 0; mCirclesBuffer[1] = 0; List<ILineDataSet> dataSets = mChart.getLineData().getDataSets(); for (int i = 0; i < dataSets.size(); i++) { ILineDataSet dataSet = dataSets.get(i); if (!dataSet.isVisible() /*|| !dataSet.isDrawCirclesEnabled()*/ || dataSet.getEntryCount() == 0) continue; mRenderPaint.setColor(dataSet.getCircleColor(0)); mCirclePaintInner.setColor(dataSet.getCircleHoleColor()); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mXBounds.set(mChart, dataSet); float circleRadius = dataSet.getCircleRadius() * 2.0f; float circleHoleRadius = dataSet.getCircleHoleRadius() * 2.0f; boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() && circleHoleRadius < circleRadius && circleHoleRadius > 0.f; Entry e = dataSet.getEntryForIndex(dataSet.getEntryCount() - 1); if (e == null) return; mCirclesBuffer[0] = e.getX(); mCirclesBuffer[1] = e.getY() * phaseY; trans.pointValuesToPixel(mCirclesBuffer); if (!mViewPortHandler.isInBoundsRight(mCirclesBuffer[0])) return; if (!mViewPortHandler.isInBoundsLeft(mCirclesBuffer[0]) || !mViewPortHandler.isInBoundsY(mCirclesBuffer[1])) return; c.drawCircle( mCirclesBuffer[0], mCirclesBuffer[1], circleRadius, mRenderPaint); if (drawCircleHole) { c.drawCircle( mCirclesBuffer[0], mCirclesBuffer[1], circleHoleRadius, mCirclePaintInner); } } }
Example 10
Source File: LineChartRenderer.java From Ticket-Analysis with MIT License | 4 votes |
protected void drawCubicBezier(ILineDataSet dataSet) { float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX())); float phaseY = mAnimator.getPhaseY(); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mXBounds.set(mChart, dataSet); float intensity = dataSet.getCubicIntensity(); cubicPath.reset(); if (mXBounds.range >= 1) { float prevDx = 0f; float prevDy = 0f; float curDx = 0f; float curDy = 0f; // Take an extra point from the left, and an extra from the right. // That's because we need 4 points for a cubic bezier (cubic=4), otherwise we get lines moving and doing weird stuff on the edges of the chart. // So in the starting `prev` and `cur`, go -2, -1 // And in the `lastIndex`, add +1 final int firstIndex = mXBounds.min + 1; final int lastIndex = mXBounds.min + mXBounds.range; Entry prevPrev; Entry prev = dataSet.getEntryForIndex(Math.max(firstIndex - 2, 0)); Entry cur = dataSet.getEntryForIndex(Math.max(firstIndex - 1, 0)); Entry next = cur; int nextIndex = -1; if (cur == null) return; // let the spline start cubicPath.moveTo(cur.getX(), cur.getY() * phaseY); for (int j = mXBounds.min + 1; j <= mXBounds.range + mXBounds.min; j++) { prevPrev = prev; prev = cur; cur = nextIndex == j ? next : dataSet.getEntryForIndex(j); nextIndex = j + 1 < dataSet.getEntryCount() ? j + 1 : j; next = dataSet.getEntryForIndex(nextIndex); prevDx = (cur.getX() - prevPrev.getX()) * intensity; prevDy = (cur.getY() - prevPrev.getY()) * intensity; curDx = (next.getX() - prev.getX()) * intensity; curDy = (next.getY() - prev.getY()) * intensity; cubicPath.cubicTo(prev.getX() + prevDx, (prev.getY() + prevDy) * phaseY, cur.getX() - curDx, (cur.getY() - curDy) * phaseY, cur.getX(), cur.getY() * phaseY); } } // if filled is enabled, close the path if (dataSet.isDrawFilledEnabled()) { cubicFillPath.reset(); cubicFillPath.addPath(cubicPath); drawCubicFill(mBitmapCanvas, dataSet, cubicFillPath, trans, mXBounds); } mRenderPaint.setColor(dataSet.getColor()); mRenderPaint.setStyle(Paint.Style.STROKE); trans.pathValueToPixel(cubicPath); mBitmapCanvas.drawPath(cubicPath, mRenderPaint); mRenderPaint.setPathEffect(null); }
Example 11
Source File: LineChartRenderer.java From android-kline with Apache License 2.0 | 4 votes |
public void drawCircle(Canvas c, Highlight high, float x) { mRenderPaint.setStyle(Paint.Style.FILL); float phaseY = mAnimator.getPhaseY(); mCirclesBuffer[0] = 0; mCirclesBuffer[1] = 0; List<ILineDataSet> dataSets = mChart.getLineData().getDataSets(); for (int i = 0; i < dataSets.size(); i++) { ILineDataSet dataSet = dataSets.get(i); if (!dataSet.isVisible() /*|| !dataSet.isDrawCirclesEnabled()*/ || dataSet.getEntryCount() == 0) continue; mRenderPaint.setColor(dataSet.getCircleColor(0)); mCirclePaintInner.setColor(dataSet.getCircleHoleColor()); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mXBounds.set(mChart, dataSet); float circleRadius = dataSet.getCircleRadius() * 2.0f; float circleHoleRadius = dataSet.getCircleHoleRadius() * 2.0f; boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() && circleHoleRadius < circleRadius && circleHoleRadius > 0.f; if (high.getX() < dataSet.getEntryCount() - 1) { Entry e = dataSet.getEntryForIndex((int) high.getX()); if (e == null) return; mCirclesBuffer[1] = e.getY() * phaseY; trans.pointValuesToPixel(mCirclesBuffer); mCirclesBuffer[0] = x; if (!mViewPortHandler.isInBoundsRight(mCirclesBuffer[0])) return; if (!mViewPortHandler.isInBoundsLeft(mCirclesBuffer[0]) || !mViewPortHandler.isInBoundsY(mCirclesBuffer[1])) return; c.drawCircle( mCirclesBuffer[0], mCirclesBuffer[1], circleRadius, mRenderPaint); if (drawCircleHole) { c.drawCircle( mCirclesBuffer[0], mCirclesBuffer[1], circleHoleRadius, mCirclePaintInner); } } } }
Example 12
Source File: LineChartRenderer.java From StockChart-MPAndroidChart with MIT License | 4 votes |
protected void drawCircles(Canvas c) { mRenderPaint.setStyle(Paint.Style.FILL); float phaseY = mAnimator.getPhaseY(); mCirclesBuffer[0] = 0; mCirclesBuffer[1] = 0; List<ILineDataSet> dataSets = mChart.getLineData().getDataSets(); for (int i = 0; i < dataSets.size(); i++) { ILineDataSet dataSet = dataSets.get(i); if (!dataSet.isVisible() || !dataSet.isDrawCirclesEnabled() || dataSet.getEntryCount() == 0) { continue; } mCirclePaintInner.setColor(dataSet.getCircleHoleColor()); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mXBounds.set(mChart, dataSet); float circleRadius = dataSet.getCircleRadius(); float circleHoleRadius = dataSet.getCircleHoleRadius(); boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() && circleHoleRadius < circleRadius && circleHoleRadius > 0.f; boolean drawTransparentCircleHole = drawCircleHole && dataSet.getCircleHoleColor() == ColorTemplate.COLOR_NONE; DataSetImageCache imageCache; if (mImageCaches.containsKey(dataSet)) { imageCache = mImageCaches.get(dataSet); } else { imageCache = new DataSetImageCache(); mImageCaches.put(dataSet, imageCache); } boolean changeRequired = imageCache.init(dataSet); // only fill the cache with new bitmaps if a change is required if (changeRequired) { imageCache.fill(dataSet, drawCircleHole, drawTransparentCircleHole); } int boundsRangeCount = mXBounds.range + mXBounds.min; for (int j = mXBounds.min; j <= boundsRangeCount; j++) { Entry e = dataSet.getEntryForIndex(j); if (e == null) { break; } mCirclesBuffer[0] = e.getX(); mCirclesBuffer[1] = e.getY() * phaseY; trans.pointValuesToPixel(mCirclesBuffer); if (!mViewPortHandler.isInBoundsRight(mCirclesBuffer[0])) { break; } if (!mViewPortHandler.isInBoundsLeft(mCirclesBuffer[0]) || !mViewPortHandler.isInBoundsY(mCirclesBuffer[1])) { continue; } Bitmap circleBitmap = imageCache.getBitmap(j); if (circleBitmap != null) { c.drawBitmap(circleBitmap, mCirclesBuffer[0] - circleRadius, mCirclesBuffer[1] - circleRadius, null); } } } }
Example 13
Source File: Transformer.java From Stayfit with Apache License 2.0 | 4 votes |
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the LINECHART. * * @param data * @return */ public float[] generateTransformedValuesLine(ILineDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) Math.ceil((to - from) * phaseX) * 2; float[] valuePoints = new float[count]; for (int j = 0; j < count; j += 2) { Entry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getXIndex(); valuePoints[j + 1] = e.getVal() * phaseY; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
Example 14
Source File: LineChartRenderer.java From android-kline with Apache License 2.0 | 4 votes |
protected void drawCubicBezier(ILineDataSet dataSet) { float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX())); float phaseY = mAnimator.getPhaseY(); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mXBounds.set(mChart, dataSet); float intensity = dataSet.getCubicIntensity(); cubicPath.reset(); if (mXBounds.range >= 1) { float prevDx = 0f; float prevDy = 0f; float curDx = 0f; float curDy = 0f; // Take an extra point from the left, and an extra from the right. // That's because we need 4 points for a cubic bezier (cubic=4), otherwise we get lines moving and doing weird stuff on the edges of the chart. // So in the starting `prev` and `cur`, go -2, -1 // And in the `lastIndex`, add +1 final int firstIndex = mXBounds.min + 1; final int lastIndex = mXBounds.min + mXBounds.range; Entry prevPrev; Entry prev = dataSet.getEntryForIndex(Math.max(firstIndex - 2, 0)); Entry cur = dataSet.getEntryForIndex(Math.max(firstIndex - 1, 0)); Entry next = cur; int nextIndex = -1; if (cur == null) return; // let the spline start cubicPath.moveTo(cur.getX(), cur.getY() * phaseY); for (int j = mXBounds.min + 1; j <= mXBounds.range + mXBounds.min; j++) { prevPrev = prev; prev = cur; cur = nextIndex == j ? next : dataSet.getEntryForIndex(j); nextIndex = j + 1 < dataSet.getEntryCount() ? j + 1 : j; next = dataSet.getEntryForIndex(nextIndex); prevDx = (cur.getX() - prevPrev.getX()) * intensity; prevDy = (cur.getY() - prevPrev.getY()) * intensity; curDx = (next.getX() - prev.getX()) * intensity; curDy = (next.getY() - prev.getY()) * intensity; cubicPath.cubicTo(prev.getX() + prevDx, (prev.getY() + prevDy) * phaseY, cur.getX() - curDx, (cur.getY() - curDy) * phaseY, cur.getX(), cur.getY() * phaseY); } } // if filled is enabled, close the path if (dataSet.isDrawFilledEnabled()) { cubicFillPath.reset(); cubicFillPath.addPath(cubicPath); drawCubicFill(mBitmapCanvas, dataSet, cubicFillPath, trans, mXBounds); } mRenderPaint.setColor(dataSet.getColor()); mRenderPaint.setStyle(Paint.Style.STROKE); trans.pathValueToPixel(cubicPath); mBitmapCanvas.drawPath(cubicPath, mRenderPaint); mRenderPaint.setPathEffect(null); }
Example 15
Source File: LineChartRenderer.java From android-kline with Apache License 2.0 | 4 votes |
protected void drawCircles(Canvas c) { mRenderPaint.setStyle(Paint.Style.FILL); float phaseY = mAnimator.getPhaseY(); mCirclesBuffer[0] = 0; mCirclesBuffer[1] = 0; List<ILineDataSet> dataSets = mChart.getLineData().getDataSets(); for (int i = 0; i < dataSets.size(); i++) { ILineDataSet dataSet = dataSets.get(i); if (!dataSet.isVisible() || !dataSet.isDrawCirclesEnabled() || dataSet.getEntryCount() == 0) continue; mCirclePaintInner.setColor(dataSet.getCircleHoleColor()); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mXBounds.set(mChart, dataSet); float circleRadius = dataSet.getCircleRadius(); float circleHoleRadius = dataSet.getCircleHoleRadius(); boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() && circleHoleRadius < circleRadius && circleHoleRadius > 0.f; boolean drawTransparentCircleHole = drawCircleHole && dataSet.getCircleHoleColor() == ColorTemplate.COLOR_NONE; DataSetImageCache imageCache; if (mImageCaches.containsKey(dataSet)) { imageCache = mImageCaches.get(dataSet); } else { imageCache = new DataSetImageCache(); mImageCaches.put(dataSet, imageCache); } boolean changeRequired = imageCache.init(dataSet); // only fill the cache with new bitmaps if a change is required if (changeRequired) { imageCache.fill(dataSet, drawCircleHole, drawTransparentCircleHole); } int boundsRangeCount = mXBounds.range + mXBounds.min; for (int j = mXBounds.min; j <= boundsRangeCount; j++) { Entry e = dataSet.getEntryForIndex(j); if (e == null) break; mCirclesBuffer[0] = e.getX(); mCirclesBuffer[1] = e.getY() * phaseY; trans.pointValuesToPixel(mCirclesBuffer); if (!mViewPortHandler.isInBoundsRight(mCirclesBuffer[0])) break; if (!mViewPortHandler.isInBoundsLeft(mCirclesBuffer[0]) || !mViewPortHandler.isInBoundsY(mCirclesBuffer[1])) continue; Bitmap circleBitmap = imageCache.getBitmap(j); if (circleBitmap != null) { c.drawBitmap(circleBitmap, mCirclesBuffer[0] - circleRadius, mCirclesBuffer[1] - circleRadius, null); } } } }
Example 16
Source File: LineChartRenderer.java From android-kline with Apache License 2.0 | 4 votes |
protected void drawCircles(Canvas c) { mRenderPaint.setStyle(Paint.Style.FILL); float phaseY = mAnimator.getPhaseY(); mCirclesBuffer[0] = 0; mCirclesBuffer[1] = 0; List<ILineDataSet> dataSets = mChart.getLineData().getDataSets(); for (int i = 0; i < dataSets.size(); i++) { ILineDataSet dataSet = dataSets.get(i); if (!dataSet.isVisible() || !dataSet.isDrawCirclesEnabled() || dataSet.getEntryCount() == 0) continue; mCirclePaintInner.setColor(dataSet.getCircleHoleColor()); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mXBounds.set(mChart, dataSet); float circleRadius = dataSet.getCircleRadius(); float circleHoleRadius = dataSet.getCircleHoleRadius(); boolean drawCircleHole = dataSet.isDrawCircleHoleEnabled() && circleHoleRadius < circleRadius && circleHoleRadius > 0.f; boolean drawTransparentCircleHole = drawCircleHole && dataSet.getCircleHoleColor() == ColorTemplate.COLOR_NONE; DataSetImageCache imageCache; if (mImageCaches.containsKey(dataSet)) { imageCache = mImageCaches.get(dataSet); } else { imageCache = new DataSetImageCache(); mImageCaches.put(dataSet, imageCache); } boolean changeRequired = imageCache.init(dataSet); // only fill the cache with new bitmaps if a change is required if (changeRequired) { imageCache.fill(dataSet, drawCircleHole, drawTransparentCircleHole); } int boundsRangeCount = mXBounds.range + mXBounds.min; for (int j = mXBounds.min; j <= boundsRangeCount; j++) { Entry e = dataSet.getEntryForIndex(j); if (e == null) break; mCirclesBuffer[0] = e.getX(); mCirclesBuffer[1] = e.getY() * phaseY; trans.pointValuesToPixel(mCirclesBuffer); if (!mViewPortHandler.isInBoundsRight(mCirclesBuffer[0])) break; if (!mViewPortHandler.isInBoundsLeft(mCirclesBuffer[0]) || !mViewPortHandler.isInBoundsY(mCirclesBuffer[1])) continue; Bitmap circleBitmap = imageCache.getBitmap(j); if (circleBitmap != null) { c.drawBitmap(circleBitmap, mCirclesBuffer[0] - circleRadius, mCirclesBuffer[1] - circleRadius, null); } } } }
Example 17
Source File: LineChartRenderer.java From android-kline with Apache License 2.0 | 4 votes |
protected void drawCubicBezier(ILineDataSet dataSet) { float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX())); float phaseY = mAnimator.getPhaseY(); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mXBounds.set(mChart, dataSet); float intensity = dataSet.getCubicIntensity(); cubicPath.reset(); if (mXBounds.range >= 1) { float prevDx = 0f; float prevDy = 0f; float curDx = 0f; float curDy = 0f; // Take an extra point from the left, and an extra from the right. // That's because we need 4 points for a cubic bezier (cubic=4), otherwise we get lines moving and doing weird stuff on the edges of the chart. // So in the starting `prev` and `cur`, go -2, -1 // And in the `lastIndex`, add +1 final int firstIndex = mXBounds.min + 1; final int lastIndex = mXBounds.min + mXBounds.range; Entry prevPrev; Entry prev = dataSet.getEntryForIndex(Math.max(firstIndex - 2, 0)); Entry cur = dataSet.getEntryForIndex(Math.max(firstIndex - 1, 0)); Entry next = cur; int nextIndex = -1; if (cur == null) return; // let the spline start cubicPath.moveTo(cur.getX(), cur.getY() * phaseY); for (int j = mXBounds.min + 1; j <= mXBounds.range + mXBounds.min; j++) { prevPrev = prev; prev = cur; cur = nextIndex == j ? next : dataSet.getEntryForIndex(j); nextIndex = j + 1 < dataSet.getEntryCount() ? j + 1 : j; next = dataSet.getEntryForIndex(nextIndex); prevDx = (cur.getX() - prevPrev.getX()) * intensity; prevDy = (cur.getY() - prevPrev.getY()) * intensity; curDx = (next.getX() - prev.getX()) * intensity; curDy = (next.getY() - prev.getY()) * intensity; cubicPath.cubicTo(prev.getX() + prevDx, (prev.getY() + prevDy) * phaseY, cur.getX() - curDx, (cur.getY() - curDy) * phaseY, cur.getX(), cur.getY() * phaseY); } } // if filled is enabled, close the path if (dataSet.isDrawFilledEnabled()) { cubicFillPath.reset(); cubicFillPath.addPath(cubicPath); drawCubicFill(mBitmapCanvas, dataSet, cubicFillPath, trans, mXBounds); } mRenderPaint.setColor(dataSet.getColor()); mRenderPaint.setStyle(Paint.Style.STROKE); trans.pathValueToPixel(cubicPath); mBitmapCanvas.drawPath(cubicPath, mRenderPaint); mRenderPaint.setPathEffect(null); }
Example 18
Source File: LineChartRenderer.java From NetKnight with Apache License 2.0 | 2 votes |
/** * Draws a cubic line. * * @param c * @param dataSet */ protected void drawHorizontalBezier(Canvas c, ILineDataSet dataSet) { Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); int entryCount = dataSet.getEntryCount(); Entry entryFrom = dataSet.getEntryForXIndex((mMinX < 0) ? 0 : mMinX, DataSet.Rounding.DOWN); Entry entryTo = dataSet.getEntryForXIndex(mMaxX, DataSet.Rounding.UP); int diff = (entryFrom == entryTo) ? 1 : 0; int minx = Math.max(dataSet.getEntryIndex(entryFrom) - diff, 0); int maxx = Math.min(Math.max(minx + 2, dataSet.getEntryIndex(entryTo) + 1), entryCount); float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX())); float phaseY = mAnimator.getPhaseY(); cubicPath.reset(); int size = (int) Math.ceil((maxx - minx) * phaseX + minx); if (size - minx >= 2) { Entry prev = dataSet.getEntryForIndex(minx); Entry cur = prev; // let the spline start cubicPath.moveTo(cur.getXIndex(), cur.getVal() * phaseY); for (int j = minx + 1, count = Math.min(size, entryCount); j < count; j++) { prev = dataSet.getEntryForIndex(j - 1); cur = dataSet.getEntryForIndex(j); final float cpx = (float)(prev.getXIndex()) + (float)(cur.getXIndex() - prev.getXIndex()) / 2.0f; cubicPath.cubicTo( cpx, prev.getVal() * phaseY, cpx, cur.getVal() * phaseY, cur.getXIndex(), cur.getVal() * phaseY); } } // if filled is enabled, close the path if (dataSet.isDrawFilledEnabled()) { cubicFillPath.reset(); cubicFillPath.addPath(cubicPath); // create a new path, this is bad for performance drawCubicFill(mBitmapCanvas, dataSet, cubicFillPath, trans, minx, size); } mRenderPaint.setColor(dataSet.getColor()); mRenderPaint.setStyle(Paint.Style.STROKE); trans.pathValueToPixel(cubicPath); mBitmapCanvas.drawPath(cubicPath, mRenderPaint); mRenderPaint.setPathEffect(null); }
Example 19
Source File: LineChartRenderer.java From android-kline with Apache License 2.0 | 2 votes |
protected void drawHorizontalBezier(ILineDataSet dataSet) { float phaseY = mAnimator.getPhaseY(); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mXBounds.set(mChart, dataSet); cubicPath.reset(); if (mXBounds.range >= 1) { Entry prev = dataSet.getEntryForIndex(mXBounds.min); Entry cur = prev; // let the spline start cubicPath.moveTo(cur.getX(), cur.getY() * phaseY); for (int j = mXBounds.min + 1; j <= mXBounds.range + mXBounds.min; j++) { prev = cur; cur = dataSet.getEntryForIndex(j); final float cpx = (prev.getX()) + (cur.getX() - prev.getX()) / 2.0f; cubicPath.cubicTo( cpx, prev.getY() * phaseY, cpx, cur.getY() * phaseY, cur.getX(), cur.getY() * phaseY); } } // if filled is enabled, close the path if (dataSet.isDrawFilledEnabled()) { cubicFillPath.reset(); cubicFillPath.addPath(cubicPath); // create a new path, this is bad for performance drawCubicFill(mBitmapCanvas, dataSet, cubicFillPath, trans, mXBounds); } mRenderPaint.setColor(dataSet.getColor()); mRenderPaint.setStyle(Paint.Style.STROKE); trans.pathValueToPixel(cubicPath); mBitmapCanvas.drawPath(cubicPath, mRenderPaint); mRenderPaint.setPathEffect(null); }
Example 20
Source File: LineChartRenderer.java From Stayfit with Apache License 2.0 | 2 votes |
@Override public void drawValues(Canvas c) { if (mChart.getLineData().getYValCount() < mChart.getMaxVisibleCount() * mViewPortHandler.getScaleX()) { List<ILineDataSet> dataSets = mChart.getLineData().getDataSets(); for (int i = 0; i < dataSets.size(); i++) { ILineDataSet dataSet = dataSets.get(i); if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0) continue; // apply the text-styling defined by the DataSet applyValueTextStyle(dataSet); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); // make sure the values do not interfear with the circles int valOffset = (int) (dataSet.getCircleRadius() * 1.75f); if (!dataSet.isDrawCirclesEnabled()) valOffset = valOffset / 2; int entryCount = dataSet.getEntryCount(); Entry entryFrom = dataSet.getEntryForXIndex((mMinX < 0) ? 0 : mMinX, DataSet.Rounding.DOWN); Entry entryTo = dataSet.getEntryForXIndex(mMaxX, DataSet.Rounding.UP); int minx = Math.max(dataSet.getEntryIndex(entryFrom), 0); int maxx = Math.min(dataSet.getEntryIndex(entryTo) + 1, entryCount); float[] positions = trans.generateTransformedValuesLine( dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), minx, maxx); for (int j = 0; j < positions.length; j += 2) { float x = positions[j]; float y = positions[j + 1]; if (!mViewPortHandler.isInBoundsRight(x)) break; if (!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y)) continue; Entry entry = dataSet.getEntryForIndex(j / 2 + minx); drawValue(c, dataSet.getValueFormatter(), entry.getVal(), entry, i, x, y - valOffset, dataSet.getValueTextColor(j / 2)); } } } }