Browse Source

comments in the graph library

Julien Clauter 10 years ago
parent
commit
7303d4eaac

+ 27 - 4
src/com/echo/holographlibrary/BarGraph.java

@@ -58,13 +58,23 @@ public class BarGraph extends View {
     private int popupImageID;
 
     private Context mContext = null;
-    
+
+
+    /**
+     * Constructor
+     * @param context Context
+     */
     public BarGraph(Context context) {
         super(context);
         mContext = context;
         this.setWillNotDraw(false);
     }
-    
+
+    /**
+     * Constructor
+     * @param context Context
+     * @param attrs AttributeSet
+     */
     public BarGraph(Context context, AttributeSet attrs) {
         super(context, attrs);
         mContext = context;
@@ -89,6 +99,7 @@ public class BarGraph extends View {
         return this.mBars;
     }
 
+    @Override
     public void onDraw(Canvas ca) {
     	super.onDraw(ca);
         if (mFullImage == null || mShouldUpdate) {
@@ -96,6 +107,7 @@ public class BarGraph extends View {
             Canvas canvas = new Canvas(mFullImage);
             canvas.drawColor(Color.TRANSPARENT);
 
+            /* A header on top of a single bar */
             /*
             Bitmap backMap = BitmapFactory.decodeResource(getResources(), this.popupImageID);
             backMap = backMap.copy(Bitmap.Config.ARGB_8888, true);
@@ -199,6 +211,10 @@ public class BarGraph extends View {
         
     }
 
+    /**
+     * Set the header image id, which is used for the header image over all bars.
+     * @param id int
+     */
     public void setPopupImageID(int id){
         this.popupImageID = id;
     }
@@ -257,11 +273,18 @@ public class BarGraph extends View {
     	super.onDetachedFromWindow();
         postInvalidate();
     }
-    
+
+    /**
+     * Sets the bar clicked listener.
+     * @param listener OnBarClickedListener
+     */
     public void setOnBarClickedListener(OnBarClickedListener listener) {
         this.mListener = listener;
     }
-    
+
+    /**
+     * Called if the user clicked a bar.
+     */
     public interface OnBarClickedListener {
         abstract void onClick(int index);
     }

+ 110 - 13
src/com/echo/holographlibrary/LineGraph.java

@@ -43,8 +43,21 @@ import java.util.ArrayList;
 
 public class LineGraph extends View {
 
+    /**
+     * The axis converter will be called, if the line graph loads / refreshed its axis.
+     */
     public interface AxisDataConverter {
+        /**
+         * returns the x axis value for a given x coord.
+         * @param x double, the x coord.
+         * @return String, formatted value for the x position.
+         */
         public String convertDataForX_Position(double x);
+        /**
+         * returns the y axis value for a given y coord.
+         * @param y double, the y coord.
+         * @return String, formatted value for the y position.
+         */
         public String convertDataForY_Position(double y);
     }
 
@@ -68,6 +81,9 @@ public class LineGraph extends View {
     static final float leftPadding = 50, rightPadding = 16;
     static final float sidePadding = rightPadding + leftPadding;
 
+    /**
+     * Step = Axis Period
+     */
     private float xAxisStep = 4;
     private float yAxisStep = 4;
 
@@ -84,25 +100,38 @@ public class LineGraph extends View {
     public float getyAxisStep(){return  this.yAxisStep;}
     public float getxAxisStep(){return this.xAxisStep;}
 
+    /**
+     * The axis converter will be called if the line graph refresh / load its axis labels.
+     * @param conv AxisDataConverter
+     */
     public void setConverter(AxisDataConverter conv){
         this.converter = conv;
     }
-	
+
+    /**
+     * Constructor
+     * @param context Context
+     */
 	public LineGraph(Context context){
 		super(context);
         this.mContext = context;
         this.setWillNotDraw(false);
     }
-	
+
+    /**
+     * Constructor
+     * @param context Context
+     * @param attrs AttributeSet
+     */
 	public LineGraph(Context context, AttributeSet attrs) {
 		super(context, attrs);
         this.mContext = context;
         this.setWillNotDraw(false);
     }
-	public void setMinY(float minY){
-		
-	}
-	
+
+    /**
+     * Removes all lines.
+     */
 	public void removeAllLines(){
 		while (lines.size() > 0){
 			lines.remove(0);
@@ -110,12 +139,23 @@ public class LineGraph extends View {
 		shouldUpdate = true;
 		//postInvalidate();
 	}
-	
+
+    /**
+     * Add a line.
+     * @param line {@link Line Line}
+     */
 	public void addLine(Line line) {
 		lines.add(line);
 		shouldUpdate = true;
 		//postInvalidate();
 	}
+
+    /**
+     * Adds a new point to a {@link Line lin}
+     * @param lineIndex the index of the line
+     * @param x double, the x coord.
+     * @param y double, the y coord.
+     */
 	public void addPointToLine(int lineIndex, double x, double y){
 		addPointToLine(lineIndex, (float) x, (float) y);
 	}
@@ -203,12 +243,19 @@ public class LineGraph extends View {
 		shouldUpdate = true;
 		//postInvalidate();
 	}
-	
+
+    /**
+     * Resets the y axis limits
+     */
 	public void resetYLimits(){
         double range = getMaxY() - getMinY();
 		setRangeY(getMinY()-range*getRangeYRatio(), getMaxY()+range*getRangeYRatio());
         isMaxYUserSet = false;
     }
+
+    /**
+     * Resets the x axis limits
+     */
 	public void resetXLimits(){
         double range = getMaxX() - getMinX();
 		setRangeX(getMinX()-range*getRangeXRatio(), getMaxX()+range*getRangeXRatio());
@@ -238,22 +285,44 @@ public class LineGraph extends View {
 	public int getSize(){
 		return lines.size();
 	}
-	
+
+    /**
+     * Sets the y axis range (minimal and maximal value for the y axis)
+     * @param min float
+     * @param max float
+     */
 	public void setRangeY(float min, float max) {
 		minY = min;
 		maxY = max;
 		isMaxYUserSet = true;
 	}
+
+    /**
+     * Sets the y axis range (minimal and maximal value for the y axis)
+     * @param min double
+     * @param max double
+     */
 	public void setRangeY(double min, double max){
 		minY = min;
 		maxY = max;
 		isMaxYUserSet = true;
 	}
+
+    /**
+     * Sets the x axis range (minimal and maximal value for the x axis)
+     * @param min float
+     * @param max float
+     */
 	public void setRangeX(float min, float max) {
 		minX = min;
 		maxX = max;
         isMaxXUserSet = true;
     }
+    /**
+     * Sets the x axis range (minimal and maximal value for the x axis)
+     * @param min double
+     * @param max double
+     */
 	public void setRangeX(double min, double max){
 		minX = min;
 		maxX = max;
@@ -325,17 +394,27 @@ public class LineGraph extends View {
 		minX = min;
 		return minX;
 	}
-	
 
+    /**
+     * Returns the title for the x coordinate by calling the converter.
+     * @param x  double, the x coord.
+     * @return String, the title
+     */
     private String getX_AxisTitle(double x){
         if (this.converter == null)return "" + (long)x;
         return this.converter.convertDataForX_Position(x);
     }
+    /**
+     * Returns the title for the y coordinate by calling the converter.
+     * @param y  double, the y coord.
+     * @return String, the title
+     */
     private String getY_AxisTitle(double y){
         if (this.converter == null)return "" + (long)y;
         return this.converter.convertDataForY_Position(y);
     }
-	 
+
+    @Override
 	public void onDraw(Canvas ca) {
         super.onDraw(ca);
 
@@ -447,6 +526,10 @@ public class LineGraph extends View {
 
 	}
 
+    /**
+     * Draw the x & y axis
+     * @param canvas Canvas
+     */
     private void drawAxis(Canvas canvas){
         //double maxX = getMaxLimX();
         //double minX = getMinLimX();
@@ -469,7 +552,10 @@ public class LineGraph extends View {
         this.drawAxisLabel(canvas);
     }
 
-
+    /**
+     * Draw the x & y axis labels.
+     * @param canvas Canvas
+     */
     private void drawAxisLabel(Canvas canvas){
         this.paint.setTextSize(AXIS_LABEL_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
 
@@ -516,6 +602,10 @@ public class LineGraph extends View {
         }
     }
 
+    /**
+     * Draw the lined background.
+     * @param canvas Canvas
+     */
     private void drawBackground(Canvas canvas){
 
         paint.reset();
@@ -688,10 +778,17 @@ public class LineGraph extends View {
         postInvalidate();
     }
 
+    /**
+     * Set the point click listener, which will be called on clicking a point.
+     * @param listener OnPointClickedListener
+     */
     public void setOnPointClickedListener(OnPointClickedListener listener) {
 		this.listener = listener;
 	}
-	
+
+    /**
+     * OnPointClickedListener will be called, if the user clicks a point.
+     */
 	public interface OnPointClickedListener {
 		abstract void onClick(int lineIndex, int pointIndex);
 	}

+ 42 - 11
src/com/echo/holographlibrary/PieGraph.java

@@ -36,7 +36,6 @@ import android.graphics.Region;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
-import android.widget.TextView;
 
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -62,22 +61,28 @@ public class PieGraph extends View {
 	
 	private boolean drawCompleted = false;
 
-    private TextView titleTextView;
-    private TextView subtitleTextView;
 
     private String title;
     private String subtitle;
 
     private Context mContext;
-	
-	
+
+    /**
+     * Constructor
+     * @param context Context
+     */
 	public PieGraph(Context context) {
 		super(context);
         this.mContext = context;
 		thickness = (int) (25f * context.getResources().getDisplayMetrics().density);
         this.setWillNotDraw(false);
 	}
-	
+
+    /**
+     * Constructor
+     * @param context Context
+     * @param attrs AttributeSet
+     */
 	public PieGraph(Context context, AttributeSet attrs) {
 		super(context, attrs);
         this.mContext = context;
@@ -85,6 +90,7 @@ public class PieGraph extends View {
         this.setWillNotDraw(false);
     }
 
+    @Override
     public void onDraw(Canvas canvas) {
         super.onDraw(canvas);
 
@@ -157,6 +163,10 @@ public class PieGraph extends View {
 		
 	}
 
+    /**
+     * Draws the title in the middle of the pie.
+     * @param canvas Canvas
+     */
     private void drawTitle(Canvas canvas){
         String title = this.title;
 
@@ -180,6 +190,11 @@ public class PieGraph extends View {
             this.paint.reset();
         }
     }
+
+    /**
+     * Draws the Subtitle in the middle of the pie.
+     * @param canvas Canvas
+     */
     private void drawSubtitle(Canvas canvas){
         String title = this.subtitle;
         if (title != null && title.length() != 0){
@@ -259,6 +274,11 @@ public class PieGraph extends View {
 	public PieSlice getSlice(int index) {
 		return slices.get(index);
 	}
+
+    /**
+     * Add a pie slice.
+     * @param slice {@link PieSlice PieSlice}
+     */
 	public void addSlice(PieSlice slice) {
         if (slice != null)
 		    this.slices.add(slice);
@@ -276,10 +296,7 @@ public class PieGraph extends View {
         this.subtitle = "" + countedValue;
 		//postInvalidate();
 	}
-	public void setOnSliceClickedListener(OnSliceClickedListener listener) {
-		this.listener = listener;
-	}
-	
+
 	public int getThickness() {
 		return thickness;
 	}
@@ -287,7 +304,10 @@ public class PieGraph extends View {
 		this.thickness = thickness;
 		//postInvalidate();
 	}
-	
+
+    /**
+     * Remove all slices.
+     */
 	public void removeSlices(){
         Iterator<PieSlice> iter = slices.iterator();
 
@@ -301,6 +321,17 @@ public class PieGraph extends View {
 		//postInvalidate();
 	}
 
+    /**
+     * Set the OnSliceClickedListener, which will be called if the user clicks a slice.
+     * @param listener
+     */
+    public void setOnSliceClickedListener(OnSliceClickedListener listener) {
+        this.listener = listener;
+    }
+
+    /**
+     * OnSliceClickedListener will be called if the user clicks a pie slice.
+     */
 	public static interface OnSliceClickedListener {
 		public abstract void onClick(int index);
 	}