|
@@ -48,7 +48,7 @@ public class LineGraph extends View {
|
|
public String convertDataForY_Position(double y);
|
|
public String convertDataForY_Position(double y);
|
|
}
|
|
}
|
|
|
|
|
|
- private final static int AXIS_LABEL_FONT_SIZE = 10;
|
|
|
|
|
|
+ private final static int AXIS_LABEL_FONT_SIZE = 8;
|
|
|
|
|
|
private ArrayList<Line> lines = new ArrayList<Line>();
|
|
private ArrayList<Line> lines = new ArrayList<Line>();
|
|
Paint paint = new Paint();
|
|
Paint paint = new Paint();
|
|
@@ -64,8 +64,8 @@ public class LineGraph extends View {
|
|
private Bitmap fullImage;
|
|
private Bitmap fullImage;
|
|
private boolean shouldUpdate = false;
|
|
private boolean shouldUpdate = false;
|
|
|
|
|
|
- static final float bottomPadding = 50, topPadding = 10;
|
|
|
|
- static final float leftPadding = 50, rightPadding = 10;
|
|
|
|
|
|
+ static final float bottomPadding = 40, topPadding = 16;
|
|
|
|
+ static final float leftPadding = 50, rightPadding = 16;
|
|
static final float sidePadding = rightPadding + leftPadding;
|
|
static final float sidePadding = rightPadding + leftPadding;
|
|
|
|
|
|
private float xAxisStep = 4;
|
|
private float xAxisStep = 4;
|
|
@@ -361,13 +361,12 @@ public class LineGraph extends View {
|
|
// DRAW THE BACKGROUND
|
|
// DRAW THE BACKGROUND
|
|
//this.drawBackground(canvas);
|
|
//this.drawBackground(canvas);
|
|
|
|
|
|
|
|
+ paint.setAntiAlias(true);
|
|
|
|
+
|
|
// DRAW THE AXIS
|
|
// DRAW THE AXIS
|
|
this.drawAxis(canvas);
|
|
this.drawAxis(canvas);
|
|
|
|
|
|
|
|
|
|
- paint.reset();
|
|
|
|
- paint.setAntiAlias(true);
|
|
|
|
-
|
|
|
|
// DRAW LINES
|
|
// DRAW LINES
|
|
for (Line line : lines){
|
|
for (Line line : lines){
|
|
int count = 0;
|
|
int count = 0;
|
|
@@ -445,20 +444,16 @@ public class LineGraph extends View {
|
|
}
|
|
}
|
|
|
|
|
|
ca.drawBitmap(fullImage, 0, 0, null);
|
|
ca.drawBitmap(fullImage, 0, 0, null);
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
private void drawAxis(Canvas canvas){
|
|
private void drawAxis(Canvas canvas){
|
|
- paint.reset();
|
|
|
|
|
|
+ //double maxX = getMaxLimX();
|
|
|
|
+ //double minX = getMinLimX();
|
|
|
|
+ //float usableWidth = getWidth() - 2*sidePadding;
|
|
|
|
+ //float usableHeight = getHeight() - bottomPadding - topPadding;
|
|
|
|
|
|
- double maxX = getMaxLimX();
|
|
|
|
- double minX = getMinLimX();
|
|
|
|
-
|
|
|
|
- float usableWidth = getWidth() - 2*sidePadding;
|
|
|
|
- float usableHeight = getHeight() - bottomPadding - topPadding;
|
|
|
|
-
|
|
|
|
- float yPixels = getHeight() - (bottomPadding*(4.f/5.f));
|
|
|
|
|
|
+ float yPixels = getHeight() - (bottomPadding - (10));
|
|
|
|
|
|
// DRAW SEPERATOR
|
|
// DRAW SEPERATOR
|
|
paint.setColor(Color.BLACK);
|
|
paint.setColor(Color.BLACK);
|
|
@@ -470,8 +465,22 @@ public class LineGraph extends View {
|
|
canvas.drawLine(leftPadding ,topPadding, leftPadding, yPixels, paint);
|
|
canvas.drawLine(leftPadding ,topPadding, leftPadding, yPixels, paint);
|
|
|
|
|
|
paint.setAlpha(255);
|
|
paint.setAlpha(255);
|
|
|
|
+
|
|
|
|
+ this.drawAxisLabel(canvas);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private void drawAxisLabel(Canvas canvas){
|
|
this.paint.setTextSize(AXIS_LABEL_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
|
|
this.paint.setTextSize(AXIS_LABEL_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
|
|
|
|
|
|
|
|
+ double maxX = getMaxLimX();
|
|
|
|
+ double minX = getMinLimX();
|
|
|
|
+
|
|
|
|
+ float usableWidth = getWidth() - 2*sidePadding;
|
|
|
|
+ float usableHeight = getHeight() - bottomPadding - topPadding;
|
|
|
|
+ float yPixels = getHeight() - (bottomPadding - (10));
|
|
|
|
+
|
|
|
|
+
|
|
// Draw y-axis label text
|
|
// Draw y-axis label text
|
|
double step = Math.max(1., (maxY - minY) / (Math.max(1., yAxisStep)));
|
|
double step = Math.max(1., (maxY - minY) / (Math.max(1., yAxisStep)));
|
|
double v = 0;
|
|
double v = 0;
|
|
@@ -485,12 +494,11 @@ public class LineGraph extends View {
|
|
canvas.drawText(title, 5.f ,(float)newYPixels + (textwidth/2), this.paint);
|
|
canvas.drawText(title, 5.f ,(float)newYPixels + (textwidth/2), this.paint);
|
|
|
|
|
|
v+=step;
|
|
v+=step;
|
|
- //value+=skippedValue;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ this.paint.setTextSize(AXIS_LABEL_FONT_SIZE * mContext.getResources().getDisplayMetrics().scaledDensity);
|
|
|
|
+
|
|
// Draw x-axis label text
|
|
// Draw x-axis label text
|
|
- //value = minX;
|
|
|
|
- //skippedValue = (maxX - minX ) / (Math.max(1,xAxisStep));
|
|
|
|
step = Math.max(1, (maxX - minX) / (Math.max(1, xAxisStep)));
|
|
step = Math.max(1, (maxX - minX) / (Math.max(1, xAxisStep)));
|
|
|
|
|
|
for (double x = minX; x <= maxX; x+=step){
|
|
for (double x = minX; x <= maxX; x+=step){
|
|
@@ -500,12 +508,12 @@ public class LineGraph extends View {
|
|
canvas.drawLine((float)newXPixels,(float) yPixels + 5,(float) newXPixels,(float) yPixels, paint);
|
|
canvas.drawLine((float)newXPixels,(float) yPixels + 5,(float) newXPixels,(float) yPixels, paint);
|
|
String title = this.getX_AxisTitle(x);
|
|
String title = this.getX_AxisTitle(x);
|
|
float textwidth = (this.paint.measureText(title));
|
|
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;
|
|
|
|
|
|
+ float x_Coord = Math.max(0.f, (float) (newXPixels - (textwidth / 2)));
|
|
|
|
+ x_Coord = Math.min(x_Coord, getWidth() - rightPadding);
|
|
|
|
+ float y_Coord = (float) (yPixels + ((bottomPadding - 10) / 1));
|
|
|
|
+ canvas.drawText(title, x_Coord , y_Coord, this.paint);
|
|
}
|
|
}
|
|
- paint.reset();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private void drawBackground(Canvas canvas){
|
|
private void drawBackground(Canvas canvas){
|