@@ -185,20 +185,34 @@ impl Kaleido {
185
185
) -> Result < String , Box < dyn std:: error:: Error > > {
186
186
let p = self . cmd_path . to_str ( ) . unwrap ( ) ;
187
187
188
+ #[ cfg( not( target_os = "macos" ) ) ]
189
+ let cmd_args = vec ! [
190
+ "plotly" ,
191
+ "--disable-gpu" ,
192
+ "--allow-file-access-from-files" ,
193
+ "--disable-breakpad" ,
194
+ "--disable-dev-shm-usage" ,
195
+ "--disable-software-rasterizer" ,
196
+ "--single-process" ,
197
+ "--no-sandbox" ,
198
+ ] ;
199
+
200
+ // Add Kaleido issue #323
201
+ #[ cfg( target_os = "macos" ) ]
202
+ let cmd_args = vec ! [
203
+ "plotly" ,
204
+ "--allow-file-access-from-files" ,
205
+ "--disable-breakpad" ,
206
+ "--disable-dev-shm-usage" ,
207
+ "--disable-software-rasterizer" ,
208
+ "--single-process" ,
209
+ "--no-sandbox" ,
210
+ ] ;
211
+
188
212
#[ allow( clippy:: zombie_processes) ]
189
213
let mut process = Command :: new ( p)
190
214
. current_dir ( self . cmd_path . parent ( ) . unwrap ( ) )
191
- . args ( [
192
- "plotly" ,
193
- "--disable-gpu" ,
194
- "--allow-file-access-from-files" ,
195
- "--disable-breakpad" ,
196
- "--disable-dev-shm-usage" ,
197
- "--disable-software-rasterizer" ,
198
- "--single-process" ,
199
- "--disable-gpu" ,
200
- "--no-sandbox" ,
201
- ] )
215
+ . args ( cmd_args)
202
216
. stdin ( Stdio :: piped ( ) )
203
217
. stdout ( Stdio :: piped ( ) )
204
218
. stderr ( Stdio :: piped ( ) )
@@ -213,7 +227,6 @@ impl Kaleido {
213
227
. to_string( )
214
228
)
215
229
} ) ;
216
-
217
230
{
218
231
let plot_data = PlotData :: new ( plotly_data, format, width, height, scale) . to_json ( ) ;
219
232
let mut process_stdin = process. stdin . take ( ) . unwrap ( ) ;
@@ -287,6 +300,47 @@ mod tests {
287
300
. unwrap ( )
288
301
}
289
302
303
+ #[ cfg( target_os = "macos" ) ]
304
+ fn create_test_surface ( ) -> Value {
305
+ to_value ( json ! ( {
306
+ "data" : [
307
+ {
308
+ "name" : "Surface" ,
309
+ "type" : "surface" ,
310
+ "x" : [
311
+ 1.0 ,
312
+ 2.0 ,
313
+ 3.0
314
+ ] ,
315
+ "y" : [
316
+ 4.0 ,
317
+ 5.0 ,
318
+ 6.0
319
+ ] ,
320
+ "z" : [
321
+ [
322
+ 1.0 ,
323
+ 2.0 ,
324
+ 3.0
325
+ ] ,
326
+ [
327
+ 4.0 ,
328
+ 5.0 ,
329
+ 6.0
330
+ ] ,
331
+ [
332
+ 7.0 ,
333
+ 8.0 ,
334
+ 9.0
335
+ ]
336
+ ]
337
+ }
338
+ ] ,
339
+ "layout" : { }
340
+ } ) )
341
+ . unwrap ( )
342
+ }
343
+
290
344
#[ test]
291
345
fn can_find_kaleido_executable ( ) {
292
346
let _k = Kaleido :: new ( ) ;
@@ -378,4 +432,76 @@ mod tests {
378
432
assert ! ( r. is_ok( ) ) ;
379
433
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
380
434
}
435
+
436
+ // Issue #241 workaround until https://github.com/plotly/Kaleido/issues/323 is resolved
437
+ #[ cfg( target_os = "macos" ) ]
438
+ #[ test]
439
+ fn save_surface_png ( ) {
440
+ let test_plot = create_test_surface ( ) ;
441
+ let k = Kaleido :: new ( ) ;
442
+ let dst = PathBuf :: from ( "example.png" ) ;
443
+ let r = k. save ( dst. as_path ( ) , & test_plot, "png" , 1200 , 900 , 4.5 ) ;
444
+ assert ! ( r. is_ok( ) ) ;
445
+ assert ! ( dst. exists( ) ) ;
446
+ let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
447
+ let file_size = metadata. len ( ) ;
448
+ assert ! ( file_size > 0 , ) ;
449
+ assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
450
+ }
451
+ #[ cfg( target_os = "macos" ) ]
452
+ #[ test]
453
+ fn save_surface_jpeg ( ) {
454
+ let test_plot = create_test_surface ( ) ;
455
+ let k = Kaleido :: new ( ) ;
456
+ let dst = PathBuf :: from ( "example.jpeg" ) ;
457
+ let r = k. save ( dst. as_path ( ) , & test_plot, "jpeg" , 1200 , 900 , 4.5 ) ;
458
+ assert ! ( r. is_ok( ) ) ;
459
+ assert ! ( dst. exists( ) ) ;
460
+ let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
461
+ let file_size = metadata. len ( ) ;
462
+ assert ! ( file_size > 0 , ) ;
463
+ assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
464
+ }
465
+ #[ cfg( target_os = "macos" ) ]
466
+ #[ test]
467
+ fn save_surface_webp ( ) {
468
+ let test_plot = create_test_surface ( ) ;
469
+ let k = Kaleido :: new ( ) ;
470
+ let dst = PathBuf :: from ( "example.webp" ) ;
471
+ let r = k. save ( dst. as_path ( ) , & test_plot, "webp" , 1200 , 900 , 4.5 ) ;
472
+ assert ! ( r. is_ok( ) ) ;
473
+ assert ! ( dst. exists( ) ) ;
474
+ let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
475
+ let file_size = metadata. len ( ) ;
476
+ assert ! ( file_size > 0 , ) ;
477
+ assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
478
+ }
479
+ #[ cfg( target_os = "macos" ) ]
480
+ #[ test]
481
+ fn save_surface_svg ( ) {
482
+ let test_plot = create_test_surface ( ) ;
483
+ let k = Kaleido :: new ( ) ;
484
+ let dst = PathBuf :: from ( "example.svg" ) ;
485
+ let r = k. save ( dst. as_path ( ) , & test_plot, "svg" , 1200 , 900 , 4.5 ) ;
486
+ assert ! ( r. is_ok( ) ) ;
487
+ assert ! ( dst. exists( ) ) ;
488
+ let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
489
+ let file_size = metadata. len ( ) ;
490
+ assert ! ( file_size > 0 , ) ;
491
+ assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
492
+ }
493
+ #[ cfg( target_os = "macos" ) ]
494
+ #[ test]
495
+ fn save_surface_pdf ( ) {
496
+ let test_plot = create_test_surface ( ) ;
497
+ let k = Kaleido :: new ( ) ;
498
+ let dst = PathBuf :: from ( "example.pdf" ) ;
499
+ let r = k. save ( dst. as_path ( ) , & test_plot, "pdf" , 1200 , 900 , 4.5 ) ;
500
+ assert ! ( r. is_ok( ) ) ;
501
+ assert ! ( dst. exists( ) ) ;
502
+ let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
503
+ let file_size = metadata. len ( ) ;
504
+ assert ! ( file_size > 0 , ) ;
505
+ assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
506
+ }
381
507
}
0 commit comments