package com.hzn.library;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;

import java.util.ArrayList;

/**
 * 折线图
 * Created by huzn on 2017/3/21.
 */
public class EasyGraphLine extends EasyGraph {

    private Paint strokePaint;
    private Paint pathPaint;
    private Path path;

    public EasyGraphLine() {
        strokePaint = new Paint();
        strokePaint.setAntiAlias(true);
        strokePaint.setColor(Color.BLUE);
        strokePaint.setStrokeWidth(5);
        strokePaint.setStyle(Paint.Style.STROKE);
        pathPaint = new Paint();
        pathPaint.setAntiAlias(true);
        pathPaint.setColor(Color.RED);
        pathPaint.setStrokeWidth(4);
        pathPaint.setStyle(Paint.Style.STROKE);
        path = new Path();
    }

    @Override
    protected void drawGraph(ArrayList<EasyPoint> rawPointList, EasyPoint pOriginal,
                             EasyPoint pMin, EasyPoint pMax, Canvas canvas) {
        if (null == rawPointList || rawPointList.size() == 0)
            return;

        sortPointByX(rawPointList);

        path.reset();
        path.moveTo(rawPointList.get(0).x, rawPointList.get(0).y);

        EasyPoint point;
        int size = rawPointList.size();
        for (int i = 0; i < size; i++) {
            point = rawPointList.get(i);
            path.lineTo(point.x, point.y);
        }
        canvas.drawPath(path, pathPaint);

        for (int i = 0; i < size; i++) {
            point = rawPointList.get(i);
            canvas.drawCircle(point.x, point.y, 10, strokePaint);
        }
    }
}

@@ -1139,75 +1139,8 @@
 t();
-%0A        path.moveTo(rawPointList.get(0).x, rawPointList.get(0).y);
 %0A%0A  
@@ -1198,24 +1198,48 @@
 ist.size();%0A
+        int start = -1;%0A
         for 
@@ -1324,39 +1324,608 @@
     
-path.lineTo(point.x, point.y);%0A
+if (point.x %3E pMin.x && point.x %3C pMax.x &&%0A                    point.y %3E pMin.y && point.y %3C pMax.y) %7B%0A                path.moveTo(point.x, point.y);%0A                start = i == 0 ? 0 : i - 1;%0A                break;%0A            %7D%0A        %7D%0A%0A        if (start != -1) %7B%0A            for (int i = start; i %3C size; i++) %7B%0A                point = rawPointList.get(i);%0A                path.lineTo(point.x, point.y);%0A                if (i != start && (point.x %3C pMin.x %7C%7C point.x %3E pMax.x %7C%7C%0A                        point.y %3C pMin.y %7C%7C point.y %3E pMax.y)) %7B%0A                    break;%0A                %7D%0A    
     
@@ -1930,32 +1930,36 @@
       %7D%0A        
+    
 canvas.drawPath(
@@ -1977,32 +1977,36 @@
 aint);%0A%0A        
+    
 for (int i = 0; 
@@ -1994,33 +1994,37 @@
    for (int i = 
-0
+start
 ; i %3C size; i++)
@@ -2018,32 +2018,36 @@
  %3C size; i++) %7B%0A
+    
             poin
@@ -2075,32 +2075,36 @@
 i);%0A            
+    
 canvas.drawCircl
@@ -2141,16 +2141,215 @@
 Paint);%0A
+                if (i != start && (point.x %3C pMin.x %7C%7C point.x %3E pMax.x %7C%7C%0A                        point.y %3C pMin.y %7C%7C point.y %3E pMax.y)) %7B%0A                    break;%0A                %7D%0A            %7D%0A
         

optimize EasyGraphLine