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

add show_html(filename) method #217

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading