@webileapps/react-native-charts-wrapper
Advanced tools
Sorry, the diff of this file is not supported yet
| package com.github.wuxudong.rncharts.charts; | ||
| import com.github.mikephil.charting.formatter.ValueFormatter; | ||
| import java.text.DecimalFormat; | ||
| import java.text.DecimalFormat; | ||
| /** | ||
| * Predefined value-formatter that formats large numbers in a pretty way. | ||
| * Outputs: 856 = 856; 1000 = 1k; 5821 = 5.8k; 10500 = 10k; 101800 = 102k; | ||
| * 2000000 = 2m; 7800000 = 7.8m; 92150000 = 92m; 123200000 = 123m; 9999999 = | ||
| * 10m; 1000000000 = 1b; Special thanks to Roman Gromov | ||
| * (https://github.com/romangromov) for this piece of code. | ||
| * | ||
| * @author Philipp Jahoda | ||
| * @author Oleksandr Tyshkovets <olexandr.tyshkovets@gmail.com> | ||
| */ | ||
| public class LargeValueFormatter extends ValueFormatter | ||
| { | ||
| private String[] mSuffix = new String[]{ | ||
| "", "k", "m", "b", "t" | ||
| }; | ||
| private int mMaxLength = 5; | ||
| private DecimalFormat mFormat; | ||
| private String mText = ""; | ||
| public LargeValueFormatter() { | ||
| mFormat = new DecimalFormat("###E00"); | ||
| } | ||
| /** | ||
| * Creates a formatter that appends a specified text to the result string | ||
| * | ||
| * @param appendix a text that will be appended | ||
| */ | ||
| public LargeValueFormatter(String appendix) { | ||
| this(); | ||
| mText = appendix; | ||
| } | ||
| @Override | ||
| public String getFormattedValue(float value) { | ||
| return makePretty(value) + mText; | ||
| } | ||
| /** | ||
| * Set an appendix text to be added at the end of the formatted value. | ||
| * | ||
| * @param appendix | ||
| */ | ||
| public void setAppendix(String appendix) { | ||
| this.mText = appendix; | ||
| } | ||
| /** | ||
| * Set custom suffix to be appended after the values. | ||
| * Default suffix: ["", "k", "m", "b", "t"] | ||
| * | ||
| * @param suffix new suffix | ||
| */ | ||
| public void setSuffix(String[] suffix) { | ||
| this.mSuffix = suffix; | ||
| } | ||
| public void setMaxLength(int maxLength) { | ||
| this.mMaxLength = maxLength; | ||
| } | ||
| /** | ||
| * Formats each number properly. Special thanks to Roman Gromov | ||
| * (https://github.com/romangromov) for this piece of code. | ||
| */ | ||
| private String makePretty(double number) { | ||
| String r = mFormat.format(number); | ||
| int numericValue1 = Character.getNumericValue(r.charAt(r.length() - 1)); | ||
| int numericValue2 = Character.getNumericValue(r.charAt(r.length() - 2)); | ||
| int combined = Integer.valueOf(numericValue2 + "" + numericValue1); | ||
| r = r.replaceAll("E[0-9][0-9]", mSuffix[combined / 3]); | ||
| if (r.length() > mMaxLength || r.matches("[0-9]+\\.[a-z]")) { | ||
| r = Math.round(Double.parseDouble(r.substring(0, r.length() - 1)))+r.substring(r.length() - 1); | ||
| } | ||
| return r; | ||
| } | ||
| public int getDecimalDigits() { | ||
| return 0; | ||
| } | ||
| } |
@@ -23,3 +23,2 @@ package com.github.wuxudong.rncharts.charts; | ||
| import com.github.mikephil.charting.formatter.IndexAxisValueFormatter; | ||
| import com.github.mikephil.charting.formatter.LargeValueFormatter; | ||
| import com.github.mikephil.charting.formatter.PercentFormatter; | ||
@@ -26,0 +25,0 @@ import com.github.mikephil.charting.highlight.Highlight; |
+1
-1
@@ -7,3 +7,3 @@ { | ||
| }, | ||
| "version": "0.0.15", | ||
| "version": "0.0.16", | ||
| "description": "A highly customized react-native charts support both android and ios. Won't scrol the graph.", | ||
@@ -10,0 +10,0 @@ "author": "wuxudong", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1297414
0.54%259
0.78%4635
1.67%