Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save chart as a png #3

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

save chart as a png #3

wants to merge 2 commits into from

Conversation

ThomAub
Copy link
Contributor

@ThomAub ThomAub commented Apr 30, 2020

This is a first working solution but it still need a lot a work. It will address the issue #2

…ly support for firefox and png at the moment
@ThomAub ThomAub requested review from mockersf and davidB April 30, 2020 15:00
@ThomAub ThomAub marked this pull request as draft April 30, 2020 15:00
@ThomAub ThomAub self-assigned this Apr 30, 2020
@ThomAub ThomAub added the enhancement New feature or request label Apr 30, 2020
let chart = Procyon::chart(
"https://raw.githubusercontent.com/procyon-rs/vega_lite_4.rs/master/examples/res/data/clustered_data.csv"
)
.mark_point()
.encode_axis("x", "y").encode_color("cluster")
.build();
.save(Path::new("/Users/aubrythomas/src/personal-git/procyon-rs/procyon/image.png")).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should add a new example instead of modifying an existing one...
and this path won't work...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes there will be scatterplot ans save_png

#![deny(
warnings,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing warning is ok while under dev, please don't commit it

src/lib.rs Outdated
Comment on lines 17 to 19
use base64;
use fantoccini::{Client, Locator};
use retry::{delay::Fixed, retry, OperationResult};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also commit the cargo.toml changes for those dependencies

Copy link
Contributor Author

@ThomAub ThomAub May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but also remember to update the Cargo.toml to point to the pending PR#15 in showata if you want to try locally

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated
@@ -115,7 +123,86 @@ impl Procyon {

new
}

/// save the image
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not enough as doc, it should mention that this methods needs gecko driver to be in path, firefox installed, the errors that can be thrown, and what the user can expect to happen when calling this method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I will add a bit more doc ;) let's discuss on the format of the doc because i'm not sure how to list all possible errors and all.

src/lib.rs Outdated
caps.insert("moz:firefoxOptions".to_string(), opts);

let mut connection_ok = false;
while !connection_ok {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may be an infinite loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the crate retry and retry_futur.
What do you think of it ?

src/lib.rs Outdated
caps.insert("moz:firefoxOptions".to_string(), opts);
let mut connection_ok = Client::with_capabilities("http://localhost:4444", caps)
.await
.is_err();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of success, the client established is thrown away, does this have side effects?

src/lib.rs Outdated
let mut connection_ok = Client::with_capabilities("http://localhost:4444", caps)
.await
.is_err();
if connection_ok == false {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should avoid a bool variable used in a if == a bool, and using negative as it degrades readability

if Client::with_capabilities("http://localhost:4444", caps).await.is_ok() {
    break;
}

does the same thing

src/lib.rs Outdated
))
.await?;
// c.goto("file:///private/var/folders/32/h6lt_67s75g6jf3h4hx_myxc0000gn/T/showata/show-1587655243189631000.html").await?;
let mut summary_button = c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the click method returns the client and not the element, you should just reassign it to c

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was to help with the understanding of the navigation when debugging. Final version can have Client only.

src/lib.rs Outdated
Comment on lines 198 to 199
let _format = &image_data_url[11..14];
let bytes: Vec<u8> = base64::decode(&image_data_url[22..]).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if it's worth the cost, but there is a crate to parse data url : https://crates.io/crates/data-url
instead of magic numbers...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't like magic numbers 😄 I will look into it ans see if i can help for svgformat

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to introduce a crate just for that, but you can replace the magic number by the "formula" used to compute eg: something like "data:".length

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw you comment a bit late. Current version of the code use DataUrl but we can discuss about it.

src/lib.rs Outdated

let mut connection_ok = false;
while !connection_ok {
thread::sleep(time::Duration::from_secs(5));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, unfortunately, means that there is no way to wait less than 5 seconds to save a plot.
Maybe start with a much smaller delay and then exponentially backoff.

Maybe it is worth splitting the method of creating a headless Browser, for instance Chromium or Firefox, from creating and storing plots in the instance.

By doing this, users can decide to call a method that first starts the Browser and then saves the plot and tears down the Browser, or to keep the instance alive and reuse it.

Of course, this looks like a future task.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will split it now because it will add readability and we can talk more specifically about this function signature and possible use.

…s with and used crate retry to handle the retry loop. Now use DataUrl to parse url content. Added save_png as a new example and added cargo.toml
/// The chrome case will be commented for now and will be tested later.str
/// It also need the port from the webdriver.
pub async fn create_headless_client(
client_type: &str,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be an enum that would force user to specify a supported browser instead of a free string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants