Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.mikephil.charting.utils.ColorTemplate
import com.github.mikephil.charting.utils.FSize
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
import com.github.mikephil.charting.utils.calcTextHeight
import com.github.mikephil.charting.utils.convertDpToPixel
import java.lang.Float
import kotlin.Array
Expand Down Expand Up @@ -224,7 +225,7 @@ class Legend() : ComponentBase() {
val label = entry.label
if (label == null) continue

val length = Utils.calcTextHeight(p, label).toFloat()
val length = p.calcTextHeight(label).toFloat()

if (length > max) max = length
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.mikephil.charting.components
import android.graphics.Color
import android.graphics.Paint
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.calcTextHeight
import com.github.mikephil.charting.utils.convertDpToPixel
import kotlin.math.abs
import kotlin.math.max
Expand Down Expand Up @@ -169,7 +170,7 @@ class YAxis : AxisBase {
* use Inifinity for disabling the maximum
* default: Float.POSITIVE_INFINITY (no maximum specified)
*/
var maxWidth: Float = Float.Companion.POSITIVE_INFINITY
var maxWidth: Float = Float.POSITIVE_INFINITY

/**
* Enum that specifies the axis a DataSet should be plotted against, either LEFT or RIGHT.
Expand Down Expand Up @@ -236,7 +237,7 @@ class YAxis : AxisBase {
* This is for normal (not horizontal) charts horizontal spacing.
*/
fun getRequiredWidthSpace(p: Paint): Float {
p.setTextSize(mTextSize)
p.textSize = mTextSize

val label = getLongestLabel(p)
var width = Utils.calcTextWidth(p, label).toFloat() + xOffset * 2f
Expand All @@ -246,7 +247,7 @@ class YAxis : AxisBase {

if (minWidth > 0f) minWidth = minWidth.convertDpToPixel()

if (maxWidth > 0f && maxWidth != Float.Companion.POSITIVE_INFINITY) maxWidth = maxWidth.convertDpToPixel()
if (maxWidth > 0f && maxWidth != Float.POSITIVE_INFINITY) maxWidth = maxWidth.convertDpToPixel()

width = max(minWidth, min(width, if (maxWidth > 0.0) maxWidth else width))

Expand All @@ -257,24 +258,20 @@ class YAxis : AxisBase {
* This is for HorizontalBarChart vertical spacing.
*/
fun getRequiredHeightSpace(p: Paint): Float {
p.setTextSize(mTextSize)
p.textSize = mTextSize

val label = getLongestLabel(p)
return Utils.calcTextHeight(p, label).toFloat() + yOffset * 2f
return p.calcTextHeight(label).toFloat() + yOffset * 2f
}

/**
* Returns true if this axis needs horizontal offset, false if no offset is needed.
*/
fun needsOffset(): Boolean {
return if (isEnabled && isDrawLabelsEnabled && this.labelPosition == YAxisLabelPosition.OUTSIDE_CHART)
true
else
false
return isEnabled && isDrawLabelsEnabled && this.labelPosition == YAxisLabelPosition.OUTSIDE_CHART
}


public override fun calculate(dataMin: Float, dataMax: Float) {
override fun calculate(dataMin: Float, dataMax: Float) {
var min = dataMin
var max = dataMax

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.Transformer
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
import com.github.mikephil.charting.utils.calcTextHeight
import com.github.mikephil.charting.utils.convertDpToPixel
import kotlin.math.ceil
import kotlin.math.min
Expand Down Expand Up @@ -278,7 +279,7 @@ open class BarChartRenderer(

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet
import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
import com.github.mikephil.charting.utils.calcTextHeight
import com.github.mikephil.charting.utils.convertDpToPixel
import kotlin.math.abs
import kotlin.math.max
Expand Down Expand Up @@ -98,7 +99,7 @@ open class BubbleChartRenderer(
if (isDrawingValuesAllowed(dataProvider)) {
val dataSets = bubbleData.dataSets

val lineHeight = Utils.calcTextHeight(paintValues, "1").toFloat()
val lineHeight = paintValues.calcTextHeight("1").toFloat()

dataSets?.let {
for (i in it.indices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.Transformer
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
import com.github.mikephil.charting.utils.calcTextHeight
import com.github.mikephil.charting.utils.convertDpToPixel
import kotlin.math.ceil
import kotlin.math.min
Expand Down Expand Up @@ -186,7 +187,7 @@ open class HorizontalBarChartRenderer(

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

val formatter = dataSet.valueFormatter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.github.mikephil.charting.interfaces.datasets.IPieDataSet
import com.github.mikephil.charting.utils.ColorTemplate
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
import com.github.mikephil.charting.utils.calcTextHeight
import com.github.mikephil.charting.utils.convertDpToPixel
import java.util.Collections
import kotlin.math.min
Expand Down Expand Up @@ -209,7 +210,7 @@ open class LegendRenderer(
val labelLineHeight = Utils.getLineHeight(labelPaint, legendFontMetrics)
val labelLineSpacing = (Utils.getLineSpacing(labelPaint, legendFontMetrics)
+ legend.yEntrySpace.convertDpToPixel())
val formYOffset = labelLineHeight - Utils.calcTextHeight(labelPaint, "ABC") / 2f
val formYOffset = labelLineHeight - labelPaint.calcTextHeight("ABC") / 2f

val entries = legend.entries

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.github.mikephil.charting.utils.ColorTemplate
import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
import com.github.mikephil.charting.utils.calcTextHeight
import com.github.mikephil.charting.utils.convertDpToPixel
import java.lang.ref.WeakReference
import kotlin.math.abs
Expand Down Expand Up @@ -405,7 +406,7 @@ open class PieChartRenderer(
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet)

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

val formatter = dataSet.valueFormatter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.Transformer
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
import com.github.mikephil.charting.utils.calcTextHeight
import com.github.mikephil.charting.utils.convertDpToPixel
import com.github.mikephil.charting.utils.drawXAxisValue
import kotlin.math.roundToInt

open class XAxisRenderer(
Expand Down Expand Up @@ -72,7 +74,7 @@ open class XAxisRenderer(
val labelSize = Utils.calcTextSize(paintAxisLabels, longest)

val labelWidth = labelSize.width
val labelHeight = Utils.calcTextHeight(paintAxisLabels, "Q").toFloat()
val labelHeight = paintAxisLabels.calcTextHeight("Q").toFloat()

val labelRotatedSize = Utils.getSizeOfRotatedRectangleByDegrees(
labelWidth,
Expand Down Expand Up @@ -102,21 +104,25 @@ open class XAxisRenderer(
pointF.y = 1.0f
drawLabels(canvas, viewPortHandler.contentTop() - yOffset, pointF)
}

XAxisPosition.TOP_INSIDE -> {
pointF.x = 0.5f
pointF.y = 1.0f
drawLabels(canvas, viewPortHandler.contentTop() + yOffset + xAxis.mLabelHeight, pointF)
}

XAxisPosition.BOTTOM -> {
pointF.x = 0.5f
pointF.y = 0.0f
drawLabels(canvas, viewPortHandler.contentBottom() + yOffset, pointF)
}

XAxisPosition.BOTTOM_INSIDE -> {
pointF.x = 0.5f
pointF.y = 0.0f
drawLabels(canvas, viewPortHandler.contentBottom() - yOffset - xAxis.mLabelHeight, pointF)
}

else -> { // BOTH SIDED
pointF.x = 0.5f
pointF.y = 1.0f
Expand Down Expand Up @@ -222,7 +228,7 @@ open class XAxisRenderer(
}

protected fun drawLabel(canvas: Canvas, formattedLabel: String?, x: Float, y: Float, anchor: MPPointF, angleDegrees: Float) {
formattedLabel?.let { Utils.drawXAxisValue(canvas, it, x, y, paintAxisLabels, anchor, angleDegrees) }
formattedLabel?.let { canvas.drawXAxisValue(it, x, y, paintAxisLabels, anchor, angleDegrees) }
}

protected open var renderGridLinesPath: Path = Path()
Expand Down Expand Up @@ -384,7 +390,7 @@ open class XAxisRenderer(

when (labelPosition) {
LimitLabelPosition.RIGHT_TOP -> {
val labelLineHeight = Utils.calcTextHeight(limitLinePaint, label).toFloat()
val labelLineHeight = limitLinePaint.calcTextHeight(label).toFloat()
limitLinePaint.textAlign = Align.LEFT
canvas.drawText(
label, position[0] + xOffset, viewPortHandler.contentTop() + yOffset + labelLineHeight,
Expand All @@ -399,7 +405,7 @@ open class XAxisRenderer(

LimitLabelPosition.LEFT_TOP -> {
limitLinePaint.textAlign = Align.RIGHT
val labelLineHeight = Utils.calcTextHeight(limitLinePaint, label).toFloat()
val labelLineHeight = limitLinePaint.calcTextHeight(label).toFloat()
canvas.drawText(
label, position[0] - xOffset, viewPortHandler.contentTop() + yOffset + labelLineHeight,
limitLinePaint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.Transformer
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
import com.github.mikephil.charting.utils.calcTextHeight
import com.github.mikephil.charting.utils.convertDpToPixel
import kotlin.math.roundToInt

Expand Down Expand Up @@ -253,7 +254,7 @@ open class XAxisRendererHorizontalBarChart(
limitLinePaint.strokeWidth = 0.5f
limitLinePaint.textSize = limitLine.textSize

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import com.github.mikephil.charting.components.YAxis
import com.github.mikephil.charting.components.YAxis.AxisDependency
import com.github.mikephil.charting.components.YAxis.YAxisLabelPosition
import com.github.mikephil.charting.utils.Transformer
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
import androidx.core.graphics.withSave
import androidx.core.graphics.withClip
import com.github.mikephil.charting.utils.calcTextHeight
import com.github.mikephil.charting.utils.convertDpToPixel

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

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

val axisDependency = yAxis.axisDependency
val labelPosition = yAxis.labelPosition
Expand Down Expand Up @@ -317,7 +317,7 @@ open class YAxisRenderer(viewPortHandler: ViewPortHandler, @JvmField protected v
limitLinePaint.strokeWidth = 0.5f
limitLinePaint.textSize = limitLine.textSize

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

Expand Down Expand Up @@ -436,7 +436,7 @@ open class YAxisRenderer(viewPortHandler: ViewPortHandler, @JvmField protected v
limitRangePaint.strokeWidth = 0.5f
limitRangePaint.textSize = limitRange.textSize

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import com.github.mikephil.charting.components.YAxis.AxisDependency
import com.github.mikephil.charting.components.YAxis.YAxisLabelPosition
import com.github.mikephil.charting.utils.MPPointD
import com.github.mikephil.charting.utils.Transformer
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
import com.github.mikephil.charting.utils.calcTextHeight
import com.github.mikephil.charting.utils.convertDpToPixel

@Suppress("MemberVisibilityCanBePrivate")
Expand Down Expand Up @@ -76,7 +76,7 @@ open class YAxisRendererHorizontalBarChart(
paintAxisLabels.textAlign = Align.CENTER

val baseYOffset = 2.5f.convertDpToPixel()
val textHeight = Utils.calcTextHeight(paintAxisLabels, "Q").toFloat()
val textHeight = paintAxisLabels.calcTextHeight("Q").toFloat()

val dependency = yAxis.axisDependency
val labelPosition = yAxis.labelPosition
Expand Down Expand Up @@ -283,7 +283,7 @@ open class YAxisRendererHorizontalBarChart(

when (position) {
LimitLabelPosition.RIGHT_TOP -> {
val labelLineHeight = Utils.calcTextHeight(limitLinePaint, label).toFloat()
val labelLineHeight = limitLinePaint.calcTextHeight(label).toFloat()
limitLinePaint.textAlign = Align.LEFT
canvas.drawText(label, pts[0] + xOffset, viewPortHandler.contentTop() + yOffset + labelLineHeight, limitLinePaint)
}
Expand All @@ -293,7 +293,7 @@ open class YAxisRendererHorizontalBarChart(
}
LimitLabelPosition.LEFT_TOP -> {
limitLinePaint.textAlign = Align.RIGHT
val labelLineHeight = Utils.calcTextHeight(limitLinePaint, label).toFloat()
val labelLineHeight = limitLinePaint.calcTextHeight(label).toFloat()
canvas.drawText(label, pts[0] - xOffset, viewPortHandler.contentTop() + yOffset + labelLineHeight, limitLinePaint)
}
else -> {
Expand Down
Loading
Loading