Skip to content

Commit

Permalink
Merge pull request PhilJay#1593 from danielgindi/yaxis-width-limits
Browse files Browse the repository at this point in the history
Added feature for min/max width limits on yAxis
  • Loading branch information
PhilJay committed Mar 17, 2016
2 parents b9995b7 + e2fc221 commit fc622ce
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 fc622ce

Please sign in to comment.