@@ -20,6 +20,7 @@ import com.github.mikephil.charting.utils.Utils
2020import com.github.mikephil.charting.utils.ViewPortHandler
2121import java.util.Collections
2222import kotlin.math.min
23+ import androidx.core.graphics.withSave
2324
2425@Suppress(" MemberVisibilityCanBePrivate" )
2526open 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 /* *
0 commit comments