@@ -20,6 +20,7 @@ import com.github.mikephil.charting.utils.Utils
20
20
import com.github.mikephil.charting.utils.ViewPortHandler
21
21
import java.util.Collections
22
22
import kotlin.math.min
23
+ import androidx.core.graphics.withSave
23
24
24
25
@Suppress(" MemberVisibilityCanBePrivate" )
25
26
open class LegendRenderer (
@@ -430,57 +431,57 @@ open class LegendRenderer(
430
431
) {
431
432
if (entry.formColor == ColorTemplate .COLOR_SKIP || entry.formColor == ColorTemplate .COLOR_NONE || entry.formColor == 0 ) return
432
433
433
- val restoreCount = c.save()
434
+ c.withSave {
434
435
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
437
438
438
- formPaint.color = entry.formColor
439
+ formPaint.color = entry.formColor
439
440
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
+ }
455
456
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
+ }
460
461
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
465
471
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
+ }
480
482
}
481
- }
482
483
483
- c.restoreToCount(restoreCount)
484
+ }
484
485
}
485
486
486
487
/* *
0 commit comments