From 6666855d58aaa2757340ec159c4d2b4ff7bbd2a4 Mon Sep 17 00:00:00 2001 From: Fer Date: Fri, 25 Oct 2024 21:49:24 +0200 Subject: [PATCH] Add toggle for scalar values visibility in RadarChart --- .../aay/compose/radarChart/DrawAxisData.kt | 24 +++++++++++-------- .../com/aay/compose/radarChart/RadarChart.kt | 5 +++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/chart/src/commonMain/kotlin/com/aay/compose/radarChart/DrawAxisData.kt b/chart/src/commonMain/kotlin/com/aay/compose/radarChart/DrawAxisData.kt index 89b9b68a..dff67868 100644 --- a/chart/src/commonMain/kotlin/com/aay/compose/radarChart/DrawAxisData.kt +++ b/chart/src/commonMain/kotlin/com/aay/compose/radarChart/DrawAxisData.kt @@ -18,7 +18,8 @@ internal fun DrawScope.drawAxisData( radarLabels: List, scalarValue: Double, scalarSteps: Int, - unit: String + unit: String, + showScalarValues: Boolean ) { val labelsEndPoints = radarChartConfig.labelsPoints @@ -31,18 +32,21 @@ internal fun DrawScope.drawAxisData( val labelHeight = textMeasurer.measure(AnnotatedString("M")).size.height - for (step in 0 until scalarSteps) { - drawText( - textMeasurer = textMeasurer, - text = (scalarStep * step).toString() + " " + unit, - style = scalarValuesStyle, - topLeft = Offset( - nextStartPoints[step].x + 5.toDp().toPx(), - nextStartPoints[step].y - textVerticalOffset + if (showScalarValues) { + for (step in 0 until scalarSteps) { + drawText( + textMeasurer = textMeasurer, + text = (scalarStep * step).toString() + " " + unit, + style = scalarValuesStyle, + topLeft = Offset( + nextStartPoints[step].x + 5.toDp().toPx(), + nextStartPoints[step].y - textVerticalOffset + ) ) - ) + } } + for (line in labelsEndPoints.indices) { drawText( textMeasurer = textMeasurer, diff --git a/chart/src/commonMain/kotlin/com/aay/compose/radarChart/RadarChart.kt b/chart/src/commonMain/kotlin/com/aay/compose/radarChart/RadarChart.kt index cb4a9b7d..5cb070ac 100644 --- a/chart/src/commonMain/kotlin/com/aay/compose/radarChart/RadarChart.kt +++ b/chart/src/commonMain/kotlin/com/aay/compose/radarChart/RadarChart.kt @@ -22,6 +22,7 @@ import com.aay.compose.radarChart.model.Polygon * @param scalarValue Scalar value to determine the scale of the radar chart. * @param scalarValuesStyle TextStyle for configuring the appearance of scalar value labels. * @param polygons List of polygons to be displayed on the radar chart. + * @param showScalarValues Flag to determine whether to display scalar values on the radar chart (default is true). * @param modifier Modifier for configuring the layout and appearance of the radar chart. * * @see Polygon @@ -37,6 +38,7 @@ fun RadarChart( scalarValue: Double, scalarValuesStyle: TextStyle, polygons: List, + showScalarValues: Boolean = true, modifier: Modifier = Modifier ) { @@ -74,7 +76,8 @@ fun RadarChart( radarLabels, scalarValue, scalarSteps, - polygons[0].unit + polygons[0].unit, + showScalarValues ) }