Skip to content

Commit 333ca58

Browse files
committed
Kotlin calcTextHeight
1 parent 7649e53 commit 333ca58

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
/**
@@ -334,7 +333,7 @@ public float getRequiredHeightSpace(Paint p) {
334333
p.setTextSize(mTextSize);
335334

336335
String label = getLongestLabel(p);
337-
return (float) Utils.calcTextHeight(p, label) + getYOffset() * 2f;
336+
return (float) CanvasUtilsKt.calcTextHeight(p, label) + getYOffset() * 2f;
338337
}
339338

340339
/**

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
@@ -277,7 +278,7 @@ open class BarChartRenderer(
277278

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

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
@@ -96,7 +97,7 @@ open class BubbleChartRenderer(
9697
if (isDrawingValuesAllowed(dataProvider)) {
9798
val dataSets = bubbleData.dataSets
9899

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

101102
for (i in dataSets.indices) {
102103
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
@@ -188,7 +189,7 @@ open class HorizontalBarChartRenderer(
188189

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

193194
val formatter = dataSet.valueFormatter
194195

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
@@ -211,7 +212,7 @@ open class LegendRenderer(
211212
val labelLineHeight = Utils.getLineHeight(labelPaint, legendFontMetrics)
212213
val labelLineSpacing = (Utils.getLineSpacing(labelPaint, legendFontMetrics)
213214
+ legend.yEntrySpace.convertDpToPixel())
214-
val formYOffset = labelLineHeight - Utils.calcTextHeight(labelPaint, "ABC") / 2f
215+
val formYOffset = labelLineHeight - labelPaint.calcTextHeight("ABC") / 2f
215216

216217
val entries = legend.entries
217218

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
@@ -21,6 +21,7 @@ import com.github.mikephil.charting.utils.ColorTemplate
2121
import com.github.mikephil.charting.utils.MPPointF
2222
import com.github.mikephil.charting.utils.Utils
2323
import com.github.mikephil.charting.utils.ViewPortHandler
24+
import com.github.mikephil.charting.utils.calcTextHeight
2425
import com.github.mikephil.charting.utils.convertDpToPixel
2526
import java.lang.ref.WeakReference
2627
import kotlin.math.abs
@@ -406,8 +407,7 @@ open class PieChartRenderer(
406407
// apply the text-styling defined by the DataSet
407408
applyValueTextStyle(dataSet)
408409

409-
val lineHeight = (Utils.calcTextHeight(paintValues, "Q")
410-
+ 4f.convertDpToPixel())
410+
val lineHeight = paintValues.calcTextHeight("Q") + 4f.convertDpToPixel()
411411

412412
val formatter = dataSet.valueFormatter
413413

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 = limitLine.textSize
252253

253-
val labelLineHeight = Utils.calcTextHeight(limitLinePaint, label).toFloat()
254+
val labelLineHeight = limitLinePaint.calcTextHeight(label).toFloat()
254255
val xOffset = 4f.convertDpToPixel() + limitLine.xOffset
255256
val yOffset = limitLine.lineWidth + labelLineHeight + limitLine.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)