Skip to content

Commit

Permalink
support for adding and removing of multiple points
Browse files Browse the repository at this point in the history
  • Loading branch information
faifai21 committed Nov 27, 2013
1 parent 09d6859 commit b2ee661
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
57 changes: 50 additions & 7 deletions HoloGraphLibrary/src/com/echo/holographlibrary/LineGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Path.Direction;
Expand All @@ -55,7 +54,6 @@ public class LineGraph extends View {
private OnPointClickedListener listener;
private Bitmap fullImage;
private boolean shouldUpdate = false;


public LineGraph(Context context){
super(context);
Expand Down Expand Up @@ -85,9 +83,8 @@ public void addPointToLine(int lineIndex, double x, double y){
addPointToLine(lineIndex, (float) x, (float) y);
}
public void addPointToLine(int lineIndex, float x, float y){
LinePoint p = new LinePoint();
p.setX(x);
p.setY(y);
LinePoint p = new LinePoint(x, y);

addPointToLine(lineIndex, p);
}

Expand All @@ -114,6 +111,47 @@ public void addPointToLine(int lineIndex, LinePoint point){
postInvalidate();
}

public void addPointsToLine(int lineIndex, LinePoint[] points){
Line line = getLine(lineIndex);
for(LinePoint point : points){
line.addPoint(point);
}
lines.set(lineIndex, line);
resetYLimits();
shouldUpdate = true;
postInvalidate();
}

public void removeAllPointsAfter(int lineIndex, double x){
removeAllPointsBetween(lineIndex, x, getMaxX());
}
public void removeAllPointsBefore(int lineIndex, double x){
removeAllPointsBetween(lineIndex, getMinX(), x);
}

public void removeAllPointsBetween(int lineIndex, double startX, double finishX){
Line line = getLine(lineIndex);
LinePoint[] pts = new LinePoint[line.getPoints().size()];
pts = line.getPoints().toArray(pts);
for(LinePoint point : pts){
if(point.getX() >= startX && point.getX() <= finishX)
line.removePoint(point);
}
lines.set(lineIndex, line);
resetYLimits();
shouldUpdate = true;
postInvalidate();
}
public void removePointsFromLine(int lineIndex, LinePoint[] points){
Line line = getLine(lineIndex);
for(LinePoint point : points){
line.removePoint(point);
}
lines.set(lineIndex, line);
resetYLimits();
shouldUpdate = true;
postInvalidate();
}
public void removePointFromLine(int lineIndex, float x, float y){
LinePoint p = null;
Line line = getLine(lineIndex);
Expand Down Expand Up @@ -211,7 +249,10 @@ public float getMinX(){
minX = min;
return minX;
}




public void onDraw(Canvas ca) {
if (fullImage == null || shouldUpdate) {
fullImage = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
Expand All @@ -227,9 +268,11 @@ public void onDraw(Canvas ca) {

float maxY = getMaxLimY();
float minY = getMinLimY();
float maxX = (float)(getMaxX()*(1+getRangeXRatio()));
float minX = (float)(getMinX()*(1-getRangeXRatio()));
float range = getMaxX() - getMinX();
float maxX = (float)(getMaxX()+range*getRangeXRatio());
float minX = (float)(getMinX()-range*getRangeXRatio());


int lineCount = 0;
for (Line line : lines){
int count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ public class LinePoint {
private float y = 0;
private Path path;
private Region region;


public LinePoint(double x, double y){
this.x = (float)x;
this.y = (float)y;
}
public LinePoint(float x, float y){
this.x = x;
this.y = y;
}
public float getX() {
return x;
}
Expand Down

0 comments on commit b2ee661

Please sign in to comment.