Closed msshin0202 closed 2 weeks ago
Hi @msshin0202 ,
dead you print something in onPieClick
?
i dont understand your problem is chart recomposition after data change or your have problem with onPieClick
calls
Hey @ehsannarmani I'm just not getting any animation when I use that code above. Am I missing something in the code? I am updating the data
with the selected
state but nothing happens. What's weird is that with print statements it works to go into the lambda but any print statements I put after data = ...
doesn't print out suggesting either a crash or some other issue.
try this: data = data.toList()
Oh yes that worked! Thanks so much!
@ehsannarmani out of curiosity though, why does doing something like this, not work?
var data = remember {
listOf(
Pie(label = "Android", data = 20.0, color = Color.Red, selectedColor = Color.Green),
Pie(label = "Windows", data = 45.0, color = Color.Cyan, selectedColor = Color.Blue),
Pie(label = "Linux", data = 35.0, color = Color.Gray, selectedColor = Color.Yellow),
)
}
PieChart(
modifier = modifier.size(200.dp),
data = data.toList(),
onPieClick = { clickedPie ->
val pieIndex = data.indexOf(clickedPie)
data = data.mapIndexed { mapIndex, pie -> pie.copy(selected = pieIndex == mapIndex) }
},
selectedScale = 1.2f,
scaleAnimEnterSpec = spring<Float>(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
),
colorAnimEnterSpec = tween(300),
colorAnimExitSpec = tween(300),
scaleAnimExitSpec = tween(300),
spaceDegreeAnimExitSpec = tween(300),
style = Pie.Style.Fill
)
It's essentially the same as what I had before, but instead using your documentation's example of overwriting the data with the mapIndexed
in this sample, data is not state, so ui wont update after data changed.
i will update and fix document
@ehsannarmani one more question for you, the LineChart
seems to cause rendering issues when put inside a Column
with a verticalScroll
modifier due to infinite height constraint. Any ideas?
hi @msshin0202 , set a fixed height for chart for example:
LineChart(
modifier= Modifier.height(300.dp)
...
)
@ehsannarmani Yeah I wanted to not have to do a fixed height, but if that's the only way!
Using this Pie Chart as followed in the documentation seems to have issues animating. After some debugging it seems like there's some issue with the
onPieClick
listener where the data is is not being overwritten properly. I am pretty sure that the way I have set up theremember
with themutableStateListOf
should be sufficient for recomposition when I trigger a change within the data but doesn't seem to be doing that. I've also tried the way it shows in the documentation with onlyremember
and avar
for the data and replacing the entiredata
list instead of modifying a singlePie
object, but same issue.