-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
…ly support for firefox and png at the moment
examples/scatterplot.rs
Outdated
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?; |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
use base64; | ||
use fantoccini::{Client, Locator}; | ||
use retry::{delay::Fixed, retry, OperationResult}; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@@ -115,7 +123,86 @@ impl Procyon { | |||
|
|||
new | |||
} | |||
|
|||
/// save the image |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
let _format = &image_data_url[11..14]; | ||
let bytes: Vec<u8> = base64::decode(&image_data_url[22..]).unwrap(); |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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 svg
format
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
This is a first working solution but it still need a lot a work. It will address the issue #2