Berislav пре 9 година
родитељ
комит
e8a3eccf33

+ 13 - 11
app/src/main/java/hr/tacitus/graphs/PieChartView.java

@@ -49,8 +49,9 @@ public class PieChartView extends View {
     private float legendSquareSize = 20f;
     private float legendWidth;
 
-    private float chartPadding = 64.f;
+    private float CHART_PADDING_DP = 12.f;
     private float chartTextSizeSp = 10.f;
+    private float chartPaddingPx;
 
 
     private String title = "This is a title";
@@ -103,7 +104,7 @@ public class PieChartView extends View {
             float left = titleRect.right - legendWidth;
             float right = titleRect.right;
             float top = titleRect.bottom;
-            float bottom = getBottom();
+            float bottom = getHeight();
 
             return new RectF(left, top, right, bottom);
         }
@@ -111,12 +112,13 @@ public class PieChartView extends View {
     }
 
     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)
             right -= legendRect.width();
-        float bottom = getBottom() - getPaddingLeft() - chartPadding;
+        float bottom = getHeight() - getPaddingBottom() - chartPaddingPx;
         RectF rectF = new RectF(left, top, right, bottom);
         // width must be equal to height
         if (rectF.width() != rectF.height()) {
@@ -144,6 +146,8 @@ public class PieChartView extends View {
     }
 
     private void init(AttributeSet attributeSet) {
+        chartPaddingPx = Utils.dipsToPixels(CHART_PADDING_DP, getResources());
+
         if (attributeSet != null)
             readAttributes(attributeSet);
 
@@ -177,6 +181,9 @@ public class PieChartView extends View {
     }
 
     private void drawChart(Canvas canvas) {
+        Paint p = new Paint();
+        p.setColor(Color.CYAN);
+        canvas.drawRect(pieChartRect, p);
 
         float startAngle = -90.f;
         for (PieChartItem item : items) {
@@ -191,11 +198,6 @@ public class PieChartView extends View {
             float x = (float) Math.cos(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 top = pieChartRect.centerY() - y;
 

+ 1 - 1
graphsapp/src/main/res/layout/activity_main.xml

@@ -22,7 +22,7 @@
     <hr.tacitus.graphs.PieChartView
         android:layout_below="@id/toolbar"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
+        android:layout_height="250dp"
         app:title="Expenses share in total costs"
         android:id="@+id/pieChart"
         />