Try to make it work with yay, maybe try dioxus again?
This commit is contained in:
parent
61865bcb7a
commit
a4c3b37019
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
11
Cargo.toml
|
@ -1,6 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
|
authors = ["David Holland <info@dustvoice.de>"]
|
||||||
name = "beanconqueror"
|
name = "beanconqueror"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -11,11 +12,9 @@ chrono = "0.4.22"
|
||||||
colourado = "0.2.0"
|
colourado = "0.2.0"
|
||||||
fast-float = "0.2.0"
|
fast-float = "0.2.0"
|
||||||
palette = "0.6.1"
|
palette = "0.6.1"
|
||||||
plotters-canvas = "*"
|
plotly = { version = "=0.8.1", features = ["wasm"] }
|
||||||
serde = "1.0.144"
|
serde = "1.0.144"
|
||||||
serde_derive = "1.0.144"
|
serde_derive = "1.0.144"
|
||||||
toml = "0.5.9"
|
toml = "0.5.9"
|
||||||
wasm-bindgen-test = "0.2"
|
yew = "0.19.0"
|
||||||
|
yew-hooks = "0.1.56"
|
||||||
[dependencies.plotters]
|
|
||||||
git = "https://github.com/plotters-rs/plotters"
|
|
||||||
|
|
122
src/main.rs
122
src/main.rs
|
@ -1,9 +1,15 @@
|
||||||
use calamine::{open_workbook, Reader, Xlsx};
|
use calamine::{open_workbook, Reader, Xlsx};
|
||||||
use chrono::{Duration, NaiveTime};
|
use chrono::{Duration, NaiveTime};
|
||||||
use colourado::{ColorPalette, PaletteType};
|
use colourado::{ColorPalette, PaletteType};
|
||||||
use plotters::prelude::*;
|
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
use plotly::{
|
||||||
|
Layout, Plot, Scatter,
|
||||||
|
common::{Mode, Title}
|
||||||
|
};
|
||||||
|
|
||||||
|
use yew::prelude::*;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
|
@ -93,9 +99,7 @@ fn process_sheet(
|
||||||
std_duration.as_secs_f32() as f64
|
std_duration.as_secs_f32() as f64
|
||||||
});
|
});
|
||||||
|
|
||||||
let map_weight_range = weight_range
|
let map_weight_range = weight_range.cells().map(|c| {
|
||||||
.cells()
|
|
||||||
.map(|c| {
|
|
||||||
c.2.get_float().unwrap_or_else(|| {
|
c.2.get_float().unwrap_or_else(|| {
|
||||||
panic!(
|
panic!(
|
||||||
"Can't get float value of weight column at position ({},{})",
|
"Can't get float value of weight column at position ({},{})",
|
||||||
|
@ -132,36 +136,19 @@ fn load_data(path: &str, cutoff: Option<f64>) -> Option<Data> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
pub fn generate_plots() -> Vec<(String, Plot)> {
|
||||||
let config_file = fs::read_to_string("config.toml").expect("Can't read config.toml");
|
let config_file = fs::read_to_string("config.toml").expect("Can't read config.toml");
|
||||||
let config: Config = toml::from_str(&config_file).expect("Can't deserialize config.toml");
|
let config: Config = toml::from_str(&config_file).expect("Can't deserialize config.toml");
|
||||||
|
|
||||||
|
let mut result: Vec<(String, Plot)> = Vec::with_capacity(config.charts.len());
|
||||||
|
|
||||||
for chart in config.charts {
|
for chart in config.charts {
|
||||||
// println!("Chart: {}\n", chart.1.title);
|
// println!("Chart: {}\n", chart.1.title);
|
||||||
|
|
||||||
let title = format!("{}/{}.svg", config.output_dir, chart.1.title);
|
let filename = format!("{}/{}.html", config.output_dir, &chart.1.title);
|
||||||
let root_area = SVGBackend::new(&title, (config.width, config.height)).into_drawing_area();
|
let mut plot = Plot::new();
|
||||||
root_area.fill(&WHITE).unwrap();
|
|
||||||
|
|
||||||
let mut ctx = ChartBuilder::on(&root_area)
|
let _shot_count = chart.1.shots.len();
|
||||||
.set_label_area_size(LabelAreaPosition::Left, 40)
|
|
||||||
.set_label_area_size(LabelAreaPosition::Bottom, 40)
|
|
||||||
.caption(&chart.1.title, ("Fira Code", 24))
|
|
||||||
.build_cartesian_2d(
|
|
||||||
0f64..(chart.1.max_time as f64),
|
|
||||||
0f64..(chart.1.max_weight as f64),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
ctx.configure_mesh()
|
|
||||||
.label_style(("Fira Code", 12))
|
|
||||||
.draw()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let shot_count = chart.1.shots.len();
|
|
||||||
|
|
||||||
let palette = ColorPalette::new(shot_count as u32, PaletteType::Random, false);
|
|
||||||
let mut palette_iter = palette.colors.iter();
|
|
||||||
|
|
||||||
for shot_nr in chart.1.shots {
|
for shot_nr in chart.1.shots {
|
||||||
if let Some(shot) = config.shots.get(&shot_nr.to_string()) {
|
if let Some(shot) = config.shots.get(&shot_nr.to_string()) {
|
||||||
|
@ -176,48 +163,63 @@ fn main() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// println!("\ttweight: {:?}, flowrate: {:?}\n", data.weight, data.flowrate);
|
|
||||||
|
|
||||||
// ctx.draw_series(data.weight.iter().map(|x| {
|
let (x, y): (Vec<_>, Vec<_>) = data.weight.into_iter().unzip();
|
||||||
// Pixel::new(*x, &RED)
|
let trace = Scatter::new(x, y).name(&shot.title).mode(Mode::Lines);
|
||||||
// })).unwrap();
|
plot.add_trace(trace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let f32_to_u8 = |color: f32| (color * 255.0) as u8;
|
let layout = Layout::new().title(Title::new(&chart.1.title));
|
||||||
|
plot.set_layout(layout);
|
||||||
|
|
||||||
let palette_color = palette_iter.next();
|
result.push((chart.1.title, plot))
|
||||||
|
// plot.use_local_plotly();
|
||||||
|
// plot.write_html(filename);
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(color) = palette_color {
|
result
|
||||||
let color = RGBAColor(
|
}
|
||||||
f32_to_u8(color.red),
|
|
||||||
f32_to_u8(color.green),
|
#[function_component(App)]
|
||||||
f32_to_u8(color.blue),
|
pub fn plot_component() -> Html {
|
||||||
1.0,
|
let plot_compounds: Vec<(String, Plot)> = generate_plots();
|
||||||
|
let (names, plots): (Vec<_>, Vec<_>) = plot_compounds.into_iter().unzip();
|
||||||
|
let ids = names.clone();
|
||||||
|
|
||||||
|
let p = yew_hooks::use_async::<_, _, ()>({
|
||||||
|
async move {
|
||||||
|
for i in names.iter().zip(plots.iter()) {
|
||||||
|
let (name, plot) = i;
|
||||||
|
plotly::bindings::new_plot(&name, &plot).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
use_effect_with_deps(
|
||||||
|
move |_| {
|
||||||
|
p.run();
|
||||||
|
|| ()
|
||||||
|
},
|
||||||
|
(),
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.draw_series(LineSeries::new(data.weight, color))
|
html! {
|
||||||
.unwrap()
|
<div id="plot-div">
|
||||||
.label(&shot.title)
|
{
|
||||||
.legend(move |(x, y)| {
|
ids.into_iter().map(|name| {
|
||||||
Rectangle::new(
|
html!{
|
||||||
[(x - 20, y + 2), (x, y - 2)],
|
<div id={name}></div>
|
||||||
ShapeStyle {
|
|
||||||
color,
|
|
||||||
filled: true,
|
|
||||||
stroke_width: 1,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
}).collect::<Html>()
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.configure_series_labels()
|
fn main() {
|
||||||
.position(SeriesLabelPosition::UpperLeft)
|
yew::start_app::<App>();
|
||||||
.margin(25)
|
|
||||||
.legend_area_size(10)
|
|
||||||
.label_font(("Fira Code", 12))
|
|
||||||
.draw()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue