Skip to content

Remove 'static lifetime requirement for Plot.to_inline_html() #115

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

Merged
merged 2 commits into from
Nov 2, 2022
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.8.2] - 2022-11-xx
### Changed
- Refactored the structure of the examples to make them more accessible, whilst adding more examples e.g. for `wasm`.
- [[#113](https://github.com/igiagkiozis/plotly/pull/113)] Refactored the structure of the examples to make them more accessible, whilst adding more examples e.g. for `wasm`.
- [[#115](https://github.com/igiagkiozis/plotly/pull/115)] Simplify the function signature of Plot.to_inline_html() so that it just takes `Option<&str>` as an argument.

## [0.8.1] - 2022-09-25
### Added
Expand Down
14 changes: 5 additions & 9 deletions plotly/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ impl Plot {
///
/// To generate a full, standalone HTML string or file, use `Plot::to_html()` and `Plot::write_html()`,
/// respectively.
pub fn to_inline_html<T: Into<Option<&'static str>>>(&self, plot_div_id: T) -> String {
let plot_div_id = plot_div_id.into();
pub fn to_inline_html(&self, plot_div_id: Option<&str>) -> String {
let plot_div_id = match plot_div_id {
Some(id) => id.to_string(),
None => Alphanumeric.sample_string(&mut thread_rng(), 20),
Expand All @@ -337,7 +336,7 @@ impl Plot {

let tmpl = JupyterNotebookPlotTemplate {
plot: self,
plot_div_id: plot_div_id.as_str(),
plot_div_id: &plot_div_id,
};
tmpl.render().unwrap()
}
Expand Down Expand Up @@ -486,18 +485,15 @@ mod tests {
#[test]
fn test_inline_plot() {
let plot = create_test_plot();
let inline_plot_data = plot.to_inline_html("replace_this_with_the_div_id");
let inline_plot_data = plot.to_inline_html(Some("replace_this_with_the_div_id"));
assert!(inline_plot_data.contains("replace_this_with_the_div_id"));
println!("{}", inline_plot_data);
let random_div_id = plot.to_inline_html(None);
println!("{}", random_div_id);
plot.to_inline_html(None);
}

#[test]
fn test_jupyter_notebook_plot() {
let plot = create_test_plot();
let inline_plot_data = plot.to_jupyter_notebook_html();
println!("{}", inline_plot_data);
plot.to_jupyter_notebook_html();
}

#[test]
Expand Down