Skip to content

Commit 8b96252

Browse files
merge main into current, adding background manually, render chart config with customization
1 parent 03c58cc commit 8b96252

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

YChartsLib/src/main/java/co/yml/charts/ui/piechart/charts/DonutPieChart.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.activity.compose.BackHandler
55
import androidx.compose.animation.core.Animatable
66
import androidx.compose.animation.core.tween
77
import androidx.compose.foundation.Canvas
8+
import androidx.compose.foundation.background
89
import androidx.compose.foundation.clickable
910
import androidx.compose.foundation.gestures.detectTapGestures
1011
import androidx.compose.foundation.layout.*
@@ -92,6 +93,7 @@ fun DonutPieChart(
9293
val boxModifier = if (pieChartConfig.isClickOnSliceEnabled) {
9394
modifier
9495
.aspectRatio(1f)
96+
.background(pieChartConfig.backgroundColor)
9597
.semantics {
9698
contentDescription = pieChartConfig.accessibilityConfig.chartDescription
9799
}

YChartsLib/src/main/java/co/yml/charts/ui/piechart/models/PieChartConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ data class PieChartConfig(
5757
val labelType: LabelType = LabelType.PERCENTAGE,
5858
val labelColor: Color = Color.White,
5959
val labelColorType: LabelColorType = LabelColorType.SPECIFIED_COLOR,
60+
val backgroundColor: Color = Color.White,
6061
val activeSliceAlpha: Float = .8f,
6162
val inActiveSliceAlpha: Float = 1f,
6263
val isEllipsizeEnabled: Boolean = false,

app/src/main/java/co/yml/ycharts/app/presentation/DonutChartActivity.kt

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,42 +157,46 @@ private fun MultipleSmallDonutCharts(context: Context) {
157157
val proportions = data.slices.proportion(sumOfValues)
158158
val firstPieChartConfig =
159159
PieChartConfig(
160-
percentVisible = true,
160+
labelVisible = true,
161161
strokeWidth = 50f,
162-
percentColor = Color.Black,
162+
labelColor = Color.Black,
163163
backgroundColor = Color.Yellow,
164164
activeSliceAlpha = .9f,
165165
isEllipsizeEnabled = true,
166-
percentageTypeface = Typeface.defaultFromStyle(Typeface.BOLD),
166+
labelTypeface = Typeface.defaultFromStyle(Typeface.BOLD),
167167
isAnimationEnable = true,
168168
chartPadding = 25,
169-
percentageFontSize = 16.sp
169+
labelFontSize = 16.sp
170170
)
171171
val secondPieChartConfig =
172172
PieChartConfig(
173-
percentVisible = true,
173+
labelVisible = true,
174174
strokeWidth = 50f,
175-
percentColor = Color.White,
176-
backgroundColor = Color.Black,
175+
labelColor = Color.Black,
177176
activeSliceAlpha = .9f,
178177
isEllipsizeEnabled = true,
179-
percentageTypeface = Typeface.defaultFromStyle(Typeface.BOLD),
178+
backgroundColor = Color.Black,
179+
labelTypeface = Typeface.defaultFromStyle(Typeface.BOLD),
180180
isAnimationEnable = true,
181181
chartPadding = 25,
182-
percentageFontSize = 16.sp
182+
labelFontSize = 16.sp,
183+
isSumVisible = true,
184+
sumUnit = "unit",
185+
labelColorType = PieChartConfig.LabelColorType.SLICE_COLOR,
186+
labelType = PieChartConfig.LabelType.VALUE
183187
)
184188
val thirdPieChartConfig =
185189
PieChartConfig(
186-
percentVisible = true,
190+
labelVisible = true,
187191
strokeWidth = 50f,
188-
percentColor = Color.Black,
192+
labelColor = Color.Black,
189193
activeSliceAlpha = .9f,
190194
backgroundColor = Color.LightGray,
191195
isEllipsizeEnabled = true,
192-
percentageTypeface = Typeface.defaultFromStyle(Typeface.BOLD),
196+
labelTypeface = Typeface.defaultFromStyle(Typeface.BOLD),
193197
isAnimationEnable = true,
194198
chartPadding = 25,
195-
percentageFontSize = 16.sp
199+
labelFontSize = 16.sp
196200
)
197201
Column(
198202
modifier = Modifier

0 commit comments

Comments
 (0)