Skip to content

Commit

Permalink
Graph: Expand orange highlight to the selected label background.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloercoli committed Jan 27, 2015
1 parent 25d51f2 commit d8a93f7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
*/
abstract public class GraphView extends LinearLayout {
static final private class GraphViewConfig {
static final float BORDER = 20;
static final float BORDER = 30;
}

private class GraphViewContentView extends View {
Expand Down Expand Up @@ -113,7 +113,7 @@ protected void onDraw(Canvas canvas) {
verlabels = generateVerlabels(graphheight);
}

// vertical lines
// vertical lines (aligned with the verLabels)
paint.setTextAlign(Align.LEFT);
int vers = verlabels.length - 1;
for (int i = 0; i < verlabels.length; i++) {
Expand All @@ -131,11 +131,24 @@ protected void onDraw(Canvas canvas) {
paint.setColor(graphViewStyle.getGridXColor());
float x = ((graphwidth / hors) * i) + horstart + (colWidth/2);
canvas.drawLine(x, height - border, x, border, paint);

// Draw the background of labels
paint.setColor(graphViewStyle.getHorizontalLabelsBackgroundColor(i));
paint.setAlpha(50);
canvas.drawRect(
((graphwidth / hors) * i) + horstart,
height - border,
((graphwidth / hors) * i) + horstart + colWidth,
height,
paint
);

// Draw the label
paint.setTextAlign(Align.CENTER);
paint.setColor(graphViewStyle.getHorizontalLabelsColor(i));

if (horLabelsToShow > 0 && (hors / horLabelsToShow) > 0) {
canvas.drawText(horlabels[i], x, height - 4, paint);
canvas.drawText(horlabels[i], x, height - (GraphViewConfig.BORDER / 2), paint);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
public class GraphViewStyle {
private int verticalLabelsColor;
private int horizontalLabelsColor;
private int horizontalBackgroundLabelsColor;
private IndexDependentColor horizontalLabelsIndexDependentColor;
private IndexDependentColor horizontalLabelsBackgroundIndexDependentColor;
private int gridXColor;
private int gridYColor;
private float textSize = 30f;
Expand All @@ -40,15 +42,17 @@ public class GraphViewStyle {
public GraphViewStyle() {
verticalLabelsColor = Color.WHITE;
horizontalLabelsColor = Color.WHITE;
horizontalBackgroundLabelsColor = Color.WHITE;
gridXColor = Color.DKGRAY;
gridYColor = Color.DKGRAY;
}

public GraphViewStyle(int vLabelsColor, int hLabelsColor, int gridXColor, int gridYColor) {
public GraphViewStyle(int vLabelsColor, int hLabelsColor, int hLabelsBackgroundColor, int gridXColor, int gridYColor) {
this.verticalLabelsColor = vLabelsColor;
this.horizontalLabelsColor = hLabelsColor;
this.gridXColor = gridXColor;
this.gridYColor = gridYColor;
this.horizontalBackgroundLabelsColor = hLabelsBackgroundColor;
}

public int getGridXColor() {
Expand All @@ -71,6 +75,18 @@ public int getHorizontalLabelsColor() {
return horizontalLabelsColor;
}

public int getHorizontalLabelsBackgroundColor(int i) {
if (horizontalLabelsBackgroundIndexDependentColor != null) {
return horizontalLabelsBackgroundIndexDependentColor.get(i);
}

return getHorizontalLabelsBackgroundColor();
}

public int getHorizontalLabelsBackgroundColor() {
return horizontalBackgroundLabelsColor;
}

public int getNumHorizontalLabels() {
return numHorizontalLabels;
}
Expand Down Expand Up @@ -144,4 +160,12 @@ public IndexDependentColor getHorizontalLabelsIndexDependentColor() {
public void setHorizontalLabelsIndexDependentColor(IndexDependentColor indexDependentColor) {
this.horizontalLabelsIndexDependentColor = indexDependentColor;
}

public IndexDependentColor getHorizontalLabelsBackgroundIndexDependentColor() {
return horizontalLabelsBackgroundIndexDependentColor;
}

public void setHorizontalLabelsBackgroundIndexDependentColor(IndexDependentColor indexDependentColor) {
this.horizontalLabelsBackgroundIndexDependentColor = indexDependentColor;
}
}

0 comments on commit d8a93f7

Please sign in to comment.