Skip to content

Commit

Permalink
add show_html(filename) method (#217)
Browse files Browse the repository at this point in the history
* update contributing file with new contact details

Signed-off-by: Andrei Gherghescu <[email protected]>

* provide alternative show_html method

 - the show() method by default creates a random named file in `/tmp`
   dir, however in some cases `/tmp` is not available, e.g., snap's Firefox
   runs in an isolated enviroment and cannot access the system's `/tmp`
 - provide a method that calls write_html followed by show for easier
   access

Closes #170

Signed-off-by: Andrei Gherghescu <[email protected]>

* fix clippy & fmt warnings

Signed-off-by: Andrei Gherghescu <[email protected]>

* revert CI clippy darling package command patch

 - temporary patch introduced in
   3130f5a to bypass clippy errors
   due to darling package: TedDriggs/darling#296

Closes #210

Signed-off-by: Andrei Gherghescu <[email protected]>

---------

Signed-off-by: Andrei Gherghescu <[email protected]>
  • Loading branch information
andrei-ng authored Jul 31, 2024
1 parent 2ab92bf commit 4e47e85
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 29 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ jobs:
components: clippy
targets: wasm32-unknown-unknown
# lint the main library workspace excluding the wasm feature
# Rust 1.79 generates a new lint in autogenerated code:
# Added clippy allow at the command line until it is fixed. See: https://github.com/rust-lang/rust-clippy/issues/12643 and https://github.com/TedDriggs/darling/issues/293
- run: cargo clippy --features plotly_ndarray,plotly_image,kaleido -- -D warnings -Aclippy::manual_unwrap_or_default
- run: cargo clippy --features plotly_ndarray,plotly_image,kaleido -- -D warnings
# lint the plotly library with wasm enabled
- run: cargo clippy --package plotly --features wasm --target wasm32-unknown-unknown -- -D warnings -Aclippy::manual_unwrap_or_default
- run: cargo clippy --package plotly --features wasm --target wasm32-unknown-unknown -- -D warnings
# lint the non-wasm examples
- run: cd ${{ github.workspace }}/examples && cargo clippy --workspace --exclude "wasm*" -- -D warnings -Aclippy::manual_unwrap_or_default
- run: cd ${{ github.workspace }}/examples && cargo clippy --workspace --exclude "wasm*" -- -D warnings
# lint the wasm examples
- run: cd ${{ github.workspace }}/examples && cargo clippy --target wasm32-unknown-unknown --package "wasm*" -- -Aclippy::manual_unwrap_or_default
- run: cd ${{ github.workspace }}/examples && cargo clippy --target wasm32-unknown-unknown --package "wasm*"

semver:
name: semver
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ When your contribution is ready for review, make a pull request with your change

## Code of Conduct

In all forums, we follow the [Rust Code of Conduct]. For escalation or moderation issues please contact Ioannis ([email protected]) instead of the Rust moderation team.
In all forums, we follow the [Rust Code of Conduct]. For escalation or moderation issues please reach out to @andrei-ng or the Plotly official community at [[email protected]](mailto:[email protected]) instead of the Rust moderation team.

[Rust Code of Conduct]: https://www.rust-lang.org/conduct.html

Expand Down
16 changes: 15 additions & 1 deletion plotly/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ impl Plot {
Plot::show_with_default_app(temp_path);
}

/// Display the fully rendered HTML `Plot` in the default system browser.
///
/// The HTML file is generated and saved in the provided filename as long as
/// the path already exists, after the file is saved, it is read and
/// displayed by the browser.
#[cfg(not(target_family = "wasm"))]
pub fn show_html<P: AsRef<Path> + std::clone::Clone>(&self, filename: P) {
let path = filename.as_ref().to_str().unwrap();
self.write_html(filename.clone());
// Hand off the job of opening the browser to an OS-specific implementation.
Plot::show_with_default_app(path);
}

/// Display the fully rendered `Plot` as a static image of the given format
/// in the default system browser.
#[cfg(not(target_family = "wasm"))]
Expand Down Expand Up @@ -311,7 +324,8 @@ impl Plot {
pub fn write_html<P: AsRef<Path>>(&self, filename: P) {
let rendered = self.to_html();

let mut file = File::create(filename).unwrap();
let mut file =
File::create(filename).expect("Provided filepath does not exist or is not accessible");
file.write_all(rendered.as_bytes())
.expect("failed to write html output");
file.flush().unwrap();
Expand Down
12 changes: 5 additions & 7 deletions plotly/src/traces/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,13 @@ where
/// `ndarray` feature.
///
/// # Arguments
/// * `x` - One dimensional array (or view) that represents the
/// `x` axis coordinates.
/// * `x`- One dimensional array (or view) that represents the `x` axis
/// coordinates.
/// * `traces_matrix` - Two dimensional array (or view) containing the `y`
/// axis coordinates of
/// the traces.
/// axis coordinates of the traces.
/// * `array_traces` - Determines whether the traces are arranged in the
/// matrix over the
/// columns (`ArrayTraces::OverColumns`) or over the rows
/// (`ArrayTraces::OverRows`).
/// matrix over the columns (`ArrayTraces::OverColumns`) or over the rows
/// (`ArrayTraces::OverRows`).
///
/// # Examples
///
Expand Down
12 changes: 5 additions & 7 deletions plotly/src/traces/scatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,13 @@ where
/// indexed by `x`. This function requires the `ndarray` feature.
///
/// # Arguments
/// * `x` - One dimensional array (or view) that represents the
/// `x` axis coordinates.
/// * `x`- One dimensional array (or view) that represents the `x` axis
/// coordinates.
/// * `traces_matrix` - Two dimensional array (or view) containing the `y`
/// axis coordinates of
/// the traces.
/// axis coordinates of the traces.
/// * `array_traces` - Determines whether the traces are arranged in the
/// matrix over the
/// columns (`ArrayTraces::OverColumns`) or over the rows
/// (`ArrayTraces::OverRows`).
/// matrix over the columns (`ArrayTraces::OverColumns`) or over the rows
/// (`ArrayTraces::OverRows`).
///
/// # Examples
///
Expand Down
12 changes: 5 additions & 7 deletions plotly/src/traces/scatter_polar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,13 @@ where
/// `ndarray` feature.
///
/// # Arguments
/// * `x` - One dimensional array (or view) that represents the
/// `x` axis coordinates.
/// * `x` - One dimensional array (or view) that represents the `x` axis
/// coordinates.
/// * `traces_matrix` - Two dimensional array (or view) containing the `y`
/// axis coordinates of
/// the traces.
/// axis coordinates of the traces.
/// * `array_traces` - Determines whether the traces are arranged in the
/// matrix over the
/// columns (`ArrayTraces::OverColumns`) or over the rows
/// (`ArrayTraces::OverRows`).
/// matrix over the columns (`ArrayTraces::OverColumns`) or over the rows
/// (`ArrayTraces::OverRows`).
///
/// # Examples
///
Expand Down

0 comments on commit 4e47e85

Please sign in to comment.