@@ -131,7 +131,7 @@ fun ggsave(
131
131
val svg = PlotSvgExport .buildSvgImageFromRawSpecs(
132
132
spec,
133
133
plotSize = plotSize,
134
- sizeUnit = sizeUnit? : PlotExportCommon .SizeUnit .PX ,
134
+ sizeUnit = sizeUnit ? : PlotExportCommon .SizeUnit .PX ,
135
135
)
136
136
if (file.notExists()) {
137
137
file.createFile()
@@ -192,6 +192,22 @@ private fun exportRasterImage(
192
192
unit : PlotExportCommon .SizeUnit ? = null,
193
193
targetDPI : Number ? = null
194
194
) {
195
+ // As of lets-plot version 4.7.2
196
+ // PlotImageExport calls SwingUtilities.invokeAndWait().
197
+ // Check if Swing is present.
198
+ try {
199
+ Class .forName(" javax.swing.SwingUtilities" )
200
+ } catch (e: ClassNotFoundException ) {
201
+ throw IllegalStateException (
202
+ """
203
+
204
+ Can't export plot to raster formats: Swing is not available in this environment.
205
+ Raster image export requires SwingUtilities which is not present in Android JRE or headless environments.
206
+ """ .trimIndent()
207
+ )
208
+ }
209
+
210
+
195
211
// lets-plot-image-export.jar might not be present in the classpath.
196
212
val imageBytes: ByteArray = try {
197
213
@@ -220,7 +236,12 @@ private fun exportRasterImage(
220
236
"""
221
237
222
238
Can't export plot to raster formats: ${e::class .simpleName} "${e.message} ".
223
- Please add "lets-plot-image-export-<version>.jar" to your classpath.
239
+ Please add "lets-plot-image-export-<version>.jar" to your classpath.
240
+ A Gradle dependency example:
241
+
242
+ implementation("org.jetbrains.lets-plot:lets-plot-image-export:<version>")
243
+
244
+ where <version> is the version of the Lets-Plot Multiplatform artifact you are using.
224
245
""" .trimIndent()
225
246
)
226
247
0 commit comments