Skip to content

Commit

Permalink
allow datapoint styling for each series
Browse files Browse the repository at this point in the history
Introduces datapoint field in GraphViewSeriesStyle. This can be configured, and will be used if LineGraphView.drawDataPoints is false.
  • Loading branch information
mobiRic committed Aug 5, 2014
1 parent 4ca8aab commit fdac71e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/com/jjoe64/graphview/GraphViewSeries.java
Expand Up @@ -40,6 +40,8 @@ static public class GraphViewSeriesStyle {

private final Paint paintBackground;
private boolean drawBackground;
private boolean drawDataPoints;
private float dataPointsRadius = 10f;

public GraphViewSeriesStyle() {
super();
Expand Down Expand Up @@ -97,6 +99,32 @@ public int getBackgroundColor() {
public void setBackgroundColor(int color) {
paintBackground.setColor(color);
}

public float getDataPointsRadius() {
return dataPointsRadius;
}

public boolean getDrawDataPoints() {
return drawDataPoints;
}

/**
* sets the radius of the circles at the data points.
* @see #setDrawDataPoints(boolean)
* @param dataPointsRadius
*/
public void setDataPointsRadius(float dataPointsRadius) {
this.dataPointsRadius = dataPointsRadius;
}

/**
* You can set the flag to let the GraphView draw circles at the data points
* @see #setDataPointsRadius(float)
* @param drawDataPoints
*/
public void setDrawDataPoints(boolean drawDataPoints) {
this.drawDataPoints = drawDataPoints;
}
}

final String description;
Expand Down
10 changes: 8 additions & 2 deletions src/com/jjoe64/graphview/LineGraphView.java
Expand Up @@ -93,6 +93,8 @@ public void drawSeries(Canvas canvas, GraphViewDataInterface[] values, float gra
if (drawDataPoints) {
//fix: last value was not drawn. Draw here now the end values
canvas.drawCircle(endX, endY, dataPointsRadius, paint);
} else if (style.getDrawDataPoints()) {
canvas.drawCircle(endX, endY, style.getDataPointsRadius(), paint);
}

canvas.drawLine(startX, startY, endX, endY, paint);
Expand All @@ -103,11 +105,15 @@ public void drawSeries(Canvas canvas, GraphViewDataInterface[] values, float gra
}
bgPath.lineTo(endX, endY);
}
} else if (drawDataPoints) {
} else if ((drawDataPoints) || (style.getDrawDataPoints())) {
//fix: last value not drawn as datapoint. Draw first point here, and then on every step the end values (above)
float first_X = (float) x + (horstart + 1);
float first_Y = (float) (border - y) + graphheight;
canvas.drawCircle(first_X, first_Y, dataPointsRadius, paint);
if (drawDataPoints) {
canvas.drawCircle(first_X, first_Y, dataPointsRadius, paint);
} else if (style.getDrawDataPoints()) {
canvas.drawCircle(first_X, first_Y, style.getDataPointsRadius(), paint);
}
}
lastEndY = y;
lastEndX = x;
Expand Down

0 comments on commit fdac71e

Please sign in to comment.