Skip to content

Commit 68f5dde

Browse files
committed
Kotlin Utils
1 parent 96dc4e5 commit 68f5dde

20 files changed

+941
-966
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ abstract class BaseDataSet<T : Entry?>() : IDataSet<T> {
249249
}
250250

251251
override fun getValueFormatter(): IValueFormatter {
252-
if (needsFormatter()) return Utils.getDefaultValueFormatter()
252+
if (needsFormatter()) return Utils.defaultValueFormatter
253253
return mValueFormatter!!
254254
}
255255

MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ class BarLineChartTouchListener(
207207
MotionEvent.ACTION_UP -> {
208208
val velocityTracker = mVelocityTracker
209209
val pointerId = event.getPointerId(0)
210-
velocityTracker!!.computeCurrentVelocity(1000, Utils.getMaximumFlingVelocity().toFloat())
210+
velocityTracker!!.computeCurrentVelocity(1000, Utils.maximumFlingVelocity.toFloat())
211211
val velocityY = velocityTracker.getYVelocity(pointerId)
212212
val velocityX = velocityTracker.getXVelocity(pointerId)
213213

214-
if (abs(velocityX.toDouble()) > Utils.getMinimumFlingVelocity() ||
215-
abs(velocityY.toDouble()) > Utils.getMinimumFlingVelocity()
214+
if (abs(velocityX.toDouble()) > Utils.minimumFlingVelocity ||
215+
abs(velocityY.toDouble()) > Utils.minimumFlingVelocity
216216
) {
217217
if (mTouchMode == DRAG && mChart!!.isDragDecelerationEnabled) {
218218
stopDeceleration()
@@ -225,8 +225,8 @@ class BarLineChartTouchListener(
225225
mDecelerationVelocity.x = velocityX
226226
mDecelerationVelocity.y = velocityY
227227

228-
Utils.postInvalidateOnAnimation(mChart) // This causes computeScroll to fire, recommended for this by
229-
// Google
228+
// This causes computeScroll to fire, recommended for this by Google
229+
Utils.postInvalidateOnAnimation(mChart!!)
230230
}
231231
}
232232

@@ -249,7 +249,7 @@ class BarLineChartTouchListener(
249249
}
250250

251251
MotionEvent.ACTION_POINTER_UP -> {
252-
Utils.velocityTrackerPointerUpCleanUpIfNecessary(event, mVelocityTracker)
252+
mVelocityTracker?.let { Utils.velocityTrackerPointerUpCleanUpIfNecessary(event, it) }
253253

254254
mTouchMode = POST_ZOOM
255255
}
@@ -469,10 +469,9 @@ class BarLineChartTouchListener(
469469
val vph = mChart!!.viewPortHandler
470470

471471
val xTrans = x - vph.offsetLeft()
472-
var yTrans = 0f
473472

474473
// check if axis is inverted
475-
yTrans = if (inverted()) {
474+
val yTrans: Float = if (inverted()) {
476475
-(y - vph.offsetTop())
477476
} else {
478477
-(mChart!!.measuredHeight - y - vph.offsetBottom())

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.kt

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,8 @@ open class BarChartRenderer(
242242
protected open fun prepareBarHighlight(x: Float, y1: Float, y2: Float, barWidthHalf: Float, trans: Transformer) {
243243
val left = x - barWidthHalf
244244
val right = x + barWidthHalf
245-
val top = y1
246-
val bottom = y2
247245

248-
barRect[left, top, right] = bottom
246+
barRect[left, y1, right] = y2
249247

250248
trans.rectToPixelPhase(barRect, animator.phaseY)
251249
}
@@ -332,14 +330,14 @@ open class BarChartRenderer(
332330
px += iconsOffset.x
333331
py += iconsOffset.y
334332

335-
Utils.drawImage(
336-
c,
337-
icon,
338-
px.toInt(),
339-
py.toInt(),
340-
icon!!.intrinsicWidth,
341-
icon.intrinsicHeight
342-
)
333+
icon?.let {
334+
Utils.drawImage(
335+
c,
336+
it,
337+
px.toInt(),
338+
py.toInt()
339+
)
340+
}
343341
}
344342
j += 4
345343
}
@@ -392,14 +390,14 @@ open class BarChartRenderer(
392390
px += iconsOffset.x
393391
py += iconsOffset.y
394392

395-
Utils.drawImage(
396-
c,
397-
icon,
398-
px.toInt(),
399-
py.toInt(),
400-
icon!!.intrinsicWidth,
401-
icon.intrinsicHeight
402-
)
393+
icon?.let {
394+
Utils.drawImage(
395+
c,
396+
it,
397+
px.toInt(),
398+
py.toInt()
399+
)
400+
}
403401
}
404402

405403
// draw stack values
@@ -471,14 +469,14 @@ open class BarChartRenderer(
471469
if (entry.icon != null && dataSet.isDrawIconsEnabled) {
472470
val icon = entry.icon
473471

474-
Utils.drawImage(
475-
c,
476-
icon,
477-
(x + iconsOffset.x).toInt(),
478-
(y + iconsOffset.y).toInt(),
479-
icon!!.intrinsicWidth,
480-
icon.intrinsicHeight
481-
)
472+
icon?.let {
473+
Utils.drawImage(
474+
c,
475+
it,
476+
(x + iconsOffset.x).toInt(),
477+
(y + iconsOffset.y).toInt()
478+
)
479+
}
482480
}
483481
k += 2
484482
}

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.github.mikephil.charting.utils.ViewPortHandler
1313
import kotlin.math.abs
1414
import kotlin.math.max
1515
import kotlin.math.min
16+
import kotlin.math.roundToInt
1617
import kotlin.math.sqrt
1718

1819
@Suppress("MemberVisibilityCanBePrivate")
@@ -128,7 +129,7 @@ open class BubbleChartRenderer(
128129
while (j < positions.size) {
129130
var valueTextColor = dataSet.getValueTextColor(j / 2 + xBounds.min)
130131
valueTextColor = Color.argb(
131-
Math.round(255f * alpha), Color.red(valueTextColor),
132+
(255f * alpha).roundToInt(), Color.red(valueTextColor),
132133
Color.green(valueTextColor), Color.blue(valueTextColor)
133134
)
134135

@@ -154,14 +155,14 @@ open class BubbleChartRenderer(
154155
if (entry.icon != null && dataSet.isDrawIconsEnabled) {
155156
val icon = entry.icon
156157

157-
Utils.drawImage(
158-
c,
159-
icon,
160-
(x + iconsOffset.x).toInt(),
161-
(y + iconsOffset.y).toInt(),
162-
icon!!.intrinsicWidth,
163-
icon.intrinsicHeight
164-
)
158+
icon?.let {
159+
Utils.drawImage(
160+
c,
161+
it,
162+
(x + iconsOffset.x).toInt(),
163+
(y + iconsOffset.y).toInt()
164+
)
165+
}
165166
}
166167
j += 2
167168
}

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ open class CandleStickChartRenderer(
265265
if (entry.icon != null && dataSet.isDrawIconsEnabled) {
266266
val icon = entry.icon
267267

268-
Utils.drawImage(
269-
c,
270-
icon,
271-
(x + iconsOffset.x).toInt(),
272-
(y + iconsOffset.y).toInt(),
273-
icon!!.intrinsicWidth,
274-
icon.intrinsicHeight
275-
)
268+
icon?.let {
269+
Utils.drawImage(
270+
c,
271+
it,
272+
(x + iconsOffset.x).toInt(),
273+
(y + iconsOffset.y).toInt()
274+
)
275+
}
276276
}
277277
j += 2
278278
}

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.kt

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@ open class HorizontalBarChartRenderer(
252252
px += iconsOffset.x
253253
py += iconsOffset.y
254254

255-
Utils.drawImage(
256-
c,
257-
icon,
258-
px.toInt(),
259-
py.toInt(),
260-
icon!!.intrinsicWidth,
261-
icon.intrinsicHeight
262-
)
255+
icon?.let {
256+
Utils.drawImage(
257+
c,
258+
it,
259+
px.toInt(),
260+
py.toInt()
261+
)
262+
}
263263
}
264264
j += 4
265265
}
@@ -328,14 +328,14 @@ open class HorizontalBarChartRenderer(
328328
px += iconsOffset.x
329329
py += iconsOffset.y
330330

331-
Utils.drawImage(
332-
c,
333-
icon,
334-
px.toInt(),
335-
py.toInt(),
336-
icon!!.intrinsicWidth,
337-
icon.intrinsicHeight
338-
)
331+
icon?.let {
332+
Utils.drawImage(
333+
c,
334+
it,
335+
px.toInt(),
336+
py.toInt()
337+
)
338+
}
339339
}
340340
} else {
341341
val transformed = FloatArray(vals.size * 2)
@@ -416,14 +416,14 @@ open class HorizontalBarChartRenderer(
416416
if (entry.icon != null && dataSet.isDrawIconsEnabled) {
417417
val icon = entry.icon
418418

419-
Utils.drawImage(
420-
c,
421-
icon,
422-
(x + iconsOffset.x).toInt(),
423-
(y + iconsOffset.y).toInt(),
424-
icon!!.intrinsicWidth,
425-
icon.intrinsicHeight
426-
)
419+
icon?.let {
420+
Utils.drawImage(
421+
c,
422+
it,
423+
(x + iconsOffset.x).toInt(),
424+
(y + iconsOffset.y).toInt()
425+
)
426+
}
427427
}
428428
k += 2
429429
}
@@ -447,10 +447,8 @@ open class HorizontalBarChartRenderer(
447447
override fun prepareBarHighlight(x: Float, y1: Float, y2: Float, barWidthHalf: Float, trans: Transformer) {
448448
val top = x - barWidthHalf
449449
val bottom = x + barWidthHalf
450-
val left = y1
451-
val right = y2
452450

453-
barRect[left, top, right] = bottom
451+
barRect[y1, top, y2] = bottom
454452

455453
trans.rectToPixelPhaseHorizontal(barRect, animator.phaseY)
456454
}

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.kt

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ class LineChartRenderer(
288288
if (j < xBounds.max) {
289289
entry = dataSet.getEntryForIndex(j + 1)
290290

291-
if (entry == null) break
292-
293291
if (isDrawSteppedEnabled) {
294292
lineBuffer[2] = entry.x
295293
lineBuffer[3] = lineBuffer[1]
@@ -545,14 +543,14 @@ class LineChartRenderer(
545543
if (entry.icon != null && dataSet.isDrawIconsEnabled) {
546544
val icon = entry.icon
547545

548-
Utils.drawImage(
549-
c,
550-
icon,
551-
(x + iconsOffset.x).toInt(),
552-
(y + iconsOffset.y).toInt(),
553-
icon!!.intrinsicWidth,
554-
icon.intrinsicHeight
555-
)
546+
icon?.let {
547+
Utils.drawImage(
548+
c,
549+
it,
550+
(x + iconsOffset.x).toInt(),
551+
(y + iconsOffset.y).toInt()
552+
)
553+
}
556554
}
557555
}
558556
j += 2
@@ -674,25 +672,6 @@ class LineChartRenderer(
674672
}
675673
}
676674

677-
var bitmapConfig: Bitmap.Config
678-
/**
679-
* Returns the Bitmap.Config that is used by this renderer.
680-
*
681-
* @return
682-
*/
683-
get() = mBitmapConfig
684-
/**
685-
* Sets the Bitmap.Config to be used by this renderer.
686-
* Default: Bitmap.Config.ARGB_8888
687-
* Use Bitmap.Config.ARGB_4444 to consume less memory.
688-
*
689-
* @param config
690-
*/
691-
set(config) {
692-
mBitmapConfig = config
693-
releaseBitmap()
694-
}
695-
696675
/**
697676
* Releases the drawing bitmap. This should be called when [LineChart.onDetachedFromWindow].
698677
*/

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineRadarRenderer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class LineRadarRenderer(animator: ChartAnimator?, viewPortHandler: View
3232
} else {
3333
throw RuntimeException(
3434
"Fill-drawables not (yet) supported below API level 18, " +
35-
"this code was run on API level " + Utils.getSDKInt() + "."
35+
"this code was run on API level " + Utils.buildSDK + "."
3636
)
3737
}
3838
}
@@ -77,6 +77,6 @@ abstract class LineRadarRenderer(animator: ChartAnimator?, viewPortHandler: View
7777
* @return
7878
*/
7979
private fun clipPathSupported(): Boolean {
80-
return Utils.getSDKInt() >= 18
80+
return Utils.buildSDK >= 18
8181
}
8282
}

0 commit comments

Comments
 (0)