Skip to content

Commit b12f2d2

Browse files
Fix #32 and improve demo examples
1 parent 22d4bc3 commit b12f2d2

File tree

6 files changed

+68
-17
lines changed

6 files changed

+68
-17
lines changed

demo/plot/compose-desktop/src/main/kotlin/demo/plot/minimal/MultiplePlotSizeLayoutCompose.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.ui.unit.dp
1212
import androidx.compose.ui.window.Window
1313
import androidx.compose.ui.window.application
1414
import org.jetbrains.letsPlot.skia.compose.PlotPanel
15+
import plotSpec.BarPlotSpec
1516
import plotSpec.DensitySpec
1617

1718
fun main() = application {
@@ -22,7 +23,7 @@ fun main() = application {
2223
) {
2324

2425
PlotPanel(
25-
figure = DensitySpec().createFigure(),
26+
figure = BarPlotSpec().createFigure(),
2627
modifier = Modifier.height(100.dp).width(100.dp)
2728
) { computationMessages ->
2829
computationMessages.forEach { println("[DEMO APP MESSAGE] $it") }

demo/plot/compose-desktop/src/main/kotlin/demo/plot/minimal/MultiplePlotWeightLayoutCompose.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,35 @@
55

66
package demo.plot.minimal
77

8-
import androidx.compose.foundation.layout.Column
9-
import androidx.compose.foundation.layout.fillMaxSize
10-
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.foundation.layout.*
119
import androidx.compose.material.MaterialTheme
1210
import androidx.compose.ui.Modifier
1311
import androidx.compose.ui.unit.dp
1412
import androidx.compose.ui.window.Window
1513
import androidx.compose.ui.window.application
1614
import org.jetbrains.letsPlot.skia.compose.PlotPanel
15+
import plotSpec.BarPlotSpec
1716
import plotSpec.DensitySpec
1817

1918
fun main() = application {
2019
Window(onCloseRequest = ::exitApplication, title = "Multiple Plot Weight Layout (Compose Desktop)") {
2120
MaterialTheme {
22-
Column(
23-
modifier = Modifier.fillMaxSize().padding(start = 10.dp, top = 10.dp, end = 10.dp, bottom = 10.dp),
21+
Row(
22+
modifier = Modifier
23+
.fillMaxSize()
24+
.padding(10.dp),
25+
horizontalArrangement = Arrangement.spacedBy(10.dp)
2426
) {
25-
2627
PlotPanel(
27-
figure = DensitySpec().createFigure(),
28-
modifier = Modifier.weight(1f)
28+
figure = BarPlotSpec().createFigure(),
29+
modifier = Modifier.fillMaxHeight().weight(1f)
2930
) { computationMessages ->
3031
computationMessages.forEach { println("[DEMO APP MESSAGE] $it") }
3132
}
3233

3334
PlotPanel(
3435
figure = DensitySpec().createFigure(),
35-
modifier = Modifier.weight(1f)
36+
modifier = Modifier.fillMaxHeight().weight(1f)
3637
) { computationMessages ->
3738
computationMessages.forEach { println("[DEMO APP MESSAGE] $it") }
3839
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2025 JetBrains s.r.o.
3+
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
4+
*/
5+
6+
package demo.plot.various
7+
8+
import androidx.compose.foundation.layout.*
9+
import androidx.compose.material.MaterialTheme
10+
import androidx.compose.ui.Modifier
11+
import androidx.compose.ui.unit.dp
12+
import androidx.compose.ui.window.Window
13+
import androidx.compose.ui.window.application
14+
import org.jetbrains.letsPlot.interact.ggtb
15+
import org.jetbrains.letsPlot.skia.compose.PlotPanel
16+
import plotSpec.AutoSpec
17+
import plotSpec.MarkdownSpec
18+
19+
fun main() = application {
20+
Window(onCloseRequest = ::exitApplication, title = "Multiple Plot Weight Layout (Compose Desktop)") {
21+
MaterialTheme {
22+
Row(
23+
modifier = Modifier
24+
.fillMaxSize()
25+
.padding(10.dp),
26+
horizontalArrangement = Arrangement.spacedBy(10.dp)
27+
) {
28+
PlotPanel(
29+
figure = AutoSpec().scatter() + ggtb(),
30+
modifier = Modifier.fillMaxHeight().weight(1f)
31+
) { computationMessages ->
32+
computationMessages.forEach { println("[DEMO APP MESSAGE] $it") }
33+
}
34+
35+
PlotPanel(
36+
figure = MarkdownSpec().mpg() + ggtb(),
37+
modifier = Modifier.fillMaxHeight().weight(1f)
38+
) { computationMessages ->
39+
computationMessages.forEach { println("[DEMO APP MESSAGE] $it") }
40+
}
41+
}
42+
}
43+
}
44+
}

demo/plot/shared/src/main/kotlin/plotSpec/AutoSpec.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import demoData.AutoMpg
99
import org.jetbrains.letsPlot.Figure
1010
import org.jetbrains.letsPlot.geom.geomLabel
1111
import org.jetbrains.letsPlot.geom.geomPoint
12+
import org.jetbrains.letsPlot.intern.Plot
1213
import org.jetbrains.letsPlot.letsPlot
1314

1415
class AutoSpec : PlotDemoSpec {
@@ -18,7 +19,7 @@ class AutoSpec : PlotDemoSpec {
1819
)
1920
}
2021

21-
fun scatter(): Figure {
22+
fun scatter(): Plot {
2223
return letsPlot(AutoMpg.map()) + geomPoint {
2324
x = "engine horsepower"
2425
y = "miles per gallon"

demo/plot/shared/src/main/kotlin/plotSpec/MarkdownSpec.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ package plotSpec
88
import demoData.AutoMpg
99
import org.jetbrains.letsPlot.Figure
1010
import org.jetbrains.letsPlot.geom.geomPoint
11+
import org.jetbrains.letsPlot.intern.Plot
1112
import org.jetbrains.letsPlot.label.labs
1213
import org.jetbrains.letsPlot.letsPlot
1314
import org.jetbrains.letsPlot.scale.scaleColorManual
1415
import org.jetbrains.letsPlot.themes.elementMarkdown
1516
import org.jetbrains.letsPlot.themes.elementText
1617
import org.jetbrains.letsPlot.themes.theme
18+
import org.jetbrains.letsPlot.tooltips.layerTooltips
1719

1820
class MarkdownSpec : PlotDemoSpec {
1921
override fun createFigureList(): List<Figure> {
@@ -22,9 +24,9 @@ class MarkdownSpec : PlotDemoSpec {
2224
)
2325
}
2426

25-
fun mpg(): Figure {
27+
fun mpg(): Plot {
2628
return letsPlot(AutoMpg.map()) +
27-
geomPoint(size=8) { x="engine displacement (cu. inches)"; y="miles per gallon"; color="number of cylinders" } +
29+
geomPoint(size=8, tooltips = layerTooltips().line("@{vehicle name}")) { x="engine displacement (cu. inches)"; y="miles per gallon"; color="number of cylinders" } +
2830
scaleColorManual(listOf("#66c2a5", "#fc8d62", "#8da0cb"), guide="none") +
2931

3032
// Enable Markdown in all titles

lets-plot-compose/src/desktopMain/kotlin/org/jetbrains/letsPlot/skia/compose/PlotPanel.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.compose.foundation.background
99
import androidx.compose.foundation.layout.Box
1010
import androidx.compose.foundation.layout.Column
1111
import androidx.compose.foundation.layout.fillMaxSize
12+
import androidx.compose.foundation.layout.fillMaxWidth
1213
import androidx.compose.runtime.*
1314
import androidx.compose.ui.Modifier
1415
import androidx.compose.ui.awt.SwingPanel
@@ -55,22 +56,23 @@ actual fun PlotPanel(
5556
}
5657
}
5758

58-
Column {
59+
Column(modifier = modifier) {
5960
if (plotFigureModel != null && GG_TOOLBAR in processedPlotSpec) {
6061
PlotToolbar(plotFigureModel!!)
6162
}
6263

6364
Box(
64-
modifier = Modifier
65-
.fillMaxSize()
65+
modifier = modifier
66+
.weight(1f) // Take remaining vertical space
67+
.fillMaxWidth() // Fill available width
6668
.onSizeChanged { newSize ->
6769
panelSize = DoubleVector(newSize.width / density, newSize.height / density)
6870
}
6971
.background(Color.Gray)
7072
) {
7173
SwingPanel(
7274
background = Color.White,
73-
modifier = modifier,
75+
modifier = Modifier.fillMaxSize(),
7476
factory = { plotContainer },
7577
update = { plotViewContainer ->
7678
LOG.print("SwingPanel.update()")

0 commit comments

Comments
 (0)