Skip to content

Commit

Permalink
Merge pull request #212 from weilanxiao/fix_y_label_width
Browse files Browse the repository at this point in the history
Solve the problem of insufficient width of Y-axis label display
  • Loading branch information
hannesa2 authored May 16, 2024
2 parents a45f5c6 + 8bb809b commit 8bea117
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.util.Log;

import com.github.mikephil.charting.formatter.DefaultAxisValueFormatter;
Expand Down Expand Up @@ -524,6 +525,33 @@ public String getLongestLabel() {
return longest;
}

/**
* Returns the longest formatted label (in terms of px), this axis
* contains.
* If paint is null, then returns the longest formatted label (in terms of characters), this axis contains.
*
* @return
*/
public String getLongestLabel(Paint p) {
if (p == null) {
return getLongestLabel();
}
String longest = "";
float max = 0f;

for (int i = 0; i < mEntries.length; i++) {
String text = getFormattedLabel(i);
if (text != null) {
float width = p.measureText(text);
if (max < width) {
longest = text;
}
}
}

return longest;
}

public String getFormattedLabel(int index) {

if (index < 0 || index >= mEntries.length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public float getRequiredWidthSpace(Paint p) {

p.setTextSize(mTextSize);

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

float minWidth = getMinWidth();
Expand All @@ -371,7 +371,7 @@ public float getRequiredHeightSpace(Paint p) {

p.setTextSize(mTextSize);

String label = getLongestLabel();
String label = getLongestLabel(p);
return (float) Utils.calcTextHeight(p, label) + getYOffset() * 2f;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshotsToCompare/ViewPagerTest_smokeTestViewPager.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8bea117

Please sign in to comment.