/** draw Y Mark */ private void drawYMark(GraphCanvasWrapper canvas) { for (int i = 0; mLineGraphVO.getIncrement() * i <= mLineGraphVO.getMaxValue(); i++) { float y = yLength * mLineGraphVO.getIncrement() * i / mLineGraphVO.getMaxValue(); canvas.drawLine(0, y, -10, y, pBaseLine); } }
private void drawBaseLine(GraphCanvasWrapper graphCanvas) { for (int i = 1; mLineGraphVO.getIncrement() * i <= mLineGraphVO.getMaxValue(); i++) { float y = yLength * mLineGraphVO.getIncrement() * i / mLineGraphVO.getMaxValue(); graphCanvas.drawLine(0, y, chartXLength, y, pBaseLineX); } }
/** draw X Mark */ private void drawXMark(GraphCanvasWrapper graphCanvas) { float x = 0; float y = 0; float xGap = xLength / (mLineGraphVO.getArrGraph().get(0).getCoordinateArr().length - 1); for (int i = 0; i < mLineGraphVO.getArrGraph().get(0).getCoordinateArr().length; i++) { x = xGap * i; y = yLength * mLineGraphVO.getArrGraph().get(0).getCoordinateArr()[i] / mLineGraphVO.getMaxValue(); graphCanvas.drawLine(x, 0, x, -10, pBaseLine); } }
@Override public void run() { Canvas canvas = null; GraphCanvasWrapper graphCanvasWrapper = null; Log.e(TAG, "height = " + height); Log.e(TAG, "width = " + width); setPaint(); isAnimation(); isDrawRegion(); animStartTime = System.currentTimeMillis(); while (isRun) { // draw only on dirty mode if (!isDirty) { try { Thread.sleep(100); } catch (InterruptedException e1) { e1.printStackTrace(); } continue; } canvas = mHolder.lockCanvas(); graphCanvasWrapper = new GraphCanvasWrapper( canvas, width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom()); try { Thread.sleep(0000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } calcTimePass(); synchronized (mHolder) { synchronized (touchLock) { try { // bg color canvas.drawColor(Color.WHITE); if (bg != null) { canvas.drawBitmap(bg, 0, 0, null); } // x coord dot line drawBaseLine(graphCanvasWrapper); // y coord graphCanvasWrapper.drawLine(0, 0, 0, chartYLength, pBaseLine); // x coord graphCanvasWrapper.drawLine(0, 0, chartXLength, 0, pBaseLine); // x, y coord mark drawXMark(graphCanvasWrapper); drawYMark(graphCanvasWrapper); // x, y coord text drawXText(graphCanvasWrapper); drawYText(graphCanvasWrapper); // Graph drawGraphRegion(graphCanvasWrapper); drawGraph(graphCanvasWrapper); drawGraphName(canvas); // isDirty = false; } catch (Exception e) { e.printStackTrace(); } finally { if (graphCanvasWrapper.getCanvas() != null) { mHolder.unlockCanvasAndPost(graphCanvasWrapper.getCanvas()); } } } } } }