Skip to content

Commit

Permalink
Minor refactorings PhilJay#1065
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJay committed Oct 4, 2015
1 parent d491144 commit 939e03b
Show file tree
Hide file tree
Showing 13 changed files with 302 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.github.mikephil.charting.utils.Utils;

/**
* This class encapsulates everything both Axis and Legend have in common.
* This class encapsulates everything both Axis, Legend and LimitLines have in common.
*
* @author Philipp Jahoda
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @author Philipp Jahoda
*/
public class LimitLine {
public class LimitLine extends ComponentBase {

/** limit / maximum (the y-value or xIndex) */
private float mLimit = 0f;
Expand All @@ -26,21 +26,12 @@ public class LimitLine {
/** the color of the limit line */
private int mLineColor = Color.rgb(237, 91, 91);

/** the color of the value-text */
private int mValueTextColor = Color.BLACK;

/** the size of the label text */
private float mTextSize = 13f;

/** the style of the label text */
private Paint.Style mTextStyle = Paint.Style.FILL_AND_STROKE;

/** label string that is drawn next to the limit line */
private String mLabel = "";

/** the typeface used for the labels */
private Typeface mTypeface = null;

/** the path effect of this LimitLine that makes dashed lines possible */
private DashPathEffect mDashPathEffect = null;

Expand Down Expand Up @@ -165,24 +156,6 @@ public DashPathEffect getDashPathEffect() {
return mDashPathEffect;
}

/**
* Sets the color of the value-text that is drawn next to the LimitLine.
*
* @param color
*/
public void setTextColor(int color) {
mValueTextColor = color;
}

/**
* Returns the color of the value-text that is drawn next to the LimitLine.
*
* @return
*/
public int getTextColor() {
return mValueTextColor;
}

/**
* Sets the color of the value-text that is drawn next to the LimitLine.
* Default: Paint.Style.FILL_AND_STROKE
Expand Down Expand Up @@ -239,40 +212,4 @@ public void setLabel(String label) {
public String getLabel() {
return mLabel;
}

/**
* Sets the size of the label-text.
*
* @param size
*/
public void setTextSize(float size) {
mTextSize = Utils.convertDpToPixel(size);
}

/**
* Returns the size of the label text.
*
* @return
*/
public float getTextSize() {
return mTextSize;
}

/**
* returns the Typeface used for the limitline label, returns null if none is set
*
* @return
*/
public Typeface getTypeface() {
return mTypeface;
}

/**
* Sets a specific Typeface to be used for the limitline label
*
* @param tf
*/
public void setTypeface(Typeface tf) {
mTypeface = tf;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
* 2000000 = 2m; 7800000 = 7.8m; 92150000 = 92m; 123200000 = 123m; 9999999 =
* 10m; 1000000000 = 1b; Special thanks to Roman Gromov
* (https://github.com/romangromov) for this piece of code.
*
*
* @author Philipp Jahoda
* @author Oleksandr Tyshkovets <[email protected]>
*/
public class LargeValueFormatter implements ValueFormatter, YAxisValueFormatter {

private static String[] SUFFIX = new String[] {
private static String[] SUFFIX = new String[]{
"", "k", "m", "b", "t"
};
private static final int MAX_LENGTH = 4;
Expand All @@ -32,6 +32,7 @@ public LargeValueFormatter() {

/**
* Creates a formatter that appends a specified text to the result string
*
* @param appendix a text that will be appended
*/
public LargeValueFormatter(String appendix) {
Expand All @@ -52,7 +53,18 @@ public String getFormattedValue(float value, YAxis yAxis) {
}

/**
* Set custom suffix to be appended after the values
* Set an appendix text to be added at the end of the formatted value.
*
* @param appendix
*/
public void setAppendix(String appendix) {
this.mText = appendix;
}

/**
* Set custom suffix to be appended after the values.
* Default suffix: ["", "k", "m", "b", "t"]
*
* @param suff new suffix
*/
public void setSuffix(String[] suff) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* This ValueFormatter is just for convenience and simply puts a "%" sign after
* each value. (Recommeded for PieChart)
*
*
* @author Philipp Jahoda
*/
public class PercentFormatter implements ValueFormatter, YAxisValueFormatter {
Expand All @@ -21,6 +21,15 @@ public PercentFormatter() {
mFormat = new DecimalFormat("###,###,##0.0");
}

/**
* Allow a custom decimalformat
*
* @param format
*/
public PercentFormatter(DecimalFormat format) {
this.mFormat = format;
}

// ValueFormatter
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,4 @@ public Transformer getTransformer() {
* @param c
*/
public abstract void renderLimitLines(Canvas c);

}
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ public void renderLimitLines(Canvas c) {

LimitLine l = limitLines.get(i);

if(!l.isEnabled())
continue;

pts[0] = l.getLimit();
pts[2] = l.getLimit();

Expand Down Expand Up @@ -246,9 +249,8 @@ public void renderLimitLines(Canvas c) {
mLimitLinePaint.setStrokeWidth(0.5f);
mLimitLinePaint.setTextSize(l.getTextSize());

float xOffset = l.getLineWidth();
float add = Utils.convertDpToPixel(4f);
float yOffset = add / 2f;
float xOffset = l.getLineWidth() + l.getXOffset();
float yOffset = Utils.convertDpToPixel(2f) + l.getYOffset();

final LimitLine.LimitLabelPosition position = l.getLabelPosition();

Expand All @@ -260,7 +262,7 @@ public void renderLimitLines(Canvas c) {
} else if (position == LimitLine.LimitLabelPosition.RIGHT_BOTTOM) {

mLimitLinePaint.setTextAlign(Align.LEFT);
c.drawText(label, pts[0] + xOffset, mViewPortHandler.contentBottom() - add, mLimitLinePaint);
c.drawText(label, pts[0] + xOffset, mViewPortHandler.contentBottom() - yOffset, mLimitLinePaint);
} else if (position == LimitLine.LimitLabelPosition.LEFT_TOP) {

mLimitLinePaint.setTextAlign(Align.RIGHT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ public void renderLimitLines(Canvas c) {

LimitLine l = limitLines.get(i);

if(!l.isEnabled())
continue;

mLimitLinePaint.setStyle(Paint.Style.STROKE);
mLimitLinePaint.setColor(l.getLineColor());
mLimitLinePaint.setStrokeWidth(l.getLineWidth());
Expand Down Expand Up @@ -219,8 +222,8 @@ public void renderLimitLines(Canvas c) {
mLimitLinePaint.setTextSize(l.getTextSize());

final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label);
float xOffset = Utils.convertDpToPixel(4f);
float yOffset = l.getLineWidth() + labelLineHeight;
float xOffset = Utils.convertDpToPixel(4f) + l.getXOffset();
float yOffset = l.getLineWidth() + labelLineHeight + l.getYOffset();

final LimitLine.LimitLabelPosition position = l.getLabelPosition();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ public void renderLimitLines(Canvas c) {

LimitLine l = limitLines.get(i);

if(!l.isEnabled())
continue;

mLimitLinePaint.setStyle(Paint.Style.STROKE);
mLimitLinePaint.setColor(l.getLineColor());
mLimitLinePaint.setStrokeWidth(l.getLineWidth());
Expand Down Expand Up @@ -324,8 +327,8 @@ public void renderLimitLines(Canvas c) {
mLimitLinePaint.setTextSize(l.getTextSize());

final float labelLineHeight = Utils.calcTextHeight(mLimitLinePaint, label);
float xOffset = Utils.convertDpToPixel(4f);
float yOffset = l.getLineWidth() + labelLineHeight;
float xOffset = Utils.convertDpToPixel(4f) + l.getXOffset();
float yOffset = l.getLineWidth() + labelLineHeight + l.getYOffset();

final LimitLine.LimitLabelPosition position = l.getLabelPosition();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ public void renderLimitLines(Canvas c) {
for (int i = 0; i < limitLines.size(); i++) {

LimitLine l = limitLines.get(i);

if(!l.isEnabled())
continue;

pts[0] = l.getLimit();
pts[2] = l.getLimit();
Expand Down Expand Up @@ -229,9 +232,8 @@ public void renderLimitLines(Canvas c) {
mLimitLinePaint.setStrokeWidth(0.5f);
mLimitLinePaint.setTextSize(l.getTextSize());

float xOffset = l.getLineWidth();
float add = Utils.convertDpToPixel(4f);
float yOffset = add / 2f;
float xOffset = l.getLineWidth() + l.getXOffset();
float yOffset = Utils.convertDpToPixel(2f) + l.getYOffset();

final LimitLine.LimitLabelPosition position = l.getLabelPosition();

Expand All @@ -243,7 +245,7 @@ public void renderLimitLines(Canvas c) {
} else if (position == LimitLine.LimitLabelPosition.RIGHT_BOTTOM) {

mLimitLinePaint.setTextAlign(Align.LEFT);
c.drawText(label, pts[0] + xOffset, mViewPortHandler.contentBottom() - add, mLimitLinePaint);
c.drawText(label, pts[0] + xOffset, mViewPortHandler.contentBottom() - yOffset, mLimitLinePaint);
} else if (position == LimitLine.LimitLabelPosition.LEFT_TOP) {

mLimitLinePaint.setTextAlign(Align.RIGHT);
Expand Down
Loading

0 comments on commit 939e03b

Please sign in to comment.