Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactoring #502

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
31 changes: 19 additions & 12 deletions src/main/java/com/jjoe64/graphview/GridLabelRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -402,7 +402,7 @@ public void resetStyles() {

mStyles.horizontalLabelsVisible = true;
mStyles.verticalLabelsVisible = true;

mStyles.horizontalLabelsAngle = 0f;

mStyles.gridStyle = GridStyle.BOTH;
Expand Down Expand Up @@ -482,7 +482,7 @@ public Paint.Align getVerticalLabelsAlign() {
public int getHorizontalLabelsColor() {
return mStyles.horizontalLabelsColor;
}

/**
* @return the angle of the horizontal labels
*/
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jjoe64/graphview/SecondScale.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/com/jjoe64/graphview/series/BarGraphSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,11 +40,6 @@
public class BarGraphSeries<E extends DataPointInterface> extends BaseSeries<E> {
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.
Expand Down Expand Up @@ -262,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;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/jjoe64/graphview/series/BaseSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -46,6 +47,12 @@
* @author jjoe64
*/
public abstract class BaseSeries<E extends DataPointInterface> implements Series<E> {

/**
* paint to do drawing on canvas
*/
protected Paint mPaint;

/**
* holds the data
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ private final class Styles {

private Paint mSelectionPaint;

/**
* internal paint object
*/
private Paint mPaint;

/**
* paint for the background
*/
Expand Down
99 changes: 45 additions & 54 deletions src/main/java/com/jjoe64/graphview/series/PointsGraphSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,11 +97,6 @@ private final class Styles {
*/
private Styles mStyles;

/**
* internal paint object
*/
private Paint mPaint;

/**
* handler to use a custom drawing
*/
Expand Down Expand Up @@ -197,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 );
}
}

Expand All @@ -239,30 +217,43 @@ 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
*
* @param point array with 3 coordinates
* @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 );
}

/**
Expand Down