|
@@ -49,8 +49,9 @@ public class PieChartView extends View {
|
|
|
private float legendSquareSize = 20f;
|
|
private float legendSquareSize = 20f;
|
|
|
private float legendWidth;
|
|
private float legendWidth;
|
|
|
|
|
|
|
|
- private float chartPadding = 64.f;
|
|
|
|
|
|
|
+ private float CHART_PADDING_DP = 12.f;
|
|
|
private float chartTextSizeSp = 10.f;
|
|
private float chartTextSizeSp = 10.f;
|
|
|
|
|
+ private float chartPaddingPx;
|
|
|
|
|
|
|
|
|
|
|
|
|
private String title = "This is a title";
|
|
private String title = "This is a title";
|
|
@@ -103,7 +104,7 @@ public class PieChartView extends View {
|
|
|
float left = titleRect.right - legendWidth;
|
|
float left = titleRect.right - legendWidth;
|
|
|
float right = titleRect.right;
|
|
float right = titleRect.right;
|
|
|
float top = titleRect.bottom;
|
|
float top = titleRect.bottom;
|
|
|
- float bottom = getBottom();
|
|
|
|
|
|
|
+ float bottom = getHeight();
|
|
|
|
|
|
|
|
return new RectF(left, top, right, bottom);
|
|
return new RectF(left, top, right, bottom);
|
|
|
}
|
|
}
|
|
@@ -111,12 +112,13 @@ public class PieChartView extends View {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private RectF getPieChartRect() {
|
|
private RectF getPieChartRect() {
|
|
|
- float left = titleRect.left + chartPadding;
|
|
|
|
|
- float top = titleRect.top + chartPadding;
|
|
|
|
|
- float right = titleRect.right - chartPadding;
|
|
|
|
|
|
|
+ // Pie chart max rectangle
|
|
|
|
|
+ float left = titleRect.left + chartPaddingPx;
|
|
|
|
|
+ float top = titleRect.bottom + chartPaddingPx;
|
|
|
|
|
+ float right = titleRect.right - chartPaddingPx;
|
|
|
if (showLegend)
|
|
if (showLegend)
|
|
|
right -= legendRect.width();
|
|
right -= legendRect.width();
|
|
|
- float bottom = getBottom() - getPaddingLeft() - chartPadding;
|
|
|
|
|
|
|
+ float bottom = getHeight() - getPaddingBottom() - chartPaddingPx;
|
|
|
RectF rectF = new RectF(left, top, right, bottom);
|
|
RectF rectF = new RectF(left, top, right, bottom);
|
|
|
// width must be equal to height
|
|
// width must be equal to height
|
|
|
if (rectF.width() != rectF.height()) {
|
|
if (rectF.width() != rectF.height()) {
|
|
@@ -144,6 +146,8 @@ public class PieChartView extends View {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void init(AttributeSet attributeSet) {
|
|
private void init(AttributeSet attributeSet) {
|
|
|
|
|
+ chartPaddingPx = Utils.dipsToPixels(CHART_PADDING_DP, getResources());
|
|
|
|
|
+
|
|
|
if (attributeSet != null)
|
|
if (attributeSet != null)
|
|
|
readAttributes(attributeSet);
|
|
readAttributes(attributeSet);
|
|
|
|
|
|
|
@@ -177,6 +181,9 @@ public class PieChartView extends View {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void drawChart(Canvas canvas) {
|
|
private void drawChart(Canvas canvas) {
|
|
|
|
|
+ Paint p = new Paint();
|
|
|
|
|
+ p.setColor(Color.CYAN);
|
|
|
|
|
+ canvas.drawRect(pieChartRect, p);
|
|
|
|
|
|
|
|
float startAngle = -90.f;
|
|
float startAngle = -90.f;
|
|
|
for (PieChartItem item : items) {
|
|
for (PieChartItem item : items) {
|
|
@@ -191,11 +198,6 @@ public class PieChartView extends View {
|
|
|
float x = (float) Math.cos(Math.toRadians(angleMiddle)) * r;
|
|
float x = (float) Math.cos(Math.toRadians(angleMiddle)) * r;
|
|
|
float y = (float) Math.sin(Math.toRadians(angleMiddle)) * r;
|
|
float y = (float) Math.sin(Math.toRadians(angleMiddle)) * r;
|
|
|
|
|
|
|
|
- String text = Double.toString(item.value);
|
|
|
|
|
- // Depending on quadrant, adjust text.
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- float textWidth = valuePaint.measureText(text);
|
|
|
|
|
float left = x + pieChartRect.centerX();
|
|
float left = x + pieChartRect.centerX();
|
|
|
float top = pieChartRect.centerY() - y;
|
|
float top = pieChartRect.centerY() - y;
|
|
|
|
|
|