Skip to content

Commit a21da1f

Browse files
jqnatividadclaude
andcommitted
Fix pedantic doc/lazy-static lints and add_frames duplication
Address clippy::missing_panics_doc, missing_errors_doc, doc_markdown, non_std_lazy_statics and cargo::redundant_homepage: - Add `# Errors` / `# Panics` sections to public fallible APIs, including the wasm-only bindings and callbacks. - Backtick identifiers in docs and fix unbalanced backticks; add clippy.toml whitelisting WebDriver, MapLibre, GeoJSON, MathJax and ModeBar as product names. - Switch theme statics to std::sync::LazyLock and drop once_cell. - Remove `homepage` fields duplicating `repository`. Also fix Plot::add_frames adding every frame twice when the plot had no frames yet, with a regression test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ea7c2bf commit a21da1f

31 files changed

Lines changed: 266 additions & 88 deletions

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ This is the last release bundling plotly.js 3.x; the upgrade to plotly.js 4.x is
3131
- `plotly_static` bumped to 0.2.0 (breaking: `ImageFormat::EPS` removed)
3232
- Bump `darling` to 0.24 and `syn` to 3 in `plotly_derive`, and `dirs` to 7 in `plotly_static`
3333
- Bump example dependencies: `reqwest` 0.13, `env_logger` 0.11, `itertools` 0.15, `ndarray` 0.17, `rand`/`rand_chacha` 0.10
34+
- Theme statics in `plotly::layout::themes` (`DEFAULT`, `PLOTLY_WHITE`, `PLOTLY_DARK`, …) are now `std::sync::LazyLock<Template>` instead of `once_cell::sync::Lazy<Template>`; the `once_cell` dependency is dropped. Code that only dereferences them is unaffected
35+
- Add `# Errors`/`# Panics` sections to public fallible APIs and tidy doc formatting (clippy `missing_errors_doc`, `missing_panics_doc`, `doc_markdown`)
3436

3537
### Removed
3638

3739
- The deprecated Kaleido static export backend: the `plotly_kaleido` crate is no longer part of the workspace, and the `kaleido` and `kaleido_download` features are gone. Use the `static_export_*` features (`plotly_static`) instead
3840
- The deprecated `ImageFormat::EPS` variant. Use `ImageFormat::SVG` or `ImageFormat::PDF` for vector output
3941

42+
### Fixed
43+
44+
- `Plot::add_frames` no longer adds every frame twice when the plot has no frames yet
45+
4046
### Security
4147

4248
- Remove the unused `zip` build-dependency from `plotly_static`; with `plotly_kaleido` gone, no workspace crate depends on `zip` directly

‎clippy.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
doc-valid-idents = ["WebDriver", "MapLibre", "GeoJSON", "MathJax", "ModeBar", ".."]

‎plotly/Cargo.toml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ authors = [
88
]
99
license = "MIT"
1010
readme = "../README.md"
11-
homepage = "https://github.com/plotly/plotly.rs"
1211
documentation = "https://docs.rs/plotly"
1312
repository = "https://github.com/plotly/plotly.rs"
1413
edition = "2021"
@@ -57,7 +56,6 @@ image = { version = "0.25", optional = true }
5756
plotly_derive = { version = "0.15", path = "../plotly_derive" }
5857
plotly_static = { version = "0.2", path = "../plotly_static", optional = true }
5958
ndarray = { version = "0.17", optional = true }
60-
once_cell = "1"
6159
serde = { version = "1.0", features = ["derive"] }
6260
serde_json = "1.0"
6361
serde_repr = "0.1"

‎plotly/src/bindings.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ extern "C" {
2222
/// The function signature is slightly constrained in that `id` is a `&str`
2323
/// which represents the `id` of an existing HTML `div` element, rather than
2424
/// also allowing an instance of a `div` element, itself.
25+
///
26+
/// # Panics
27+
///
28+
/// Panics if plotly.js rejects the plot (e.g. no element with the given `id`
29+
/// exists).
2530
pub async fn new_plot(id: &str, plot: &Plot) {
2631
let plot_obj = &plot.to_js_object();
2732

@@ -37,6 +42,11 @@ pub async fn new_plot(id: &str, plot: &Plot) {
3742
/// The function signature is slightly constrained in that `id` is a `&str`
3843
/// which represents the `id` of an existing HTML `div` element, rather than
3944
/// also allowing an instance of a `div` element, itself.
45+
///
46+
/// # Panics
47+
///
48+
/// Panics if plotly.js rejects the plot (e.g. no element with the given `id`
49+
/// exists).
4050
pub async fn react(id: &str, plot: &Plot) {
4151
let plot_obj = &plot.to_js_object();
4252

‎plotly/src/callbacks.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ extern "C" {
5757
/// web_sys::console::log_1(&format!("{:?}", evt).into());
5858
/// });
5959
/// ```
60+
///
61+
/// # Panics
62+
///
63+
/// Panics if no element with the given `div_id` exists. The registered
64+
/// listener panics if a click event cannot be deserialized into
65+
/// `ClickEvent`.
6066
pub fn bind_click<F>(div_id: &str, mut cb: F)
6167
where
6268
F: 'static + FnMut(ClickEvent),

‎plotly/src/common/color.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ impl Color for i16 {}
4949
impl Color for i8 {}
5050
impl Color for usize {}
5151

52-
/// ColorArray is only used internally to provide a helper method for converting
53-
/// Vec<impl Color> to Vec<Box<dyn Color>>, as we would otherwise fall foul of
54-
/// the orphan rules.
52+
/// `ColorArray` is only used internally to provide a helper method for
53+
/// converting Vec<impl Color> to Vec<Box<dyn Color>>, as we would otherwise
54+
/// fall foul of the orphan rules.
5555
pub(crate) struct ColorArray<C: Color>(pub(crate) Vec<C>);
5656

5757
#[allow(clippy::from_over_into)]

‎plotly/src/configuration.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ impl Configuration {
211211

212212
/// When set it determines base URL for the "Edit in Chart Studio"
213213
/// `show_edit_in_chart_studio`/`show_send_to_cloud` mode bar button and
214-
/// the show_link/send_data on-graph link. To enable sending your data to
215-
/// Chart Studio Cloud, you need to set both `plotly_server_url` to <https://chart-studio.plotly.com> and
214+
/// the `show_link`/`send_data` on-graph link. To enable sending your data
215+
/// to Chart Studio Cloud, you need to set both `plotly_server_url` to <https://chart-studio.plotly.com> and
216216
/// also set `showSendToCloud` to `true`.
217217
pub fn plotly_server_url(mut self, plotly_server_url: &str) -> Self {
218218
self.plotly_server_url = Some(plotly_server_url.to_string());
@@ -228,7 +228,7 @@ impl Configuration {
228228
}
229229

230230
/// Determines whether the graphs are plotted with respect to
231-
/// layout.auto_size: true and infer its container size.
231+
/// `layout.auto_size: true` and infer its container size.
232232
pub fn autosizable(mut self, autosizable: bool) -> Self {
233233
self.autosizable = Some(autosizable);
234234
self

‎plotly/src/export.rs‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ pub mod sync {
77
/// Extension methods for exporting plots using a synchronous exporter.
88
pub trait ExporterSyncExt {
99
/// Convert the `Plot` to a static image of the given image format and
10-
/// save at the given location using a provided StaticExporter.
10+
/// save at the given location using a provided `StaticExporter`.
1111
///
12-
/// This method allows you to reuse a StaticExporter instance across
12+
/// This method allows you to reuse a `StaticExporter` instance across
1313
/// multiple plots, which is more efficient than creating a new one for
1414
/// each operation.
1515
///
@@ -18,7 +18,7 @@ pub mod sync {
1818
///
1919
/// # Arguments
2020
///
21-
/// * `exporter` - A mutable reference to a StaticExporter instance
21+
/// * `exporter` - A mutable reference to a `StaticExporter` instance
2222
/// * `filename` - The destination path for the output file
2323
/// * `format` - The desired output image format
2424
/// * `width` - The width of the output image in pixels
@@ -45,6 +45,11 @@ pub mod sync {
4545
///
4646
/// exporter.close();
4747
/// ```
48+
///
49+
/// # Errors
50+
///
51+
/// Returns an error if the export fails, if the image file cannot be
52+
/// written, or if called from within an async (Tokio) context.
4853
fn write_image<P: AsRef<Path>>(
4954
&mut self,
5055
plot: &Plot,
@@ -56,10 +61,10 @@ pub mod sync {
5661
) -> Result<(), Box<dyn std::error::Error>>;
5762

5863
/// Convert the `Plot` to a static image and return the image as a
59-
/// `base64` string. Supported formats are [ImageFormat::JPEG],
60-
/// [ImageFormat::PNG] and [ImageFormat::WEBP].
64+
/// `base64` string. Supported formats are [`ImageFormat::JPEG`],
65+
/// [`ImageFormat::PNG`] and [`ImageFormat::WEBP`].
6166
///
62-
/// This method allows you to reuse the same StaticExporter instance
67+
/// This method allows you to reuse the same `StaticExporter` instance
6368
/// across multiple plots, which is more efficient than creating
6469
/// a new one for each operation.
6570
///
@@ -91,6 +96,11 @@ pub mod sync {
9196
///
9297
/// exporter.close();
9398
/// ```
99+
///
100+
/// # Errors
101+
///
102+
/// Returns an error if `format` is not JPEG, PNG or WEBP, if the export
103+
/// fails, or if called from within an async (Tokio) context.
94104
fn to_base64(
95105
&mut self,
96106
plot: &Plot,
@@ -102,7 +112,7 @@ pub mod sync {
102112

103113
/// Convert the `Plot` to SVG and return it as a String.
104114
///
105-
/// This method allows you to reuse the same StaticExporter instance
115+
/// This method allows you to reuse the same `StaticExporter` instance
106116
/// across multiple plots, which is more efficient than creating
107117
/// a new one for each operation.
108118
///
@@ -133,6 +143,11 @@ pub mod sync {
133143
///
134144
/// exporter.close();
135145
/// ```
146+
///
147+
/// # Errors
148+
///
149+
/// Returns an error if the export fails, or if called from within an
150+
/// async (Tokio) context.
136151
fn to_svg(
137152
&mut self,
138153
plot: &Plot,
@@ -218,7 +233,7 @@ pub mod r#async {
218233
/// the given location using the asynchronous exporter.
219234
///
220235
/// The exporter must have been built with the `build_async` method of
221-
/// the StaticExporterBuilder.
236+
/// the `StaticExporterBuilder`.
222237
///
223238
/// Functionally signature equivalent to the sync version in
224239
/// [`crate::export::sync::ExporterSyncExt::write_image`], but meant for
@@ -239,7 +254,7 @@ pub mod r#async {
239254
/// `base64` string using the asynchronous exporter.
240255
///
241256
/// The exporter must have been built with the `build_async` method of
242-
/// the StaticExporterBuilder.
257+
/// the `StaticExporterBuilder`.
243258
///
244259
/// Functionally signature equivalent to the sync version in
245260
/// [`crate::export::sync::ExporterSyncExt::to_base64`], but meant for

‎plotly/src/layout/animation.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use serde::Serialize;
1111
use crate::{Layout, Traces};
1212

1313
/// A frame represents a single state in an animation sequence.
14-
/// Based on Plotly.js frame_attributes.js specification
14+
/// Based on Plotly.js `frame_attributes.js` specification
1515
#[serde_with::skip_serializing_none]
1616
#[derive(Serialize, Clone, FieldSetter)]
1717
pub struct Frame {
@@ -63,7 +63,7 @@ impl Default for Animation {
6363

6464
impl Animation {
6565
/// Create a new animation args with default values for options and
66-
/// FramesMode set to all frames
66+
/// `FramesMode` set to all frames
6767
pub fn new() -> Self {
6868
Self::default()
6969
}
@@ -139,7 +139,7 @@ impl Serialize for FrameListMode {
139139
}
140140

141141
/// Animation configuration options
142-
/// Based on actual Plotly.js animation API from animation_attributes.js
142+
/// Based on actual Plotly.js animation API from `animation_attributes.js`
143143
#[serde_with::skip_serializing_none]
144144
#[derive(Serialize, Clone, Debug, FieldSetter)]
145145
pub struct AnimationOptions {

‎plotly/src/layout/axis.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl Axis {
622622

623623
/// Set the range of the axis. This method accepts various types and
624624
/// converts them to `AxisRange` while also keeping backward compatibility
625-
/// with API prior to AxisRange introduction.
625+
/// with API prior to `AxisRange` introduction.
626626
pub fn range(mut self, range: impl Into<AxisRange>) -> Self {
627627
self.range = Some(range.into());
628628
self

0 commit comments

Comments
 (0)