@Override public void renderGridLines(Canvas c) { if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled()) return; // pre alloc float[] position = new float[] {0f, 0f}; mGridPaint.setColor(mXAxis.getGridColor()); mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth()); mGridPaint.setPathEffect(mXAxis.getGridDashPathEffect()); Path gridLinePath = new Path(); for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) { String label = mXAxis.getValues().get(i); position[0] = i; mTrans.pointValuesToPixel(position); if (position[0] >= mViewPortHandler.offsetLeft() && position[0] <= mViewPortHandler.getChartWidth()) { gridLinePath.moveTo(position[0], mViewPortHandler.contentBottom() * topchartScale); gridLinePath.lineTo(position[0], mViewPortHandler.contentTop()); // draw a path because lines don't support dashing on lower android versions c.drawPath(gridLinePath, mGridPaint); } gridLinePath.reset(); if (position[0] >= mViewPortHandler.offsetLeft() && position[0] <= mViewPortHandler.getChartWidth()) { gridLinePath.moveTo( position[0], mViewPortHandler.contentBottom() * (topchartScale + 0.08f)); gridLinePath.lineTo(position[0], mViewPortHandler.contentBottom()); // draw a path because lines don't support dashing on lower android versions c.drawPath(gridLinePath, mGridPaint); } gridLinePath.reset(); } }
@Override public void renderAxisLine(Canvas c) { if (!mXAxis.isDrawAxisLineEnabled() || !mXAxis.isEnabled()) return; mAxisLinePaint.setColor(mXAxis.getAxisLineColor()); mAxisLinePaint.setStrokeWidth(mXAxis.getAxisLineWidth()); // if (mXAxis.getPosition() == XAxisPosition.TOP // || mXAxis.getPosition() == XAxisPosition.TOP_INSIDE // || mXAxis.getPosition() == XAxisPosition.BOTH_SIDED) { c.drawLine( mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), mViewPortHandler.contentRight(), mViewPortHandler.contentTop(), mAxisLinePaint); // } // if (mXAxis.getPosition() == XAxisPosition.BOTTOM // || mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE // || mXAxis.getPosition() == XAxisPosition.BOTH_SIDED) { c.drawLine( mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom() * topchartScale, mViewPortHandler.contentRight(), mViewPortHandler.contentBottom() * topchartScale, mAxisLinePaint); float yoffset = mViewPortHandler.contentBottom() * 0.08f - Utils.convertDpToPixel(1); c.drawLine( mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom() * topchartScale + yoffset, mViewPortHandler.contentRight(), mViewPortHandler.contentBottom() * topchartScale + yoffset, mAxisLinePaint); c.drawLine( mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom() - 1, mViewPortHandler.contentRight(), mViewPortHandler.contentBottom() - 1, mAxisLinePaint); // } }
@Override public void renderAxisLabels(Canvas c) { if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled()) return; float yoffset = Utils.convertDpToPixel(4f); mAxisLabelPaint.setTypeface(mXAxis.getTypeface()); mAxisLabelPaint.setTextSize(mXAxis.getTextSize()); mAxisLabelPaint.setColor(mXAxis.getTextColor()); if (mXAxis.getPosition() == XAxisPosition.TOP) { drawLabels(c, mViewPortHandler.offsetTop() - yoffset); } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM) { drawLabels( c, mViewPortHandler.contentBottom() * topchartScale + (mViewPortHandler.contentBottom() * 0.04f) + mXAxis.mLabelHeight / 2); } else if (mXAxis.getPosition() == XAxisPosition.BOTTOM_INSIDE) { drawLabels(c, mViewPortHandler.contentBottom() - yoffset); } else if (mXAxis.getPosition() == XAxisPosition.TOP_INSIDE) { drawLabels(c, mViewPortHandler.offsetTop() + yoffset + mXAxis.mLabelHeight); } else { // BOTH SIDED drawLabels(c, mViewPortHandler.offsetTop() - yoffset); drawLabels(c, mViewPortHandler.contentBottom() + mXAxis.mLabelHeight + yoffset * 1.6f); } }