|
@@ -35,10 +35,15 @@ public class BarGraphView extends View {
|
|
|
private String noDataText;
|
|
private String noDataText;
|
|
|
|
|
|
|
|
private Paint averageLinePaint = null;
|
|
private Paint averageLinePaint = null;
|
|
|
- private Paint canvasPaint = null;
|
|
|
|
|
private Paint axisPaint = null;
|
|
private Paint axisPaint = null;
|
|
|
private Paint textPaint = null;
|
|
private Paint textPaint = null;
|
|
|
|
|
|
|
|
|
|
+ private int textColor = Color.BLACK;
|
|
|
|
|
+ private int valueTextColor = Color.BLACK;
|
|
|
|
|
+ private int barColor = Color.parseColor("#81E5F0");
|
|
|
|
|
+ private int lineAverageColor = Color.RED;
|
|
|
|
|
+ private int axisColor = Color.BLACK;
|
|
|
|
|
+
|
|
|
private DisplayMetrics dm = null;
|
|
private DisplayMetrics dm = null;
|
|
|
|
|
|
|
|
private BarGraphAdapter adapter;
|
|
private BarGraphAdapter adapter;
|
|
@@ -140,6 +145,12 @@ public class BarGraphView extends View {
|
|
|
if (a.hasValue(R.styleable.BarGraph_noDataText))
|
|
if (a.hasValue(R.styleable.BarGraph_noDataText))
|
|
|
noDataText = a.getString(R.styleable.BarGraph_noDataText);
|
|
noDataText = a.getString(R.styleable.BarGraph_noDataText);
|
|
|
|
|
|
|
|
|
|
+ textColor = a.getColor(R.styleable.BarGraph_textColor, textColor);
|
|
|
|
|
+ valueTextColor = a.getColor(R.styleable.BarGraph_valueTextColor, valueTextColor);
|
|
|
|
|
+ barColor = a.getColor(R.styleable.BarGraph_barColor, barColor);
|
|
|
|
|
+ lineAverageColor = a.getColor(R.styleable.BarGraph_lineAverageColor, lineAverageColor);
|
|
|
|
|
+ axisColor = a.getColor(R.styleable.BarGraph_axisColor, axisColor);
|
|
|
|
|
+
|
|
|
} finally {
|
|
} finally {
|
|
|
a.recycle();
|
|
a.recycle();
|
|
|
}
|
|
}
|
|
@@ -149,22 +160,17 @@ public class BarGraphView extends View {
|
|
|
private void cacheValues() {
|
|
private void cacheValues() {
|
|
|
// Initialize paints used in onDraw
|
|
// Initialize paints used in onDraw
|
|
|
averageLinePaint = new Paint();
|
|
averageLinePaint = new Paint();
|
|
|
- averageLinePaint.setColor(Color.RED);
|
|
|
|
|
|
|
+ averageLinePaint.setColor(lineAverageColor);
|
|
|
averageLinePaint.setStrokeWidth(getDimensionFromDp(AVERAGE_LINE_STROKE_WIDTH));
|
|
averageLinePaint.setStrokeWidth(getDimensionFromDp(AVERAGE_LINE_STROKE_WIDTH));
|
|
|
|
|
|
|
|
- canvasPaint = new Paint();
|
|
|
|
|
- canvasPaint.setStyle(Paint.Style.FILL);
|
|
|
|
|
- canvasPaint.setColor(Color.WHITE);
|
|
|
|
|
- // canvasPaint.setAntiAlias(true);
|
|
|
|
|
-
|
|
|
|
|
axisPaint = new Paint();
|
|
axisPaint = new Paint();
|
|
|
axisPaint.setStyle(Paint.Style.FILL);
|
|
axisPaint.setStyle(Paint.Style.FILL);
|
|
|
- axisPaint.setColor(Color.BLACK);
|
|
|
|
|
|
|
+ axisPaint.setColor(axisColor);
|
|
|
axisPaint.setAntiAlias(true);
|
|
axisPaint.setAntiAlias(true);
|
|
|
|
|
|
|
|
textPaint = new Paint();
|
|
textPaint = new Paint();
|
|
|
textPaint.setStyle(Paint.Style.FILL);
|
|
textPaint.setStyle(Paint.Style.FILL);
|
|
|
- textPaint.setColor(Color.BLACK);
|
|
|
|
|
|
|
+ textPaint.setColor(textColor);
|
|
|
textPaint.setAntiAlias(true);
|
|
textPaint.setAntiAlias(true);
|
|
|
textPaint.setTextSize(getDimensionFromSp(NO_DATA_TEXT_SIZE_SP));
|
|
textPaint.setTextSize(getDimensionFromSp(NO_DATA_TEXT_SIZE_SP));
|
|
|
}
|
|
}
|
|
@@ -217,8 +223,6 @@ public class BarGraphView extends View {
|
|
|
protected void onDraw(Canvas canvas) {
|
|
protected void onDraw(Canvas canvas) {
|
|
|
super.onDraw(canvas);
|
|
super.onDraw(canvas);
|
|
|
|
|
|
|
|
- canvas.drawPaint(canvasPaint);
|
|
|
|
|
-
|
|
|
|
|
if (adapter == null) {
|
|
if (adapter == null) {
|
|
|
drawNoDataText(canvas);
|
|
drawNoDataText(canvas);
|
|
|
return;
|
|
return;
|
|
@@ -245,12 +249,12 @@ public class BarGraphView extends View {
|
|
|
|
|
|
|
|
if (x1 <= getWidth() - getPaddingRight()) {
|
|
if (x1 <= getWidth() - getPaddingRight()) {
|
|
|
if (x1 >= verticalAxisRect.getWidth() + getPaddingLeft()) {
|
|
if (x1 >= verticalAxisRect.getWidth() + getPaddingLeft()) {
|
|
|
- canvas.drawLine(x1, y1, x2, y2, horizontalAxisRect.getPaintLine());
|
|
|
|
|
|
|
+ canvas.drawLine(x1, y1, x2, y2, axisPaint);
|
|
|
if (horizontalAxisRect.isShowValues()) {
|
|
if (horizontalAxisRect.isShowValues()) {
|
|
|
String horizontalDescription = adapter.getHorizontalValueDescription(i);
|
|
String horizontalDescription = adapter.getHorizontalValueDescription(i);
|
|
|
if (horizontalDescription != null) {
|
|
if (horizontalDescription != null) {
|
|
|
- float textWidth = horizontalAxisRect.getPaintLine().measureText(horizontalDescription);
|
|
|
|
|
- canvas.drawText(horizontalDescription, x1 - (textWidth / 2), horizontalAxisRect.getMarkingValuesY(), horizontalAxisRect.getPaintLine());
|
|
|
|
|
|
|
+ float textWidth = horizontalAxisRect.getPaintMarkingsText().measureText(horizontalDescription);
|
|
|
|
|
+ canvas.drawText(horizontalDescription, x1 - (textWidth / 2), horizontalAxisRect.getMarkingValuesY(), horizontalAxisRect.getPaintMarkingsText());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -279,7 +283,7 @@ public class BarGraphView extends View {
|
|
|
float y1 = yStart;
|
|
float y1 = yStart;
|
|
|
float y2 = y1;
|
|
float y2 = y1;
|
|
|
|
|
|
|
|
- canvas.drawLine(x1, y1, x2, y2, verticalAxisRect.getPaintLine());
|
|
|
|
|
|
|
+ canvas.drawLine(x1, y1, x2, y2, axisPaint);
|
|
|
|
|
|
|
|
if (verticalAxisRect.isShowValues()) {
|
|
if (verticalAxisRect.isShowValues()) {
|
|
|
// draw bounding rect before rotating text
|
|
// draw bounding rect before rotating text
|
|
@@ -287,10 +291,10 @@ public class BarGraphView extends View {
|
|
|
canvas.save();
|
|
canvas.save();
|
|
|
|
|
|
|
|
String markingText = adapter.getVerticalMarkingText(i * verticalAxisValues.getYieldBetweenMarkings());
|
|
String markingText = adapter.getVerticalMarkingText(i * verticalAxisValues.getYieldBetweenMarkings());
|
|
|
- float textWidth = verticalAxisRect.getPaintLine().measureText(markingText);
|
|
|
|
|
|
|
+ float textWidth = verticalAxisRect.getPaintMarkingsText().measureText(markingText);
|
|
|
|
|
|
|
|
canvas.rotate(-90.f, rect.exactCenterX(), yStart + rect.exactCenterY());
|
|
canvas.rotate(-90.f, rect.exactCenterX(), yStart + rect.exactCenterY());
|
|
|
- canvas.drawText(markingText, -(textWidth / 2), yStart + verticalAxisRect.getValuesX() + getPaddingLeft(), verticalAxisRect.getPaintLine());
|
|
|
|
|
|
|
+ canvas.drawText(markingText, -(textWidth / 2), yStart + verticalAxisRect.getValuesX() + getPaddingLeft(), verticalAxisRect.getPaintMarkingsText());
|
|
|
canvas.restore();
|
|
canvas.restore();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -448,7 +452,7 @@ public class BarGraphView extends View {
|
|
|
// max vrijednost unutar Data arraya, max vrijednost podataka koje imamo
|
|
// max vrijednost unutar Data arraya, max vrijednost podataka koje imamo
|
|
|
maxDataValue = getDataMaxValue();
|
|
maxDataValue = getDataMaxValue();
|
|
|
String maxValueFormatted = adapter.getVerticalMarkingText(maxDataValue);
|
|
String maxValueFormatted = adapter.getVerticalMarkingText(maxDataValue);
|
|
|
- float maxValueTextWidth = verticalAxisRect.getPaintLine().measureText(maxValueFormatted);
|
|
|
|
|
|
|
+ float maxValueTextWidth = verticalAxisRect.getPaintMarkingsText().measureText(maxValueFormatted);
|
|
|
verticalAxisValues.setMinDistanceBetweenMarkings(maxValueTextWidth);
|
|
verticalAxisValues.setMinDistanceBetweenMarkings(maxValueTextWidth);
|
|
|
|
|
|
|
|
// max vrijednost grafa, ovisi o max vrijednosti data arraya, ali nije
|
|
// max vrijednost grafa, ovisi o max vrijednosti data arraya, ali nije
|
|
@@ -685,6 +689,46 @@ public class BarGraphView extends View {
|
|
|
this.noDataText = noDataText;
|
|
this.noDataText = noDataText;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public int getTextColor() {
|
|
|
|
|
+ return textColor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setTextColor(int textColor) {
|
|
|
|
|
+ this.textColor = textColor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int getValueTextColor() {
|
|
|
|
|
+ return valueTextColor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setValueTextColor(int valueTextColor) {
|
|
|
|
|
+ this.valueTextColor = valueTextColor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int getBarColor() {
|
|
|
|
|
+ return barColor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setBarColor(int barColor) {
|
|
|
|
|
+ this.barColor = barColor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int getLineAverageColor() {
|
|
|
|
|
+ return lineAverageColor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setLineAverageColor(int lineAverageColor) {
|
|
|
|
|
+ this.lineAverageColor = lineAverageColor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int getAxisColor() {
|
|
|
|
|
+ return axisColor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setAxisColor(int axisColor) {
|
|
|
|
|
+ this.axisColor = axisColor;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private class BarConfig {
|
|
private class BarConfig {
|
|
|
private float padding;
|
|
private float padding;
|
|
|
private float whiteSpace;
|
|
private float whiteSpace;
|
|
@@ -695,11 +739,11 @@ public class BarGraphView extends View {
|
|
|
public void init() {
|
|
public void init() {
|
|
|
float fontSize = barFontSizePx;
|
|
float fontSize = barFontSizePx;
|
|
|
paintRect = new Paint();
|
|
paintRect = new Paint();
|
|
|
- paintRect.setColor(Color.parseColor("#81E5F0"));
|
|
|
|
|
|
|
+ paintRect.setColor(barColor);
|
|
|
paintRect.setAntiAlias(true);
|
|
paintRect.setAntiAlias(true);
|
|
|
|
|
|
|
|
paintText = new Paint();
|
|
paintText = new Paint();
|
|
|
- paintText.setColor(Color.parseColor("#000000"));
|
|
|
|
|
|
|
+ paintText.setColor(valueTextColor);
|
|
|
paintText.setAntiAlias(true);
|
|
paintText.setAntiAlias(true);
|
|
|
paintText.setTextSize(fontSize);
|
|
paintText.setTextSize(fontSize);
|
|
|
|
|
|
|
@@ -757,7 +801,7 @@ public class BarGraphView extends View {
|
|
|
float fontSize;
|
|
float fontSize;
|
|
|
float axisMarkingsLength;
|
|
float axisMarkingsLength;
|
|
|
|
|
|
|
|
- Paint paintLine = null;
|
|
|
|
|
|
|
+ Paint paintMarkingsText = null;
|
|
|
Paint paintDescription = null;
|
|
Paint paintDescription = null;
|
|
|
|
|
|
|
|
boolean showValues = true;
|
|
boolean showValues = true;
|
|
@@ -767,21 +811,21 @@ public class BarGraphView extends View {
|
|
|
fontSize = axisValuesFontSizePx;
|
|
fontSize = axisValuesFontSizePx;
|
|
|
axisMarkingsLength = getDimensionFromDp(DEFAULT_MARKINGS_LENGTH_DP);
|
|
axisMarkingsLength = getDimensionFromDp(DEFAULT_MARKINGS_LENGTH_DP);
|
|
|
|
|
|
|
|
- paintLine = new Paint();
|
|
|
|
|
- paintLine.setAntiAlias(true);
|
|
|
|
|
- paintLine.setColor(Color.BLACK);
|
|
|
|
|
- paintLine.setTextSize(fontSize);
|
|
|
|
|
|
|
+ paintMarkingsText = new Paint();
|
|
|
|
|
+ paintMarkingsText.setAntiAlias(true);
|
|
|
|
|
+ paintMarkingsText.setColor(textColor);
|
|
|
|
|
+ paintMarkingsText.setTextSize(fontSize);
|
|
|
|
|
|
|
|
paintDescription = new Paint();
|
|
paintDescription = new Paint();
|
|
|
paintDescription.setAntiAlias(true);
|
|
paintDescription.setAntiAlias(true);
|
|
|
- paintDescription.setColor(Color.BLACK);
|
|
|
|
|
|
|
+ paintDescription.setColor(textColor);
|
|
|
paintDescription.setTextSize(getDimensionFromSp(DEFAULT_AXIS_DESCRIPTION_FONT_SIZE_SP));
|
|
paintDescription.setTextSize(getDimensionFromSp(DEFAULT_AXIS_DESCRIPTION_FONT_SIZE_SP));
|
|
|
|
|
|
|
|
lineSpacing = getDimensionFromDp(DEFAULT_AXIS_LINE_SPACING_DP);
|
|
lineSpacing = getDimensionFromDp(DEFAULT_AXIS_LINE_SPACING_DP);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Paint getPaintLine() {
|
|
|
|
|
- return paintLine;
|
|
|
|
|
|
|
+ public Paint getPaintMarkingsText() {
|
|
|
|
|
+ return paintMarkingsText;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public float getFontSize() {
|
|
public float getFontSize() {
|
|
@@ -820,7 +864,7 @@ public class BarGraphView extends View {
|
|
|
|
|
|
|
|
public int getTextHeight() {
|
|
public int getTextHeight() {
|
|
|
Rect bounds = new Rect();
|
|
Rect bounds = new Rect();
|
|
|
- paintLine.getTextBounds("0", 0, 1, bounds);
|
|
|
|
|
|
|
+ paintMarkingsText.getTextBounds("0", 0, 1, bounds);
|
|
|
return bounds.height();
|
|
return bounds.height();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -849,7 +893,7 @@ public class BarGraphView extends View {
|
|
|
|
|
|
|
|
public float getWidth() {
|
|
public float getWidth() {
|
|
|
float res = getAxisLeft();
|
|
float res = getAxisLeft();
|
|
|
- res += paintLine.getStrokeWidth();
|
|
|
|
|
|
|
+ res += paintMarkingsText.getStrokeWidth();
|
|
|
return res;
|
|
return res;
|
|
|
}
|
|
}
|
|
|
|
|
|