From a4fa9a1a87ccda6e3406596c308a6bab11f879b2 Mon Sep 17 00:00:00 2001 From: TaniaSolo Date: Sun, 2 Apr 2017 18:31:48 -0700 Subject: [PATCH 1/7] Update gradle. --- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7c943b4ce..e5db68b94 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jun 02 09:21:22 CEST 2016 +#Sun Apr 02 18:29:40 PDT 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip From fba24629e28ab6940ac00c7b106109f4b70d11ed Mon Sep 17 00:00:00 2001 From: TaniaSolo Date: Sun, 2 Apr 2017 18:33:39 -0700 Subject: [PATCH 2/7] Dealing with Generalization: Pull Up Field --- .../java/com/jjoe64/graphview/series/BarGraphSeries.java | 5 ----- src/main/java/com/jjoe64/graphview/series/BaseSeries.java | 7 +++++++ .../java/com/jjoe64/graphview/series/LineGraphSeries.java | 5 ----- .../com/jjoe64/graphview/series/PointsGraphSeries.java | 5 ----- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/jjoe64/graphview/series/BarGraphSeries.java b/src/main/java/com/jjoe64/graphview/series/BarGraphSeries.java index 5db99e1da..79a4c3953 100644 --- a/src/main/java/com/jjoe64/graphview/series/BarGraphSeries.java +++ b/src/main/java/com/jjoe64/graphview/series/BarGraphSeries.java @@ -42,11 +42,6 @@ public class BarGraphSeries extends BaseSeries { private static final long ANIMATION_DURATION = 333; - /** - * paint to do drawing on canvas - */ - private Paint mPaint; - /** * custom paint that can be used. * this will ignore the value dependent color. diff --git a/src/main/java/com/jjoe64/graphview/series/BaseSeries.java b/src/main/java/com/jjoe64/graphview/series/BaseSeries.java index 141b7497d..767932356 100644 --- a/src/main/java/com/jjoe64/graphview/series/BaseSeries.java +++ b/src/main/java/com/jjoe64/graphview/series/BaseSeries.java @@ -17,6 +17,7 @@ package com.jjoe64.graphview.series; import android.graphics.Canvas; +import android.graphics.Paint; import android.graphics.PointF; import android.util.Log; @@ -46,6 +47,12 @@ * @author jjoe64 */ public abstract class BaseSeries implements Series { + + /** + * paint to do drawing on canvas + */ + protected Paint mPaint; + /** * holds the data */ diff --git a/src/main/java/com/jjoe64/graphview/series/LineGraphSeries.java b/src/main/java/com/jjoe64/graphview/series/LineGraphSeries.java index a7ba85941..83a45cc8f 100644 --- a/src/main/java/com/jjoe64/graphview/series/LineGraphSeries.java +++ b/src/main/java/com/jjoe64/graphview/series/LineGraphSeries.java @@ -87,11 +87,6 @@ private final class Styles { private Paint mSelectionPaint; - /** - * internal paint object - */ - private Paint mPaint; - /** * paint for the background */ diff --git a/src/main/java/com/jjoe64/graphview/series/PointsGraphSeries.java b/src/main/java/com/jjoe64/graphview/series/PointsGraphSeries.java index 2ec74a526..518478e46 100644 --- a/src/main/java/com/jjoe64/graphview/series/PointsGraphSeries.java +++ b/src/main/java/com/jjoe64/graphview/series/PointsGraphSeries.java @@ -98,11 +98,6 @@ private final class Styles { */ private Styles mStyles; - /** - * internal paint object - */ - private Paint mPaint; - /** * handler to use a custom drawing */ From 9b1a2817032deb2db184428a1582de010f982eb6 Mon Sep 17 00:00:00 2001 From: TaniaSolo Date: Sun, 2 Apr 2017 19:14:31 -0700 Subject: [PATCH 3/7] Composing Methods: Inline Temp --- .../java/com/jjoe64/graphview/series/BarGraphSeries.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/com/jjoe64/graphview/series/BarGraphSeries.java b/src/main/java/com/jjoe64/graphview/series/BarGraphSeries.java index 79a4c3953..dbcf791e7 100644 --- a/src/main/java/com/jjoe64/graphview/series/BarGraphSeries.java +++ b/src/main/java/com/jjoe64/graphview/series/BarGraphSeries.java @@ -18,9 +18,7 @@ import android.graphics.Canvas; import android.graphics.Paint; -import android.graphics.RectF; import android.support.v4.view.ViewCompat; -import android.util.Log; import android.view.animation.AccelerateInterpolator; import com.jjoe64.graphview.GraphView; @@ -257,9 +255,7 @@ public void draw(GraphView graphView, Canvas canvas, boolean isSecondScale) { double ratY = valY / diffY; double y = contentHeight * ratY; - double valY0 = 0 - minY; - double ratY0 = valY0 / diffY; - double y0 = contentHeight * ratY0; + double y0 = contentHeight * (0 - minY) / diffY; double valueX = value.getX(); double valX = valueX - minX; From 91f38e0eaa97acd54c03e860c1e7b0465d209924 Mon Sep 17 00:00:00 2001 From: TaniaSolo Date: Sun, 2 Apr 2017 19:37:09 -0700 Subject: [PATCH 4/7] Making Method Calls Simpler: Remove Parameter --- .../com/jjoe64/graphview/helper/DateAsXAxisLabelFormatter.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/jjoe64/graphview/helper/DateAsXAxisLabelFormatter.java b/src/main/java/com/jjoe64/graphview/helper/DateAsXAxisLabelFormatter.java index f429c6cbb..f6409ce3b 100644 --- a/src/main/java/com/jjoe64/graphview/helper/DateAsXAxisLabelFormatter.java +++ b/src/main/java/com/jjoe64/graphview/helper/DateAsXAxisLabelFormatter.java @@ -63,10 +63,9 @@ public DateAsXAxisLabelFormatter(Context context) { * create the formatter with your own custom * date format to convert the x-values. * - * @param context the application context * @param dateFormat custom date format */ - public DateAsXAxisLabelFormatter(Context context, DateFormat dateFormat) { + public DateAsXAxisLabelFormatter(DateFormat dateFormat) { mDateFormat = dateFormat; mCalendar = Calendar.getInstance(); } From f3005ef7924bb9b4941f836174555186dc338ca8 Mon Sep 17 00:00:00 2001 From: TaniaSolo Date: Sun, 2 Apr 2017 20:10:04 -0700 Subject: [PATCH 5/7] Simplifying Conditional Expressions: Consolidate Conditional Expression --- .../graphview/series/PointsGraphSeries.java | 94 +++++++++---------- 1 file changed, 45 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/jjoe64/graphview/series/PointsGraphSeries.java b/src/main/java/com/jjoe64/graphview/series/PointsGraphSeries.java index 518478e46..6d831fc3f 100644 --- a/src/main/java/com/jjoe64/graphview/series/PointsGraphSeries.java +++ b/src/main/java/com/jjoe64/graphview/series/PointsGraphSeries.java @@ -17,7 +17,6 @@ package com.jjoe64.graphview.series; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Point; @@ -192,40 +191,24 @@ public void draw(GraphView graphView, Canvas canvas, boolean isSecondScale) { double orgX = x; double orgY = y; - // overdraw - boolean overdraw = false; - if (x > graphWidth) { // end right - overdraw = true; - } - if (y < 0) { // end bottom - overdraw = true; - } - if (y > graphHeight) { // end top - overdraw = true; - } - /* Fix a bug that continue to show the DOT after Y axis */ - if(x < 0) { - overdraw = true; - } - - float endX = (float) x + (graphLeft + 1); - float endY = (float) (graphTop - y) + graphHeight; - registerDataPoint(endX, endY, value); + float endX = ( float ) x + ( graphLeft + 1 ); + float endY = ( float ) ( graphTop - y ) + graphHeight; + registerDataPoint( endX, endY, value ); // draw data point - if (!overdraw) { - if (mCustomShape != null) { - mCustomShape.draw(canvas, mPaint, endX, endY, value); - } else if (mStyles.shape == Shape.POINT) { - canvas.drawCircle(endX, endY, mStyles.size, mPaint); - } else if (mStyles.shape == Shape.RECTANGLE) { - canvas.drawRect(endX-mStyles.size, endY-mStyles.size, endX+mStyles.size, endY+mStyles.size, mPaint); - } else if (mStyles.shape == Shape.TRIANGLE) { - Point[] points = new Point[3]; - points[0] = new Point((int)endX, (int)(endY-getSize())); - points[1] = new Point((int)(endX+getSize()), (int)(endY+getSize()*0.67)); - points[2] = new Point((int)(endX-getSize()), (int)(endY+getSize()*0.67)); - drawArrows(points, canvas, mPaint); + if ( !isOverdraw(graphWidth, graphHeight, x, y) ) { + if ( mCustomShape != null ) { + mCustomShape.draw( canvas, mPaint, endX, endY, value ); + } else if ( mStyles.shape == Shape.POINT ) { + canvas.drawCircle( endX, endY, mStyles.size, mPaint ); + } else if ( mStyles.shape == Shape.RECTANGLE ) { + canvas.drawRect( endX - mStyles.size, endY - mStyles.size, endX + mStyles.size, endY + mStyles.size, mPaint ); + } else if ( mStyles.shape == Shape.TRIANGLE ) { + Point[] points = new Point[ 3 ]; + points[ 0 ] = new Point( ( int ) endX, ( int ) ( endY - getSize() ) ); + points[ 1 ] = new Point( ( int ) ( endX + getSize() ), ( int ) ( endY + getSize() * 0.67 ) ); + points[ 2 ] = new Point( ( int ) ( endX - getSize() ), ( int ) ( endY + getSize() * 0.67 ) ); + drawArrows( points, canvas, mPaint ); } } @@ -234,6 +217,19 @@ public void draw(GraphView graphView, Canvas canvas, boolean isSecondScale) { } + /** + * checker for overdraw + * + * @param graphWidth float width + * @param graphHeight float height + * @param x double coordinate + * @param y double coordinate + */ + private boolean isOverdraw( float graphWidth, float graphHeight, double x, double y ) { + + return x > graphWidth || y < 0 || y > graphHeight || x < 0; + } + /** * helper to draw triangle * @@ -241,23 +237,23 @@ public void draw(GraphView graphView, Canvas canvas, boolean isSecondScale) { * @param canvas canvas to draw on * @param paint paint object */ - private void drawArrows(Point[] point, Canvas canvas, Paint paint) { - float [] points = new float[8]; - points[0] = point[0].x; - points[1] = point[0].y; - points[2] = point[1].x; - points[3] = point[1].y; - points[4] = point[2].x; - points[5] = point[2].y; - points[6] = point[0].x; - points[7] = point[0].y; - - canvas.drawVertices(Canvas.VertexMode.TRIANGLES, 8, points, 0, null, 0, null, 0, null, 0, 0, paint); + private void drawArrows( Point[] point, Canvas canvas, Paint paint ) { + float[] points = new float[ 8 ]; + points[ 0 ] = point[ 0 ].x; + points[ 1 ] = point[ 0 ].y; + points[ 2 ] = point[ 1 ].x; + points[ 3 ] = point[ 1 ].y; + points[ 4 ] = point[ 2 ].x; + points[ 5 ] = point[ 2 ].y; + points[ 6 ] = point[ 0 ].x; + points[ 7 ] = point[ 0 ].y; + + canvas.drawVertices( Canvas.VertexMode.TRIANGLES, 8, points, 0, null, 0, null, 0, null, 0, 0, paint ); Path path = new Path(); - path.moveTo(point[0].x , point[0].y); - path.lineTo(point[1].x,point[1].y); - path.lineTo(point[2].x,point[2].y); - canvas.drawPath(path,paint); + path.moveTo( point[ 0 ].x, point[ 0 ].y ); + path.lineTo( point[ 1 ].x, point[ 1 ].y ); + path.lineTo( point[ 2 ].x, point[ 2 ].y ); + canvas.drawPath( path, paint ); } /** From 520419195033b941f1aa2f152778a0302fbb9860 Mon Sep 17 00:00:00 2001 From: TaniaSolo Date: Sun, 2 Apr 2017 20:43:49 -0700 Subject: [PATCH 6/7] Organizing Data: Encapsulate Field --- src/main/java/com/jjoe64/graphview/SecondScale.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jjoe64/graphview/SecondScale.java b/src/main/java/com/jjoe64/graphview/SecondScale.java index 6dede5ecf..a4a1f54d7 100644 --- a/src/main/java/com/jjoe64/graphview/SecondScale.java +++ b/src/main/java/com/jjoe64/graphview/SecondScale.java @@ -83,12 +83,12 @@ public class SecondScale { /** * font size of the vertical axis title */ - public float mVerticalAxisTitleTextSize; + private float mVerticalAxisTitleTextSize; /** * font color of the vertical axis title */ - public int mVerticalAxisTitleColor; + private int mVerticalAxisTitleColor; /** * creates the second scale. From a47f29d7cb42ed7ddd2fd1ffbd7f13e82c243618 Mon Sep 17 00:00:00 2001 From: TaniaSolo Date: Sun, 2 Apr 2017 22:41:45 -0700 Subject: [PATCH 7/7] Moving Features Between Objects: Introduce Foreign Method --- .../jjoe64/graphview/GridLabelRenderer.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/jjoe64/graphview/GridLabelRenderer.java b/src/main/java/com/jjoe64/graphview/GridLabelRenderer.java index 1a756ed9c..1ebbf74e7 100644 --- a/src/main/java/com/jjoe64/graphview/GridLabelRenderer.java +++ b/src/main/java/com/jjoe64/graphview/GridLabelRenderer.java @@ -125,7 +125,7 @@ public final class Styles { * font color of the horizontal axis title */ public int horizontalAxisTitleColor; - + /** * angle of the horizontal axis label in * degrees between 0 and 180 @@ -402,7 +402,7 @@ public void resetStyles() { mStyles.horizontalLabelsVisible = true; mStyles.verticalLabelsVisible = true; - + mStyles.horizontalLabelsAngle = 0f; mStyles.gridStyle = GridStyle.BOTH; @@ -482,7 +482,7 @@ public Paint.Align getVerticalLabelsAlign() { public int getHorizontalLabelsColor() { return mStyles.horizontalLabelsColor; } - + /** * @return the angle of the horizontal labels */ @@ -553,7 +553,7 @@ protected boolean adjustVerticalSecondScale() { exactSteps = (maxY - minY) / (numVerticalLabels - 1); // round because of floating error - exactSteps = Math.round(exactSteps * 1000000d) / 1000000d; + exactSteps = getRoundExactSteps(exactSteps , false); } else { // TODO auto adjusting throw new IllegalStateException("Not yet implemented"); @@ -683,11 +683,10 @@ protected boolean adjustVertical(boolean changeBounds) { exactSteps = (maxY - minY) / (numVerticalLabels - 1); // round because of floating error - exactSteps = Math.round(exactSteps * 1000000d) / 1000000d; + exactSteps = getRoundExactSteps(exactSteps , true); // smallest viewport - if (exactSteps == 0d) { - exactSteps = 0.0000001d; + if (exactSteps == 0.0000001d) { maxY = minY + exactSteps * (numVerticalLabels - 1); } @@ -822,11 +821,10 @@ protected boolean adjustHorizontal(boolean changeBounds) { exactSteps = (maxX - minX) / (numHorizontalLabels - 1); // round because of floating error - exactSteps = Math.round(exactSteps * 1000000d) / 1000000d; + exactSteps = getRoundExactSteps(exactSteps , true); // smallest viewport - if (exactSteps == 0d) { - exactSteps = 0.0000001d; + if (exactSteps == 0.0000001d) { maxX = minX + exactSteps * (numHorizontalLabels - 1); } @@ -930,6 +928,15 @@ protected boolean adjustHorizontal(boolean changeBounds) { return true; } + private double getRoundExactSteps(double exactSteps, boolean isSmallestViewport) { + exactSteps = Math.round(exactSteps * 1000000d) / 1000000d; + + if (isSmallestViewport && exactSteps == 0d) { + exactSteps = 0.0000001d; + } + return exactSteps; + } + /** * adjusts the grid and labels to match to the data * this will automatically change the bounds to @@ -1198,7 +1205,7 @@ protected void drawHorizontalSteps(Canvas canvas) { label = ""; } String[] lines = label.split("\n"); - + // If labels are angled, calculate adjustment to line them up with the grid int labelWidthAdj = 0; if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) { @@ -1492,7 +1499,7 @@ public void setVerticalLabelsColor(int verticalLabelsColor) { public void setHorizontalLabelsColor(int horizontalLabelsColor) { mStyles.horizontalLabelsColor = horizontalLabelsColor; } - + /** * @param horizontalLabelsAngle the angle of the horizontal labels in degrees */