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

Added square lines #133

Merged
merged 1 commit into from
May 17, 2015
Merged
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
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