Skip to content

Commit 1e5558d

Browse files
committed
Add fun ggbunch(), deprecate class GGBunch.
1 parent 9abfd62 commit 1e5558d

File tree

9 files changed

+202
-103
lines changed

9 files changed

+202
-103
lines changed

demo/browser/src/main/kotlin/exportHtmlDemo/GGBunchHtml.kt

+18-10
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,34 @@ package exportHtmlDemo
88
import BrowserDemoUtil
99
import org.jetbrains.letsPlot.core.util.PlotHtmlExport
1010
import org.jetbrains.letsPlot.core.util.PlotHtmlHelper
11-
import org.jetbrains.letsPlot.GGBunch
1211
import org.jetbrains.letsPlot.export.VersionChecker
1312
import org.jetbrains.letsPlot.geom.geomBoxplot
1413
import org.jetbrains.letsPlot.geom.geomDensity
14+
import org.jetbrains.letsPlot.ggbunch
1515
import org.jetbrains.letsPlot.letsPlot
16+
import org.jetbrains.letsPlot.themes.elementRect
17+
import org.jetbrains.letsPlot.themes.theme
18+
import org.jetbrains.letsPlot.themes.themeBW
1619
import kotlin.math.abs
1720

1821
@Suppress("DuplicatedCode")
1922
object GGBunchHtml {
2023
@JvmStatic
2124
fun main(args: Array<String>) {
22-
val density = letsPlot(densityData()) + geomDensity(color = "red", alpha = 0.3, size = 5.0) { x = "x" }
23-
val boxplot = letsPlot(boxplotData()) { x = "cat"; y = "val" } + geomBoxplot(outlierColor = "red")
24-
25-
// Create plot spec using lets-plot Kotlin API
26-
val w = 300
27-
val h = 250
28-
val bunch = GGBunch()
29-
bunch.addPlot(density, 0, 0, w, h)
30-
bunch.addPlot(boxplot, w + 10, h + 10, w, h)
25+
val theme = themeBW() + theme(plotBackground = elementRect(size = 1))
26+
val density = letsPlot(densityData()) +
27+
geomDensity(color = "red", alpha = 0.3, size = 5.0) { x = "x" } + theme
28+
val boxplot = letsPlot(boxplotData()) { x = "cat"; y = "val" } +
29+
geomBoxplot(outlierColor = "red") + theme
30+
31+
// Plots in opposite corners
32+
val bunch = ggbunch(
33+
listOf(density, boxplot),
34+
regions = listOf(
35+
listOf(0, 0, 0.49, 0.49),
36+
listOf(0.51, 0.51, 0.49, 0.49),
37+
)
38+
)
3139

3240
val spec = bunch.toSpec()
3341

demo/browser/src/main/kotlin/exportSvgDemo/GGBunchSvg.kt

+18-10
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,34 @@
66
package exportSvgDemo
77

88
import BrowserDemoUtil
9-
import org.jetbrains.letsPlot.GGBunch
109
import org.jetbrains.letsPlot.awt.plot.PlotSvgExport
1110
import org.jetbrains.letsPlot.geom.geomBoxplot
1211
import org.jetbrains.letsPlot.geom.geomDensity
12+
import org.jetbrains.letsPlot.ggbunch
1313
import org.jetbrains.letsPlot.letsPlot
14+
import org.jetbrains.letsPlot.themes.elementRect
15+
import org.jetbrains.letsPlot.themes.theme
16+
import org.jetbrains.letsPlot.themes.themeBW
1417
import kotlin.math.abs
1518

1619
@Suppress("DuplicatedCode")
1720
object GGBunchSvg {
1821
@JvmStatic
1922
fun main(args: Array<String>) {
20-
val density = letsPlot(densityData()) + geomDensity(color = "red", alpha = 0.3, size = 5.0) { x = "x" }
21-
val boxplot = letsPlot(boxplotData()) { x = "cat"; y = "val" } + geomBoxplot(outlierColor = "red")
22-
23-
// Create plot spec using lets-plot Kotlin API
24-
val w = 300
25-
val h = 250
26-
val bunch = GGBunch()
27-
bunch.addPlot(density, 0, 0, w, h)
28-
bunch.addPlot(boxplot, w + 10, h + 10, w, h)
23+
val theme = themeBW() + theme(plotBackground = elementRect(size = 1))
24+
val density = letsPlot(densityData()) +
25+
geomDensity(color = "red", alpha = 0.3, size = 5.0) { x = "x" } + theme
26+
val boxplot = letsPlot(boxplotData()) { x = "cat"; y = "val" } +
27+
geomBoxplot(outlierColor = "red") + theme
28+
29+
// Plots in opposite corners
30+
val bunch = ggbunch(
31+
listOf(density, boxplot),
32+
regions = listOf(
33+
listOf(0, 0, 0.49, 0.49),
34+
listOf(0.51, 0.51, 0.49, 0.49),
35+
)
36+
)
2937

3038
val spec = bunch.toSpec()
3139

demo/browser/src/main/kotlin/frontendContextDemo/scripts/GGBunchDemo.kt

+28-25
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,42 @@
66
package frontendContextDemo.scripts
77

88
import frontendContextDemo.ScriptInBrowserContext
9-
import org.jetbrains.letsPlot.GGBunch
109
import org.jetbrains.letsPlot.geom.geomBoxplot
1110
import org.jetbrains.letsPlot.geom.geomDensity
12-
import org.jetbrains.letsPlot.ggsize
11+
import org.jetbrains.letsPlot.ggbunch
1312
import org.jetbrains.letsPlot.letsPlot
13+
import org.jetbrains.letsPlot.themes.elementRect
14+
import org.jetbrains.letsPlot.themes.theme
15+
import org.jetbrains.letsPlot.themes.themeBW
1416
import kotlin.math.abs
1517

1618
object GGBunchDemo {
1719
@JvmStatic
1820
fun main(args: Array<String>) {
19-
ScriptInBrowserContext.eval("GGBunch: Density + Boxplot") {
20-
val density = letsPlot(densityData()) + geomDensity(color = "red", alpha = 0.3, size = 5.0) { x = "x" }
21-
val boxplot = letsPlot(boxplotData()) { x = "cat"; y = "val" } + geomBoxplot(outlierColor = "red")
22-
23-
// set plot size via `addPlot` func param
24-
val w = 300
25-
val h = 250
26-
var bunch = GGBunch()
27-
bunch.addPlot(density, 0, 0, w, h)
28-
bunch.addPlot(boxplot, w + 10, h + 10, w, h)
29-
bunch.show()
30-
31-
// set plot size via `ggsize`
32-
bunch = GGBunch()
33-
bunch.addPlot(density + ggsize(w, h), 0, 0)
34-
bunch.addPlot(boxplot + ggsize(w, h), w + 10, h + 10)
35-
bunch.show()
36-
37-
// default plot sizes
38-
bunch = GGBunch()
39-
bunch.addPlot(density, 0, 0)
40-
bunch.addPlot(boxplot, w + 10, h + 10)
41-
bunch.show()
21+
ScriptInBrowserContext.eval("ggbunch(): Density + Boxplot") {
22+
val theme = themeBW() + theme(plotBackground = elementRect(size = 1))
23+
val density = letsPlot(densityData()) +
24+
geomDensity(color = "red", alpha = 0.3, size = 5.0) { x = "x" } + theme
25+
val boxplot = letsPlot(boxplotData()) { x = "cat"; y = "val" } +
26+
geomBoxplot(outlierColor = "red") + theme
27+
28+
// Plots in opposite corners
29+
ggbunch(
30+
listOf(density, boxplot),
31+
regions = listOf(
32+
listOf(0, 0, 0.49, 0.49),
33+
listOf(0.51, 0.51, 0.49, 0.49),
34+
)
35+
).show()
36+
37+
// Overlapped plots
38+
ggbunch(
39+
listOf(density, boxplot),
40+
regions = listOf(
41+
listOf(0, 0, 0.6, 0.6),
42+
listOf(0.4, 0.4, 0.6, 0.6),
43+
)
44+
).show()
4245
}
4346
}
4447

demo/jvm-batik/src/main/kotlin/frontendContextDemo/scripts/GGBunchDemo.kt

+26-23
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,45 @@
66
package frontendContextDemo.scripts
77

88
import frontendContextDemo.ScriptInBatikContext
9-
import org.jetbrains.letsPlot.GGBunch
109
import org.jetbrains.letsPlot.geom.geomBoxplot
1110
import org.jetbrains.letsPlot.geom.geomDensity
12-
import org.jetbrains.letsPlot.ggsize
11+
import org.jetbrains.letsPlot.ggbunch
1312
import org.jetbrains.letsPlot.letsPlot
13+
import org.jetbrains.letsPlot.themes.elementRect
14+
import org.jetbrains.letsPlot.themes.theme
15+
import org.jetbrains.letsPlot.themes.themeBW
1416
import kotlin.math.abs
1517

1618
object GGBunchDemo {
1719
@JvmStatic
1820
fun main(args: Array<String>) {
1921
ScriptInBatikContext.eval(
20-
"GGBunch: Density + Boxplot",
22+
"ggbunch(): Density + Boxplot",
2123
maxCol = 2
2224
) {
23-
val density = letsPlot(densityData()) + geomDensity(color = "red", alpha = 0.3, size = 5.0) { x = "x" }
24-
val boxplot = letsPlot(boxplotData()) { x = "cat"; y = "val" } + geomBoxplot(outlierColor = "red")
25+
val theme = themeBW() + theme(plotBackground = elementRect(size = 1))
26+
val density = letsPlot(densityData()) +
27+
geomDensity(color = "red", alpha = 0.3, size = 5.0) { x = "x" } + theme
28+
val boxplot = letsPlot(boxplotData()) { x = "cat"; y = "val" } +
29+
geomBoxplot(outlierColor = "red") + theme
2530

26-
// set plot size via `addPlot` func param
27-
val w = 300
28-
val h = 250
29-
var bunch = GGBunch()
30-
bunch.addPlot(density, 0, 0, w, h)
31-
bunch.addPlot(boxplot, w + 10, h + 10, w, h)
32-
bunch.show()
31+
// Plots in opposite corners
32+
ggbunch(
33+
listOf(density, boxplot),
34+
regions = listOf(
35+
listOf(0, 0, 0.49, 0.49),
36+
listOf(0.51, 0.51, 0.49, 0.49),
37+
)
38+
).show()
3339

34-
// set plot size via `ggsize`
35-
bunch = GGBunch()
36-
bunch.addPlot(density + ggsize(w, h), 0, 0)
37-
bunch.addPlot(boxplot + ggsize(w, h), w + 10, h + 10)
38-
bunch.show()
39-
40-
// default plot sizes
41-
bunch = GGBunch()
42-
bunch.addPlot(density, 0, 0)
43-
bunch.addPlot(boxplot, w + 10, h + 10)
44-
bunch.show()
40+
// Overlapped plots
41+
ggbunch(
42+
listOf(density, boxplot),
43+
regions = listOf(
44+
listOf(0, 0, 0.6, 0.6),
45+
listOf(0.4, 0.4, 0.6, 0.6),
46+
)
47+
).show()
4548
}
4649
}
4750

demo/jvm-batik/src/main/kotlin/frontendContextDemo/scripts/ScaleLimitsContinuous.kt

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
package frontendContextDemo.scripts
77

88
import frontendContextDemo.ScriptInBatikContext
9-
import org.jetbrains.letsPlot.GGBunch
109
import org.jetbrains.letsPlot.geom.geomPoint
10+
import org.jetbrains.letsPlot.gggrid
1111
import org.jetbrains.letsPlot.ggsize
1212
import org.jetbrains.letsPlot.letsPlot
1313
import org.jetbrains.letsPlot.scale.scaleColorContinuous
@@ -39,21 +39,20 @@ object ScaleLimitsContinuous {
3939

4040
// Each plot uses different size limits
4141
run {
42-
val b = GGBunch()
43-
.addPlot(p0, 0, 0)
44-
.addPlot(p1, 0, 100)
45-
b.show()
42+
gggrid(listOf(p0, p1), ncol = 1).show()
4643
}
4744

4845
// Both plots use the same size limits
4946
run {
5047
val scales = scaleSize(limits = 0 to 9) +
5148
scaleColorContinuous(limits = 0 to 9) +
5249
scaleXContinuous(limits = 0 to 9)
53-
val b = GGBunch()
54-
.addPlot(p0 + scales, 0, 0)
55-
.addPlot(p1 + scales, 0, 100)
56-
b.show()
50+
gggrid(
51+
listOf(
52+
p0 + scales,
53+
p1 + scales,
54+
), ncol = 1
55+
).show()
5756
}
5857
}
5958
}

demo/jvm-javafx/src/main/kotlin/frontendContextDemo/scripts/GGBunchDemo.kt

+28-25
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,42 @@
66
package frontendContextDemo.scripts
77

88
import frontendContextDemo.ScriptInJfxContext
9-
import org.jetbrains.letsPlot.GGBunch
109
import org.jetbrains.letsPlot.geom.geomBoxplot
1110
import org.jetbrains.letsPlot.geom.geomDensity
12-
import org.jetbrains.letsPlot.ggsize
11+
import org.jetbrains.letsPlot.ggbunch
1312
import org.jetbrains.letsPlot.letsPlot
13+
import org.jetbrains.letsPlot.themes.elementRect
14+
import org.jetbrains.letsPlot.themes.theme
15+
import org.jetbrains.letsPlot.themes.themeBW
1416
import kotlin.math.abs
1517

1618
object GGBunchDemo {
1719
@JvmStatic
1820
fun main(args: Array<String>) {
19-
ScriptInJfxContext.eval("GGBunch: Density + Boxplot", maxCol = 2) {
20-
val density = letsPlot(densityData()) + geomDensity(color = "red", alpha = 0.3, size = 5.0) { x = "x" }
21-
val boxplot = letsPlot(boxplotData()) { x = "cat"; y = "val" } + geomBoxplot(outlierColor = "red")
22-
23-
// set plot size via `addPlot` func param
24-
val w = 300
25-
val h = 250
26-
var bunch = GGBunch()
27-
bunch.addPlot(density, 0, 0, w, h)
28-
bunch.addPlot(boxplot, w + 10, h + 10, w, h)
29-
bunch.show()
30-
31-
// set plot size via `ggsize`
32-
bunch = GGBunch()
33-
bunch.addPlot(density + ggsize(w, h), 0, 0)
34-
bunch.addPlot(boxplot + ggsize(w, h), w + 10, h + 10)
35-
bunch.show()
36-
37-
// default plot sizes
38-
bunch = GGBunch()
39-
bunch.addPlot(density, 0, 0)
40-
bunch.addPlot(boxplot, w + 10, h + 10)
41-
bunch.show()
21+
ScriptInJfxContext.eval("ggbunch(): Density + Boxplot", maxCol = 2) {
22+
val theme = themeBW() + theme(plotBackground = elementRect(size = 1))
23+
val density = letsPlot(densityData()) +
24+
geomDensity(color = "red", alpha = 0.3, size = 5.0) { x = "x" } + theme
25+
val boxplot = letsPlot(boxplotData()) { x = "cat"; y = "val" } +
26+
geomBoxplot(outlierColor = "red") + theme
27+
28+
// Plots in opposite corners
29+
ggbunch(
30+
listOf(density, boxplot),
31+
regions = listOf(
32+
listOf(0, 0, 0.49, 0.49),
33+
listOf(0.51, 0.51, 0.49, 0.49),
34+
)
35+
).show()
36+
37+
// Overlapped plots
38+
ggbunch(
39+
listOf(density, boxplot),
40+
regions = listOf(
41+
listOf(0, 0, 0.6, 0.6),
42+
listOf(0.4, 0.4, 0.6, 0.6),
43+
)
44+
).show()
4245
}
4346
}
4447

plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/GGBunch.kt renamed to plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/GGBunch_old.kt

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import org.jetbrains.letsPlot.intern.toSpec
2323
*
2424
* - [geom_smooth.ipynb](https://nbviewer.org/github/JetBrains/lets-plot-docs/blob/master/source/kotlin_examples/cookbook/geom_smooth.ipynb)
2525
*/
26+
@Deprecated(
27+
message = "Class GGBunch is replaced with function ggbunch()." +
28+
"Please use it to combine several plots into a single figure with custom layout.",
29+
level = DeprecationLevel.WARNING
30+
)
2631
class GGBunch : Figure {
2732
private val items: MutableList<PlotItem> = ArrayList()
2833

0 commit comments

Comments
 (0)