Skip to content

Commit

Permalink
Added feature for min/max width limits on yAxis
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Mar 17, 2016
1 parent b9995b7 commit e2fc221
Showing 1 changed file with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ public enum YAxisLabelPosition {
*/
private AxisDependency mAxisDependency;

/**
* the minimum width that the axis should take (in dp).
*
* default: 0.0
*/
protected float mMinWidth = 0.f;

/**
* the maximum width that the axis can take (in dp).
* use Inifinity for disabling the maximum
* default: Float.POSITIVE_INFINITY (no maximum specified)
*/
protected float mMaxWidth = Float.POSITIVE_INFINITY;

/**
* When true, axis labels are controlled by the `granularity` property.
* When false, axis values could possibly be repeated.
Expand Down Expand Up @@ -161,6 +175,36 @@ public AxisDependency getAxisDependency() {
return mAxisDependency;
}

/**
* @return the minimum width that the axis should take (in dp).
*/
public float getMinWidth() {
return mMinWidth;
}

/**
* Sets the minimum width that the axis should take (in dp).
* @param minWidth
*/
public void setMinWidth(float minWidth) {
mMinWidth = minWidth;
}

/**
* @return the maximum width that the axis can take (in dp).
*/
public float getMaxWidth() {
return mMaxWidth;
}

/**
* Sets the maximum width that the axis can take (in dp).
* @param maxWidth
*/
public void setMaxWidth(float maxWidth) {
mMaxWidth = maxWidth;
}

/**
* @return true if granularity is enabled
*/
Expand Down Expand Up @@ -447,7 +491,20 @@ public float getRequiredWidthSpace(Paint p) {
p.setTextSize(mTextSize);

String label = getLongestLabel();
return (float) Utils.calcTextWidth(p, label) + getXOffset() * 2f;
float width = (float) Utils.calcTextWidth(p, label) + getXOffset() * 2f;

float minWidth = getMinWidth();
float maxWidth = getMaxWidth();

if (minWidth > 0.f)
minWidth = Utils.convertDpToPixel(minWidth);

if (maxWidth > 0.f && maxWidth != Float.POSITIVE_INFINITY)
maxWidth = Utils.convertDpToPixel(maxWidth);

width = Math.max(minWidth, Math.min(width, maxWidth > 0.0 ? maxWidth : width));

return width;
}

/**
Expand Down

0 comments on commit e2fc221

Please sign in to comment.