Added feature for min/max width limits on yAxis
diff --git a/MPChartLib/src/com/github/mikephil/charting/components/YAxis.java b/MPChartLib/src/com/github/mikephil/charting/components/YAxis.java
index bebaffe..dd23bb8 100644
--- a/MPChartLib/src/com/github/mikephil/charting/components/YAxis.java
+++ b/MPChartLib/src/com/github/mikephil/charting/components/YAxis.java
@@ -124,6 +124,20 @@
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.
* This could happen if two adjacent axis values are rounded to same value.
@@ -162,6 +176,36 @@
}
/**
+ * @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
*/
public boolean isGranularityEnabled() {
@@ -447,7 +491,20 @@
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;
}
/**