Skip to content

Commit 644a145

Browse files
authored
Merge pull request #356 from AppDevNext/CodeSuggestion
Apply code suggestion with an extension
2 parents 007f0c4 + e709382 commit 644a145

10 files changed

+892
-888
lines changed

MPChartLib/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ android {
4848
dependencies {
4949
implementation 'androidx.annotation:annotation:1.9.1'
5050
implementation 'androidx.core:core:1.16.0'
51+
implementation "androidx.activity:activity-ktx:1.10.1"
5152
testImplementation 'junit:junit:4.13.2'
5253
}
5354

@@ -90,7 +91,7 @@ mavenPublishing {
9091
// Github packages
9192
repositories {
9293
maven {
93-
version = version+"-SNAPSHOT"
94+
version = version + "-SNAPSHOT"
9495
name = "GitHubPackages"
9596
url = "https://maven.pkg.github.com/AppDevNext/AndroidChart"
9697
credentials {

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

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.github.mikephil.charting.utils.Utils
2020
import com.github.mikephil.charting.utils.ViewPortHandler
2121
import java.util.Collections
2222
import kotlin.math.min
23+
import androidx.core.graphics.withSave
2324

2425
@Suppress("MemberVisibilityCanBePrivate")
2526
open class LegendRenderer(
@@ -430,57 +431,57 @@ open class LegendRenderer(
430431
) {
431432
if (entry.formColor == ColorTemplate.COLOR_SKIP || entry.formColor == ColorTemplate.COLOR_NONE || entry.formColor == 0) return
432433

433-
val restoreCount = c.save()
434+
c.withSave {
434435

435-
var form = entry.form
436-
if (form == LegendForm.DEFAULT) form = legend.form
436+
var form = entry.form
437+
if (form == LegendForm.DEFAULT) form = legend.form
437438

438-
formPaint.color = entry.formColor
439+
formPaint.color = entry.formColor
439440

440-
val formSize = Utils.convertDpToPixel(
441-
if (java.lang.Float.isNaN(entry.formSize))
442-
legend.formSize
443-
else
444-
entry.formSize
445-
)
446-
val half = formSize / 2f
447-
448-
when (form) {
449-
LegendForm.NONE -> {}
450-
LegendForm.EMPTY -> {}
451-
LegendForm.DEFAULT, LegendForm.CIRCLE -> {
452-
formPaint.style = Paint.Style.FILL
453-
c.drawCircle(x + half, y, half, formPaint)
454-
}
441+
val formSize = Utils.convertDpToPixel(
442+
if (java.lang.Float.isNaN(entry.formSize))
443+
legend.formSize
444+
else
445+
entry.formSize
446+
)
447+
val half = formSize / 2f
448+
449+
when (form) {
450+
LegendForm.NONE -> {}
451+
LegendForm.EMPTY -> {}
452+
LegendForm.DEFAULT, LegendForm.CIRCLE -> {
453+
formPaint.style = Paint.Style.FILL
454+
c.drawCircle(x + half, y, half, formPaint)
455+
}
455456

456-
LegendForm.SQUARE -> {
457-
formPaint.style = Paint.Style.FILL
458-
c.drawRect(x, y - half, x + formSize, y + half, formPaint)
459-
}
457+
LegendForm.SQUARE -> {
458+
formPaint.style = Paint.Style.FILL
459+
c.drawRect(x, y - half, x + formSize, y + half, formPaint)
460+
}
460461

461-
LegendForm.LINE -> {
462-
val formLineWidth = Utils.convertDpToPixel(
463-
if (java.lang.Float.isNaN(entry.formLineWidth))
464-
legend.formLineWidth
462+
LegendForm.LINE -> {
463+
val formLineWidth = Utils.convertDpToPixel(
464+
if (java.lang.Float.isNaN(entry.formLineWidth))
465+
legend.formLineWidth
466+
else
467+
entry.formLineWidth
468+
)
469+
val formLineDashEffect = if (entry.formLineDashEffect == null)
470+
legend.formLineDashEffect
465471
else
466-
entry.formLineWidth
467-
)
468-
val formLineDashEffect = if (entry.formLineDashEffect == null)
469-
legend.formLineDashEffect
470-
else
471-
entry.formLineDashEffect
472-
formPaint.style = Paint.Style.STROKE
473-
formPaint.strokeWidth = formLineWidth
474-
formPaint.setPathEffect(formLineDashEffect)
475-
476-
mLineFormPath.reset()
477-
mLineFormPath.moveTo(x, y)
478-
mLineFormPath.lineTo(x + formSize, y)
479-
c.drawPath(mLineFormPath, formPaint)
472+
entry.formLineDashEffect
473+
formPaint.style = Paint.Style.STROKE
474+
formPaint.strokeWidth = formLineWidth
475+
formPaint.setPathEffect(formLineDashEffect)
476+
477+
mLineFormPath.reset()
478+
mLineFormPath.moveTo(x, y)
479+
mLineFormPath.lineTo(x + formSize, y)
480+
c.drawPath(mLineFormPath, formPaint)
481+
}
480482
}
481-
}
482483

483-
c.restoreToCount(restoreCount)
484+
}
484485
}
485486

486487
/**

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.graphics.drawable.Drawable
77
import com.github.mikephil.charting.animation.ChartAnimator
88
import com.github.mikephil.charting.utils.Utils
99
import com.github.mikephil.charting.utils.ViewPortHandler
10+
import androidx.core.graphics.withClip
1011

1112
abstract class LineRadarRenderer(animator: ChartAnimator?, viewPortHandler: ViewPortHandler?) :
1213
LineScatterCandleRadarRenderer(animator, viewPortHandler) {
@@ -19,18 +20,15 @@ abstract class LineRadarRenderer(animator: ChartAnimator?, viewPortHandler: View
1920
*/
2021
protected fun drawFilledPath(c: Canvas, filledPath: Path, drawable: Drawable) {
2122
if (clipPathSupported()) {
22-
val save = c.save()
23-
c.clipPath(filledPath)
24-
25-
drawable.setBounds(
26-
viewPortHandler.contentLeft().toInt(),
27-
viewPortHandler.contentTop().toInt(),
28-
viewPortHandler.contentRight().toInt(),
29-
viewPortHandler.contentBottom().toInt()
30-
)
31-
drawable.draw(c)
32-
33-
c.restoreToCount(save)
23+
c.withClip(filledPath) {
24+
drawable.setBounds(
25+
viewPortHandler.contentLeft().toInt(),
26+
viewPortHandler.contentTop().toInt(),
27+
viewPortHandler.contentRight().toInt(),
28+
viewPortHandler.contentBottom().toInt()
29+
)
30+
drawable.draw(c)
31+
}
3432
} else {
3533
throw RuntimeException(
3634
"Fill-drawables not (yet) supported below API level 18, " +
@@ -52,12 +50,9 @@ abstract class LineRadarRenderer(animator: ChartAnimator?, viewPortHandler: View
5250
val color = (fillAlpha shl 24) or (fillColor and 0xffffff)
5351

5452
if (clipPathSupported()) {
55-
val save = c.save()
56-
57-
c.clipPath(filledPath)
58-
59-
c.drawColor(color)
60-
c.restoreToCount(save)
53+
c.withClip(filledPath) {
54+
c.drawColor(color)
55+
}
6156
} else {
6257
// save
6358

0 commit comments

Comments
 (0)