@@ -15,30 +15,30 @@ import java.text.DecimalFormat
1515 */
1616open class LargeValueFormatter () : IValueFormatter, IAxisValueFormatter {
1717
18- private var mSuffix = arrayOf(
18+ private var suffix = arrayOf(
1919 " " , " k" , " m" , " b" , " t"
2020 )
21- private var mMaxLength = 5
22- private val mFormat : DecimalFormat = DecimalFormat (" ###E00" )
23- private var mText = " "
21+ private var maxLength = 5
22+ private val decimalFormat : DecimalFormat = DecimalFormat (" ###E00" )
23+ private var text = " "
2424
2525 /* *
2626 * Creates a formatter that appends a specified text to the result string
2727 *
2828 * @param appendix a text that will be appended
2929 */
3030 constructor (appendix: String ) : this () {
31- mText = appendix
31+ text = appendix
3232 }
3333
3434 // IValueFormatter
3535 override fun getFormattedValue (value : Float , entry : Entry ? , dataSetIndex : Int , viewPortHandler : ViewPortHandler ? ): String {
36- return makePretty(value.toDouble()) + mText
36+ return makePretty(value.toDouble()) + text
3737 }
3838
3939 // IAxisValueFormatter
4040 override fun getFormattedValue (value : Float , axis : AxisBase ? ): String {
41- return makePretty(value.toDouble()) + mText
41+ return makePretty(value.toDouble()) + text
4242 }
4343
4444 /* *
@@ -47,37 +47,37 @@ open class LargeValueFormatter() : IValueFormatter, IAxisValueFormatter {
4747 * @param appendix
4848 */
4949 fun setAppendix (appendix : String ) {
50- mText = appendix
50+ text = appendix
5151 }
5252
5353 /* *
5454 * Set custom suffix to be appended after the values.
5555 * Default suffix: ["", "k", "m", "b", "t"]
5656 *
57- * @param suffix new suffix
57+ * @param suffixArray new suffix
5858 */
59- fun setSuffix (suffix : Array <String >) {
60- mSuffix = suffix
59+ fun setSuffix (suffixArray : Array <String >) {
60+ suffix = suffixArray
6161 }
6262
63- fun setMaxLength (maxLength : Int ) {
64- mMaxLength = maxLength
63+ fun setMaxLength (max : Int ) {
64+ maxLength = max
6565 }
6666
6767 /* *
6868 * Formats each number properly. Special thanks to Roman Gromov
6969 * (https://github.com/romangromov) for this piece of code.
7070 */
7171 private fun makePretty (number : Double ): String {
72- var r = mFormat .format(number)
73- val numericValue1 = Character .getNumericValue(r[r .length - 1 ])
74- val numericValue2 = Character .getNumericValue(r[r .length - 2 ])
72+ var decimalFormat = decimalFormat .format(number)
73+ val numericValue1 = Character .getNumericValue(decimalFormat[decimalFormat .length - 1 ])
74+ val numericValue2 = Character .getNumericValue(decimalFormat[decimalFormat .length - 2 ])
7575 val combined = Integer .valueOf(numericValue2.toString() + " " + numericValue1)
76- r = r .replace(" E[0-9][0-9]" .toRegex(), mSuffix [combined / 3 ])
77- while (r .length > mMaxLength || r .matches(" [0-9]+\\ .[a-z]" .toRegex())) {
78- r = r .substring(0 , r .length - 2 ) + r .substring(r .length - 1 )
76+ decimalFormat = decimalFormat .replace(" E[0-9][0-9]" .toRegex(), suffix [combined / 3 ])
77+ while (decimalFormat .length > maxLength || decimalFormat .matches(" [0-9]+\\ .[a-z]" .toRegex())) {
78+ decimalFormat = decimalFormat .substring(0 , decimalFormat .length - 2 ) + decimalFormat .substring(decimalFormat .length - 1 )
7979 }
80- return r
80+ return decimalFormat
8181 }
8282
8383}
0 commit comments