From 864d083d167c39763a25599788d25719ae48298a Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sat, 27 Dec 2025 10:00:50 +0100 Subject: [PATCH] Use other Canvas function --- .../charting/renderer/BarChartRenderer.kt | 11 +++----- .../charting/renderer/BubbleChartRenderer.kt | 5 ++-- .../renderer/CandleStickChartRenderer.kt | 5 ++-- .../renderer/HorizontalBarChartRenderer.kt | 11 +++----- .../charting/renderer/LineChartRenderer.kt | 5 ++-- .../charting/renderer/PieChartRenderer.kt | 5 ++-- .../charting/renderer/RadarChartRenderer.kt | 5 ++-- .../charting/renderer/ScatterChartRenderer.kt | 5 ++-- .../info/appdev/charting/utils/Utils.kt | 26 ------------------- 9 files changed, 21 insertions(+), 57 deletions(-) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarChartRenderer.kt index 34aca9426..91b44ab76 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BarChartRenderer.kt @@ -12,10 +12,10 @@ import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.utils.Fill import info.appdev.charting.utils.PointF import info.appdev.charting.utils.Transformer -import info.appdev.charting.utils.Utils import info.appdev.charting.utils.ViewPortHandler import info.appdev.charting.utils.calcTextHeight import info.appdev.charting.utils.convertDpToPixel +import info.appdev.charting.utils.drawImage import kotlin.math.ceil import kotlin.math.min @@ -332,8 +332,7 @@ open class BarChartRenderer( py += iconsOffset.y icon?.let { - Utils.drawImage( - canvas, + canvas.drawImage( it, px.toInt(), py.toInt() @@ -392,8 +391,7 @@ open class BarChartRenderer( py += iconsOffset.y icon?.let { - Utils.drawImage( - canvas, + canvas.drawImage( it, px.toInt(), py.toInt() @@ -471,8 +469,7 @@ open class BarChartRenderer( val icon = barEntry.icon icon?.let { - Utils.drawImage( - canvas, + canvas.drawImage( it, (x + iconsOffset.x).toInt(), (y + iconsOffset.y).toInt() diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BubbleChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BubbleChartRenderer.kt index 998781e63..79b12e2d4 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/BubbleChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/BubbleChartRenderer.kt @@ -8,10 +8,10 @@ import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.dataprovider.BubbleDataProvider import info.appdev.charting.interfaces.datasets.IBubbleDataSet import info.appdev.charting.utils.PointF -import info.appdev.charting.utils.Utils import info.appdev.charting.utils.ViewPortHandler import info.appdev.charting.utils.calcTextHeight import info.appdev.charting.utils.convertDpToPixel +import info.appdev.charting.utils.drawImage import kotlin.math.abs import kotlin.math.max import kotlin.math.min @@ -161,8 +161,7 @@ open class BubbleChartRenderer( val icon = bubbleEntry.icon icon?.let { ico -> - Utils.drawImage( - canvas, + canvas.drawImage( ico, (x + iconsOffset.x).toInt(), (y + iconsOffset.y).toInt() diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/CandleStickChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/CandleStickChartRenderer.kt index 260711d73..1fd1cc3d1 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/CandleStickChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/CandleStickChartRenderer.kt @@ -8,9 +8,9 @@ import info.appdev.charting.interfaces.dataprovider.CandleDataProvider import info.appdev.charting.interfaces.datasets.ICandleDataSet import info.appdev.charting.utils.ColorTemplate import info.appdev.charting.utils.PointF -import info.appdev.charting.utils.Utils import info.appdev.charting.utils.ViewPortHandler import info.appdev.charting.utils.convertDpToPixel +import info.appdev.charting.utils.drawImage open class CandleStickChartRenderer( var dataProvider: CandleDataProvider, animator: ChartAnimator, @@ -268,8 +268,7 @@ open class CandleStickChartRenderer( val icon = entry.icon icon?.let { ico -> - Utils.drawImage( - canvas, + canvas.drawImage( ico, (x + iconsOffset.x).toInt(), (y + iconsOffset.y).toInt() diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/HorizontalBarChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/HorizontalBarChartRenderer.kt index 61d05628c..f9cb3ac7d 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/HorizontalBarChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/HorizontalBarChartRenderer.kt @@ -12,11 +12,11 @@ import info.appdev.charting.interfaces.datasets.IBarDataSet import info.appdev.charting.utils.Fill import info.appdev.charting.utils.PointF import info.appdev.charting.utils.Transformer -import info.appdev.charting.utils.Utils import info.appdev.charting.utils.ViewPortHandler import info.appdev.charting.utils.calcTextHeight import info.appdev.charting.utils.calcTextWidth import info.appdev.charting.utils.convertDpToPixel +import info.appdev.charting.utils.drawImage import kotlin.math.ceil import kotlin.math.min @@ -256,8 +256,7 @@ open class HorizontalBarChartRenderer( py += iconsOffset.y icon?.let { - Utils.drawImage( - canvas, + canvas.drawImage( it, px.toInt(), py.toInt() @@ -332,8 +331,7 @@ open class HorizontalBarChartRenderer( py += iconsOffset.y icon?.let { myIcon -> - Utils.drawImage( - canvas, + canvas.drawImage( myIcon, px.toInt(), py.toInt() @@ -417,8 +415,7 @@ open class HorizontalBarChartRenderer( val icon = it.icon icon?.let { myIcon -> - Utils.drawImage( - canvas, + canvas.drawImage( myIcon, (x + iconsOffset.x).toInt(), (y + iconsOffset.y).toInt() diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt index 77f2ab3bc..8816ff62b 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/LineChartRenderer.kt @@ -16,9 +16,9 @@ import info.appdev.charting.interfaces.datasets.ILineDataSet import info.appdev.charting.utils.ColorTemplate import info.appdev.charting.utils.PointF import info.appdev.charting.utils.Transformer -import info.appdev.charting.utils.Utils import info.appdev.charting.utils.ViewPortHandler import info.appdev.charting.utils.convertDpToPixel +import info.appdev.charting.utils.drawImage import java.lang.ref.WeakReference import kotlin.math.max import kotlin.math.min @@ -542,8 +542,7 @@ open class LineChartRenderer( val icon = entry.icon icon?.let { - Utils.drawImage( - canvas, + canvas.drawImage( it, (x + iconsOffset.x).toInt(), (y + iconsOffset.y).toInt() diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt index 2801f8d77..59403e3d4 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt @@ -23,6 +23,7 @@ import info.appdev.charting.utils.Utils import info.appdev.charting.utils.ViewPortHandler import info.appdev.charting.utils.calcTextHeight import info.appdev.charting.utils.convertDpToPixel +import info.appdev.charting.utils.drawImage import java.lang.ref.WeakReference import kotlin.math.abs import kotlin.math.ceil @@ -571,8 +572,8 @@ open class PieChartRenderer( y += iconsOffset.x icon?.let { - Utils.drawImage( - this, it, x.toInt(), y.toInt() + this.drawImage( + it, x.toInt(), y.toInt() ) } } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/RadarChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/RadarChartRenderer.kt index c16ee4162..ba56f2509 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/RadarChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/RadarChartRenderer.kt @@ -11,10 +11,10 @@ import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.datasets.IRadarDataSet import info.appdev.charting.utils.ColorTemplate import info.appdev.charting.utils.PointF -import info.appdev.charting.utils.Utils import info.appdev.charting.utils.ViewPortHandler import info.appdev.charting.utils.convertDpToPixel import info.appdev.charting.utils.getPosition +import info.appdev.charting.utils.drawImage open class RadarChartRenderer( protected var chart: RadarChart, animator: ChartAnimator, @@ -179,8 +179,7 @@ open class RadarChartRenderer( pIcon.y += iconsOffset.x icon?.let { - Utils.drawImage( - canvas, + canvas.drawImage( it, pIcon.x.toInt(), pIcon.y.toInt() diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/ScatterChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/ScatterChartRenderer.kt index dae52fddc..4a9c2d944 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/ScatterChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/ScatterChartRenderer.kt @@ -6,9 +6,9 @@ import info.appdev.charting.highlight.Highlight import info.appdev.charting.interfaces.dataprovider.ScatterDataProvider import info.appdev.charting.interfaces.datasets.IScatterDataSet import info.appdev.charting.utils.PointF -import info.appdev.charting.utils.Utils import info.appdev.charting.utils.ViewPortHandler import info.appdev.charting.utils.convertDpToPixel +import info.appdev.charting.utils.drawImage import timber.log.Timber import kotlin.math.ceil import kotlin.math.min @@ -136,8 +136,7 @@ open class ScatterChartRenderer(var dataProvider: ScatterDataProvider, animator: val icon = entry.icon icon?.let { - Utils.drawImage( - canvas, + canvas.drawImage( it, (positions[j] + iconsOffset.x).toInt(), (positions[j + 1] + iconsOffset.y).toInt() diff --git a/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt b/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt index 3606c3b87..89b40ea96 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/utils/Utils.kt @@ -1,15 +1,12 @@ package info.appdev.charting.utils import android.content.Context -import android.graphics.Canvas import android.graphics.Rect -import android.graphics.drawable.Drawable import android.view.MotionEvent import android.view.VelocityTracker import android.view.ViewConfiguration import info.appdev.charting.formatter.DefaultValueFormatter import info.appdev.charting.formatter.IValueFormatter -import info.appdev.charting.utils.PointF.Companion.instance import kotlin.Int import kotlin.IntArray import kotlin.Suppress @@ -88,29 +85,6 @@ object Utils { private val mDrawableBoundsCache = Rect() - fun drawImage(canvas: Canvas, drawable: Drawable, x: Int, y: Int) { - val width = drawable.intrinsicWidth - val height = drawable.intrinsicHeight - - val drawOffset = instance - drawOffset.x = x - (width / 2).toFloat() - drawOffset.y = y - (height / 2).toFloat() - - drawable.copyBounds(mDrawableBoundsCache) - drawable.setBounds( - mDrawableBoundsCache.left, - mDrawableBoundsCache.top, - mDrawableBoundsCache.left + width, - mDrawableBoundsCache.top + width - ) - - val saveId = canvas.save() - // translate to the correct position and draw - canvas.translate(drawOffset.x, drawOffset.y) - drawable.draw(canvas) - canvas.restoreToCount(saveId) - } - /** * Returns a recyclable FSize instance. * Represents size of a rotated rectangle by degrees.