File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
MPChartLib/src/main/java/com/github/mikephil/charting/components Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 33
44import android .graphics .Color ;
55import android .graphics .DashPathEffect ;
6+ import android .graphics .Paint ;
67import android .util .Log ;
78
89import com .github .mikephil .charting .formatter .DefaultAxisValueFormatter ;
@@ -524,6 +525,33 @@ public String getLongestLabel() {
524525 return longest ;
525526 }
526527
528+ /**
529+ * Returns the longest formatted label (in terms of px), this axis
530+ * contains.
531+ * If paint is null, then returns the longest formatted label (in terms of characters), this axis contains.
532+ *
533+ * @return
534+ */
535+ public String getLongestLabel (Paint p ) {
536+ if (p == null ) {
537+ return getLongestLabel ();
538+ }
539+ String longest = "" ;
540+ float max = 0f ;
541+
542+ for (int i = 0 ; i < mEntries .length ; i ++) {
543+ String text = getFormattedLabel (i );
544+ if (text != null ) {
545+ float width = p .measureText (text );
546+ if (max < width ) {
547+ longest = text ;
548+ }
549+ }
550+ }
551+
552+ return longest ;
553+ }
554+
527555 public String getFormattedLabel (int index ) {
528556
529557 if (index < 0 || index >= mEntries .length )
Original file line number Diff line number Diff line change @@ -344,7 +344,7 @@ public float getRequiredWidthSpace(Paint p) {
344344
345345 p .setTextSize (mTextSize );
346346
347- String label = getLongestLabel ();
347+ String label = getLongestLabel (p );
348348 float width = (float ) Utils .calcTextWidth (p , label ) + getXOffset () * 2f ;
349349
350350 float minWidth = getMinWidth ();
@@ -371,7 +371,7 @@ public float getRequiredHeightSpace(Paint p) {
371371
372372 p .setTextSize (mTextSize );
373373
374- String label = getLongestLabel ();
374+ String label = getLongestLabel (p );
375375 return (float ) Utils .calcTextHeight (p , label ) + getYOffset () * 2f ;
376376 }
377377
You can’t perform that action at this time.
0 commit comments