Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency update #50

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,725 changes: 1,289 additions & 436 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = {version="0.13", features = ["multi-threaded", "bevy_render", "bevy_core_pipeline", "bevy_asset", "bevy_sprite", "bevy_winit", "png", "x11", "bevy_ui", "tga", "bmp", "jpeg", "webgl2"], default-features=false }
bevy_egui = "0.25"
bevy_pancam = { version = "0.11.0", features = ["bevy_egui"] }
bevy_prototype_lyon = "0.11.0"
bevy = {version="0.14.0", features = [ "bevy_render", "bevy_core_pipeline", "bevy_asset", "bevy_sprite", "bevy_winit", "png", "x11", "bevy_ui", "tga", "bmp", "jpeg", "webgl2"], default-features=false }
bevy_egui = "0.28.0"
bevy_pancam = { version = "0.13.0", features = ["bevy_egui"] }
bevy_prototype_lyon = "0.12.0"
colorgrad = "0.6.2"
itertools = "0.12.1"
fastrand = "2.0.1"
serde = "1.0.197"
serde_json = "1.0.114"
proc-macro2 = "1.0.76"
chrono = "0.4.35"
itertools = "0.13.0"
fastrand = "2.1.0"
serde = "1.0.208"
serde_json = "1.0.125"
proc-macro2 = "1.0.86"
chrono = "0.4.38"
roarsvg = "0.4.1"
anyhow = "1.0.80"
image = "0.24.9"

image = "0.25.2"
thiserror="1.0"
# dependencies exclusive for wasm32
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2.92", features = ["serde", "serde-serialize"] }
Expand Down
30 changes: 16 additions & 14 deletions src/aesthetics.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use crate::escher::{ArrowTag, CircleTag, Hover, Tag};
use crate::funcplot::{
build_grad, from_grad_clamped, lerp, max_f32, min_f32, path_to_vec, plot_box_point, plot_hist,
plot_kde, plot_line, plot_scales, zero_lerp, IgnoreSave,
use crate::{
escher::{ArrowTag, CircleTag, Hover, Tag},
funcplot::{
build_grad, from_grad_clamped, lerp, max_f32, min_f32, path_to_vec, plot_box_point,
plot_hist, plot_kde, plot_line, plot_scales, zero_lerp, IgnoreSave,
},
geom::{
AesFilter, AnyTag, Drag, GeomArrow, GeomHist, GeomMetabolite, HistPlot, HistTag, PopUp,
Side, VisCondition, Xaxis,
},
gui::{or_color, ActiveData, UiState},
};
use crate::geom::{
AesFilter, AnyTag, Drag, GeomArrow, GeomHist, GeomMetabolite, HistPlot, HistTag, PopUp, Side,
VisCondition, Xaxis,
};
use crate::gui::{or_color, ActiveData, UiState};
use itertools::Itertools;
use std::collections::HashMap;

Expand Down Expand Up @@ -137,7 +139,7 @@ pub fn plot_arrow_color(
if let Some(index) = aes.identifiers.iter().position(|r| r == tag.id()) {
stroke.color = from_grad_clamped(&grad, colors.0[index], min_val, max_val);
} else {
stroke.color = Color::rgb(0.85, 0.85, 0.85);
stroke.color = Color::srgb(0.85, 0.85, 0.85);
}
}
}
Expand Down Expand Up @@ -168,7 +170,7 @@ pub fn plot_metabolite_color(
if let Some(index) = aes.identifiers.iter().position(|r| r == tag.id()) {
fill.color = from_grad_clamped(&grad, colors.0[index], min_val, max_val);
} else {
fill.color = Color::rgb(0.85, 0.85, 0.85);
fill.color = Color::srgb(0.85, 0.85, 0.85);
}
}
}
Expand Down Expand Up @@ -503,7 +505,7 @@ fn plot_side_hist(
},
..default()
},
Fill::color(Color::hex(hex).unwrap()),
Fill::color(Srgba::hex(hex).unwrap()),
VisCondition {
condition: aes.condition.clone(),
},
Expand Down Expand Up @@ -686,7 +688,7 @@ fn plot_hover_hist(
},
..default()
};
let fill = Fill::color(Color::hex("ffb73388").unwrap());
let fill = Fill::color(Srgba::hex("ffb73388").unwrap());
let scales = plot_scales(this_dist, 600., font.clone(), 12.);
commands
.spawn((
Expand Down Expand Up @@ -756,7 +758,7 @@ fn normalize_histogram_height(
Some(cond) => or_color(cond, color_ref, true),
None => or_color(&ui_condition, color_ref, false),
};
Color::rgba_linear(color.r(), color.g(), color.b(), color.a())
Color::linear_rgba(color.r(), color.g(), color.b(), color.a())
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/data.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//! Input data logic.

use std::collections::HashSet;

use crate::aesthetics;
use crate::escher::EscherMap;
use crate::geom::{self, HistTag, Xaxis};
use crate::geom::{AesFilter, GeomHist, HistPlot};
use crate::info::Info;
use bevy::asset::io::Reader;
use bevy::asset::{AssetLoader, AsyncReadExt, LoadContext};
use bevy::prelude::*;
use bevy::reflect::TypePath;
use bevy::utils::thiserror;
use bevy::utils::BoxedFuture;
use crate::{
aesthetics,
escher::EscherMap,
geom::{self, AesFilter, GeomHist, HistPlot, HistTag, Xaxis},
info::Info,
};
use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
prelude::*,
reflect::TypePath,
utils::BoxedFuture,
};
use itertools::Itertools;
use serde::Deserialize;

use std::collections::HashSet;
use thiserror::Error as ThisError;
pub struct DataPlugin;

impl Plugin for DataPlugin {
Expand All @@ -36,7 +36,7 @@ pub struct CustomAssetLoader<A> {

/// Possible errors that can be produced by [`CustomAssetLoader`]
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
#[derive(Debug, ThisError)]
pub enum CustomJsonLoaderError {
/// An [IO](std::io) Error
#[error("Could not load asset: {0}")]
Expand All @@ -61,8 +61,8 @@ where
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let custom_asset = serde_json::from_slice::<A>(&bytes)?;
reader.read_to_end(&mut bytes).await.map_err(CustomJsonLoaderError::Io).unwrap();
Guelakais marked this conversation as resolved.
Show resolved Hide resolved
let custom_asset = serde_json::from_slice::<A>(&bytes).unwrap();
Ok(custom_asset)
})
}
Expand Down Expand Up @@ -207,7 +207,7 @@ fn load_data(
to_remove: Query<Entity, Or<(With<aesthetics::Aesthetics>, With<HistTag>, With<Xaxis>)>>,
) {
let custom_asset = if let Some(reac_handle) = &state.reaction_data {
if let Some(bevy::asset::LoadState::Failed) = asset_server.get_load_state(reac_handle) {
if let Some(bevy::asset::LoadState::Failed(_)) = asset_server.get_load_state(reac_handle) {
info_state
.notify("Failed loading data! Check if your metabolism.json is in correct format.");
state.reaction_data = None;
Expand Down
21 changes: 11 additions & 10 deletions src/escher.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
//! Data model of escher JSON maps
//! TODO: borrow strings
use crate::funcplot::draw_arrow;
use crate::geom::{GeomHist, HistTag, Side, Xaxis};
use crate::info::Info;
use crate::scale::DefaultFontSize;
use bevy::prelude::*;
use bevy::reflect::TypePath;
use crate::{
funcplot::draw_arrow,
geom::{GeomHist, HistTag, Side, Xaxis},
info::Info,
scale::DefaultFontSize,
};
use bevy::{prelude::*, reflect::TypePath};
use bevy_prototype_lyon::prelude::*;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::{cmp::Ordering, collections::HashMap};

pub const ARROW_COLOR: Color = Color::rgba(95. / 255., 94. / 255., 95. / 255., 1.0);
pub const MET_COLOR: Color = Color::rgb(190. / 255., 185. / 255., 185. / 255.);
pub const MET_STROK: Color = Color::rgb(95. / 255., 94. / 255., 95. / 255.);
pub const ARROW_COLOR: Color = Color::srgba(95. / 255., 94. / 255., 95. / 255., 1.0);
pub const MET_COLOR: Color = Color::srgb(190. / 255., 185. / 255., 185. / 255.);
pub const MET_STROK: Color = Color::srgb(95. / 255., 94. / 255., 95. / 255.);

pub struct EscherPlugin;

Expand Down Expand Up @@ -373,7 +374,7 @@ pub fn load_map(
mut existing_geom_hist: Query<&mut GeomHist>,
) {
let custom_asset = custom_assets.get_mut(&state.escher_map);
if let (Some(bevy::asset::LoadState::Failed), false) =
if let (Some(bevy::asset::LoadState::Failed(_)), false) =
(asset_server.get_load_state(&state.escher_map), state.loaded)
{
info_state.notify("Failed loading map! Check that you JSON is correct.");
Expand Down
4 changes: 2 additions & 2 deletions src/funcplot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub fn plot_scales(samples: &[f32], size: f32, font: Handle<Font>, font_size: f3
size,
font,
font_size,
Color::rgb(51. / 255., 78. / 255., 107. / 255.),
Color::srgb(51. / 255., 78. / 255., 107. / 255.),
)
}

Expand Down Expand Up @@ -346,7 +346,7 @@ fn to_grad(col: &bevy_egui::egui::Rgba) -> GradColor {
pub fn from_grad_clamped(grad: &Gradient, t: f32, min_val: f32, max_val: f32) -> Color {
let t = f32::clamp(t, min_val, max_val) as f64;
let rgba = grad.at(t).to_linear_rgba();
Color::rgba(rgba.0 as f32, rgba.1 as f32, rgba.2 as f32, rgba.3 as f32)
Color::srgba(rgba.0 as f32, rgba.1 as f32, rgba.2 as f32, rgba.3 as f32)
}

/// Build a `Gradient` for color interpolation between two colors from
Expand Down
34 changes: 20 additions & 14 deletions src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
//! Gui (windows and panels) to upload data and hover.

use crate::data::{Data, ReactionState};
use crate::escher::{ArrowTag, EscherMap, Hover, MapState, NodeToText, ARROW_COLOR};
use crate::extra_egui::NewTabHyperlink;
use crate::geom::{AnyTag, Drag, HistTag, VisCondition, Xaxis};
use crate::info::Info;
use crate::screenshot::ScreenshotEvent;
use bevy::prelude::*;
use bevy::window::PrimaryWindow;
use bevy_egui::egui::color_picker::{color_edit_button_rgba, Alpha};
use bevy_egui::egui::epaint::Rgba;
use bevy_egui::{egui, EguiContexts, EguiPlugin, EguiSettings};
use crate::{
data::{Data, ReactionState},
escher::{ArrowTag, EscherMap, Hover, MapState, NodeToText, ARROW_COLOR},
extra_egui::NewTabHyperlink,
geom::{AnyTag, Drag, HistTag, VisCondition, Xaxis},
info::Info,
screenshot::ScreenshotEvent,
};
use bevy::{prelude::*, window::PrimaryWindow};
use bevy_egui::{
egui,
egui::{
color_picker::{color_edit_button_rgba, Alpha},
epaint::Rgba,
},
EguiContexts, EguiPlugin, EguiSettings,
};
use bevy_prototype_lyon::prelude::Path;
use chrono::offset::Utc;
use itertools::Itertools;
Expand Down Expand Up @@ -44,7 +50,7 @@ impl Plugin for GuiPlugin {
building.add_systems(Update, (listen_js_escher, listen_js_data, listen_js_info));
}
}
const HIGH_COLOR: Color = Color::rgb(183. / 255., 210. / 255., 255.);
const HIGH_COLOR: Color = Color::srgb(183. / 255., 210. / 255., 255.);

/// Retrieve a mutable reference to the color or insert
/// * a random color with the alpha that is already in the map at the empty string; or
Expand Down Expand Up @@ -507,11 +513,11 @@ fn mouse_click_ui_system(
Interaction::Hovered | Interaction::Pressed => {
drag.dragged = mouse_button_input.pressed(MouseButton::Middle);
drag.rotating = mouse_button_input.pressed(MouseButton::Right);
*background_color = BackgroundColor(Color::rgba(0.9, 0.9, 0.9, 0.2));
*background_color = BackgroundColor(Color::srgba(0.9, 0.9, 0.9, 0.2));
}
_ => {
drag.dragged &= mouse_button_input.pressed(MouseButton::Middle);
*background_color = BackgroundColor(Color::rgba(1.0, 1.0, 1.0, 0.0));
*background_color = BackgroundColor(Color::srgba(1.0, 1.0, 1.0, 0.0));
}
}
}
Expand Down
23 changes: 13 additions & 10 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::funcplot::{lerp, IgnoreSave};
use std::time::Duration;

use bevy::prelude::*;
use bevy::{color::palettes::css, prelude::*};

pub struct InfoPlugin;
impl Plugin for InfoPlugin {
Expand Down Expand Up @@ -72,7 +72,7 @@ fn spawn_info_box(mut commands: Commands, top: f32, right: f32) {
},
focus_policy: bevy::ui::FocusPolicy::Block,
z_index: ZIndex::Global(10),
background_color: BackgroundColor(Color::DARK_GRAY),
background_color: BackgroundColor(css::DARK_GRAY.into()),
..Default::default()
})
.insert(InfoBox)
Expand Down Expand Up @@ -105,7 +105,7 @@ fn display_information(
TextStyle {
font: font.clone(),
font_size: 20.,
color: Color::hex("F49596").unwrap(),
color: Srgba::hex("F49596").unwrap().into(),
},
);
}
Expand Down Expand Up @@ -138,12 +138,15 @@ fn pop_infobox(
}
}
// fade out
color.0.set_a(lerp(
info_state.timer.elapsed_secs(),
0.,
info_state.timer.duration().as_secs_f32(),
1.,
0.,
));
color
.0
.set(Box::new(lerp(
info_state.timer.elapsed_secs(),
0.,
info_state.timer.duration().as_secs_f32(),
1.,
0.,
)))
.map_err(|e|format!("Error:{}",e.get_represented_type_info().unwrap().type_path())).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unwrap is not acceptable either.

Removing the unwrap (leaving the error unhandled) makes drag and dropping work but we should investigate why exactly this error arises.

}
}
24 changes: 14 additions & 10 deletions src/legend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ fn color_legend_histograms(
let image = images.get_mut(&img_legend.texture).unwrap();
if condition == "ALL" {
// show all conditions laminating the legend
background_color.0 = Color::rgba_linear(1., 1., 1., 1.);
background_color.0 = Color::linear_rgba(1., 1., 1., 1.);
let conditions = ui_state.conditions.clone();
let color_ref = match side {
Side::Left => &mut ui_state.color_left,
Expand All @@ -251,13 +251,17 @@ fn color_legend_histograms(
// depending on the order of execution, the colors
// might have not been initialized by the histogram plotter
let cl = or_color(k, color_ref, true);
let c = Color::rgba_linear(cl.r(), cl.g(), cl.b(), cl.a())
.as_rgba();
let c = Srgba::from(Color::linear_rgba(
cl.r(),
cl.g(),
cl.b(),
cl.a(),
));
[
(c.r() * 255.) as u8,
(c.g() * 255.) as u8,
(c.b() * 255.) as u8,
(c.a() * 255.) as u8,
(c.red * 255.) as u8,
(c.green * 255.) as u8,
(c.blue * 255.) as u8,
(c.alpha * 255.) as u8,
]
})
.collect();
Expand All @@ -276,7 +280,7 @@ fn color_legend_histograms(
});
image.data = data.collect::<Vec<u8>>();
} else {
if background_color.0 == Color::rgba_linear(1., 1., 1., 1.) {
if background_color.0 == Color::linear_rgba(1., 1., 1., 1.) {
// previous condition was ALL (or never changed)
// reset the image data that was painted with colors
let data = image.data.chunks(4).flat_map(|pixel| {
Expand All @@ -295,7 +299,7 @@ fn color_legend_histograms(
_ => panic!("unexpected side"),
};
let color = or_color(&condition, ref_col, true);
Color::rgba_linear(color.r(), color.g(), color.b(), color.a())
Color::linear_rgba(color.r(), color.g(), color.b(), color.a())
};
}
}
Expand Down Expand Up @@ -412,7 +416,7 @@ fn display_conditions(
TextStyle {
font: font.clone(),
font_size: 12.,
color: Color::hex("504d50").unwrap(),
color: Srgba::hex("504d50").unwrap().into(),
},
),
..Default::default()
Expand Down
Loading
Loading