Skip to content

Commit

Permalink
Merge pull request #133 from jorisvergeer/feature/square-lines
Browse files Browse the repository at this point in the history
Added square lines
  • Loading branch information
lecho committed May 17, 2015
2 parents f19102d + dbb282b commit de93e90
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions hellocharts-library/src/lecho/lib/hellocharts/model/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Line {
private boolean hasLabels = false;
private boolean hasLabelsOnlyForSelected = false;
private boolean isCubic = false;
private boolean isSquare = false;
private boolean isFilled = false;
private ValueShape shape = ValueShape.CIRCLE;
private PathEffect pathEffect;
Expand Down Expand Up @@ -200,6 +201,19 @@ public boolean isCubic() {

public Line setCubic(boolean isCubic) {
this.isCubic = isCubic;
if(isSquare)
setSquare(false);
return this;
}

public boolean isSquare() {
return isSquare;
}

public Line setSquare(boolean isSquare) {
this.isSquare = isSquare;
if(isCubic)
setCubic(false);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public void draw(Canvas canvas) {
if (line.hasLines()) {
if (line.isCubic()) {
drawSmoothPath(drawCanvas, line);
} else if (line.isSquare()) {
drawSquarePath(drawCanvas, line);
} else {
drawPath(drawCanvas, line);
}
Expand Down Expand Up @@ -237,6 +239,38 @@ private void drawPath(Canvas canvas, final Line line) {
path.reset();
}

private void drawSquarePath(Canvas canvas, final Line line) {
prepareLinePaint(line);

int valueIndex = 0;
float previousRawY = 0;
for (PointValue pointValue : line.getValues()) {

final float rawX = computator.computeRawX(pointValue.getX());
final float rawY = computator.computeRawY(pointValue.getY());

if (valueIndex == 0) {
path.moveTo(rawX, rawY);
} else {
path.lineTo(rawX, previousRawY);
path.lineTo(rawX, rawY);
}

previousRawY = rawY;

++valueIndex;

}

canvas.drawPath(path, linePaint);

if (line.isFilled()) {
drawArea(canvas, line);
}

path.reset();
}

private void drawSmoothPath(Canvas canvas, final Line line) {
prepareLinePaint(line);

Expand Down

0 comments on commit de93e90

Please sign in to comment.