66package org.jetbrains.letsPlot.skia.compose
77
88import androidx.compose.foundation.background
9- import androidx.compose.foundation.layout.*
9+ import androidx.compose.foundation.layout.Box
10+ import androidx.compose.foundation.layout.Column
11+ import androidx.compose.foundation.layout.fillMaxSize
12+ import androidx.compose.foundation.layout.fillMaxWidth
1013import androidx.compose.foundation.text.BasicTextField
1114import androidx.compose.runtime.*
1215import androidx.compose.ui.Modifier
@@ -40,24 +43,6 @@ actual fun PlotPanelRaw(
4043 computationMessagesHandler : (List <String >) -> Unit
4144) {
4245
43- // Background
44-
45- // Check if the modifier already has a background
46- val hasBackground = modifier.foldIn(false ) { hasBg, element ->
47- hasBg || element.toString().contains(" BackgroundElement" )
48- }
49-
50- // Apply a plot background only if the user hasn't set one
51- val finalModifier = if (! hasBackground) {
52- val lpBackground = rawSpec.let {
53- val lpColor = PlotThemeHelper .plotBackground(rawSpec)
54- Color (lpColor.red, lpColor.green, lpColor.blue, lpColor.alpha)
55- }
56- modifier.background(lpBackground)
57- } else {
58- modifier
59- }
60-
6146 // Update density on each recomposition to handle monitor DPI changes (e.g., drag between HIDPI/regular monitor)
6247 val density = LocalDensity .current.density.toDouble()
6348
@@ -72,6 +57,25 @@ actual fun PlotPanelRaw(
7257 val plotContainer by remember { mutableStateOf(PlotContainer ()) }
7358 var plotFigureModel by remember { mutableStateOf<PlotFigureModel ?>(null ) }
7459
60+
61+ val showErrorMessage = PlotConfig .isFailure(processedPlotSpec)
62+
63+ // Background
64+ val finalModifier = if (showErrorMessage) {
65+ modifier.background(Color .LightGray )
66+ } else {
67+ if (containsBackground(modifier)) {
68+ // Do not change the user-defined background
69+ modifier
70+ } else {
71+ // Use background color from the plot theme
72+ val lpColor = PlotThemeHelper .plotBackground(processedPlotSpec)
73+ val lpBackground = Color (lpColor.red, lpColor.green, lpColor.blue, lpColor.alpha)
74+ modifier.background(lpBackground)
75+ }
76+ }
77+
78+
7579 DisposableEffect (plotContainer) {
7680 onDispose {
7781 plotContainer.dispose()
@@ -92,7 +96,8 @@ actual fun PlotPanelRaw(
9296 panelSize = DoubleVector (newSize.width / density, newSize.height / density)
9397 }
9498 ) {
95- if (PlotConfig .isFailure(processedPlotSpec)) {
99+ if (showErrorMessage) {
100+ // Show error message
96101 BasicTextField (
97102 value = PlotConfig .getErrorMessage(processedPlotSpec),
98103 onValueChange = { },
@@ -101,6 +106,7 @@ actual fun PlotPanelRaw(
101106 modifier = errorModifier
102107 )
103108 } else {
109+ // Render the plot
104110 LaunchedEffect (panelSize, processedPlotSpec, specOverrideList) {
105111 if (panelSize != DoubleVector .ZERO ) {
106112 LOG .print (" Plot update triggered" )
@@ -155,3 +161,9 @@ actual fun PlotPanelRaw(
155161 }
156162 }
157163}
164+
165+ private fun containsBackground (modifier : Modifier ): Boolean {
166+ return modifier.foldIn(false ) { hasBg, element ->
167+ hasBg || element.toString().contains(" BackgroundElement" )
168+ }
169+ }
0 commit comments