Skip to content

Commit e05e4b2

Browse files
committed
first try
1 parent 0eb83eb commit e05e4b2

File tree

5 files changed

+105
-2
lines changed

5 files changed

+105
-2
lines changed

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "isotope_plotter"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
plotly = { path = "../../plotly", features = ["wasm"] }
10+
yew = "0.19.0"
11+
yew-hooks = "0.1.56"
12+
log = "0.4.6"
13+
wasm-logger = "0.2"

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# isotope_plotter.rs
2-
A prototype Rust WASM nuclear data plotter for nuclide cross sections
1+
Work in progress
2+
3+
https://openmc-data-storage.github.io/isotope_plotter.rs/

index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>Plotly Yew</title>
7+
<script src="https://cdn.plot.ly/plotly-2.14.0.min.js"></script>
8+
</head>
9+
10+
<body></body>
11+
12+
</html>

out.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
</head>
7+
8+
<body>
9+
<div>
10+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-svg.js"></script>
11+
<script src="https://cdn.plot.ly/plotly-2.12.1.min.js"></script>
12+
<div id="plotly-html-element" class="plotly-graph-div" style="height:100%; width:100%;"></div>
13+
14+
<script type="module">
15+
const graph_div = document.getElementById("plotly-html-element");
16+
await Plotly.newPlot(graph_div, {
17+
"data": [
18+
{
19+
"type": "scatter",
20+
"x": [
21+
0,
22+
1,
23+
2
24+
],
25+
"y": [
26+
2,
27+
1,
28+
0
29+
]
30+
}
31+
],
32+
"layout": {},
33+
"config": {}
34+
});
35+
</script>
36+
</div>
37+
</body>
38+
39+
</html>

src/main.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use plotly::{Plot, Scatter};
2+
use yew::prelude::*;
3+
4+
#[function_component(App)]
5+
pub fn plot_component() -> Html {
6+
let p = yew_hooks::use_async::<_, _, ()>({
7+
let id = "plot-div";
8+
let mut plot = Plot::new();
9+
let trace = Scatter::new(vec![0, 1, 2], vec![2, 1, 0]);
10+
plot.add_trace(trace);
11+
12+
let layout =
13+
plotly::Layout::new().title(plotly::common::Title::new("Displaying a Chart in Yew"));
14+
plot.set_layout(layout);
15+
16+
async move {
17+
plotly::bindings::new_plot(id, &plot).await;
18+
Ok(())
19+
}
20+
});
21+
22+
use_effect_with_deps(
23+
move |_| {
24+
p.run();
25+
|| ()
26+
},
27+
(),
28+
);
29+
30+
html! {
31+
<div id="plot-div"></div>
32+
}
33+
}
34+
35+
fn main() {
36+
wasm_logger::init(wasm_logger::Config::default());
37+
yew::start_app::<App>();
38+
}

0 commit comments

Comments
 (0)