From 901f5ddd28ad87d0f05dec66de5f21ddfd2e7731 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Tue, 10 Feb 2026 06:30:40 +0100 Subject: [PATCH] Property access for centerAxisLabels --- .../BarChartActivityMultiDataset.kt | 2 +- .../chartexample/BarChartPositiveNegative.kt | 2 +- .../chartexample/LineChartTimeActivity.kt | 2 +- .../StackedBarActivityNegative.kt | 2 +- .../charting/charts/BarLineChartBase.kt | 2 +- .../charting/charts/HorizontalBarChart.kt | 2 +- .../charting/charts/PieRadarChartBase.kt | 2 +- .../info/appdev/charting/charts/RadarChart.kt | 2 +- .../appdev/charting/components/AxisBase.kt | 38 +++++++++---------- .../info/appdev/charting/components/XAxis.kt | 5 +-- .../appdev/charting/renderer/XAxisRenderer.kt | 8 ++-- .../XAxisRendererHorizontalBarChart.kt | 4 +- .../renderer/XAxisRendererRadarChart.kt | 4 +- 13 files changed, 35 insertions(+), 40 deletions(-) diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt index efad124f7..522a876de 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartActivityMultiDataset.kt @@ -80,7 +80,7 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar val xAxis = binding.chart1.xAxis xAxis.typeface = tfLight xAxis.granularity = 1f - xAxis.setCenterAxisLabels(true) + xAxis.centerAxisLabels = true xAxis.valueFormatter = object : IAxisValueFormatter { override fun getFormattedValue(value: Float, axis: AxisBase?): String { return value.toInt().toString() diff --git a/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt b/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt index 04e6e370d..58fc64310 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/BarChartPositiveNegative.kt @@ -54,7 +54,7 @@ class BarChartPositiveNegative : DemoBase() { xAxis.textColor = Color.LTGRAY xAxis.textSize = 13f xAxis.labelCount = 5 - xAxis.setCenterAxisLabels(true) + xAxis.centerAxisLabels = true xAxis.granularity = 1f val left = binding.chart1.axisLeft diff --git a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt index fd1a1bb72..fdd99c287 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/LineChartTimeActivity.kt @@ -74,7 +74,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener { xAxis.isDrawAxisLine = false xAxis.isDrawGridLines = true xAxis.textColor = Color.rgb(255, 192, 56) - xAxis.setCenterAxisLabels(true) + xAxis.centerAxisLabels = true xAxis.granularity = 1f // one hour xAxis.valueFormatter = object : IAxisValueFormatter { private val simpleDateFormat = SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH) diff --git a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt index accf2d40b..2bf282d58 100644 --- a/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt +++ b/app/src/main/kotlin/info/appdev/chartexample/StackedBarActivityNegative.kt @@ -65,7 +65,7 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener { xAxis.textSize = 9f xAxis.axisMinimum = 0f xAxis.axisMaximum = 110f - xAxis.setCenterAxisLabels(true) + xAxis.centerAxisLabels = true xAxis.labelCount = 12 xAxis.granularity = 10f xAxis.valueFormatter = object : IAxisValueFormatter { diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt index 7d9f37ca9..a4eab0f84 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/BarLineChartBase.kt @@ -491,7 +491,7 @@ abstract class BarLineChartBase>> val x = this.xAxis if (x.isEnabled && x.isDrawLabelsEnabled) { - minOffset = max(minOffset, x.mLabelWidth.toFloat()) + minOffset = max(minOffset, x.labelWidth.toFloat()) } } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/charts/RadarChart.kt b/chartLib/src/main/kotlin/info/appdev/charting/charts/RadarChart.kt index c8335441a..aa8e60cee 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/charts/RadarChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/charts/RadarChart.kt @@ -274,7 +274,7 @@ open class RadarChart : PieRadarChartBase { } override val requiredBaseOffset: Float - get() = if (mXAxis.isEnabled && mXAxis.isDrawLabelsEnabled) mXAxis.mLabelWidth.toFloat() else 10f.convertDpToPixel() + get() = if (mXAxis.isEnabled && mXAxis.isDrawLabelsEnabled) mXAxis.labelWidth.toFloat() else 10f.convertDpToPixel() override val radius: Float get() { diff --git a/chartLib/src/main/kotlin/info/appdev/charting/components/AxisBase.kt b/chartLib/src/main/kotlin/info/appdev/charting/components/AxisBase.kt index d2f8fbe1e..19e7f2b1d 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/components/AxisBase.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/components/AxisBase.kt @@ -17,7 +17,7 @@ abstract class AxisBase : ComponentBase() { /** * custom formatter that is used instead of the auto-formatter if set */ - protected var mAxisValueFormatter: IAxisValueFormatter? = null + protected var axisValueFormatter: IAxisValueFormatter? = null /** * The color of the grid lines for this axis (the horizontal lines @@ -96,7 +96,11 @@ abstract class AxisBase : ComponentBase() { var isDrawLabelsEnabled = true protected set - protected var mCenterAxisLabels: Boolean = false + /** + * Centers the axis labels instead of drawing them at their original position. + * This is useful especially for grouped BarChart. + */ + var centerAxisLabels: Boolean = false /** * the path effect of the axis line that makes dashed lines possible @@ -212,16 +216,8 @@ abstract class AxisBase : ComponentBase() { this.limitRanges = ArrayList() } - /** - * Centers the axis labels instead of drawing them at their original position. - * This is useful especially for grouped BarChart. - */ - fun setCenterAxisLabels(enabled: Boolean) { - mCenterAxisLabels = enabled - } - val isCenterAxisLabelsEnabled: Boolean - get() = mCenterAxisLabels && entryCount > 0 + get() = centerAxisLabels && entryCount > 0 /** * The width of the border surrounding the chart in dp. @@ -401,16 +397,18 @@ abstract class AxisBase : ComponentBase() { */ var valueFormatter: IAxisValueFormatter? get() { - if (mAxisValueFormatter == null || (mAxisValueFormatter is DefaultAxisValueFormatter && - (mAxisValueFormatter as DefaultAxisValueFormatter).decimalDigits != decimals) + if (axisValueFormatter == null || + (axisValueFormatter is DefaultAxisValueFormatter && (axisValueFormatter as DefaultAxisValueFormatter).decimalDigits != decimals) ) - mAxisValueFormatter = DefaultAxisValueFormatter(decimals) + axisValueFormatter = DefaultAxisValueFormatter(decimals) - return mAxisValueFormatter + return axisValueFormatter } set(f) { - if (f == null) mAxisValueFormatter = DefaultAxisValueFormatter(decimals) - else mAxisValueFormatter = f + if (f == null) + axisValueFormatter = DefaultAxisValueFormatter(decimals) + else + axisValueFormatter = f } /** @@ -518,8 +516,7 @@ abstract class AxisBase : ComponentBase() { /** * By calling this method, any custom maximum value that has been previously set is reseted, - * and the calculation is - * done automatically. + * and the calculation is done automatically. */ fun resetAxisMaximum() { this.isAxisMaxCustom = false @@ -527,8 +524,7 @@ abstract class AxisBase : ComponentBase() { /** * By calling this method, any custom minimum value that has been previously set is reseted, - * and the calculation is - * done automatically. + * and the calculation is done automatically. */ fun resetAxisMinimum() { this.isAxisMinCustom = false diff --git a/chartLib/src/main/kotlin/info/appdev/charting/components/XAxis.kt b/chartLib/src/main/kotlin/info/appdev/charting/components/XAxis.kt index cb93037a3..73e5d23d2 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/components/XAxis.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/components/XAxis.kt @@ -12,20 +12,19 @@ class XAxis : AxisBase() { * width of the x-axis labels in pixels - this is automatically * calculated by the computeSize() methods in the renderers */ - var mLabelWidth: Int = 1 + var labelWidth: Int = 1 /** * height of the x-axis labels in pixels - this is automatically * calculated by the computeSize() methods in the renderers */ - var mLabelHeight: Int = 1 + var labelHeight: Int = 1 /** * This is the angle for drawing the X axis labels (in degrees) */ var labelRotationAngle: Float = 0f - /** * if set to true, the chart will avoid that the first and last label entry * in the chart "clip" off the edge of the chart diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRenderer.kt index 0f4e10662..dd93481c9 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRenderer.kt @@ -84,8 +84,8 @@ open class XAxisRenderer( xAxis.labelRotationAngle ) - xAxis.mLabelWidth = labelRotatedSize.width.roundToInt() - xAxis.mLabelHeight = labelRotatedSize.height.roundToInt() + xAxis.labelWidth = labelRotatedSize.width.roundToInt() + xAxis.labelHeight = labelRotatedSize.height.roundToInt() FSize.recycleInstance(labelRotatedSize) FSize.recycleInstance(labelSize) @@ -110,7 +110,7 @@ open class XAxisRenderer( XAxisPosition.TOP_INSIDE -> { pointF.x = 0.5f pointF.y = 1.0f - drawLabels(canvas, viewPortHandler.contentTop() + yOffset + xAxis.mLabelHeight, pointF) + drawLabels(canvas, viewPortHandler.contentTop() + yOffset + xAxis.labelHeight, pointF) } XAxisPosition.BOTTOM -> { @@ -122,7 +122,7 @@ open class XAxisRenderer( XAxisPosition.BOTTOM_INSIDE -> { pointF.x = 0.5f pointF.y = 0.0f - drawLabels(canvas, viewPortHandler.contentBottom() - yOffset - xAxis.mLabelHeight, pointF) + drawLabels(canvas, viewPortHandler.contentBottom() - yOffset - xAxis.labelHeight, pointF) } else -> { // BOTH SIDED diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRendererHorizontalBarChart.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRendererHorizontalBarChart.kt index 781dd86cf..02edf3666 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRendererHorizontalBarChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRendererHorizontalBarChart.kt @@ -71,8 +71,8 @@ open class XAxisRendererHorizontalBarChart( xAxis.labelRotationAngle ) - xAxis.mLabelWidth = labelRotatedSize.width.roundToInt() - xAxis.mLabelHeight = labelRotatedSize.height.roundToInt() + xAxis.labelWidth = labelRotatedSize.width.roundToInt() + xAxis.labelHeight = labelRotatedSize.height.roundToInt() FSize.recycleInstance(labelRotatedSize) } diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRendererRadarChart.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRendererRadarChart.kt index 9f0acfc18..853a0f296 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRendererRadarChart.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/XAxisRendererRadarChart.kt @@ -37,10 +37,10 @@ class XAxisRendererRadarChart( val angle = (sliceAngle * i + chart.rotationAngle) % 360f - pOut = center.getPosition(chart.yRange * factor + xAxis.mLabelWidth / 2f, angle) + pOut = center.getPosition(chart.yRange * factor + xAxis.labelWidth / 2f, angle) drawLabel( - canvas, label, pOut.x, pOut.y - xAxis.mLabelHeight / 2f, + canvas, label, pOut.x, pOut.y - xAxis.labelHeight / 2f, drawLabelAnchor, labelRotationAngleDegrees ) }