55
66package demo.plot.pixeldensity
77
8+ import androidx.compose.foundation.background
89import androidx.compose.foundation.layout.*
910import androidx.compose.material.Button
1011import androidx.compose.material.MaterialTheme
1112import androidx.compose.material.Slider
1213import androidx.compose.material.Text
1314import androidx.compose.runtime.*
14- import androidx.compose.ui.Alignment
1515import androidx.compose.ui.Modifier
16+ import androidx.compose.ui.graphics.Color
1617import androidx.compose.ui.platform.LocalDensity
1718import androidx.compose.ui.unit.Density
1819import androidx.compose.ui.unit.dp
@@ -22,10 +23,12 @@ import org.jetbrains.letsPlot.Figure
2223import org.jetbrains.letsPlot.geom.geomPoint
2324import org.jetbrains.letsPlot.letsPlot
2425import org.jetbrains.letsPlot.skia.compose.PlotPanel
26+ import org.jetbrains.letsPlot.themes.flavorDarcula
27+ import org.jetbrains.letsPlot.themes.flavorHighContrastDark
2528
2629fun main () = application {
2730 var pixelDensity by remember { mutableFloatStateOf(1.0f ) }
28-
31+
2932 Window (onCloseRequest = ::exitApplication, title = " Pixel Density Test Demo" ) {
3033 MaterialTheme {
3134 CompositionLocalProvider (LocalDensity provides Density (pixelDensity)) {
@@ -38,14 +41,14 @@ fun main() = application {
3841 Column (modifier = Modifier .padding(16 .dp)) {
3942 Text (" Current Pixel Density: ${String .format(" %.2f" , pixelDensity)} " )
4043 Text (" Effective DPI: ${String .format(" %.0f" , pixelDensity * 96 )} " )
41-
44+
4245 Slider (
4346 value = pixelDensity,
4447 onValueChange = { pixelDensity = it },
4548 valueRange = 0.5f .. 3.0f ,
4649 modifier = Modifier .fillMaxWidth()
4750 )
48-
51+
4952 Row (
5053 horizontalArrangement = Arrangement .spacedBy(8 .dp)
5154 ) {
@@ -56,7 +59,7 @@ fun main() = application {
5659 }
5760 }
5861 }
59-
62+
6063 // Plot panel that reacts to pixel density changes
6164 PlotPanel (
6265 figure = createTestFigure(),
@@ -89,15 +92,15 @@ private fun Card(
8992private fun createTestFigure (): Figure {
9093 val n = 100
9194 val rand = kotlin.random.Random (42 )
92-
95+
9396 val data = mapOf (
9497 " x" to List (n) { rand.nextDouble() * 10 },
9598 " y" to List (n) { rand.nextDouble() * 10 },
9699 " color" to List (n) { listOf (" A" , " B" , " C" , " D" ).random(rand) }
97100 )
98-
99- return letsPlot(data) +
100- geomPoint(size = 3.0 , alpha = 0.7 ) {
101- x = " x" ; y = " y" ; color = " color"
102- }
101+
102+ return letsPlot(data) +
103+ geomPoint(size = 3.0 , alpha = 0.7 ) {
104+ x = " x" ; y = " y" ; color = " color"
105+ } + flavorHighContrastDark()
103106}
0 commit comments