Skip to content

Commit 39b5361

Browse files
authored
Merge pull request #3 from openmc-data-storage/adding-legend
adding-label-related-to-data
2 parents d9984ae + fa15f08 commit 39b5361

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/sauce/home.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct XsCache {
2727
pub energy_values: Vec<Vec<f64>>,
2828
pub cross_section_values: Vec<Vec<f64>>,
2929
pub checkbox_selected: Vec<bool>,
30+
pub labels: Vec<String>,
3031
}
3132

3233
#[derive(Properties, PartialEq)]
@@ -54,22 +55,22 @@ pub fn plot_component(props: &PlotProps) -> Html {
5455
for (i, (energy, cross_section)) in cache.energy_values.iter().zip(&cache.cross_section_values).enumerate() {
5556
if cache.checkbox_selected[i] {
5657
let trace = Scatter::new(energy.clone(), cross_section.clone())
57-
.name(&format!("Scatter Plot {}", i));
58+
.name(&format!("{}", cache.labels[i]));
5859
plot.add_trace(trace);
5960
}
6061
}
6162

6263
let y_axis = plotly::layout::Axis::new()
6364
.title("Cross section [barns]")
64-
.show_line(true)
65+
// .show_line(true)
6566
.zero_line(true)
6667
// .range(0) not sure how to set lower value
6768
.type_(if *is_y_log { AxisType::Log } else { AxisType::Linear });
6869

6970
let x_axis = plotly::layout::Axis::new()
7071
.title("Energy [eV]")
7172
.zero_line(true)
72-
.show_line(true)
73+
// .show_line(true)
7374
.type_(if *is_x_log { AxisType::Log } else { AxisType::Linear });
7475

7576
let layout = plotly::Layout::new()
@@ -129,23 +130,26 @@ async fn generate_cache(selected: &HashSet<usize>) -> XsCache {
129130
let mut cache_energy_values = Vec::new();
130131
let mut cache_cross_section_values = Vec::new();
131132
let mut cache_checkbox_selected = Vec::new();
133+
let mut cache_labels = Vec::new();
132134
console::log_1(&serde_wasm_bindgen::to_value("selected_id").unwrap());
133135
for &selected_id in selected.iter() {
134-
let (energy, cross_section) = get_values_by_id(selected_id as i32).await.expect("Failed to get values by ID");
136+
let (energy, cross_section, label) = get_values_by_id(selected_id as i32).await.expect("Failed to get values by ID");
135137
cache_energy_values.push(energy);
136138
cache_cross_section_values.push(cross_section);
137139
cache_checkbox_selected.push(true);
140+
cache_labels.push(label);
138141
console::log_1(&selected_id.clone().into());
139142
}
140143

141144
XsCache {
142145
energy_values: cache_energy_values,
143146
cross_section_values: cache_cross_section_values,
144147
checkbox_selected: cache_checkbox_selected,
148+
labels: cache_labels,
145149
}
146150
}
147151

148-
async fn get_values_by_id(id: i32) -> Result<(Vec<f64>, Vec<f64>), reqwest::Error> {
152+
async fn get_values_by_id(id: i32) -> Result<(Vec<f64>, Vec<f64>, String), reqwest::Error> {
149153
let data = crate::types::mock_data::Data::default();
150154
let entry = data.data.iter().find(|entry| entry.id == id).expect("Entry not found");
151155
let output = convert_string(entry);
@@ -161,7 +165,9 @@ async fn get_values_by_id(id: i32) -> Result<(Vec<f64>, Vec<f64>), reqwest::Erro
161165
.await?;
162166
console::log_1(&serde_wasm_bindgen::to_value("downloaded data").unwrap());
163167
console::log_1(&serde_wasm_bindgen::to_value(&downloaded_reaction_data).unwrap());
164-
Ok((downloaded_reaction_data.energy_values, downloaded_reaction_data.cross_section_values))
168+
169+
let label = entry.element.clone() + entry.nucleons.to_string().as_str() + " " + entry.reaction.as_str(); // + " " +entry.library.as_str() +" " + entry.temperature.as_str();
170+
Ok((downloaded_reaction_data.energy_values, downloaded_reaction_data.cross_section_values, label))
165171
}
166172

167173

0 commit comments

Comments
 (0)