Skip to content

Commit

Permalink
refs #277 space between labels and graph content can be defined
Browse files Browse the repository at this point in the history
  • Loading branch information
jogehring committed Jan 18, 2015
1 parent e6d0766 commit f702c61
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main/java/com/jjoe64/graphview/GridLabelRenderer.java
Expand Up @@ -127,6 +127,11 @@ public final class Styles {
* defines which lines will be drawn in the background
*/
GridStyle gridStyle;

/**
* the space between the labels text and the graph content
*/
int labelsSpace;
}

/**
Expand Down Expand Up @@ -310,6 +315,7 @@ public void resetStyles() {
mStyles.gridColor = color2;
mStyles.textSize = size;
mStyles.padding = size2;
mStyles.labelsSpace = (int) mStyles.textSize/5;

mStyles.verticalLabelsAlign = Paint.Align.RIGHT;
mStyles.verticalLabelsSecondScaleAlign = Paint.Align.LEFT;
Expand Down Expand Up @@ -735,6 +741,9 @@ protected void calcLabelVerticalSize(Canvas canvas) {
// add some pixel to get a margin
mLabelVerticalWidth += 6;

// space between text and graph content
mLabelVerticalWidth += mStyles.labelsSpace;

// multiline
int lines = 1;
for (byte c : testLabel.getBytes()) {
Expand Down Expand Up @@ -790,6 +799,9 @@ protected void calcLabelHorizontalSize(Canvas canvas) {
if (c == '\n') lines++;
}
mLabelHorizontalHeight *= lines;

// space between text and graph content
mLabelHorizontalHeight += mStyles.labelsSpace;
}

/**
Expand Down Expand Up @@ -926,7 +938,7 @@ protected void drawHorizontalSteps(Canvas canvas) {
String[] lines = mLabelFormatter.formatLabel(e.getValue(), true).split("\n");
for (int li = 0; li < lines.length; li++) {
// for the last line y = height
float y = (canvas.getHeight() - mStyles.padding - getHorizontalAxisTitleHeight()) - (lines.length - li - 1) * getTextSize() * 1.1f;
float y = (canvas.getHeight() - mStyles.padding - getHorizontalAxisTitleHeight()) - (lines.length - li - 1) * getTextSize() * 1.1f + mStyles.labelsSpace;
canvas.drawText(lines[li], e.getKey(), y, mPaintLabel);
}
}
Expand Down Expand Up @@ -1001,6 +1013,7 @@ protected void drawVerticalSteps(Canvas canvas) {
int labelsOffset = 0;
if (getVerticalLabelsAlign() == Paint.Align.RIGHT) {
labelsOffset = labelsWidth;
labelsOffset -= mStyles.labelsSpace;
} else if (getVerticalLabelsAlign() == Paint.Align.CENTER) {
labelsOffset = labelsWidth / 2;
}
Expand Down Expand Up @@ -1375,4 +1388,20 @@ public GridStyle getGridStyle() {
public void setGridStyle(GridStyle gridStyle) {
mStyles.gridStyle = gridStyle;
}

/**
* @return the space between the labels text and the graph content
*/
public int getLabelsSpace() {
return mStyles.labelsSpace;
}

/**
* the space between the labels text and the graph content
*
* @param labelsSpace the space between the labels text and the graph content
*/
public void setLabelsSpace(int labelsSpace) {
mStyles.labelsSpace = labelsSpace;
}
}

0 comments on commit f702c61

Please sign in to comment.