Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e80f837

Browse files
Rework wasm feature and make it work with getrandom 0.3 (#277)
* update rand requirement from 0.8 to 0.9 * update rand_distr requirement from 0.4 to 0.5 * update getrandom requirement from 0.2 to 0.3 * update code to work with rand=0.9 and rand_distr=0.5 crates * fix issues with latest getrandom 0.3 and wasm target - reworked the wasm use case and removed the wasm feature flag, putting everything behind the target specific dependencies Signed-off-by: Andrei Gherghescu <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 7c63fbe commit e80f837

File tree

20 files changed

+63
-58
lines changed

20 files changed

+63
-58
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.wasm32-unknown-unknown]
2+
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']

.github/workflows/ci.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ jobs:
3737
with:
3838
components: clippy
3939
targets: wasm32-unknown-unknown
40-
# lint the main library workspace excluding the wasm feature
41-
- run: cargo clippy --features plotly_ndarray,plotly_image,kaleido -- -D warnings
42-
# lint the plotly library with wasm enabled
43-
- run: cargo clippy --package plotly --features wasm --target wasm32-unknown-unknown -- -D warnings
40+
# lint the main library workspace for non-wasm target
41+
- run: cargo clippy --all-features -- -D warnings
4442
# lint the non-wasm examples
4543
- run: cd ${{ github.workspace }}/examples && cargo clippy --workspace --exclude "wasm*" -- -D warnings
44+
# lint the plotly library for wasm target
45+
- run: cargo clippy --package plotly --target wasm32-unknown-unknown -- -D warnings
4646
# lint the wasm examples
4747
- run: cd ${{ github.workspace }}/examples && cargo clippy --target wasm32-unknown-unknown --package "wasm*"
4848

@@ -83,8 +83,6 @@ jobs:
8383
with:
8484
components: llvm-tools-preview
8585
- uses: taiki-e/install-action@cargo-llvm-cov
86-
# we are skipping anything to do with wasm here
87-
- run: cargo llvm-cov --workspace --features plotly_ndarray,plotly_image,kaleido --lcov --output-path lcov.info
8886
- uses: codecov/codecov-action@v3
8987

9088
build_examples:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
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).
55

6+
## [0.13.0] - 2025-02-xx
7+
### Changed
8+
- [[#277](https://github.com/plotly/plotly.rs/pull/277)] Removed `wasm` feature flag and put evrything behind target specific dependencies. Added `.cargo/config.toml` for configuration flags needed by `getrandom` version 0.3 on `wasm` targets.
9+
610
## [0.12.1] - 2025-01-02
711
### Fixed
812
- [[#269](https://github.com/plotly/plotly.rs/pull/269)] Fix publishing to crates.io issue

docs/book/src/fundamentals/shapes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use plotly::layout::{
1212
ShapeType,
1313
};
1414
use plotly::{Bar, color::NamedColor, Plot, Scatter};
15-
use rand::thread_rng;
15+
use rand::rng;
1616
use rand_distr::{Distribution, Normal};
1717
```
1818

examples/3d_charts/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ edition = "2021"
66

77
[dependencies]
88
ndarray = "0.16"
9-
rand = "0.8"
9+
rand = "0.9"
1010
plotly = { path = "../../plotly" }

examples/3d_charts/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ fn colorscale_plot(show: bool) -> Plot {
218218
let _color: Vec<usize> = (0..z.len()).collect();
219219
let _color: Vec<u8> = (0..z.len()).map(|x| x as u8).collect();
220220
let _color: Vec<i16> = {
221-
let mut rng = rand::thread_rng();
222-
(0..z.len()).map(|_| rng.gen_range(0..100)).collect()
221+
let mut rng = rand::rng();
222+
(0..z.len()).map(|_| rng.random_range(0..100)).collect()
223223
};
224224

225225
let color_max = color.iter().fold(f64::MIN, |acc, x| acc.max(*x as f64));

examples/basic_charts/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ edition = "2021"
77
[dependencies]
88
ndarray = "0.16"
99
plotly = { path = "../../plotly" }
10-
rand = "0.8"
11-
rand_distr = "0.4"
10+
rand = "0.9"
11+
rand_distr = "0.5"

examples/basic_charts/src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn simple_scatter_plot(show: bool) -> Plot {
3838
// ANCHOR: line_and_scatter_plots
3939
fn line_and_scatter_plots(show: bool) -> Plot {
4040
let n: usize = 100;
41-
let mut rng = rand::thread_rng();
41+
let mut rng = rand::rng();
4242
let random_x: Vec<f64> = Array::linspace(0., 1., n).into_raw_vec_and_offset().0;
4343
let random_y0: Vec<f64> = Normal::new(5., 1.)
4444
.unwrap()
@@ -273,8 +273,12 @@ fn colored_and_styled_scatter_plot(show: bool) -> Plot {
273273
// ANCHOR: large_data_sets
274274
fn large_data_sets(show: bool) -> Plot {
275275
let n: usize = 100_000;
276-
let mut rng = rand::thread_rng();
277-
let r: Vec<f64> = Uniform::new(0., 1.).sample_iter(&mut rng).take(n).collect();
276+
let mut rng = rand::rng();
277+
let r: Vec<f64> = Uniform::new(0., 1.)
278+
.unwrap()
279+
.sample_iter(&mut rng)
280+
.take(n)
281+
.collect();
278282
let theta: Vec<f64> = Normal::new(0., 2. * std::f64::consts::PI)
279283
.unwrap()
280284
.sample_iter(&mut rng)

examples/customization/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ edition = "2021"
66

77
[dependencies]
88
build_html = "2.5.0"
9-
rand = "0.8"
9+
rand = "0.9"
1010
ndarray = "0.16"
1111
plotly = { path = "../../plotly" }

examples/customization/src/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,11 @@ fn write_html(html_data: &str) -> String {
121121
use std::env;
122122
use std::{fs::File, io::Write};
123123

124-
use rand::{
125-
distributions::{Alphanumeric, DistString},
126-
thread_rng,
127-
};
124+
use rand::distr::{Alphanumeric, SampleString};
128125

129126
// Set up the temp file with a unique filename.
130127
let mut temp = env::temp_dir();
131-
let mut plot_name = Alphanumeric.sample_string(&mut thread_rng(), 22);
128+
let mut plot_name = Alphanumeric.sample_string(&mut rand::rng(), 22);
132129
plot_name.push_str(".html");
133130
plot_name = format!("plotly_{}", plot_name);
134131
temp.push(plot_name);

0 commit comments

Comments
 (0)