GeezerVison is showing github.com — Avoid creating a new formatter if null · FlyingAndroid/MPAndroidChart@2176873
File treeExpand file treeCollapse file tree Open diff view settings MPChartLib/src/main/java/com/github/mikephil/charting
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -98,7 +98,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent | 98 | 98 | /** | 99 | 99 | * default value-formatter, number of digits depends on provided chart-data | 100 | 100 | */ | 101 | | - protected DefaultValueFormatter mDefaultFormatter = new DefaultValueFormatter(0); | | 101 | + protected DefaultValueFormatter mDefaultValueFormatter = new DefaultValueFormatter(0); | 102 | 102 |
| 103 | 103 | /** | 104 | 104 | * paint object used for drawing the description text in the bottom right | @@ -305,8 +305,8 @@ public void setData(T data) { | 305 | 305 | setupDefaultFormatter(data.getYMin(), data.getYMax()); | 306 | 306 |
| 307 | 307 | for (IDataSet set : mData.getDataSets()) { | 308 | | - if (set.needsFormatter() || set.getValueFormatter() == mDefaultFormatter) | 309 | | - set.setValueFormatter(mDefaultFormatter); | | 308 | + if (set.needsFormatter() || set.getValueFormatter() == mDefaultValueFormatter) | | 309 | + set.setValueFormatter(mDefaultValueFormatter); | 310 | 310 | } | 311 | 311 |
| 312 | 312 | // let the chart know there is new data | @@ -393,7 +393,7 @@ protected void setupDefaultFormatter(float min, float max) { | 393 | 393 | int digits = Utils.getDecimals(reference); | 394 | 394 |
| 395 | 395 | // setup the formatter with a new number of digits | 396 | | - mDefaultFormatter.setup(digits); | | 396 | + mDefaultValueFormatter.setup(digits); | 397 | 397 | } | 398 | 398 |
| 399 | 399 | /** | @@ -981,7 +981,7 @@ public XAxis getXAxis() { | 981 | 981 | * @return | 982 | 982 | */ | 983 | 983 | public IValueFormatter getDefaultValueFormatter() { | 984 | | - return mDefaultFormatter; | | 984 | + return mDefaultValueFormatter; | 985 | 985 | } | 986 | 986 |
| 987 | 987 | /** | |
Collapse file Copy file name to clipboardExpand all lines: MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -268,7 +268,7 @@ public void setValueFormatter(IValueFormatter f) { | 268 | 268 | @Override | 269 | 269 | public IValueFormatter getValueFormatter() { | 270 | 270 | if (needsFormatter()) | 271 | | - return new DefaultValueFormatter(1); | | 271 | + return Utils.getDefaultValueFormatter(); | 272 | 272 | return mValueFormatter; | 273 | 273 | } | 274 | 274 |
| |
Collapse file Copy file name to clipboardExpand all lines: MPChartLib/src/main/java/com/github/mikephil/charting/utils/Utils.java +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | import android.view.View; | 19 | 19 | import android.view.ViewConfiguration; | 20 | 20 |
| | 21 | +import com.github.mikephil.charting.formatter.DefaultValueFormatter; | | 22 | +import com.github.mikephil.charting.formatter.IValueFormatter; | | 23 | + | 21 | 24 | import java.util.List; | 22 | 25 |
| 23 | 26 | /** | @@ -233,6 +236,19 @@ public static void calcTextSize(Paint paint, String demoText, FSize outputFSize) | 233 | 236 | 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 | 234 | 237 | }; | 235 | 238 |
| | 239 | + private static IValueFormatter mDefaultValueFormatter = generateDefaultValueFormatter(); | | 240 | + | | 241 | + private static IValueFormatter generateDefaultValueFormatter() { | | 242 | + final DefaultValueFormatter formatter = new DefaultValueFormatter(1); | | 243 | + return formatter; | | 244 | + } | | 245 | + | | 246 | + /// - returns: The default value formatter used for all chart components that needs a default | | 247 | + public static IValueFormatter getDefaultValueFormatter() | | 248 | + { | | 249 | + return mDefaultValueFormatter; | | 250 | + } | | 251 | + | 236 | 252 | /** | 237 | 253 | * Formats the given number to the given number of decimals, and returns the | 238 | 254 | * number as a string, maximum 35 characters. If thousands are separated, the separating | |
|