Skip to content

Commit

Permalink
try macos kaleido
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Gherghescu <[email protected]>
  • Loading branch information
andrei-ng committed Dec 20, 2024
1 parent 45c1b05 commit ecce533
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
27 changes: 18 additions & 9 deletions plotly/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ impl PartialEq for Plot {
mod tests {
use std::path::PathBuf;

use base64::{engine::general_purpose, Engine as _};
use serde_json::{json, to_value};

use super::*;
Expand Down Expand Up @@ -748,7 +749,7 @@ mod tests {
assert!(!dst.exists());
}

#[cfg(target_os = "linux")]
// #[cfg(not(target_os = "macos"))]
#[test]
#[cfg(feature = "kaleido")]
fn test_save_to_png() {
Expand All @@ -760,19 +761,21 @@ mod tests {
assert!(!dst.exists());
}

#[cfg(target_os = "linux")]
// #[cfg(not(target_os = "macos"))]
#[test]
#[cfg(feature = "kaleido")]
fn test_save_to_jpeg() {
let plot = create_test_plot();
let dst = PathBuf::from("example.jpeg");
plot.write_image(&dst, ImageFormat::JPEG, 1024, 680, 1.0);
assert!(dst.exists());
let imgSize = std::fs::metadata("example.jpeg").unwrap().len();
dbg!(imgSize);
assert!(!dst.exists());
assert!(std::fs::remove_file(&dst).is_ok());
assert!(!dst.exists());
}

#[cfg(target_os = "linux")]
// #[cfg(not(target_os = "macos"))]
#[test]
#[cfg(feature = "kaleido")]
fn test_save_to_svg() {
Expand All @@ -796,7 +799,7 @@ mod tests {
assert!(!dst.exists());
}

#[cfg(target_os = "linux")]
// #[cfg(not(target_os = "macos"))]
#[test]
#[cfg(feature = "kaleido")]
fn test_save_to_pdf() {
Expand All @@ -820,16 +823,18 @@ mod tests {
assert!(!dst.exists());
}

#[cfg(target_os = "linux")]
#[test]
#[ignore] // Fails in the CI
// #[cfg(not(target_os = "macos"))]
#[cfg(feature = "kaleido")]
fn test_image_to_base64() {
use base64::engine::general_purpose;
use base64::Engine;
let plot = create_test_plot();

let image_base64 = plot.to_base64(ImageFormat::PNG, 200, 150, 1.0);

std::thread::sleep(std::time::Duration::from_secs(2));

dbg!(&image_base64);
assert!(!image_base64.is_empty());

let result_decoded = general_purpose::STANDARD.decode(image_base64).unwrap();
Expand All @@ -850,13 +855,17 @@ mod tests {
assert!(image_base64.is_empty());
}

#[cfg(target_os = "linux")]
#[test]
#[ignore] // Fails in the CI
#[cfg(not(target_os = "macos"))]
#[cfg(feature = "kaleido")]
fn test_image_to_svg_string() {
let plot = create_test_plot();
let image_svg = plot.to_svg(200, 150, 1.0);

std::thread::sleep(std::time::Duration::from_secs(2));
dbg!(&image_svg);

assert!(!image_svg.is_empty());

let expected = "<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"150\" style=\"\" viewBox=\"0 0 200 150\"><rect x=\"0\" y=\"0\" width=\"200\" height=\"150\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-2dc70a\"><g class=\"clips\"><clipPath id=\"clip2dc70axyplot\" class=\"plotclip\"><rect width=\"40\" height=\"2\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2dc70ax\"><rect x=\"80\" y=\"0\" width=\"40\" height=\"150\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2dc70ay\"><rect x=\"0\" y=\"82\" width=\"200\" height=\"2\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2dc70axy\"><rect x=\"80\" y=\"82\" width=\"40\" height=\"2\"/></clipPath></g><g class=\"gradients\"/></defs><g class=\"bglayer\"/><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(100,0)\" d=\"M0,82v2\" style=\"stroke: rgb(238, 238, 238); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(114.25,0)\" d=\"M0,82v2\" style=\"stroke: rgb(238, 238, 238); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"/></g><g class=\"zerolinelayer\"><path class=\"xzl zl crisp\" transform=\"translate(85.75,0)\" d=\"M0,82v2\" style=\"stroke: rgb(68, 68, 68); stroke-opacity: 1; stroke-width: 1px;\"/></g><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(80,82)\" clip-path=\"url('#clip2dc70axyplot')\"><g class=\"scatterlayer mlayer\"><g class=\"trace scatter trace86f735\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"><path class=\"js-line\" d=\"M5.75,1L20,0L34.25,2\" style=\"vector-effect: non-scaling-stroke; fill: none; stroke: rgb(31, 119, 180); stroke-opacity: 1; stroke-width: 2px; opacity: 1;\"/></g><g class=\"points\"><path class=\"point\" transform=\"translate(5.75,1)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(20,0)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(34.25,2)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/></g><g class=\"text\"/></g></g></g><g class=\"overplot\"/><path class=\"xlines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><path class=\"ylines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><g class=\"overlines-above\"/><g class=\"xaxislayer-above\"><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"97\" transform=\"translate(85.75,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">0</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"97\" transform=\"translate(100,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">1</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"97\" transform=\"translate(114.25,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">2</text></g></g><g class=\"yaxislayer-above\"><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,84)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">2</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,83.5)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">4</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,83)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">6</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,82.5)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">8</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,82)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">10</text></g></g><g class=\"overaxes-above\"/></g></g><g class=\"polarlayer\"/><g class=\"ternarylayer\"/><g class=\"geolayer\"/><g class=\"funnelarealayer\"/><g class=\"pielayer\"/><g class=\"treemaplayer\"/><g class=\"sunburstlayer\"/><g class=\"glimages\"/><defs id=\"topdefs-2dc70a\"><g class=\"clips\"/></defs><g class=\"layer-above\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"infolayer\"><g class=\"g-gtitle\"/><g class=\"g-xtitle\"/><g class=\"g-ytitle\"/></g></svg>";
Expand Down
13 changes: 8 additions & 5 deletions plotly_kaleido/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ impl Kaleido {
"--disable-dev-shm-usage",
"--disable-software-rasterizer",
"--single-process",
"--disable-gpu-driver-bug-workarounds",
"--disable-gpu-driver-workarounds",
"--disable-gpu-vsync",
])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
Expand Down Expand Up @@ -297,7 +300,7 @@ mod tests {
}

// This seems to fail unpredictably on MacOs.
#[cfg(target_os = "linux")]
#[cfg(not(target_os = "macos"))]
#[test]
fn test_save_png() {
let test_plot = create_test_plot();
Expand All @@ -309,7 +312,7 @@ mod tests {
}

// This seems to fail unpredictably on MacOs.
#[cfg(target_os = "linux")]
#[cfg(not(target_os = "macos"))]
#[test]
fn test_save_jpeg() {
let test_plot = create_test_plot();
Expand All @@ -321,7 +324,7 @@ mod tests {
}

// This seems to fail unpredictably on MacOs.
#[cfg(target_os = "linux")]
#[cfg(not(target_os = "macos"))]
#[test]
fn test_save_webp() {
let test_plot = create_test_plot();
Expand All @@ -333,7 +336,7 @@ mod tests {
}

// This seems to fail unpredictably on MacOs.
#[cfg(target_os = "linux")]
#[cfg(not(target_os = "macos"))]
#[test]
fn test_save_svg() {
let test_plot = create_test_plot();
Expand All @@ -345,7 +348,7 @@ mod tests {
}

// This seems to fail unpredictably on MacOs.
#[cfg(target_os = "linux")]
#[cfg(not(target_os = "macos"))]
#[test]
fn test_save_pdf() {
let test_plot = create_test_plot();
Expand Down

0 comments on commit ecce533

Please sign in to comment.