@@ -20,17 +20,22 @@ private const val DEF_EXPORT_DIR = "lets-plot-images"
20
20
21
21
/* *
22
22
* Exports plot to a file.
23
- * Supported formats: SVG, HTML, PNG, JPEG and TIFF.
23
+ * Supported formats: SVG, HTML, PNG, JPEG, and TIFF.
24
24
* Note: in some configurations raster formats might not be supported.
25
25
*
26
26
* If `path` is not specified, the output file will be saved in
27
27
* `${user.dir}/lets-plot-images`.
28
28
*
29
29
* ## Notes
30
30
*
31
+ * Large plot dimensions without units require explicit unit specification.
32
+ * When `w` or `h` value exceeds 20 without specifying units (e.g., `ggsave(p, 300, 400)`),
33
+ * we ask to specify units explicitly:
34
+ * `ggsave(p, 300, 400, unit='px')` or `ggsave(p, 3, 4, unit='in')`.
35
+ *
31
36
* The output format is inferred from the file extension.
32
37
*
33
- * **For PNG and PDF:**
38
+ * **For PNG and PDF: **
34
39
*
35
40
* - If `w`, `h`, `unit`, and `dpi` are all specified:
36
41
*
@@ -54,14 +59,14 @@ private const val DEF_EXPORT_DIR = "lets-plot-images"
54
59
* - The plot maintains its aspect ratio, preserving layout, tick labels, and other visual elements.
55
60
* - Useful for generating high-resolution images suitable for publication.
56
61
*
57
- * **For SVG:**
62
+ * **For SVG: **
58
63
*
59
64
* - If `w`, `h`, and `unit` are specified:
60
65
*
61
66
* - The plot's pixel size (default or set via [ggsize()][org.jetbrains.letsPlot.ggsize]) is ignored.
62
67
* - The output size is set from the given values.
63
68
*
64
- * **For HTML:**
69
+ * **For HTML: **
65
70
*
66
71
* - If `w` and `h` are specified:
67
72
*
@@ -192,22 +197,21 @@ private fun exportRasterImage(
192
197
unit : PlotExportCommon .SizeUnit ? = null,
193
198
targetDPI : Number ? = null
194
199
) {
195
- // As of lets-plot version 4.7.2
196
- // PlotImageExport calls SwingUtilities.invokeAndWait().
197
- // Check if Swing is present.
200
+ // As of lets-plot version 4.7.3
201
+ // PlotImageExport uses java.awt.image.BufferedImage
202
+ // Check if java.awt is present.
198
203
try {
199
- Class .forName(" javax.swing.SwingUtilities " )
204
+ Class .forName(" java.awt.image.BufferedImage " )
200
205
} catch (e: ClassNotFoundException ) {
201
206
throw IllegalStateException (
202
207
"""
203
208
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.
209
+ Can't export plot to raster formats: 'java.awt.image.BufferedImage' is not available in this environment.
210
+ Raster image export requires 'java.awt.image.BufferedImage' which is not present in Android JRE or headless environments.
206
211
""" .trimIndent()
207
212
)
208
213
}
209
214
210
-
211
215
// lets-plot-image-export.jar might not be present in the classpath.
212
216
val imageBytes: ByteArray = try {
213
217
0 commit comments