Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when graph get's resized to zero height #200

Closed
MFlisar opened this issue Mar 8, 2023 · 3 comments
Closed

Crash when graph get's resized to zero height #200

MFlisar opened this issue Mar 8, 2023 · 3 comments
Assignees

Comments

@MFlisar
Copy link

MFlisar commented Mar 8, 2023

I Just placed a graph inside my layout and my layout is collapsible and resizes its content. If I place your graph inside it it crashes (when it gets resized to 0, because it tries to call coerceIn with an empty or range).

It's probably a rare use case, but the graph should at least not crash if it gets resized to a zero height... My suggestion is to use 0 in such a case instead of coerceIn which in case of the exception I see below would be the correct y value if the graph is to small to draw anything on the y axis anyway... Or alternatively skip the drawing at all...

Version:
compose-m3:1.6.4

Code

val chartEntryModel = entryModelOf(4f, 12f, 8f, 16f, 20f, 5f, 34f, 72f, 15f, 4f, 12f, 8f, 16f, 20f, 5f, 34f, 72f, 15f)
Chart(
	modifier = Modifier
		.fillMaxWidth()
		.height(100.dp)
		.padding(8.dp),
	chart = lineChart(),
	model = chartEntryModel,
	startAxis = startAxis(),
	bottomAxis = bottomAxis()
)

Stacktrace

java.lang.IllegalArgumentException: Cannot coerce value to an empty range: maximum -30.5 is less than minimum 27.5.
	at kotlin.ranges.RangesKt___RangesKt.coerceIn(_Ranges.kt:1441)
	at com.patrykandpatrick.vico.core.chart.line.LineChart$drawChart$1$1$1.invoke(LineChart.kt:340)
	at com.patrykandpatrick.vico.core.chart.line.LineChart$drawChart$1$1$1.invoke(LineChart.kt:301)
	at com.patrykandpatrick.vico.core.chart.line.LineChart.forEachPointWithinBoundsIndexed(LineChart.kt:469)
	at com.patrykandpatrick.vico.core.chart.line.LineChart.drawChart(LineChart.kt:301)
	at com.patrykandpatrick.vico.core.chart.BaseChart.drawChartInternal(BaseChart.kt:133)
	at com.patrykandpatrick.vico.core.chart.BaseChart.drawScrollableContent(BaseChart.kt:92)
	at com.patrykandpatrick.vico.core.chart.BaseChart.drawScrollableContent(BaseChart.kt:37)
	at com.patrykandpatrick.vico.compose.chart.ChartsKt$ChartImpl$6.invoke(Charts.kt:382)
	at com.patrykandpatrick.vico.compose.chart.ChartsKt$ChartImpl$6.invoke(Charts.kt:335)
	at androidx.compose.ui.draw.DrawBackgroundModifier.draw(DrawModifier.kt:114)
	...
@Gowsky Gowsky added the bug label Mar 8, 2023
@patrickmichalik
Copy link
Member

Thanks for the bug report! We’ll look into it.

@Gowsky Gowsky self-assigned this Mar 11, 2023
Gowsky added a commit that referenced this issue Mar 11, 2023
…ts-resized-to-zero-height

Fix a crash occurring when chart bounds are invalid #200
@TheRedSpy15
Copy link

TheRedSpy15 commented Apr 4, 2023

Also causing crashes for me. Trying to use AnimatedVisibility() with the composable chart and they don't seem to get along

Edit: I fixed it for my situation by wrapping the Chart() inside a Box() that is set to the size I need the chart to eventually resize to

@patrickmichalik
Copy link
Member

Vico 1.6.5, which is now rolling out, resolves this issue. Thanks again for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

4 participants