Browse Source

bug fi xin axis scaling in statistics line graph

Julien Clauter 10 years ago
parent
commit
3740b50cb3

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

@@ -253,7 +253,7 @@ public class LineGraph extends View {
 		maxX = max;
         isMaxXUserSet = true;
     }
-	private void setRangeX(double min, double max){
+	public void setRangeX(double min, double max){
 		minX = min;
 		maxX = max;
         isMaxXUserSet = true;

+ 46 - 27
src/de/tudarmstadt/informatik/hostage/ui2/fragment/StatisticsFragment.java

@@ -743,28 +743,11 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
         }
 
         this.lineGraph.removeAllLines();
-        double rangeMax = 0;
-        double rangeMin = 0;
+        double rangeMax_Y = 0;
+        double rangeMin_Y = 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);
-        }
+        double rangeMax_X = 0;
+        double rangeMin_X = 0;
 
         int count = 0;
         for (PlotComparisonItem lineItem : this.currentData){
@@ -781,11 +764,15 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
                 p.setY(value2);
                 p.setColor(lineColor);
                 l.addPoint(p);
-                rangeMax = Math.max(pointItem.getValue2(), rangeMax);
+                rangeMax_Y = Math.max(pointItem.getValue2(), rangeMax_Y);
+                rangeMax_X = Math.max(pointItem.getValue1(), rangeMax_X);
+
                 if (count != 0){
-                    rangeMin = Math.min(pointItem.getValue2(), rangeMin);
+                    rangeMin_Y = Math.min(pointItem.getValue2(), rangeMin_Y);
+                    rangeMin_X = Math.min(pointItem.getValue1(), rangeMin_X);
                 } else {
-                    rangeMin = pointItem.getValue2();
+                    rangeMin_Y = pointItem.getValue2();
+                    rangeMin_X = pointItem.getValue1();
                 }
                 index++;
                 count++;
@@ -793,10 +780,42 @@ public class StatisticsFragment extends Fragment implements ChecklistDialog.Chec
             this.lineGraph.addLine(l);
         }
         // add a bit more space
-        rangeMax++;
-        rangeMin--;
+        rangeMax_Y++;
+        rangeMin_Y--;
+
+        boolean shouldUseDate = this.selectedCompareData.equals(COMPARE_TITLE_AttacksPerDate);
+        if (shouldUseDate){
+            this.lineGraph.resetXLimits();
+
+            if (this.filter.hasBelowTimestamp()){
+                rangeMax_X = Math.max(this.filter.belowTimestamp, rangeMax_X);
+            }
+            if (this.filter.hasAboveTimestamp()){
+                rangeMin_X = Math.min(this.filter.aboveTimestamp, rangeMin_X);
+            }
+
+            double stepRange = (rangeMax_X - rangeMin_X)/(60*60*24*1000);
+            this.lineGraph.setxAxisStep(Math.max(1,(float)Math.min(stepRange, 4)));
+
+            this.lineGraph.setRangeX(rangeMin_X  , rangeMax_X);
+
+            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);
+        }
 
-        this.lineGraph.setRangeY(rangeMin, rangeMax);
+        this.lineGraph.setRangeY(rangeMin_Y, rangeMax_Y);
         this.lineGraph.setLineToFill(0);
         this.lineGraph.invalidate();
     }