Bladeren bron

added axis to linebar

Julien Clauter 10 jaren geleden
bovenliggende
commit
3940f05471

+ 1 - 1
src/com/echo/holographlibrary/BarGraph.java

@@ -43,7 +43,7 @@ import java.util.ArrayList;
 
 public class BarGraph extends View {
 
-	private final static int VALUE_FONT_SIZE = 23, AXIS_LABEL_FONT_SIZE = 15;
+	private final static int VALUE_FONT_SIZE = 23, AXIS_LABEL_FONT_SIZE = 12;
 	
     private ArrayList<Bar> mBars = new ArrayList<Bar>();
     private Paint mPaint = new Paint();

+ 250 - 122
src/com/echo/holographlibrary/LineGraph.java

@@ -42,11 +42,18 @@ import android.view.View;
 import java.util.ArrayList;
 
 public class LineGraph extends View {
-	
-	private ArrayList<Line> lines = new ArrayList<Line>();
+
+    public interface AxisDataConverter {
+        public String convertDataForX_Position(double x);
+        public String convertDataForY_Position(double y);
+    }
+
+    private final static int AXIS_LABEL_FONT_SIZE = 10;
+
+    private ArrayList<Line> lines = new ArrayList<Line>();
 	Paint paint = new Paint();
-	private float minY = 0, minX = 0;
-	private float maxY = 0, maxX = 0;
+	private double minY = 0, minX = 0;
+	private double maxY = 0, maxX = 0;
 	private double rangeYRatio = 0;
 	private double rangeXRatio = 0;
 	private boolean isMaxYUserSet = false;
@@ -56,14 +63,39 @@ public class LineGraph extends View {
 	private OnPointClickedListener listener;
 	private Bitmap fullImage;
 	private boolean shouldUpdate = false;
+
+    static final float bottomPadding = 40, topPadding = 10;
+    static final float rightPadding = 10;
+    static final float leftPadding = 50;
+    static final float sidePadding = rightPadding + leftPadding;
+
+    private float xAxisStep = 4;
+    private float yAxisStep = 4;
+
+    private AxisDataConverter converter;
+
+    private Context mContext;
+
+    public void setxAxisStep(float step){
+        this.xAxisStep = step;
+    }
+    public void setYAxisStep(float step){
+        this.yAxisStep = step;
+    }
+
+    public void setConverter(AxisDataConverter conv){
+        this.converter = conv;
+    }
 	
 	public LineGraph(Context context){
 		super(context);
+        this.mContext = context;
         this.setWillNotDraw(false);
     }
 	
 	public LineGraph(Context context, AttributeSet attrs) {
 		super(context, attrs);
+        this.mContext = context;
         this.setWillNotDraw(false);
     }
 	public void setMinY(float minY){
@@ -172,13 +204,15 @@ public class LineGraph extends View {
 	}
 	
 	public void resetYLimits(){
-		float range = getMaxY() - getMinY();
+        double range = getMaxY() - getMinY();
 		setRangeY(getMinY()-range*getRangeYRatio(), getMaxY()+range*getRangeYRatio());
-	}
+        isMaxYUserSet = false;
+    }
 	public void resetXLimits(){
-		float range = getMaxX() - getMinX();
+        double range = getMaxX() - getMinX();
 		setRangeX(getMinX()-range*getRangeXRatio(), getMaxX()+range*getRangeXRatio());
-	}
+        isMaxXUserSet = false;
+    }
 	public void resetLimits() {
 		resetYLimits();
 		resetXLimits();
@@ -209,21 +243,24 @@ public class LineGraph extends View {
 		maxY = max;
 		isMaxYUserSet = true;
 	}
-	private void setRangeY(double min, double max){
-		minY = (float)min;
-		maxY = (float)max;
-		isMaxXUserSet = true;
+	public void setRangeY(double min, double max){
+		minY = min;
+		maxY = max;
+		isMaxYUserSet = true;
 	}
 	public void setRangeX(float min, float max) {
 		minX = min;
 		maxX = max;
-	}
+        isMaxXUserSet = true;
+    }
 	private void setRangeX(double min, double max){
-		minX = (float)min;
-		maxX = (float)max;
-	}
-	public float getMaxY(){
-		float max = lines.get(0).getPoint(0).getY();
+		minX = min;
+		maxX = max;
+        isMaxXUserSet = true;
+    }
+	public double getMaxY(){
+        if (isMaxYUserSet)return maxY;
+        double max = lines.get(0).getPoint(0).getY();
 		for (Line line : lines){
 			for (LinePoint point : line.getPoints()){
 				max = point.getY() > max ? point.getY() : max;
@@ -233,8 +270,9 @@ public class LineGraph extends View {
 		return maxY;	
 	}
 
-	public float getMinY(){
-		float min = lines.get(0).getPoint(0).getY();
+	public double getMinY(){
+        if (isMaxYUserSet)return minY;
+        double min = lines.get(0).getPoint(0).getY();
 		for (Line line : lines){
 			for (LinePoint point : line.getPoints()){
 				min = point.getY() < min ? point.getY() : min;
@@ -243,16 +281,21 @@ public class LineGraph extends View {
 		minY = min;
 		return minY;
 	}
-	public float getMinLimY(){
+	public double getMinLimY(){
 		return minY;
 	}
-	public float getMaxLimY(){
+	public double getMaxLimY(){
 		return maxY;
 	}
-	public float getMinLimX(){
-		return minX;
+	public double getMinLimX(){
+        if (isMaxXUserSet) {
+            return minX;
+        }
+        else {
+            return getMinX();
+        }
 	}
-	public float getMaxLimX(){
+	public double getMaxLimX(){
 		if (isMaxXUserSet) {
 			return maxX;
 		}
@@ -260,22 +303,22 @@ public class LineGraph extends View {
 			return getMaxX();
 		}
 	}
-	public float getMaxX(){
-		float max = lines.size() > 0 ? lines.get(0).getPoint(0).getX() : 0;
+	public double getMaxX(){
+        double max = lines.size() > 0 ? lines.get(0).getPoint(0).getX() : 0;
 		for (Line line : lines){
 			for (LinePoint point : line.getPoints()){
-				max = point.getX() > max ? point.getX() : max;
+				max =Math.max(point.getX(), max);// point.getX() > max ? point.getX() : max;
 			}
 		}
 		maxX = max;
 		return maxX;
 		
 	}
-	public float getMinX(){
-		float min = lines.size() > 0 ? lines.get(0).getPoint(0).getX() : 0;
+	public double getMinX(){
+        double min = lines.size() > 0 ? lines.get(0).getPoint(0).getX() : 0;
 		for (Line line : lines){
 			for (LinePoint point : line.getPoints()){
-				min = point.getX() < min ? point.getX() : min;
+				min =Math.min(point.getX(), min);// point.getX() < min ? point.getX() : min;
 			}
 		}
 		minX = min;
@@ -283,7 +326,14 @@ public class LineGraph extends View {
 	}
 	
 
-
+    private String getX_AxisTitle(double x){
+        if (this.converter == null)return "" + (long)x;
+        return this.converter.convertDataForX_Position(x);
+    }
+    private String getY_AxisTitle(double y){
+        if (this.converter == null)return "" + (long)y;
+        return this.converter.convertDataForY_Position(y);
+    }
 	 
 	public void onDraw(Canvas ca) {
         super.onDraw(ca);
@@ -295,91 +345,26 @@ public class LineGraph extends View {
 			paint.reset();
 			Path path = new Path();
 
-			float bottomPadding = 10, topPadding = 10;
-			float sidePadding = 10;
+
 			float usableHeight = getHeight() - bottomPadding - topPadding;
 			float usableWidth = getWidth() - 2*sidePadding;
 
-			float maxY = getMaxLimY();
-			float minY = getMinLimY();
-			float maxX = getMaxLimX();
-			float minX = getMinLimX();
+            double maxY = getMaxLimY();
+            double minY = getMinLimY();
+            double maxX = getMaxLimX();
+            double minX = getMinLimX();
 
-	        
-			int lineCount = 0;
-			for (Line line : lines){
-				int count = 0;
-				float firstXPixels = 0, lastXPixels = 0, newYPixels = 0;
-				float lastYPixels = 0, newXPixels = 0;
-				
-				if (lineCount == lineToFill){
-					paint.setColor(Color.BLACK);
-					paint.setAlpha(30);
-					paint.setStrokeWidth(2);
-					for (int i = 10; i-getWidth() < getHeight(); i = i+20){
-						canvas.drawLine(i, getHeight()-bottomPadding, 0, getHeight()-bottomPadding-i, paint);
-					}
-					
-					paint.reset();
-					
-					paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
-					for (LinePoint p : line.getPoints()){
-						float yPercent = (p.getY()-minY)/(maxY - minY);
-						float xPercent = (p.getX()-minX)/(maxX - minX);
-						if (count == 0){
-							lastXPixels = sidePadding + (xPercent*usableWidth);
-							lastYPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
-							firstXPixels = lastXPixels;
-							path.moveTo(lastXPixels, lastYPixels);
-						} else {
-							newXPixels = sidePadding + (xPercent*usableWidth);
-							newYPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
-							path.lineTo(newXPixels, newYPixels);
-							Path pa = new Path();
-							pa.moveTo(lastXPixels, lastYPixels);
-							pa.lineTo(newXPixels, newYPixels);
-							pa.lineTo(newXPixels, 0);
-							pa.lineTo(lastXPixels, 0);
-							pa.close();
-							canvas.drawPath(pa, paint);
-							lastXPixels = newXPixels;
-							lastYPixels = newYPixels;
-						}
-						count++;
-					}
-					
-					path.reset();
-					
-					path.moveTo(0, getHeight()-bottomPadding);
-					path.lineTo(sidePadding, getHeight()-bottomPadding);
-					path.lineTo(sidePadding, 0);
-					path.lineTo(0, 0);
-					path.close();
-					canvas.drawPath(path, paint);
-					
-					path.reset();
-					
-					path.moveTo(getWidth(), getHeight()-bottomPadding);
-					path.lineTo(getWidth()-sidePadding, getHeight()-bottomPadding);
-					path.lineTo(getWidth()-sidePadding, 0);
-					path.lineTo(getWidth(), 0);
-					path.close();
-					
-					canvas.drawPath(path, paint);
-					
-				}
-				
-				lineCount++;
-			}
-			
-			paint.reset();
-			
-			paint.setColor(Color.BLACK);
-			paint.setAlpha(50);
-			paint.setAntiAlias(true);
-			canvas.drawLine(sidePadding, getHeight() - bottomPadding, getWidth()-sidePadding, getHeight()-bottomPadding, paint);
-			paint.setAlpha(255);
-			
+
+	        // DRAW THE BACKGROUND
+            //this.drawBackground(canvas);
+
+            // DRAW THE AXIS
+            this.drawAxis(canvas);
+
+
+            paint.reset();
+
+            // DRAW LINES
 			for (Line line : lines){
 				int count = 0;
 				float lastXPixels = 0, newYPixels = 0;
@@ -389,8 +374,8 @@ public class LineGraph extends View {
 				paint.setStrokeWidth(getStrokeWidth(line));
 				
 				for (LinePoint p : line.getPoints()){
-					float yPercent = (p.getY()-minY)/(maxY - minY);
-					float xPercent = (p.getX()-minX)/(maxX - minX);
+                    float yPercent =(float) ((p.getY()-minY)/(maxY - minY));
+                    float xPercent = (float)((p.getX()-minX)/(maxX - minX));
 					if (count == 0){
 						lastXPixels = sidePadding + (xPercent*usableWidth);
 						lastYPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
@@ -407,7 +392,7 @@ public class LineGraph extends View {
 			
 			
 			int pointCount = 0;
-			
+			// DRAW POINTS
 			for (Line line : lines){
 
 				paint.setColor(line.getColor());
@@ -416,10 +401,10 @@ public class LineGraph extends View {
 				
 				if (line.isShowingPoints()){
 					for (LinePoint p : line.getPoints()){
-						float yPercent = (p.getY()-minY)/(maxY - minY);
-						float xPercent = (p.getX()-minX)/(maxX - minX);
+                        float yPercent =(float) ((p.getY()-minY)/(maxY - minY));
+						float xPercent =(float) ((p.getX()-minX)/(maxX - minX));
 						float xPixels = sidePadding + (xPercent*usableWidth);
-						float yPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
+                        float yPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
 
 						int outerRadius;
 						if (line.isUsingDips()) {
@@ -431,12 +416,12 @@ public class LineGraph extends View {
 						int innerRadius = outerRadius / 2;
 
 						paint.setColor(p.getColor());
-						canvas.drawCircle(xPixels, yPixels, outerRadius, paint);
+						canvas.drawCircle(xPixels,(float) yPixels, outerRadius, paint);
 						paint.setColor(Color.WHITE);
-						canvas.drawCircle(xPixels, yPixels, innerRadius, paint);
+						canvas.drawCircle(xPixels,(float) yPixels, innerRadius, paint);
 						
 						Path path2 = new Path();
-						path2.addCircle(xPixels, yPixels, 30, Direction.CW);
+						path2.addCircle(xPixels,(float) yPixels, 30, Direction.CW);
 						p.setPath(path2);
 						p.setRegion(new Region((int)(xPixels-30), (int)(yPixels-30), (int)(xPixels+30), (int)(yPixels+30)));
 						
@@ -460,6 +445,149 @@ public class LineGraph extends View {
 		
 	}
 
+    private void drawAxis(Canvas canvas){
+        paint.reset();
+
+        double maxX = getMaxLimX();
+        double minX = getMinLimX();
+
+        float usableWidth = getWidth() - 2*sidePadding;
+        float usableHeight = getHeight() - bottomPadding - topPadding;
+
+        float yPixels = getHeight() - (bottomPadding*3/5);
+
+        // DRAW SEPERATOR
+        paint.setColor(Color.BLACK);
+        paint.setAlpha(50);
+        paint.setAntiAlias(true);
+        // x Axis
+        canvas.drawLine(leftPadding ,yPixels, getWidth()-sidePadding, yPixels, paint);
+        // y Axis
+        canvas.drawLine(leftPadding ,topPadding, leftPadding, yPixels, paint);
+
+        paint.setAlpha(255);
+        this.paint.setTextSize(AXIS_LABEL_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
+
+        // Draw y-axis label text
+        //double skippedValue = (maxY - minY ) / (Math.max(1., yAxisStep));
+        double step = Math.max(1., (maxY - minY) / (Math.max(1., yAxisStep)));
+
+        for (double y = minY; y <= maxY; y+=step){
+            double yPercent = (y-minY)/(maxY - minY);
+
+            double newYPixels = topPadding + (yPercent*usableHeight);
+            canvas.drawLine((float)leftPadding,(float)newYPixels,(float)leftPadding-5.f,(float)newYPixels, paint);
+            String title = this.getY_AxisTitle(maxY - y);
+            float textwidth = (this.paint.measureText(title));
+            canvas.drawText(title, 5.f ,(float)newYPixels + (textwidth/2), this.paint);
+
+            //value+=skippedValue;
+        }
+
+        // Draw x-axis label text
+        //value = minX;
+        //skippedValue = (maxX - minX ) / (Math.max(1,xAxisStep));
+        step = Math.max(1, (maxX - minX) / (Math.max(1, xAxisStep)));
+
+        for (double x = minX; x <= maxX; x+=step){
+            double xPercent = (x-minX)/(maxX - minX);
+
+            double newXPixels = sidePadding + (xPercent*usableWidth);
+            canvas.drawLine((float)newXPixels,(float) yPixels + 5,(float) newXPixels,(float) yPixels, paint);
+            String title = this.getX_AxisTitle(x);
+            float textwidth = (this.paint.measureText(title));
+            //this.paint.setTextSize(AXIS_LABEL_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
+            canvas.drawText(title,(float) newXPixels - (textwidth/2),(float) yPixels + (bottomPadding / 2), this.paint);
+
+            //value+=skippedValue;
+        }
+        paint.reset();
+    }
+
+    private void drawBackground(Canvas canvas){
+
+        paint.reset();
+
+
+        float usableHeight = getHeight() - bottomPadding - topPadding;
+        float usableWidth = getWidth() - 2*sidePadding;
+
+        double maxY = getMaxLimY();
+        double minY = getMinLimY();
+        double maxX = getMaxLimX();
+        double minX = getMinLimX();
+
+        Path path = new Path();
+
+        // DRAW THE BACKGROUND
+			int lineCount = 0;
+			for (Line line : lines){
+				int count = 0;
+				float firstXPixels = 0, lastXPixels = 0, newYPixels = 0;
+				float lastYPixels = 0, newXPixels = 0;
+
+				if (lineCount == lineToFill){
+					paint.setColor(Color.BLACK);
+					paint.setAlpha(30);
+					paint.setStrokeWidth(2);
+					for (int i = 10; i-getWidth() < getHeight(); i = i+20){
+						canvas.drawLine(i, getHeight()-bottomPadding, 0, getHeight()-bottomPadding-i, paint);
+					}
+
+
+					paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
+					for (LinePoint p : line.getPoints()){
+						float yPercent =(float) ((p.getY()-minY)/(maxY - minY));
+						float xPercent =(float) ((p.getX()-minX)/(maxX - minX));
+						if (count == 0){
+							lastXPixels = sidePadding + (xPercent*usableWidth);
+							lastYPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
+							firstXPixels = lastXPixels;
+							path.moveTo(lastXPixels, lastYPixels);
+						} else {
+							newXPixels = sidePadding + (xPercent*usableWidth);
+							newYPixels = getHeight() - bottomPadding - (usableHeight*yPercent);
+							path.lineTo(newXPixels, newYPixels);
+							Path pa = new Path();
+							pa.moveTo(lastXPixels, lastYPixels);
+							pa.lineTo(newXPixels, newYPixels);
+							pa.lineTo(newXPixels, 0);
+							pa.lineTo(lastXPixels, 0);
+							pa.close();
+							canvas.drawPath(pa, paint);
+							lastXPixels = newXPixels;
+							lastYPixels = newYPixels;
+						}
+						count++;
+					}
+
+					path.reset();
+
+					path.moveTo(0, getHeight()-bottomPadding);
+					path.lineTo(sidePadding, getHeight()-bottomPadding);
+					path.lineTo(sidePadding, 0);
+					path.lineTo(0, 0);
+					path.close();
+					canvas.drawPath(path, paint);
+
+					path.reset();
+
+					path.moveTo(getWidth(), getHeight()-bottomPadding);
+					path.lineTo(getWidth()-sidePadding, getHeight()-bottomPadding);
+					path.lineTo(getWidth()-sidePadding, 0);
+					path.lineTo(getWidth(), 0);
+					path.close();
+
+					canvas.drawPath(path, paint);
+
+				}
+
+				lineCount++;
+			}
+
+        this.paint.reset();
+    }
+
 	private int getStrokeWidth(Line line) {
 		int strokeWidth;
 		if (line.isUsingDips()) {

+ 8 - 8
src/com/echo/holographlibrary/LinePoint.java

@@ -28,8 +28,8 @@ import android.graphics.Path;
 import android.graphics.Region;
 
 public class LinePoint {
-	private float x = 0;
-	private float y = 0;
+	private double x = 0;
+	private double y = 0;
 	private Path path;
 	private Region region;
     private Integer color;
@@ -38,20 +38,20 @@ public class LinePoint {
     }
 
 	public LinePoint(double x, double y){
-		this.x = (float)x;
-		this.y = (float)y;
+		this.x = x;
+		this.y = y;
 	}
 	public LinePoint(float x, float y){
 		this.x = x;
 		this.y = y;
 	}
-	public float getX() {
+	public double getX() {
 		return x;
 	}
 	public void setX(float x) {
 		this.x = x;
 	}
-	public float getY() {
+	public double getY() {
 		return y;
 	}
 	public void setY(float y) {
@@ -59,11 +59,11 @@ public class LinePoint {
 	}
 	
 	public void setX(double x){
-		this.x = (float) x;
+		this.x =  x;
 	}
 	
 	public void setY(double y){
-		this.y = (float) y;
+		this.y =  y;
 	}
 	public Region getRegion() {
 		return region;

+ 113 - 89
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -545,23 +545,62 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         if (this.currentData == null){
             this.currentData = new ArrayList<PlotComparisonItem>();
         }
-        int index = 0;
 
         this.lineGraph.removeAllLines();
-        Line l = new Line();
-        l.setColor(this.getColor(0));
+        double rangeMax = 0;
+        double rangeMin = 0;
+
+        boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
+        if (shouldUseDate){
+            this.lineGraph.resetXLimits();
+            this.lineGraph.setxAxisStep(4);
+            this.lineGraph.setConverter(new LineGraph.AxisDataConverter() {
+                @Override
+                public String convertDataForX_Position(double x) {
+                    return StatisticsFragment.this.getDateAsDayString((long)x);
+                }
+                @Override
+                public  String convertDataForY_Position(double y){
+                    return "" + (long)y;
+                }
+            });
+        } else {
+            this.lineGraph.setxAxisStep(12.f);
+            this.lineGraph.setRangeX(0  , 24);
+            this.lineGraph.setConverter(null);
+        }
 
-        for (PlotComparisonItem item : this.currentData){
-            LinePoint p = new LinePoint();
-            p.setX(index);
-            Double value2 = (Double) item.getValue2();
-            p.setY(value2.floatValue());
-            p.setColor(item.getColor());
-            l.addPoint(p);
-            index++;
+        int count = 0;
+        for (PlotComparisonItem lineItem : this.currentData){
+            ArrayList<PlotComparisonItem> data = lineItem.getOtherData();
+            int index = 0;
+            Line l = new Line();
+            int lineColor = lineItem.getColor();
+            l.setColor(lineColor);
+
+            for (PlotComparisonItem pointItem : data){
+                LinePoint p = new LinePoint();
+                p.setX(pointItem.getValue1());
+                Double value2 = pointItem.getValue2();
+                p.setY(value2);
+                p.setColor(lineColor);
+                l.addPoint(p);
+                rangeMax = Math.max(pointItem.getValue2(), rangeMax);
+                if (count != 0){
+                    rangeMin = Math.min(pointItem.getValue2(), rangeMin);
+                } else {
+                    rangeMin = pointItem.getValue2();
+                }
+                index++;
+                count++;
+            }
+            this.lineGraph.addLine(l);
         }
-        this.lineGraph.addLine(l);
-        this.lineGraph.setRangeY(0, index);
+        // add a bit more space
+        rangeMax++;
+        rangeMin--;
+
+        this.lineGraph.setRangeY(rangeMin, rangeMax);
         this.lineGraph.setLineToFill(0);
         this.lineGraph.invalidate();
     }
@@ -660,23 +699,17 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         String protocol = this.getCurrentSelectedProtocol();
 
         if (protocol.length() > 0){
-            if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerESSID)){
-                return this.attacksPerESSID(protocol);
+            if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerBSSID)){
+                return this.attacksPerBSSID(protocol);
             }
-
             // DEFAULT
-            return this.attacksPerBSSID(protocol);
+            return this.attacksPerESSID(protocol);
         }
-
         // Nothing available
         return new ArrayList<PlotComparisonItem>();
     }
     public ArrayList<PlotComparisonItem> getLineData(){
-        if (this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerTime)){
-            return this.attacksPerTime();
-        }
-        // DEFAULT
-        return this.attacksPerDate();
+        return this.attacksPerTime();
     }
 
     /*
@@ -720,67 +753,76 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         return plotItems;
     }
     /*LINE PLOT DATA*/
-    public ArrayList<PlotComparisonItem> attacksPerDate(){
-        ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
-        HashMap<Long, ArrayList<Record> > recordMap = new HashMap<Long, ArrayList<Record> >();
+
+    public ArrayList<PlotComparisonItem> attacksPerTime(){
+        HashMap<String,HashMap<Long, ArrayList<Record> > > lineMap = new HashMap<String, HashMap<Long, ArrayList<Record>>>();
+
+        boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
 
         for (Record record : this.getFetchedRecords()){
             long timestamp = record.getTimestamp();
-            long date = this.getDateFromMilliseconds(timestamp);
-            ArrayList<Record> list = recordMap.get(date);
-            if (list == null){
-                list = new ArrayList<Record>();
-                recordMap.put(date, list);
+            long time = 0;
+            if (shouldUseDate){
+                time = this.getDateFromMilliseconds(timestamp);
+            } else {
+                time = this.getDayHourFromDate(timestamp);
             }
-            list.add(record);
-        }
-        int index = 0;
-        for (long date : recordMap.keySet()){
-            ArrayList<Record> list = recordMap.get(date);
-            if (list.size() == 0) continue;
-            // TODO SET CORRECT COLOR
-            PlotComparisonItem item = new PlotComparisonItem(this.getDateAsDayString(date), this.getColor(0), (double) date, (double)list.size());
-            plotItems.add(item);
-            index++;
-        }
-        Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
-            @Override
-            public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
-                return s1.getValue1().compareTo(s2.getValue1());
+
+            // GET CORRECT MAP
+            HashMap<Long, ArrayList<Record> > recordMap;
+            String groupKey = record.getSsid();
+            if (lineMap.containsKey(groupKey)){
+                recordMap = lineMap.get(record.getSsid());
+            } else {
+                recordMap = new HashMap<Long, ArrayList<Record> >();
+                lineMap.put(groupKey, recordMap);
             }
-        });
-        return  plotItems;
-    }
-    public ArrayList<PlotComparisonItem> attacksPerTime(){
-        ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
-        HashMap<Long, ArrayList<Record> > recordMap = new HashMap<Long, ArrayList<Record> >();
 
-        for (Record record : this.getFetchedRecords()){
-            long timestamp = record.getTimestamp();
-            long time = this.getDayHourFromDate(timestamp);
-            ArrayList<Record> list = recordMap.get(time);
-            if (list == null){
+            // GET LIST OF RECORDS
+            ArrayList<Record> list;
+            if (recordMap.containsKey(time)){
+                list = recordMap.get(time);
+            } else {
                 list = new ArrayList<Record>();
                 recordMap.put(time, list);
             }
             list.add(record);
         }
+
+        ArrayList<PlotComparisonItem> plotItems = new ArrayList<PlotComparisonItem>();
+
         int index = 0;
-        for (long time : recordMap.keySet()){
-            ArrayList<Record> list = recordMap.get(time);
-            if (list.size() == 0) continue;
-            // TODO SET CURRECT COLOR
-            PlotComparisonItem item = new PlotComparisonItem(this.getDateAsTimeString(time), this.getColor(0) , (double)time, (double) list.size());
+        for (String groupKey : lineMap.keySet()){
+            HashMap<Long, ArrayList<Record> > recordMap = lineMap.get(groupKey);
+            ArrayList<PlotComparisonItem> singleLineItems = new ArrayList<PlotComparisonItem>();
+
+            for (long time : recordMap.keySet()){
+                ArrayList<Record>list = recordMap.get(time);
+                if (list.size() == 0) continue;
+                PlotComparisonItem item = new PlotComparisonItem(this.getHourAsTimeString(time), 0 , (double)time, (double) list.size());
+                singleLineItems.add(item);
+            }
+
+            Collections.sort(singleLineItems, new Comparator<PlotComparisonItem>() {
+                @Override
+                public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
+                    return s1.getValue1().compareTo(s2.getValue1());
+                }
+            });
+
+
+            PlotComparisonItem item = new PlotComparisonItem(groupKey, this.getColor(index), 0., (double) singleLineItems.size());
+            item.setOtherData(singleLineItems);
             plotItems.add(item);
             index++;
         }
         Collections.sort(plotItems, new Comparator<PlotComparisonItem>() {
             @Override
             public int compare(PlotComparisonItem s1, PlotComparisonItem s2) {
-                return s1.getValue1().compareTo(s2.getValue1());
+                return s2.getValue2().compareTo(s1.getValue2());
             }
         });
-        return  plotItems;
+        return plotItems;
     }
     // BAR PLOT DATA
     public ArrayList<PlotComparisonItem> attacksPerBSSID(String protocol){
@@ -850,7 +892,7 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             }
         });
 
-        return this.resizeData(plotItems);
+        return plotItems;// this.resizeData(plotItems);
     }
 
 
@@ -1001,34 +1043,16 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         long millisInDay = 60 * 60 * 24 * 1000;
         return (timeInMillis / millisInDay) * millisInDay;
 
-        /*
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTimeInMillis (timeInMillis);
-
-        int year    = calendar.get(Calendar.YEAR) ;
-        int month   = calendar.get(Calendar.MONTH);
-        int day     = calendar.get(Calendar.DATE);
-
-        calendar.set(year, month, day, 0,0);
-        return calendar.getTimeInMillis();
-        */
     }
 
-    static final DateFormat timeFormat = new SimpleDateFormat("H:mm");
-    @SuppressLint("SimpleDateFormat")
-    private String getDateAsTimeString(long timeStamp) {
-        return "" + timeStamp + ":00";
-        /*
-        try {
-            Date netDate = (new Date(timeStamp));
-            return timeFormat.format(netDate);
-        } catch (Exception ex) {
-            return "xx";
-        }
-        */
+    /*
+    *
+    * */
+    private String getHourAsTimeString(long hour) {
+        return "" + hour + ":00";
     }
 
-    static final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
+    static final DateFormat dateFormat = new SimpleDateFormat("d.M.yyyy");
     @SuppressLint("SimpleDateFormat")
     private String getDateAsDayString(long timeStamp) {
         try {