Skip to content

Commit

Permalink
In Donut chart add center label and fix legend bags
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-ananiev committed Mar 6, 2023
1 parent ac62f7c commit 9fa8f0f
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import co.yml.charts.common.model.LegendLabel
import co.yml.charts.common.model.LegendsConfig
import kotlin.math.roundToInt

/**
* Renders the list of legends in a grid format for given given grid column count
Expand All @@ -33,14 +34,15 @@ fun Legends(modifier: Modifier = Modifier, legendsConfig: LegendsConfig) {
),
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
val legendsInColumn = legendLabelList.size/columnCount
val legendsInColumn = legendLabelList.size/columnCount +
if (legendLabelList.size % columnCount > 0) 1 else 0
var index = 0
for (col in (0 until columnCount)) {
for (col in (1..columnCount)) {
Column(
modifier = Modifier.weight((1.0/columnCount).toFloat()),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
for (i in (index..legendsInColumn * col)) {
for (i in (index until legendsInColumn * col)) {
if (i < legendLabelList.size) Legend(legendsConfig, legendLabelList[i])
index++
}
Expand Down

0 comments on commit 9fa8f0f

Please sign in to comment.