Skip to content

Commit 73d467c

Browse files
committed
Kotlin calcTextHeight
1 parent fe33dcf commit 73d467c

File tree

13 files changed

+37
-39
lines changed

13 files changed

+37
-39
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/components/Legend.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public float getMaximumEntryHeight(Paint p) {
222222
String label = entry.label;
223223
if (label == null) continue;
224224

225-
float length = (float) Utils.calcTextHeight(p, label);
225+
float length = (float) CanvasUtilsKt.calcTextHeight(p, label);
226226

227227
if (length > max)
228228
max = length;

MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.graphics.Paint;
55

66
import com.github.mikephil.charting.utils.CanvasUtilsKt;
7-
import com.github.mikephil.charting.utils.Utils;
87
import com.github.mikephil.charting.utils.UtilsKtKt;
98

109
/**
@@ -337,7 +336,7 @@ public float getRequiredHeightSpace(Paint p) {
337336
p.setTextSize(mTextSize);
338337

339338
String label = getLongestLabel(p);
340-
return (float) Utils.calcTextHeight(p, label) + getYOffset() * 2f;
339+
return (float) CanvasUtilsKt.calcTextHeight(p, label) + getYOffset() * 2f;
341340
}
342341

343342
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.github.mikephil.charting.utils.MPPointF
1414
import com.github.mikephil.charting.utils.Transformer
1515
import com.github.mikephil.charting.utils.Utils
1616
import com.github.mikephil.charting.utils.ViewPortHandler
17+
import com.github.mikephil.charting.utils.calcTextHeight
1718
import com.github.mikephil.charting.utils.convertDpToPixel
1819
import kotlin.math.ceil
1920
import kotlin.math.min
@@ -276,7 +277,7 @@ open class BarChartRenderer(
276277

277278
// calculate the correct offset depending on the draw position of
278279
// the value
279-
val valueTextHeight = Utils.calcTextHeight(paintValues, "8").toFloat()
280+
val valueTextHeight = paintValues.calcTextHeight("8").toFloat()
280281
posOffset = (if (drawValueAboveBar) -valueOffsetPlus else valueTextHeight + valueOffsetPlus)
281282
negOffset = (if (drawValueAboveBar) valueTextHeight + valueOffsetPlus else -valueOffsetPlus)
282283

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet
1010
import com.github.mikephil.charting.utils.MPPointF
1111
import com.github.mikephil.charting.utils.Utils
1212
import com.github.mikephil.charting.utils.ViewPortHandler
13+
import com.github.mikephil.charting.utils.calcTextHeight
1314
import com.github.mikephil.charting.utils.convertDpToPixel
1415
import kotlin.math.abs
1516
import kotlin.math.max
@@ -95,7 +96,7 @@ open class BubbleChartRenderer(
9596
if (isDrawingValuesAllowed(dataProvider)) {
9697
val dataSets = bubbleData.dataSets
9798

98-
val lineHeight = Utils.calcTextHeight(paintValues, "1").toFloat()
99+
val lineHeight = paintValues.calcTextHeight("1").toFloat()
99100

100101
for (i in dataSets.indices) {
101102
val dataSet = dataSets[i]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.github.mikephil.charting.utils.MPPointF
1414
import com.github.mikephil.charting.utils.Transformer
1515
import com.github.mikephil.charting.utils.Utils
1616
import com.github.mikephil.charting.utils.ViewPortHandler
17+
import com.github.mikephil.charting.utils.calcTextHeight
1718
import com.github.mikephil.charting.utils.calcTextWidth
1819
import com.github.mikephil.charting.utils.convertDpToPixel
1920
import kotlin.math.ceil
@@ -187,7 +188,7 @@ open class HorizontalBarChartRenderer(
187188

188189
// apply the text-styling defined by the DataSet
189190
applyValueTextStyle(dataSet)
190-
val halfTextHeight = Utils.calcTextHeight(paintValues, "10") / 2f
191+
val halfTextHeight = paintValues.calcTextHeight("10") / 2f
191192

192193
val formatter = dataSet.valueFormatter
193194

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.github.mikephil.charting.interfaces.datasets.IPieDataSet
1919
import com.github.mikephil.charting.utils.ColorTemplate
2020
import com.github.mikephil.charting.utils.Utils
2121
import com.github.mikephil.charting.utils.ViewPortHandler
22+
import com.github.mikephil.charting.utils.calcTextHeight
2223
import com.github.mikephil.charting.utils.calcTextWidth
2324
import com.github.mikephil.charting.utils.convertDpToPixel
2425
import java.util.Collections
@@ -210,7 +211,7 @@ open class LegendRenderer(
210211
val labelLineHeight = Utils.getLineHeight(labelPaint, legendFontMetrics)
211212
val labelLineSpacing = (Utils.getLineSpacing(labelPaint, legendFontMetrics)
212213
+ legend.yEntrySpace.convertDpToPixel())
213-
val formYOffset = labelLineHeight - Utils.calcTextHeight(labelPaint, "ABC") / 2f
214+
val formYOffset = labelLineHeight - labelPaint.calcTextHeight("ABC") / 2f
214215

215216
val entries = legend.entries
216217

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.github.mikephil.charting.utils.ColorTemplate
2222
import com.github.mikephil.charting.utils.MPPointF
2323
import com.github.mikephil.charting.utils.Utils
2424
import com.github.mikephil.charting.utils.ViewPortHandler
25+
import com.github.mikephil.charting.utils.calcTextHeight
2526
import com.github.mikephil.charting.utils.convertDpToPixel
2627
import java.lang.ref.WeakReference
2728
import kotlin.math.abs
@@ -408,8 +409,7 @@ open class PieChartRenderer(
408409
// apply the text-styling defined by the DataSet
409410
applyValueTextStyle(dataSet)
410411

411-
val lineHeight = (Utils.calcTextHeight(paintValues, "Q")
412-
+ 4f.convertDpToPixel())
412+
val lineHeight = paintValues.calcTextHeight("Q") + 4f.convertDpToPixel()
413413

414414
val formatter = dataSet.valueFormatter
415415

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.github.mikephil.charting.utils.MPPointF
1818
import com.github.mikephil.charting.utils.Transformer
1919
import com.github.mikephil.charting.utils.Utils
2020
import com.github.mikephil.charting.utils.ViewPortHandler
21+
import com.github.mikephil.charting.utils.calcTextHeight
2122
import com.github.mikephil.charting.utils.calcTextWidth
2223
import com.github.mikephil.charting.utils.convertDpToPixel
2324
import com.github.mikephil.charting.utils.drawXAxisValue
@@ -75,7 +76,7 @@ open class XAxisRenderer(
7576
val labelSize = Utils.calcTextSize(paintAxisLabels, longest)
7677

7778
val labelWidth = labelSize.width
78-
val labelHeight = Utils.calcTextHeight(paintAxisLabels, "Q").toFloat()
79+
val labelHeight = paintAxisLabels.calcTextHeight("Q").toFloat()
7980

8081
val labelRotatedSize = Utils.getSizeOfRotatedRectangleByDegrees(
8182
labelWidth,
@@ -388,7 +389,7 @@ open class XAxisRenderer(
388389

389390
when (labelPosition) {
390391
LimitLabelPosition.RIGHT_TOP -> {
391-
val labelLineHeight = Utils.calcTextHeight(limitLinePaint, label).toFloat()
392+
val labelLineHeight = limitLinePaint.calcTextHeight(label).toFloat()
392393
limitLinePaint.textAlign = Align.LEFT
393394
canvas.drawText(
394395
label, position[0] + xOffset, viewPortHandler.contentTop() + yOffset + labelLineHeight,
@@ -401,7 +402,7 @@ open class XAxisRenderer(
401402
}
402403
LimitLabelPosition.LEFT_TOP -> {
403404
limitLinePaint.textAlign = Align.RIGHT
404-
val labelLineHeight = Utils.calcTextHeight(limitLinePaint, label).toFloat()
405+
val labelLineHeight = limitLinePaint.calcTextHeight(label).toFloat()
405406
canvas.drawText(
406407
label, position[0] - xOffset, viewPortHandler.contentTop() + yOffset + labelLineHeight,
407408
limitLinePaint

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.github.mikephil.charting.utils.MPPointF
1515
import com.github.mikephil.charting.utils.Transformer
1616
import com.github.mikephil.charting.utils.Utils
1717
import com.github.mikephil.charting.utils.ViewPortHandler
18+
import com.github.mikephil.charting.utils.calcTextHeight
1819
import com.github.mikephil.charting.utils.convertDpToPixel
1920
import kotlin.math.roundToInt
2021

@@ -250,7 +251,7 @@ open class XAxisRendererHorizontalBarChart(
250251
limitLinePaint.strokeWidth = 0.5f
251252
limitLinePaint.textSize = l.textSize
252253

253-
val labelLineHeight = Utils.calcTextHeight(limitLinePaint, label).toFloat()
254+
val labelLineHeight = limitLinePaint.calcTextHeight(label).toFloat()
254255
val xOffset = 4f.convertDpToPixel() + l.xOffset
255256
val yOffset = l.lineWidth + labelLineHeight + l.yOffset
256257

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import com.github.mikephil.charting.components.YAxis
1111
import com.github.mikephil.charting.components.YAxis.AxisDependency
1212
import com.github.mikephil.charting.components.YAxis.YAxisLabelPosition
1313
import com.github.mikephil.charting.utils.Transformer
14-
import com.github.mikephil.charting.utils.Utils
1514
import com.github.mikephil.charting.utils.ViewPortHandler
1615
import androidx.core.graphics.withSave
1716
import androidx.core.graphics.withClip
17+
import com.github.mikephil.charting.utils.calcTextHeight
1818
import com.github.mikephil.charting.utils.convertDpToPixel
1919

2020
open class YAxisRenderer(viewPortHandler: ViewPortHandler, @JvmField protected var yAxis: YAxis, trans: Transformer?) :
@@ -61,7 +61,7 @@ open class YAxisRenderer(viewPortHandler: ViewPortHandler, @JvmField protected v
6161
paintAxisLabels.textSize = yAxis.textSize
6262
paintAxisLabels.color = yAxis.textColor
6363

64-
val yOffset = Utils.calcTextHeight(paintAxisLabels, "A") / 2.5f + yAxis.yOffset
64+
val yOffset = paintAxisLabels.calcTextHeight("A") / 2.5f + yAxis.yOffset
6565

6666
val dependency = yAxis.axisDependency
6767
val labelPosition = yAxis.labelPosition
@@ -314,7 +314,7 @@ open class YAxisRenderer(viewPortHandler: ViewPortHandler, @JvmField protected v
314314
limitLinePaint.strokeWidth = 0.5f
315315
limitLinePaint.textSize = limitLine.textSize
316316

317-
val labelLineHeight = Utils.calcTextHeight(limitLinePaint, label).toFloat()
317+
val labelLineHeight = limitLinePaint.calcTextHeight(label).toFloat()
318318
val xOffset = 4f.convertDpToPixel() + limitLine.xOffset
319319
val yOffset = limitLine.lineWidth + labelLineHeight + limitLine.yOffset
320320

@@ -433,7 +433,7 @@ open class YAxisRenderer(viewPortHandler: ViewPortHandler, @JvmField protected v
433433
limitRangePaint.strokeWidth = 0.5f
434434
limitRangePaint.textSize = limitRange.textSize
435435

436-
val labelLineHeight = Utils.calcTextHeight(limitRangePaint, label).toFloat()
436+
val labelLineHeight = limitRangePaint.calcTextHeight(label).toFloat()
437437
val xOffset = 4f.convertDpToPixel() + limitRange.xOffset
438438
val yOffset = limitRange.lineWidth + labelLineHeight + limitRange.yOffset
439439

0 commit comments

Comments
 (0)