diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..83bcd989 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 + +updates: + - package-ecosystem: cargo + directory: / + schedule: + interval: daily diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3c24480..261d3677 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,9 +3,9 @@ name: CI on: workflow_dispatch: pull_request: - branches: [ master ] + branches: [ main ] push: - branches: [ master ] + branches: [ main ] # Cancel any in-flight jobs for the same PR/branch so there's only one active # at a time @@ -21,18 +21,18 @@ jobs: name: Rustfmt runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt - run: cargo fmt --all -- --check - run: cd ${{ github.workspace }}/examples && cargo fmt --all -- --check - + clippy: name: Clippy runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: components: clippy @@ -46,6 +46,20 @@ jobs: # lint the wasm examples - run: cd ${{ github.workspace }}/examples && cargo clippy --target wasm32-unknown-unknown --package "wasm*" + semver: + name: semver + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check semver + uses: obi1kenobi/cargo-semver-checks-action@v2 + with: + package: plotly + feature-group: only-explicit-features + features: kaleido + rust-toolchain: stable + release-type: minor + test: name: Tests strategy: @@ -54,15 +68,17 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - run: cargo test --features plotly_ndarray,plotly_image,kaleido - + - if: ${{ matrix.os == 'windows-latest' }} + run: gci -recurse -filter "*example*" + code-coverage: name: Code Coverage runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: components: llvm-tools-preview @@ -70,7 +86,7 @@ jobs: # we are skipping anything to do with wasm here - run: cargo llvm-cov --workspace --features plotly_ndarray,plotly_image,kaleido --lcov --output-path lcov.info - uses: codecov/codecov-action@v3 - + build_examples: name: Build Examples strategy: @@ -91,10 +107,10 @@ jobs: ] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - run: cd ${{ github.workspace }}/examples/${{ matrix.example }} && cargo build - + build_wasm_examples: name: Build Wasm Examples strategy: @@ -103,7 +119,7 @@ jobs: example: [wasm-yew-minimal] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: targets: wasm32-unknown-unknown diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 88c3d407..e64c3a6e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: name: Deploy to crates.io runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - run: cargo login ${{ env.CRATES_IO_TOKEN }} env: diff --git a/CHANGELOG.md b/CHANGELOG.md index e0a39420..5b5a0819 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,35 +3,38 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.8.5] - 2023-xx-xx +## [0.8.5] - 2024-xx-xx ### Added -- [[#153](https://github.com/igiagkiozis/plotly/pull/153)] Added `LayoutScene` +- [[#181](https://github.com/plotly/plotly,rs/pull/181)] Fix compilation error when mixing the crate with `askama/with-axum` by adding `with-axum` feature. +- [[#180](https://github.com/plotly/plotly.rs/pull/180)] Add setter for `Mapbox::domain`. +- [[#163](https://github.com/plotly/plotly.rs/pull/163)] Added `DensityMapbox`. +- [[#153](https://github.com/plotly/plotly.rs/pull/153)] Added `LayoutScene`. ## [0.8.4] - 2023-07-09 ### Added -- [[#143](https://github.com/igiagkiozis/plotly/pull/143)] Widen version range of `askama`. +- [[#143](https://github.com/plotly/plotly.rs/pull/143)] Widen version range of `askama`. ### Fixed -- [[#129](https://github.com/igiagkiozis/plotly/pull/129)] Fix issue for plots not showing in browser in Windows. Thanks to [@juanespj](https://github.com/juanespj) and [@M-NK-Y](https://github.com/M-NK-Y) for the PRs. -- [[#147](https://github.com/igiagkiozis/plotly/pull/147)] Update documentation for `jupyter notebook` example. +- [[#129](https://github.com/plotly/plotly.rs/pull/129)] Fix issue for plots not showing in browser in Windows. Thanks to [@juanespj](https://github.com/juanespj) and [@M-NK-Y](https://github.com/M-NK-Y) for the PRs. +- [[#147](https://github.com/plotly/plotly.rs/pull/147)] Update documentation for `jupyter notebook` example. ## [0.8.3] - 2022-11-04 ### Fixed -- [[#122](https://github.com/igiagkiozis/plotly/pull/122)] Compilation error for the `wasm` feature. -- [[#123](https://github.com/igiagkiozis/plotly/pull/123)] Compilation error for the `plotly_kaleido` feature. +- [[#122](https://github.com/plotly/plotly.rs/pull/122)] Compilation error for the `wasm` feature. +- [[#123](https://github.com/plotly/plotly.rs/pull/123)] Compilation error for the `plotly_kaleido` feature. ## [0.8.2] - 2022-11-03 ### Added -- [[#110](https://github.com/igiagkiozis/plotly/pull/110)] `LegendGroupTitle` to existing traces. -- [[#88](https://github.com/igiagkiozis/plotly/pull/88)] `Mesh3D`, `Image`, `ScatterMapbox` traces. +- [[#110](https://github.com/plotly/plotly.rs/pull/110)] `LegendGroupTitle` to existing traces. +- [[#88](https://github.com/plotly/plotly.rs/pull/88)] `Mesh3D`, `Image`, `ScatterMapbox` traces. ### Changed -- [[#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. +- [[#113](https://github.com/plotly/plotly.rs/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/plotly/plotly.rs/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 -- Button support (i.e. [updatemenus](https://plotly.com/javascript/reference/layout/updatemenus/)) contibuted by [@sreenathkrishnan](https://github.com/sreenathkrishnan). Details and examples in this well written PR [#99](https://github.com/igiagkiozis/plotly/pull/99). +- Button support (i.e. [updatemenus](https://plotly.com/javascript/reference/layout/updatemenus/)) contibuted by [@sreenathkrishnan](https://github.com/sreenathkrishnan). Details and examples in this well written PR [#99](https://github.com/plotly/plotly.rs/pull/99). - Internally, there is now a `plotly-derive` crate which defines a `FieldSetter` procedural macro. This massively cuts down the amount of code duplication by generating the setter methods based on the struct fields. Again thanks to @sreenathkrishnan for this effort. ## [0.8.0] - 2022-08-26 @@ -46,8 +49,7 @@ Version 0.8.0 represents a significant release which refactors a lot of the code - Support for `Sankey` diagrams - Support for `Plot3D` - 3D plots for scatter, line and surface data ### Changed -- Improve implementation of `private::NumOrString` to support more primitive types ([Issue -#47](https://github.com/igiagkiozis/plotly/issues/47)) +- Improve implementation of `private::NumOrString` to support more primitive types ([Issue #47](https://github.com/plotly/plotly.rs/issues/47)) - Remove `private::TruthyEnum` in favour of a more robust way of serializing to `String` or `bool` - Refactor `Color` module - Refactored HTML templates with cleaner Javascript code @@ -57,7 +59,7 @@ Version 0.8.0 represents a significant release which refactors a lot of the code - `Plot::to_html()` now has similar behaviour to `Plot::to_inline_html()` and just returns a `String` ### Fixed - Typos in `CONTRIBUTING.md` -- Serialization of `plotly_kaleido::PlotData` ([Issue #50](https://github.com/igiagkiozis/plotly/issues/50)) +- Serialization of `plotly_kaleido::PlotData` ([Issue #50](https://github.com/plotly/plotly.rs/issues/50)) ### Updated - `ndarray` to `0.15.4`. - `serde` to `1.0.132`. @@ -85,11 +87,11 @@ Version 0.8.0 represents a significant release which refactors a lot of the code ## [0.6.0] - 2020-07-25 ### Added -- Shapes support ([documentation](https://igiagkiozis.github.io/plotly/content/fundamentals/shapes.html)). +- Shapes support ([documentation](https://plotly.github.io/plotly.rs/content/fundamentals/shapes.html)). - Annotations support. - Docstrings to `Scatter`. -- `ndarray` support ([documentation](https://igiagkiozis.github.io/plotly/content/fundamentals/ndarray_support.html)). -- Jupyter lab and notebook support ([documentation](https://igiagkiozis.github.io/plotly/content/fundamentals/jupyter_support.html)). +- `ndarray` support ([documentation](https://plotly.github.io/plotly.rs/content/fundamentals/ndarray_support.html)). +- Jupyter lab and notebook support ([documentation](https://plotly.github.io/plotly.rs/content/fundamentals/jupyter_support.html)). ### Changed - Removed `num` dependence. - Removed `plotly_orca` and the `orca` feature. Use the `kaleido` feature for static image generation. @@ -107,7 +109,7 @@ Version 0.8.0 represents a significant release which refactors a lot of the code ## [0.5.0] - 2020-07-12 ### Added -- [Plotly.rs Book](https://igiagkiozis.github.io/plotly/). +- [Plotly.rs Book](https://plotly.github.io/plotly.rs/). - Using plotly.js from the official CDN is now the default. To use the local version use the `Plot::use_local_plotly` method. - Plot rasterization to `png`, `jpg`, `eps`, `pdf`, `webp` and `svg` using [plotly/Kaleido](https://github.com/plotly/Kaleido), enabled using the `kaleido` feature. - Multi-axis support and examples. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 50818248..0364fc57 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,11 +12,11 @@ When making a feature request, please make it clear what problem you intend to s ## Pull Requests -Before spending time and effort in making changes to the library, it's a good idea to discuss it first on the issue tracker to see whether your change is likely to be accepted. +Before spending time and effort in making changes to the library, it's a good idea to discuss it first on the issue tracker to see whether your change is likely to be accepted. -Fork [plotly](https://igiagkiozis.github.io/plotly/) to your own account and create a new branch for your feature. Remember to update the [changelog](CHANGELOG.md) - use previous entries as a template. +Fork [plotly](https://github.com/plotly/plotly.rs.git) to your own account and create a new branch for your feature. Remember to update the [changelog](CHANGELOG.md) - use previous entries as a template. -When your contribution is ready for review, make a pull request with your changes directly to the `master` branch. One of the maintainers will have a look at what you've done, suggest any necessary changes and, when everyone is happy, merge the pull request. +When your contribution is ready for review, make a pull request with your changes directly to the `main` branch. One of the maintainers will have a look at what you've done, suggest any necessary changes and, when everyone is happy, merge the pull request. ## Code of Conduct diff --git a/README.md b/README.md index 76ea74f9..50518376 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@

Plotly.rs

Plotly for Rust

- - Build status + + Build status Crates.io @@ -14,18 +14,18 @@ Documentation - + Code coverage

- Getting Started + Getting Started | - Recipes + Recipes | API Docs | - Changelog + Changelog

@@ -44,10 +44,10 @@ A plotting library for Rust powered by [Plotly.js](https://plot.ly/javascript/). -Documentation and numerous interactive examples are available in the [Plotly.rs Book](https://igiagkiozis.github.io/plotly/content/getting_started.html), the [examples/](https://github.com/igiagkiozis/plotly/tree/master/examples) directory and [docs.rs](https://docs.rs/crate/plotly). +Documentation and numerous interactive examples are available in the [Plotly.rs Book](https://plotly.github.io/plotly.rs/content/getting_started.html), the [examples/](https://github.com/plotly/plotly.rs/tree/main/examples) directory and [docs.rs](https://docs.rs/crate/plotly). -For changes since the last version, please consult the [changelog](https://github.com/igiagkiozis/plotly/blob/master/CHANGELOG.md). +For changes since the last version, please consult the [changelog](https://github.com/plotly/plotly.rs/tree/main/CHANGELOG.md). # Basic Usage @@ -163,13 +163,13 @@ pub fn plot_component() -> Html { } }); - + use_effect_with_deps(move |_| { p.run(); || () }, (), ); - + html! {
@@ -177,7 +177,7 @@ pub fn plot_component() -> Html { } ``` -More detailed standalone examples can be found in the [examples/](https://github.com/igiagkiozis/plotly/tree/master/examples) directory. +More detailed standalone examples can be found in the [examples/](https://github.com/plotly/plotly.rs/tree/main/examples) directory. # Crate Feature Flags @@ -201,12 +201,12 @@ Enables compilation for the `wasm32-unknown-unknown` target and provides access # Contributing -* If you've spotted a bug or would like to see a new feature, please submit an issue on the [issue tracker](https://github.com/igiagkiozis/plotly/issues). +* If you've spotted a bug or would like to see a new feature, please submit an issue on the [issue tracker](https://github.com/plotly/plotly.rs/issues). -* Pull requests are welcome, see the [contributing guide](https://github.com/igiagkiozis/plotly/blob/master/CONTRIBUTING.md) for more information. +* Pull requests are welcome, see the [contributing guide](https://github.com/plotly/plotly.rs/tree/main/CONTRIBUTING.md) for more information. # License `Plotly.rs` is distributed under the terms of the MIT license. -See [LICENSE-MIT](https://github.com/igiagkiozis/plotly/blob/master/LICENSE-MIT), and [COPYRIGHT](https://github.com/igiagkiozis/plotly/blob/master/COPYRIGHT) for details. +See [LICENSE-MIT](https://github.com/plotly/plotly.rs/tree/main/LICENSE-MIT), and [COPYRIGHT](https://github.com/plotly/plotly.rs/tree/main/COPYRIGHT) for details. diff --git a/docs/book/src/fundamentals.md b/docs/book/src/fundamentals.md index 6ef36d87..9fea76a1 100644 --- a/docs/book/src/fundamentals.md +++ b/docs/book/src/fundamentals.md @@ -1,9 +1,9 @@
- - build status + + build status - - build status + + Build status Crates.io @@ -18,4 +18,4 @@ # Fundamentals -Functionality that applies to the library as a whole is described in the next sections. \ No newline at end of file +Functionality that applies to the library as a whole is described in the next sections. \ No newline at end of file diff --git a/docs/book/src/fundamentals/jupyter_support.md b/docs/book/src/fundamentals/jupyter_support.md index 2576aa91..b329ef30 100644 --- a/docs/book/src/fundamentals/jupyter_support.md +++ b/docs/book/src/fundamentals/jupyter_support.md @@ -1,12 +1,12 @@ # Jupyter Support -As of version `0.7.0`, [Plotly.rs](https://github.com/igiagkiozis/plotly) has native support for the [EvCxR Jupyter Kernel](https://github.com/google/evcxr/tree/master/evcxr_jupyter). +As of version `0.7.0`, [Plotly.rs](https://github.com/plotly/plotly.rs) has native support for the [EvCxR Jupyter Kernel](https://github.com/google/evcxr/tree/master/evcxr_jupyter). Once you've installed the required packages you'll be able to run all the examples shown here as well as all [the recipes](../recipes.md) in Jupyter Lab! ## Installation -It is assumed that an installation of the [Anaconda](https://www.anaconda.com/products/individual) Python distribution is already present in the system. If that is not the case you can follow these [instructions](https://www.anaconda.com/products/individual) to get up and running with `Anaconda`. +It is assumed that an installation of the [Anaconda](https://www.anaconda.com/products/individual) Python distribution is already present in the system. If that is not the case you can follow these [instructions](https://www.anaconda.com/products/individual) to get up and running with `Anaconda`. ```shell script conda install -c plotly plotly=4.9.0 @@ -20,17 +20,17 @@ conda install notebook Although there are alternative methods to enable support for the [EvCxR Jupyter Kernel](https://github.com/google/evcxr/tree/master/evcxr_jupyter), we have elected to keep the requirements consistent with what those of other languages, e.g. Julia, Python and R. This way users know what to expect; and also the folks at [Plotly](https://plotly.com/python/getting-started/#jupyter-notebook-support) have done already most of the heavy lifting to create an extension for Jupyter Lab that works very well. -Run the following to install the Plotly Jupyter Lab extension: +Run the following to install the Plotly Jupyter Lab extension: ```shell script jupyter labextension install jupyterlab-plotly@4.9.0 ``` -Once this step is complete to make sure the installation so far was successful, run the following command: +Once this step is complete to make sure the installation so far was successful, run the following command: ```shell script jupyter lab ``` -Open a `Python 3` kernel copy/paste the following code in a cell and run it: +Open a `Python 3` kernel copy/paste the following code in a cell and run it: ```python import plotly.graph_objects as go fig = go.Figure(data=go.Bar(x=['a', 'b', 'c'], y=[11, 22, 33])) @@ -62,7 +62,7 @@ If you're not familiar with the EvCxR kernel it would be good that you at least ## Usage -Launch Jupyter Lab: +Launch Jupyter Lab: ```shell script jupyter lab ``` @@ -104,6 +104,6 @@ plot.set_layout(layout); plot.lab_display(); format!("EVCXR_BEGIN_CONTENT application/vnd.plotly.v1+json\n{}\nEVCXR_END_CONTENT", plot.to_json()) ``` -For Jupyter Lab there are two ways to display a plot in the `EvCxR` kernel, either have the plot object be in the last line without a semicolon or directly invoke the `Plot::lab_display` method on it; both have the same result. You can also find an example notebook [here](https://github.com/igiagkiozis/plotly/blob/master/examples/jupyter/jupyter_lab.ipynb) that will periodically be updated with examples. +For Jupyter Lab there are two ways to display a plot in the `EvCxR` kernel, either have the plot object be in the last line without a semicolon or directly invoke the `Plot::lab_display` method on it; both have the same result. You can also find an example notebook [here](https://github.com/plotly/plotly.rs/tree/main/examples/jupyter/jupyter_lab.ipynb) that will periodically be updated with examples. -The process for Jupyter Notebook is very much the same with one exception; the `Plot::notebook_display` method must be used to display the plot. You can find an example notebook [here](https://github.com/igiagkiozis/plotly/blob/master/examples/jupyter/jupyter_notebook.ipynb) +The process for Jupyter Notebook is very much the same with one exception; the `Plot::notebook_display` method must be used to display the plot. You can find an example notebook [here](https://github.com/plotly/plotly.rs/tree/main/examples/jupyter/jupyter_notebook.ipynb) diff --git a/docs/book/src/fundamentals/ndarray_support.md b/docs/book/src/fundamentals/ndarray_support.md index b1048dda..c708a635 100644 --- a/docs/book/src/fundamentals/ndarray_support.md +++ b/docs/book/src/fundamentals/ndarray_support.md @@ -1,16 +1,16 @@ -# `ndarray` Support +# `ndarray` Support -To enable [ndarray](https://github.com/rust-ndarray/ndarray) support in [Plotly.rs](https://github.com/igiagkiozis/plotly) add the following feature to your `Cargo.toml` file: +To enable [ndarray](https://github.com/rust-ndarray/ndarray) support in [Plotly.rs](https://github.com/plotly/plotly.rs) add the following feature to your `Cargo.toml` file: ```toml [dependencies] plotly = { version = ">=0.7.0", features = ["plotly_ndarray"] } ``` -This extends the [Plotly.rs](https://github.com/igiagkiozis/plotly) API in two ways: +This extends the [Plotly.rs](https://github.com/plotly/plotly.rs) API in two ways: * `Scatter` traces can now be created using the `Scatter::from_ndarray` constructor, * and also multiple traces can be created with the `Scatter::to_traces` method. -The full source code for the examples below can be found [here](https://github.com/igiagkiozis/plotly/blob/master/plotly/examples/ndarray_support.rs). +The full source code for the examples below can be found [here](https://github.com/plotly/plotly.rs/tree/main/examples/ndarray_support). ## `ndarray` Traces @@ -55,7 +55,7 @@ var layout = {}; ### Multiple Traces -To display a `2D` array (`Array<_, Ix2>`) you can use the `Scatter::to_traces` method. The first argument of the method represents the common axis for the traces (`x` axis) whilst the second argument contains a collection of traces. At this point it should be noted that there is some ambiguity when passing a `2D` array; namely are the traces arranged along the columns or the rows of the matrix? This ambiguity is resolved by the third argument of the `Scatter::to_traces` method. If that argument is set to `ArrayTraces::OverColumns` then the library assumes that every column represents an individual trace, alternatively if this is set to `ArrayTraces::OverRows` the assumption is that every row represents a trace. +To display a `2D` array (`Array<_, Ix2>`) you can use the `Scatter::to_traces` method. The first argument of the method represents the common axis for the traces (`x` axis) whilst the second argument contains a collection of traces. At this point it should be noted that there is some ambiguity when passing a `2D` array; namely are the traces arranged along the columns or the rows of the matrix? This ambiguity is resolved by the third argument of the `Scatter::to_traces` method. If that argument is set to `ArrayTraces::OverColumns` then the library assumes that every column represents an individual trace, alternatively if this is set to `ArrayTraces::OverRows` the assumption is that every row represents a trace. To illustrate this distinction consider the following examples: ```rust diff --git a/docs/book/src/getting_started.md b/docs/book/src/getting_started.md index 47dc5cc5..e0a83086 100644 --- a/docs/book/src/getting_started.md +++ b/docs/book/src/getting_started.md @@ -1,9 +1,9 @@
- - build status + + build status - - build status + + Build status Crates.io @@ -18,26 +18,26 @@ # Getting Started -To start using [plotly.rs](https://github.com/igiagkiozis/plotly) in your project add the following to your `Cargo.toml`: +To start using [plotly.rs](https://github.com/plotly/plotly.rs) in your project add the following to your `Cargo.toml`: ```toml [dependencies] plotly = "0.8.4" ``` -[Plotly.rs](https://github.com/igiagkiozis/plotly) is ultimately a thin wrapper around the `plotly.js` library. The main job of this library is to provide `structs` and `enums` which get serialized to `json` and passed to the `plotly.js` library to actually do the heavy lifting. As such, if you are familiar with `plotly.js` or its derivatives (e.g. the equivalent Python library), then you should find [`plotly.rs`](https://github.com/igiagkiozis/plotly) intuitive to use. +[Plotly.rs](https://github.com/plotly/plotly.rs) is ultimately a thin wrapper around the `plotly.js` library. The main job of this library is to provide `structs` and `enums` which get serialized to `json` and passed to the `plotly.js` library to actually do the heavy lifting. As such, if you are familiar with `plotly.js` or its derivatives (e.g. the equivalent Python library), then you should find [`plotly.rs`](https://github.com/plotly/plotly.rs) intuitive to use. A `Plot` struct contains one or more `Trace` objects which describe the structure of data to be displayed. Optional `Layout` and `Configuration` structs can be used to specify the layout and config of the plot, respectively. The builder pattern is used extensively throughout the library, which means you only need to specify the attributes and details you desire. Any attributes that are not set will fall back to the default value used by `plotly.js`. -All available traces (e.g. `Scatter`, `Bar`, `Histogram`, etc), the `Layout`, `Configuration` and `Plot` have been hoisted in the `plotly` namespace so that they can be imported simply using the following: +All available traces (e.g. `Scatter`, `Bar`, `Histogram`, etc), the `Layout`, `Configuration` and `Plot` have been hoisted in the `plotly` namespace so that they can be imported simply using the following: ```rust use plotly::{Plot, Layout, Scatter}; ``` -The aforementioned components can be combined to produce as simple plot as follows: +The aforementioned components can be combined to produce as simple plot as follows: ```rust use plotly::common::Mode; @@ -65,17 +65,17 @@ fn main() -> std::io::Result<()> { } ``` -which results in the following figure (displayed here as a static png file): +which results in the following figure (displayed here as a static png file): ![line_and_scatter_plot](img/line_and_scatter_plot.png) -The above code will generate an interactive `html` page of the `Plot` and display it in the default browser. The `html` for the plot is stored in the platform specific temporary directory. To save the `html` result, you can do so quite simply: +The above code will generate an interactive `html` page of the `Plot` and display it in the default browser. The `html` for the plot is stored in the platform specific temporary directory. To save the `html` result, you can do so quite simply: ```rust plot.write_html("/home/user/line_and_scatter_plot.html"); ``` -It is often the case that plots are produced to be included in a document and a different format for the plot is desirable (e.g. png, jpeg, etc). Given that the `html` version of the plot is composed of vector graphics, the display when converted to a non-vector format (e.g. png) is not guaranteed to be identical to the one displayed in `html`. This means that some fine tuning may be required to get to the desired output. To support that iterative workflow, `Plot` has a `show_image()` method which will display the rasterised output to the target format, for example: +It is often the case that plots are produced to be included in a document and a different format for the plot is desirable (e.g. png, jpeg, etc). Given that the `html` version of the plot is composed of vector graphics, the display when converted to a non-vector format (e.g. png) is not guaranteed to be identical to the one displayed in `html`. This means that some fine tuning may be required to get to the desired output. To support that iterative workflow, `Plot` has a `show_image()` method which will display the rasterised output to the target format, for example: ```rust plot.show_image(ImageFormat::PNG, 1280, 900); @@ -83,7 +83,7 @@ plot.show_image(ImageFormat::PNG, 1280, 900); will display in the browser the rasterised plot; 1280 pixels wide and 900 pixels tall, in png format. -Once a satisfactory result is achieved, and assuming the [`kaleido`](getting_started#saving-plots) feature is enabled, the plot can be saved using the following: +Once a satisfactory result is achieved, and assuming the [`kaleido`](getting_started#saving-plots) feature is enabled, the plot can be saved using the following: ```rust plot.write_image("/home/user/plot_name.ext", ImageFormat::PNG, 1280, 900, 1.0); @@ -93,7 +93,7 @@ The extension in the file-name path is optional as the appropriate extension (`I ## Saving Plots -To add the ability to save plots in the following formats: png, jpeg, webp, svg, pdf and eps, you can use the `kaleido` feature. This feature depends on [plotly/Kaleido](https://github.com/plotly/Kaleido): a cross-platform open source library for generating static images. All the necessary binaries have been included with `plotly_kaleido` for `Linux`, `Windows` and `MacOS`. Previous versions of [plotly.rs](https://github.com/igiagkiozis/plotly) used the `orca` feature, however, this has been deprecated as it provided the same functionality but required additional installation steps. To enable the `kaleido` feature add the following to your `Cargo.toml`: +To add the ability to save plots in the following formats: png, jpeg, webp, svg, pdf and eps, you can use the `kaleido` feature. This feature depends on [plotly/Kaleido](https://github.com/plotly/Kaleido): a cross-platform open source library for generating static images. All the necessary binaries have been included with `plotly_kaleido` for `Linux`, `Windows` and `MacOS`. Previous versions of [plotly.rs](https://github.com/plotly/plotly.rs) used the `orca` feature, however, this has been deprecated as it provided the same functionality but required additional installation steps. To enable the `kaleido` feature add the following to your `Cargo.toml`: ```toml [dependencies] @@ -102,7 +102,7 @@ plotly = { version = "0.8.4", features = ["kaleido"] } ## WebAssembly Support -As of v0.8.0, [plotly.rs](https://github.com/igiagkiozis/plotly) can now be used in a `Wasm` environment by enabling the `wasm` feature in your `Cargo.toml`: +As of v0.8.0, [plotly.rs](https://github.com/plotly/plotly.rs) can now be used in a `Wasm` environment by enabling the `wasm` feature in your `Cargo.toml`: ```toml [dependencies] diff --git a/docs/book/src/plotly_rs.md b/docs/book/src/plotly_rs.md index 19af18d6..24bdf51c 100644 --- a/docs/book/src/plotly_rs.md +++ b/docs/book/src/plotly_rs.md @@ -1,9 +1,9 @@
- - build status + + build status - - build status + + Build status Crates.io @@ -20,17 +20,17 @@ Plotly.rs is a plotting library powered by [Plotly.js](https://plot.ly/javascript/). The aim is to bring over to Rust all the functionality that `Python` users have come to rely on with the added benefit of type safety and speed. -Plotly.rs is free and open source. You can find the source on [GitHub](https://github.com/igiagkiozis/plotly). Issues and feature requests can be posted on the [issue tracker](https://github.com/igiagkiozis/plotly/issues). +Plotly.rs is free and open source. You can find the source on [GitHub](https://github.com/plotly/plotly.rs). Issues and feature requests can be posted on the [issue tracker](https://github.com/plotly/plotly.rs/issues). ## API Docs This book is intended to be a recipe index, which closely follows the [plotly.js examples](https://plotly.com/javascript/), and is complemented by the [API documentation](https://docs.rs/plotly). ## Contributing -Contributions are always welcomed, no matter how large or small. Refer to the [contributing guidelines](https://github.com/igiagkiozis/plotly/blob/master/CONTRIBUTING.md) for further pointers, and, if in doubt, [open an issue](https://github.com/igiagkiozis/plotly/issues). +Contributions are always welcomed, no matter how large or small. Refer to the [contributing guidelines](https://github.com/plotly/plotly.rs/tree/main/CONTRIBUTING.md) for further pointers, and, if in doubt, [open an issue](https://github.com/plotly/plotly.rs/issues). ## License Plotly.rs is distributed under the terms of the MIT license. -See [LICENSE-MIT](https://github.com/igiagkiozis/plotly/blob/master/LICENSE-MIT), and [COPYRIGHT](https://github.com/igiagkiozis/plotly/blob/master/COPYRIGHT) for details. \ No newline at end of file +See [LICENSE-MIT](https://github.com/plotly/plotly.rs/tree/main/LICENSE-MIT), and [COPYRIGHT](https://github.com/plotly/plotly.rs/tree/main/COPYRIGHT) for details. \ No newline at end of file diff --git a/docs/book/src/recipes.md b/docs/book/src/recipes.md index 870a45a2..5c27ecf2 100644 --- a/docs/book/src/recipes.md +++ b/docs/book/src/recipes.md @@ -1,9 +1,9 @@
- - build status + + build status - - build status + + Build status Crates.io @@ -18,4 +18,4 @@ # Recipes -Most of the recipes presented here have been adapted from the official documentation for [plotly.js](https://plotly.com/javascript/) and [plotly.py](https://plotly.com/python/). Contributions of interesting plots that showcase the capabilities of the library are most welcome. For more information on the process please see [the contributing guidelines](https://github.com/igiagkiozis/plotly/blob/master/CONTRIBUTING.md). +Most of the recipes presented here have been adapted from the official documentation for [plotly.js](https://plotly.com/javascript/) and [plotly.py](https://plotly.com/python/). Contributions of interesting plots that showcase the capabilities of the library are most welcome. For more information on the process please see [the contributing guidelines](https://github.com/plotly/plotly.rs/tree/main/CONTRIBUTING.md). diff --git a/docs/book/src/recipes/3dcharts.md b/docs/book/src/recipes/3dcharts.md index 35731c94..852337bb 100644 --- a/docs/book/src/recipes/3dcharts.md +++ b/docs/book/src/recipes/3dcharts.md @@ -1,6 +1,6 @@ # 3D Charts -The complete source code for the following examples can also be found [here](https://github.com/igiagkiozis/plotly/blob/master/plotly/examples/plot3d.rs). +The complete source code for the following examples can also be found [here](https://github.com/plotly/plotly.rs/tree/main/examples/plot3d). Kind | Link :---|:----: diff --git a/docs/book/src/recipes/basic_charts.md b/docs/book/src/recipes/basic_charts.md index 24e0e5df..c8e3a77f 100644 --- a/docs/book/src/recipes/basic_charts.md +++ b/docs/book/src/recipes/basic_charts.md @@ -1,6 +1,6 @@ # Basic Charts -The source code for the following examples can also be found [here](https://github.com/igiagkiozis/plotly/blob/master/plotly/examples/basic_charts.rs). +The source code for the following examples can also be found [here](https://github.com/plotly/plotly.rs/tree/main/examples/basic_charts). Kind | Link :---|:----: diff --git a/docs/book/src/recipes/financial_charts.md b/docs/book/src/recipes/financial_charts.md index 4cca705a..6a811d9a 100644 --- a/docs/book/src/recipes/financial_charts.md +++ b/docs/book/src/recipes/financial_charts.md @@ -1,6 +1,6 @@ # Financial Charts -The source code for the following examples can also be found [here](https://github.com/igiagkiozis/plotly/blob/master/plotly/examples/financial_charts.rs). +The source code for the following examples can also be found [here](https://github.com/plotly/plotly.rs/tree/main/examples/financial_charts). Kind | Link :---|:----: diff --git a/docs/book/src/recipes/scientific_charts.md b/docs/book/src/recipes/scientific_charts.md index 2b18ea47..36549951 100644 --- a/docs/book/src/recipes/scientific_charts.md +++ b/docs/book/src/recipes/scientific_charts.md @@ -1,6 +1,6 @@ # Scientific Charts -The source code for the following examples can also be found [here](https://github.com/igiagkiozis/plotly/blob/master/plotly/examples/scientific_charts.rs). +The source code for the following examples can also be found [here](https://github.com/plotly/plotly.rs/tree/main/examples/scientific_charts). Kind | Link :---|:----: diff --git a/docs/book/src/recipes/statistical_charts.md b/docs/book/src/recipes/statistical_charts.md index adef8b98..4f446d1d 100644 --- a/docs/book/src/recipes/statistical_charts.md +++ b/docs/book/src/recipes/statistical_charts.md @@ -1,6 +1,6 @@ # Statistical Charts -The complete source code for the following examples can also be found [here](https://github.com/igiagkiozis/plotly/blob/master/plotly/examples/statistical_charts.rs). +The complete source code for the following examples can also be found [here](https://github.com/plotly/plotly.rs/tree/main/examples/statistical_charts). Kind | Link :---|:----: diff --git a/docs/book/src/recipes/subplots.md b/docs/book/src/recipes/subplots.md index 0f40e075..490ead55 100644 --- a/docs/book/src/recipes/subplots.md +++ b/docs/book/src/recipes/subplots.md @@ -1,6 +1,6 @@ # Subplots -The complete source code for the following examples can also be found [here](https://github.com/igiagkiozis/plotly/blob/master/plotly/examples/subplots.rs). +The complete source code for the following examples can also be found [here](https://github.com/plotly/plotly.rs/tree/main/examples/subplots). Kind | Link :---|:----: diff --git a/examples/images/Cargo.toml b/examples/images/Cargo.toml index 144ac7a4..59a3bc34 100644 --- a/examples/images/Cargo.toml +++ b/examples/images/Cargo.toml @@ -5,6 +5,6 @@ authors = ["Michael Freeborn "] edition = "2021" [dependencies] -image = "0.24.4" +image = "0.25" ndarray = "0.15.6" plotly = { path = "../../plotly", features = ["plotly_image", "plotly_ndarray"] } diff --git a/examples/maps/src/main.rs b/examples/maps/src/main.rs index 10312ced..1258e6ae 100644 --- a/examples/maps/src/main.rs +++ b/examples/maps/src/main.rs @@ -3,7 +3,7 @@ use plotly::{ common::Marker, layout::{Center, DragMode, Mapbox, MapboxStyle, Margin}, - Layout, Plot, ScatterMapbox, + DensityMapbox, Layout, Plot, ScatterMapbox, }; fn scatter_mapbox() { @@ -27,8 +27,29 @@ fn scatter_mapbox() { plot.show(); } +fn density_mapbox() { + let trace = DensityMapbox::new(vec![45.5017], vec![-73.5673], vec![0.75]).zauto(true); + + let layout = Layout::new() + .drag_mode(DragMode::Zoom) + .margin(Margin::new().top(0).left(0).bottom(0).right(0)) + .mapbox( + Mapbox::new() + .style(MapboxStyle::OpenStreetMap) + .center(Center::new(45.5017, -73.5673)) + .zoom(5), + ); + + let mut plot = Plot::new(); + plot.add_trace(trace); + plot.set_layout(layout); + + plot.show(); +} + fn main() { // Uncomment any of these lines to display the example. // scatter_mapbox(); + // density_mapbox(); } diff --git a/examples/statistical_charts/src/main.rs b/examples/statistical_charts/src/main.rs index 5d2a7190..b8c83d34 100644 --- a/examples/statistical_charts/src/main.rs +++ b/examples/statistical_charts/src/main.rs @@ -345,7 +345,7 @@ fn fully_styled_box_plot() { v }; - let x_data = vec![ + let x_data = [ "Carmelo
Anthony", "Dwyane
Wade", "Deron
Williams", diff --git a/examples/wasm-yew-minimal/Cargo.toml b/examples/wasm-yew-minimal/Cargo.toml index ea8d220d..86b11c3e 100644 --- a/examples/wasm-yew-minimal/Cargo.toml +++ b/examples/wasm-yew-minimal/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] plotly = { path = "../../plotly", features = ["wasm"] } -yew = "0.19.0" -yew-hooks = "0.1.56" +yew = "0.21.0" +yew-hooks = "0.3.2" log = "0.4.6" wasm-logger = "0.2" \ No newline at end of file diff --git a/examples/wasm-yew-minimal/src/main.rs b/examples/wasm-yew-minimal/src/main.rs index 8649c03c..f38ab848 100644 --- a/examples/wasm-yew-minimal/src/main.rs +++ b/examples/wasm-yew-minimal/src/main.rs @@ -18,14 +18,10 @@ pub fn plot_component() -> Html { Ok(()) } }); - - use_effect_with_deps( - move |_| { - p.run(); - || () - }, - (), - ); + // Only on first render + use_effect_with((), move |_| { + p.run(); + }); html! {
@@ -34,5 +30,5 @@ pub fn plot_component() -> Html { fn main() { wasm_logger::init(wasm_logger::Config::default()); - yew::start_app::(); + yew::Renderer::::new().render(); } diff --git a/plotly/Cargo.toml b/plotly/Cargo.toml index bd6ba120..55df4e53 100644 --- a/plotly/Cargo.toml +++ b/plotly/Cargo.toml @@ -5,9 +5,9 @@ description = "A plotting library powered by Plotly.js" authors = ["Ioannis Giagkiozis "] license = "MIT" readme = "../README.md" -homepage = "https://github.com/igiagkiozis/plotly" +homepage = "https://github.com/plotly/plotly.rs" documentation = "https://docs.rs/plotly" -repository = "https://github.com/igiagkiozis/plotly" +repository = "https://github.com/plotly/plotly.rs" edition = "2018" keywords = ["plot", "chart", "plotly"] @@ -18,13 +18,15 @@ kaleido = ["plotly_kaleido"] plotly_ndarray = ["ndarray"] plotly_image = ["image"] wasm = ["getrandom", "js-sys", "wasm-bindgen", "wasm-bindgen-futures"] +with-axum = ["askama/with-axum", "askama_axum"] [dependencies] askama = { version = ">=0.11.0, <0.13.0", features = ["serde-json"] } +askama_axum = { version = "0.4.0", optional = true } dyn-clone = "1" -erased-serde = "0.3" +erased-serde = "0.4" getrandom = { version = "0.2", features = ["js"], optional = true } -image = { version = "0.24.2", optional = true } +image = { version = "0.25", optional = true } js-sys = { version = "0.3", optional = true } plotly_derive = { version = "0.8.4", path = "../plotly_derive" } plotly_kaleido = { version = "0.8.4", path = "../plotly_kaleido", optional = true } @@ -33,15 +35,15 @@ once_cell = "1" serde = { version = "1.0.132", features = ["derive"] } serde_json = "1.0.73" serde_repr = "0.1" -serde_with = "2" +serde_with = ">=2, <4" rand = "0.8" wasm-bindgen = { version = "0.2", optional = true } wasm-bindgen-futures = { version = "0.4", optional = true } [dev-dependencies] csv = "1.1.6" -image = "0.24.4" -itertools = "0.10.3" +image = "0.25" +itertools = ">=0.10, <0.14" itertools-num = "0.1.3" ndarray = "0.15.4" plotly_kaleido = { version = "0.8.4", path = "../plotly_kaleido" } diff --git a/plotly/src/common/mod.rs b/plotly/src/common/mod.rs index 44fece3a..d6cc3082 100644 --- a/plotly/src/common/mod.rs +++ b/plotly/src/common/mod.rs @@ -201,6 +201,7 @@ pub enum PlotType { Ohlc, Sankey, Surface, + DensityMapbox, } #[derive(Serialize, Clone, Debug)] diff --git a/plotly/src/layout/mod.rs b/plotly/src/layout/mod.rs index 6026e6ed..55e2dfd8 100644 --- a/plotly/src/layout/mod.rs +++ b/plotly/src/layout/mod.rs @@ -7,6 +7,7 @@ use plotly_derive::FieldSetter; use serde::{Serialize, Serializer}; use update_menu::UpdateMenu; +use crate::common::Domain; use crate::{ color::Color, common::{ @@ -1370,6 +1371,8 @@ pub struct Mapbox { bearing: Option, /// Sets the latitude and longitude of the center of the map. center: Option
, + /// Sets the domain within which the mapbox will be drawn. + domain: Option, /// Sets the pitch angle of the map in degrees, where `0` means /// perpendicular to the surface of the map. pitch: Option, diff --git a/plotly/src/layout/update_menu.rs b/plotly/src/layout/update_menu.rs index 4823385e..eea463f0 100644 --- a/plotly/src/layout/update_menu.rs +++ b/plotly/src/layout/update_menu.rs @@ -100,7 +100,7 @@ impl ButtonBuilder { pub fn new() -> Self { Default::default() } - pub fn push_restyle(mut self, restyle: impl Restyle + Serialize) -> Self { + pub fn push_restyle(mut self, restyle: impl Restyle) -> Self { let restyle = serde_json::to_value(&restyle).unwrap(); for (k, v) in restyle.as_object().unwrap() { self.restyles.insert(k.clone(), v.clone()); diff --git a/plotly/src/lib.rs b/plotly/src/lib.rs index 2d0a1e15..72dbbc34 100644 --- a/plotly/src/lib.rs +++ b/plotly/src/lib.rs @@ -30,11 +30,13 @@ pub use configuration::Configuration; pub use layout::Layout; pub use plot::{ImageFormat, Plot, Trace}; // Also provide easy access to modules which contain additional trace-specific types -pub use traces::{box_plot, contour, histogram, image, mesh3d, sankey, scatter_mapbox, surface}; +pub use traces::{ + box_plot, contour, heat_map, histogram, image, mesh3d, sankey, scatter_mapbox, surface, +}; // Bring the different trace types into the top-level scope pub use traces::{ - Bar, BoxPlot, Candlestick, Contour, HeatMap, Histogram, Image, Mesh3D, Ohlc, Sankey, Scatter, - Scatter3D, ScatterMapbox, ScatterPolar, Surface, + Bar, BoxPlot, Candlestick, Contour, DensityMapbox, HeatMap, Histogram, Image, Mesh3D, Ohlc, + Sankey, Scatter, Scatter3D, ScatterMapbox, ScatterPolar, Surface, }; pub trait Restyle: serde::Serialize {} diff --git a/plotly/src/plot.rs b/plotly/src/plot.rs index ac80af65..03fe4ae0 100644 --- a/plotly/src/plot.rs +++ b/plotly/src/plot.rs @@ -20,6 +20,7 @@ struct PlotTemplate<'a> { #[derive(Template)] #[template(path = "static_plot.html", escape = "none")] +#[cfg(not(target_family = "wasm"))] struct StaticPlotTemplate<'a> { plot: &'a Plot, format: ImageFormat, @@ -61,7 +62,7 @@ let height = 680; let scale = 1.0; plot.write_image("filename", ImageFormat::PNG, width, height, scale); -See https://igiagkiozis.github.io/plotly/content/getting_started.html for further details. +See https://plotly.github.io/plotly.rs/content/getting_started.html for further details. "#; /// Image format for static image export. @@ -162,7 +163,7 @@ impl Traces { /// /// let layout = Layout::new().title("Line and Scatter Plot".into()); /// plot.set_layout(layout); -/// +/// /// # if false { // We don't actually want to try and display the plot in a browser when running a doctest. /// plot.show(); /// # } @@ -650,6 +651,7 @@ mod tests { assert!(!dst.exists()); } + #[cfg(not(target_os = "windows"))] #[test] #[cfg(feature = "kaleido")] fn test_save_to_png() { @@ -661,6 +663,7 @@ mod tests { assert!(!dst.exists()); } + #[cfg(not(target_os = "windows"))] #[test] #[cfg(feature = "kaleido")] fn test_save_to_jpeg() { @@ -672,6 +675,7 @@ mod tests { assert!(!dst.exists()); } + #[cfg(not(target_os = "windows"))] #[test] #[cfg(feature = "kaleido")] fn test_save_to_svg() { @@ -695,6 +699,7 @@ mod tests { assert!(!dst.exists()); } + #[cfg(not(target_os = "windows"))] #[test] #[cfg(feature = "kaleido")] fn test_save_to_pdf() { @@ -706,6 +711,7 @@ mod tests { assert!(!dst.exists()); } + #[cfg(not(target_os = "windows"))] #[test] #[cfg(feature = "kaleido")] fn test_save_to_webp() { diff --git a/plotly/src/traces/density_mapbox.rs b/plotly/src/traces/density_mapbox.rs new file mode 100644 index 00000000..dd66ce67 --- /dev/null +++ b/plotly/src/traces/density_mapbox.rs @@ -0,0 +1,146 @@ +//! Density mapbox scatter plot + +use plotly_derive::FieldSetter; +use serde::Serialize; + +use crate::common::{LegendGroupTitle, Line, PlotType, Visible}; +use crate::Trace; + +#[serde_with::skip_serializing_none] +#[derive(Serialize, Clone, Debug, FieldSetter)] +#[field_setter(box_self, kind = "trace")] +pub struct DensityMapbox +where + Lat: Serialize + Clone, + Lon: Serialize + Clone, + Z: Serialize + Clone, +{ + #[field_setter(default = "PlotType::DensityMapbox")] + r#type: PlotType, + /// Sets the trace name. The trace name appear as the legend item and on + /// hover. + name: Option, + /// Determines whether or not this trace is visible. If + /// `Visible::LegendOnly`, the trace is not drawn, but can appear as a + /// legend item (provided that the legend itself is visible). + visible: Option, + + /// Determines whether or not an item corresponding to this trace is shown + /// in the legend. + #[serde(rename = "showlegend")] + show_legend: Option, + + /// Sets the legend rank for this trace. Items and groups with smaller ranks + /// are presented on top/left side while with `"reversed" + /// `legend.trace_order` they are on bottom/right side. The default + /// legendrank is 1000, so that you can use ranks less than 1000 to + /// place certain items before all unranked items, and ranks greater + /// than 1000 to go after all unranked items. + #[serde(rename = "legendrank")] + legend_rank: Option, + /// Sets the legend group for this trace. Traces part of the same legend + /// group show/hide at the same time when toggling legend items. + #[serde(rename = "legendgroup")] + legend_group: Option, + /// Set and style the title to appear for the legend group. + #[serde(rename = "legendgrouptitle")] + legend_group_title: Option, + + /// Line display properties. + line: Option, + + lat: Option>, + lon: Option>, + z: Option>, + + /// Sets the opacity of the trace. + opacity: Option, + + /// Sets a reference between this trace's data coordinates and a mapbox + /// subplot. If "mapbox" (the default value), the data refer to + /// `layout.mapbox`. If "mapbox2", the data refer to `layout.mapbox2`, and + /// so on. + subplot: Option, + + /// Determines whether or not the color domain is computed + /// with respect to the input data (here in `z`) or the bounds set + /// in `zmin` and `zmax`. Defaults to false when `zmin` and `zmax` are + /// set by the user. + zauto: Option, + + /// Sets the upper bound of the color domain. Value should have the + /// same units as in `z` and if set, `zmin` must be set as well. + zmax: Option, + + zmid: Option, + + zmin: Option, + + zoom: Option, + + radius: Option, + //color_continuous_scale: Option>, + //color_continuous_midpoint: Option, +} + +impl DensityMapbox +where + Lat: Serialize + Clone + std::default::Default, // TODO why is "+ Default" necessary? + Lon: Serialize + Clone + std::default::Default, + Z: Serialize + Clone + std::default::Default, +{ + pub fn new(lat: Vec, lon: Vec, z: Vec) -> Box { + Box::new(Self { + lat: Some(lat), + lon: Some(lon), + z: Some(z), + ..Default::default() + }) + } +} + +impl Trace for DensityMapbox +where + Lat: Serialize + Clone, + Lon: Serialize + Clone, + Z: Serialize + Clone, +{ + fn to_json(&self) -> String { + serde_json::to_string(&self).unwrap() + } +} + +#[cfg(test)] +mod tests { + use serde_json::{json, to_value}; + + use super::*; + + #[test] + fn test_serialize_density_mapbox() { + let density_mapbox = DensityMapbox::new(vec![45.5017], vec![-73.5673], vec![1.0]) + .name("name") + .visible(Visible::True) + .show_legend(true) + .legend_rank(1000) + .legend_group("legend group") + .zoom(5) + .radius(20) + .opacity(0.5); + let expected = json!({ + "type": "densitymapbox", + "lat": [45.5017], + "lon": [-73.5673], + "z": [1.0], + "name": "name", + "visible": true, + "showlegend": true, + "legendrank": 1000, + "legendgroup": "legend group", + "opacity": 0.5, + "zoom": 5, + "radius": 20, + }); + assert_eq!(to_value(density_mapbox.clone()).unwrap(), expected); + } +} diff --git a/plotly/src/traces/mod.rs b/plotly/src/traces/mod.rs index 28f6079e..27f55f89 100644 --- a/plotly/src/traces/mod.rs +++ b/plotly/src/traces/mod.rs @@ -4,7 +4,8 @@ pub mod bar; pub mod box_plot; mod candlestick; pub mod contour; -mod heat_map; +mod density_mapbox; +pub mod heat_map; pub mod histogram; pub mod image; pub mod mesh3d; @@ -20,6 +21,7 @@ pub use bar::Bar; pub use box_plot::BoxPlot; pub use candlestick::Candlestick; pub use contour::Contour; +pub use density_mapbox::DensityMapbox; pub use heat_map::HeatMap; pub use histogram::Histogram; pub use mesh3d::Mesh3D; diff --git a/plotly_derive/Cargo.toml b/plotly_derive/Cargo.toml index 34be9693..5cd66285 100644 --- a/plotly_derive/Cargo.toml +++ b/plotly_derive/Cargo.toml @@ -4,17 +4,17 @@ version = "0.8.4" description = "Internal proc macro crate for Plotly-rs." authors = ["Ioannis Giagkiozis "] license = "MIT" -homepage = "https://github.com/igiagkiozis/plotly" +homepage = "https://github.com/plotly/plotly.rs" documentation = "https://docs.rs/plotly" -repository = "https://github.com/igiagkiozis/plotly" +repository = "https://github.com/plotly/plotly.rs" edition = "2018" keywords = ["plot", "chart", "plotly"] [dependencies] -quote = "1.0" -syn = "1.0" -proc-macro2 = "1.0" -darling = "0.14.1" +quote = "1" +syn = "2" +proc-macro2 = "1" +darling = "0.20" [lib] proc-macro = true diff --git a/plotly_derive/README.md b/plotly_derive/README.md index 868ba5c3..6c2b83d6 100644 --- a/plotly_derive/README.md +++ b/plotly_derive/README.md @@ -1,3 +1,3 @@ # plotly_derive -This is an internal crate defining procedural macros for [Plotly.rs](https://github.com/igiagkiozis/plotly). \ No newline at end of file +This is an internal crate defining procedural macros for [Plotly.rs](https://github.com/plotly/plotly.rs). \ No newline at end of file diff --git a/plotly_derive/src/field_setter.rs b/plotly_derive/src/field_setter.rs index a1642989..f330be21 100644 --- a/plotly_derive/src/field_setter.rs +++ b/plotly_derive/src/field_setter.rs @@ -492,7 +492,7 @@ impl FieldReceiver { self.attrs .iter() .filter(|attr| { - attr.path + attr.path() .segments .first() .map_or(false, |p| p.ident == name) diff --git a/plotly_kaleido/Cargo.toml b/plotly_kaleido/Cargo.toml index c05b3aa5..73b873cb 100644 --- a/plotly_kaleido/Cargo.toml +++ b/plotly_kaleido/Cargo.toml @@ -6,9 +6,9 @@ authors = ["Ioannis Giagkiozis "] license = "MIT" readme = "README.md" workspace = ".." -homepage = "https://github.com/igiagkiozis/plotly" +homepage = "https://github.com/plotly/plotly.rs" documentation = "https://docs.rs/plotly_kaleido" -repository = "https://github.com/igiagkiozis/plotly" +repository = "https://github.com/plotly/plotly.rs" edition = "2018" keywords = ["plot", "chart", "plotly", "ndarray"] @@ -17,14 +17,10 @@ exclude = ["target/*", "kaleido/*", "examples/*"] [dependencies] serde = { version = "1.0.132", features = ["derive"] } serde_json = "1.0.73" -base64 = "0.13.0" +base64 = "0.22" dunce = "1.0.2" -directories = "4.0.1" - -[dev-dependencies] -zip = "0.5.13" +directories = ">=4, <6" [build-dependencies] -zip = "0.5.13" -directories = "4.0.1" - +zip = "2.1" +directories = ">=4, <6" diff --git a/plotly_kaleido/README.md b/plotly_kaleido/README.md index f38830d4..0d0eae99 100644 --- a/plotly_kaleido/README.md +++ b/plotly_kaleido/README.md @@ -1,7 +1,7 @@ # plotly_kaleido -This is an internal crate which implements the `kaleido` feature for [Plotly.rs](https://github.com/igiagkiozis/plotly). - -The `kaleido` feature enables `Plot` conversion to the following output formats: `png`, `jpeg`, `webp`, `svg`, `pdf` and `eps`. +This is an internal crate which implements the `kaleido` feature for [Plotly.rs](https://github.com/plotly/plotly.rs). -See [examples/](https://github.com/igiagkiozis/plotly/tree/master/examples/kaleido) for usage demonstrations. \ No newline at end of file +The `kaleido` feature enables `Plot` conversion to the following output formats: `png`, `jpeg`, `webp`, `svg`, `pdf` and `eps`. + +See [examples/](https://github.com/plotly/plotly.rs/tree/main/examples/kaleido) for usage demonstrations. \ No newline at end of file diff --git a/plotly_kaleido/build.rs b/plotly_kaleido/build.rs index 5a4342c5..cf47e82d 100644 --- a/plotly_kaleido/build.rs +++ b/plotly_kaleido/build.rs @@ -10,10 +10,14 @@ use std::process::Command; use directories::ProjectDirs; -#[cfg(target_os = "linux")] +#[cfg(all(target_arch = "x86_64", target_os = "linux"))] const KALEIDO_URL: &str = "https://github.com/plotly/Kaleido/releases/download/v0.2.1/kaleido_linux_x64.zip"; +#[cfg(all(target_arch = "aarch64", target_os = "linux"))] +const KALEIDO_URL: &str = + "https://github.com/plotly/Kaleido/releases/download/v0.2.1/kaleido_linux_arm64.zip"; + #[cfg(target_os = "windows")] const KALEIDO_URL: &str = "https://github.com/plotly/Kaleido/releases/download/v0.2.1/kaleido_win_x64.zip"; diff --git a/plotly_kaleido/src/lib.rs b/plotly_kaleido/src/lib.rs index ce0d67cc..8fbfebe7 100644 --- a/plotly_kaleido/src/lib.rs +++ b/plotly_kaleido/src/lib.rs @@ -1,5 +1,5 @@ //! # Plotly Kaleido -//! Plotly Kaleido implements the `kaleido` feature for [Plotly.rs](https://github.com/igiagkiozis/plotly) +//! Plotly Kaleido implements the `kaleido` feature for [Plotly.rs](https://github.com/plotly/plotly.rs) //! //! The `kaleido` feature enables `Plot` conversion to the following output //! formats: png, jpeg, webp, svg, pdf and eps. It has the added benefit over @@ -16,6 +16,7 @@ use std::io::BufReader; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; +use base64::{engine::general_purpose, Engine as _}; use directories::ProjectDirs; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -163,12 +164,12 @@ impl Kaleido { } let output_lines = BufReader::new(process.stdout.unwrap()).lines(); - for line in output_lines.flatten() { + for line in output_lines.map_while(Result::ok) { let res = KaleidoResult::from(line.as_str()); if let Some(image_data) = res.result { let data: Vec = match format { "svg" | "eps" => image_data.as_bytes().to_vec(), - _ => base64::decode(image_data).unwrap(), + _ => general_purpose::STANDARD.decode(image_data).unwrap(), }; let mut file = File::create(dst.as_path())?; file.write_all(&data)?; @@ -237,6 +238,7 @@ mod tests { assert_eq!(to_value(kaleido_data).unwrap(), expected); } + #[cfg(not(target_os = "windows"))] #[test] fn test_save_png() { let test_plot = create_test_plot(); @@ -247,6 +249,7 @@ mod tests { assert!(std::fs::remove_file(dst.as_path()).is_ok()); } + #[cfg(not(target_os = "windows"))] #[test] fn test_save_jpeg() { let test_plot = create_test_plot(); @@ -257,6 +260,7 @@ mod tests { assert!(std::fs::remove_file(dst.as_path()).is_ok()); } + #[cfg(not(target_os = "windows"))] #[test] fn test_save_webp() { let test_plot = create_test_plot(); @@ -267,6 +271,7 @@ mod tests { assert!(std::fs::remove_file(dst.as_path()).is_ok()); } + #[cfg(not(target_os = "windows"))] #[test] fn test_save_svg() { let test_plot = create_test_plot(); @@ -277,6 +282,7 @@ mod tests { assert!(std::fs::remove_file(dst.as_path()).is_ok()); } + #[cfg(not(target_os = "windows"))] #[test] fn test_save_pdf() { let test_plot = create_test_plot();