private void calcViewportY(Viewport viewport) { mViewportYMax = -Float.MAX_VALUE; mViewportYMin = Float.MAX_VALUE; for (PointValue e : getVisiblePoints(viewport)) { calcViewportMinMax(e); } }
@Override public void calcMinMax(Viewport viewport) { if (mPointValues == null || mPointValues.isEmpty()) return; calcViewportY(viewport); }
@Override public int getEntryCount() { if (mPointValues == null) return 0; if (mForceValueCount > 0) return mForceValueCount; int entryCount = mPointValues.size(); if (getMinValueCount() > entryCount) { entryCount = getMinValueCount(); } return entryCount; }
mRenderPaint.setStrokeWidth(lineDataSet.getLineThickness()); mRenderPaint.setColor(lineDataSet.getColor()); int valueCount = lineDataSet.getEntryCount(); switch (lineDataSet.getAxisDependency()) { case AxisY.DEPENDENCY_RIGHT: min = rMin; final float count = lineDataSet.getVisibleRange(mViewport); float width = 0; if (count > 0) { int offset = lineDataSet.getStartIndexOffset(); boolean shaderSplit = !Float.isNaN(lineDataSet.getShaderBaseValue()) && lineDataSet.getShaderBaseValue() < max && lineDataSet.getShaderBaseValue() > min; lastIndex = (int) (Math.floor(lineDataSet.getValues().size() * mChartAnimator.getPhaseX()) - 1); for (; i < valuePhaseCount && i < lineDataSet.getValues().size(); i++) { PointValue point = lineDataSet.getEntryForIndex(i); float xPosition = startX + step * (i + lineDataSet.getStartIndexOffset()); float yPosition = (max - point.getValue()) / (max - min) * mContentRect.height(); float baseValue = lineDataSet.getShaderBaseValue(); float baseValueY = mContentRect.height() / (max - min) * (max - baseValue);
@Override public void touch(float x, float y) { if (chart.isHighlightDisable()) return; synchronized (chart) { for (LineDataSet line : getDataSet()) { if (line.isHighlightedVerticalEnable() && !line.getValues().isEmpty()) { highlight.setTouchX(x); highlight.setTouchY(y); int offset = line.getStartIndexOffset(); int index = getEntryIndexByCoordinate(x, y) - offset; if (index > 0 && index < line.getValues().size()) { final PointValue pointValue = line.getEntryForIndex(index); float xPosition = pointValue.getX(); float yPosition = pointValue.getY(); if (xPosition >= 0 && yPosition >= 0) { highlight.setX(xPosition); highlight.setY(yPosition); highlight.setDataIndex(index); chart.highlightValue(highlight); } } } } } } });
values.add(new PointValue(value)); line = new LineDataSet(values, AxisY.DEPENDENCY_LEFT); line.setHighlightedVerticalEnable(true);
@Override public boolean addEntry(PointValue e) { if (e == null) return false; if (mPointValues == null) { mPointValues = new ArrayList<>(); } calcViewportMinMax(e); // add the entry return mPointValues.add(e); }
@Override public void calcMinMax(Viewport viewport) { super.calcMinMax(viewport); if (mLastClose > 0) { if (getValues() != null && getValues().size() > 0) { float maxDiff = Math.max(Math.abs(mViewportYMin - mLastClose), Math.abs(mViewportYMax - mLastClose)); maxDiff = Math.max(mLastClose * 0.01f, maxDiff); mViewportYMin = mLastClose - maxDiff; mViewportYMax = mLastClose + maxDiff; } else { mViewportYMin = mLastClose * 0.9f; mViewportYMax = mLastClose * 1.1f; } } }
values.add(new PointValue(value)); line = new LineDataSet(values);