diff --git a/Cargo.lock b/Cargo.lock index 1944e7a..8000d5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -952,8 +952,7 @@ dependencies = [ [[package]] name = "bevy_prototype_lyon" version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e02ff6a3e8b4867eaed81a2bb2cc0bcddc33150849eefa369b4a170ef337aaa8" +source = "git+https://github.com/Nilirad/bevy_prototype_lyon?rev=d2dc33d#d2dc33d63acec2a7c586a1c1a6f8f7f2608a4422" dependencies = [ "bevy", "lyon_algorithms", diff --git a/Cargo.toml b/Cargo.toml index e480cce..de5d5e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" bevy = {version="0.15", 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.31" bevy_pancam = { version = "0.16.0", features = ["bevy_egui"] } -bevy_prototype_lyon = "0.13.0" +bevy_prototype_lyon = {git="https://github.com/Nilirad/bevy_prototype_lyon", rev = "d2dc33d"} colorgrad = "0.6.2" itertools = "0.13.0" fastrand = "2.1.0" diff --git a/src/aesthetics.rs b/src/aesthetics.rs index f4e8ac4..16ec2af 100644 --- a/src/aesthetics.rs +++ b/src/aesthetics.rs @@ -12,9 +12,8 @@ use itertools::Itertools; use std::collections::HashMap; use bevy::prelude::*; -use bevy_prototype_lyon::prelude::{ - shapes, Fill, GeometryBuilder, Path, ShapeBundle, ShapePath, Stroke, -}; +// use bevy_prototype_lyon::prelude::*; +use bevy_prototype_lyon::prelude::*; pub struct AesPlugin; @@ -177,7 +176,7 @@ pub fn plot_metabolite_color( /// Plot size as numerical variable in metabolic circles. pub fn plot_metabolite_size( ui_state: Res, - mut query: Query<(&mut Path, &CircleTag)>, + mut query: Query<(&mut Shape, &CircleTag)>, mut aes_query: Query<(&Point, &Aesthetics), (With, With)>, ) { for (sizes, aes) in aes_query.iter_mut() { @@ -214,7 +213,7 @@ pub fn plot_metabolite_size( fn restore_geoms( mut restore_event: EventReader, mut query: ParamSet<( - Query<(&mut Fill, &mut Path), With>, + Query<(&mut Fill, &mut Shape), With>, Query<&mut Stroke, (With, Without)>, )>, ) { @@ -241,7 +240,7 @@ fn restore_geoms( /// Each Side of an arrow is assigned a different axis, shared across conditions. fn build_axes( mut commands: Commands, - mut query: Query<(&Transform, &ArrowTag, &Path)>, + mut query: Query<(&Transform, &ArrowTag, &Shape)>, mut aes_query: Query< (&Distribution, &Aesthetics, &mut GeomHist), (With, Without), @@ -334,7 +333,7 @@ fn build_axes( /// Build axis. fn build_point_axes( mut commands: Commands, - mut query: Query<(&Transform, &ArrowTag, &Path)>, + mut query: Query<(&Transform, &ArrowTag, &Shape)>, mut aes_query: Query< (&Aesthetics, &mut GeomHist), (With, Without, With>), @@ -493,13 +492,8 @@ fn plot_side_hist( }; commands.spawn(( - ShapeBundle { - path: GeometryBuilder::build_as(&line), - // increment z to avoid flickering problems - transform: trans - .with_translation(trans.translation + Vec3::new(0., 0., *z_eps)), - ..default() - }, + GeometryBuilder::build_as(&line), + trans.with_translation(trans.translation + Vec3::new(0., 0., *z_eps)), Fill::color(Color::Srgba(Srgba::hex(hex).unwrap())), VisCondition { condition: aes.condition.clone(), @@ -566,11 +560,8 @@ fn plot_side_box( .unwrap_or(0), ); ( - ShapeBundle { - path: GeometryBuilder::build_as(&line_box), - transform: trans.with_scale(Vec3::new(1., 1., 1.)), - ..default() - }, + GeometryBuilder::build_as(&line_box), + trans.with_scale(Vec3::new(1., 1., 1.)), Fill::color(color), Stroke::new(Color::BLACK, 2.), ) @@ -592,11 +583,8 @@ fn plot_side_box( center: Vec2::new(circle_center, 20.), }; ( - ShapeBundle { - path: GeometryBuilder::build_as(&shape), - transform: trans.with_scale(Vec3::new(1., 1., 1.)), - ..default() - }, + GeometryBuilder::build_as(&shape), + trans.with_scale(Vec3::new(1., 1., 1.)), Fill::color(color), Stroke::new(Color::BLACK, 2.), ) @@ -668,12 +656,11 @@ fn plot_hover_hist( trans.translation.y + 150., 40. + *z_eps, ); - let geometry = ShapeBundle { - path: GeometryBuilder::build_as(&line), + let geometry = ( + GeometryBuilder::build_as(&line), transform, - visibility: Visibility::Hidden, - ..default() - }; + Visibility::Hidden, + ); let fill = Fill::color(Color::Srgba(Srgba::hex("ffb73388").unwrap())); let scales = plot_scales::(this_dist, 600., font.clone(), 12.); commands @@ -717,7 +704,7 @@ fn normalize_histogram_height( mut query: Query< ( &mut Transform, - &mut Path, + &mut Shape, &mut Fill, &HistTag, &VisCondition, @@ -753,10 +740,10 @@ fn change_color( ui_state: Res, mut query: Query<(&mut Fill, &HistTag, &ColorListener), With>, ) { - let mut gradients: HashMap = HashMap::new(); + let mut gradients: HashMap<&Side, colorgrad::Gradient> = HashMap::new(); if ui_state.is_changed() { for (mut fill, hist, color) in query.iter_mut() { - let grad = gradients.entry(hist.side.clone()).or_insert(build_grad( + let grad = gradients.entry(&hist.side).or_insert(build_grad( ui_state.zero_white, color.min_val, color.max_val, diff --git a/src/escher.rs b/src/escher.rs index 0255e6a..91cb370 100644 --- a/src/escher.rs +++ b/src/escher.rs @@ -429,11 +429,8 @@ pub fn load_map( }; z_eps += 1e-6; commands.spawn(( - ShapeBundle { - path: GeometryBuilder::build_as(&shape), - transform: Transform::from_xyz(met.x - center_x, -met.y + center_y, 2. + z_eps), - ..Default::default() - }, + GeometryBuilder::build_as(&shape), + Transform::from_xyz(met.x - center_x, -met.y + center_y, 2. + z_eps), Fill::color(MET_COLOR), Stroke::new(MET_STROK, 4.0), circle.clone(), @@ -532,11 +529,8 @@ pub fn load_map( builder = builder.add(&arrow_heads.build()); z_eps += 1e-6; commands.spawn(( - ShapeBundle { - path: builder.build(), - transform: Transform::from_xyz(ori.x - center_x, ori.y + center_y, 1. + z_eps), - ..Default::default() - }, + builder.build(), + Transform::from_xyz(ori.x - center_x, ori.y + center_y, 1. + z_eps), Stroke::new(ARROW_COLOR, 10.0), arrow.clone(), )); diff --git a/src/funcplot.rs b/src/funcplot.rs index 998e006..9fc4079 100644 --- a/src/funcplot.rs +++ b/src/funcplot.rs @@ -1,12 +1,11 @@ //! Functions for plotting data. use bevy::{ - prelude::{Color, Component, Font, Handle, Text2d, TextColor, TextFont, Transform, Vec2}, + prelude::{Color, Component, Font, Handle, TextColor, TextFont, Transform, Vec2, Visibility}, text::TextRoot, }; use bevy_prototype_lyon::{ - entity::ShapeBundle, - prelude::{GeometryBuilder, Path, PathBuilder, Stroke}, + prelude::{GeometryBuilder, PathBuilder, Shape, Stroke}, shapes, }; use colorgrad::{Color as GradColor, CustomGradient, Gradient}; @@ -59,7 +58,7 @@ enum PlottingState { /// /// This way, artifacts produced when tesselating infinitesimal areas or when the /// path is not closed are avoided. -pub fn plot_kde(samples: &[f32], n: u32, size: f32, xlimits: (f32, f32)) -> Option { +pub fn plot_kde(samples: &[f32], n: u32, size: f32, xlimits: (f32, f32)) -> Option { let center = size / 2.; let anchors = linspace(-center, center, n); if center.is_nan() { @@ -101,7 +100,7 @@ pub fn plot_kde(samples: &[f32], n: u32, size: f32, xlimits: (f32, f32)) -> Opti } /// Histogram plotting with n bins. -pub fn plot_hist(samples: &[f32], bins: u32, size: f32, xlimits: (f32, f32)) -> Option { +pub fn plot_hist(samples: &[f32], bins: u32, size: f32, xlimits: (f32, f32)) -> Option { let center = size / 2.; // a bin should not be less than a data point let bins = u32::min(samples.len() as u32 / 2, bins); @@ -164,7 +163,7 @@ fn plot_spike( } /// Plot a box where the color is the mean of the samples. -pub fn plot_box_point(n_cond: usize, cond_index: usize) -> Path { +pub fn plot_box_point(n_cond: usize, cond_index: usize) -> Shape { let box_size = 40.; let box_center = if n_cond == 0 { 0. @@ -229,17 +228,14 @@ impl ScaleBundle { } } -pub fn plot_line(size: f32, transform: Transform) -> (ShapeBundle, Stroke) { +pub fn plot_line(size: f32, transform: Transform) -> (Shape, Visibility, Transform, Stroke) { let mut path_builder = PathBuilder::new(); path_builder.move_to(Vec2::new(-size / 2., 0.)); path_builder.line_to(Vec2::new(size / 2., 0.)); ( - ShapeBundle { - path: GeometryBuilder::build_as(&path_builder.build()), - visibility: bevy::prelude::Visibility::Hidden, - transform, - ..Default::default() - }, + GeometryBuilder::build_as(&path_builder.build()), + bevy::prelude::Visibility::Hidden, + transform, Stroke::color(Color::BLACK), ) } @@ -267,7 +263,7 @@ pub fn plot_scales( ) } -fn get_extreme(path: &Path, maximum: bool, x: bool) -> f32 { +fn get_extreme(path: &Shape, maximum: bool, x: bool) -> f32 { let vec = &path .0 .iter() @@ -286,7 +282,7 @@ fn get_extreme(path: &Path, maximum: bool, x: bool) -> f32 { } /// Get the size of a path as the largest distance between its points. -pub fn path_to_vec(path: &Path) -> Vec2 { +pub fn path_to_vec(path: &Shape) -> Vec2 { let first_point = Vec2::new( get_extreme(path, false, true), get_extreme(path, false, false), diff --git a/src/gui.rs b/src/gui.rs index 302dcd2..fba3aaa 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -11,7 +11,7 @@ use bevy_egui::egui::color_picker::{color_edit_button_rgba, Alpha}; use bevy_egui::egui::epaint::Rgba; use bevy_egui::egui::Hyperlink; use bevy_egui::{egui, EguiContexts, EguiPlugin, EguiSettings}; -use bevy_prototype_lyon::prelude::Path; +use bevy_prototype_lyon::prelude::Shape; use chrono::offset::Utc; use itertools::Itertools; use std::collections::HashMap; @@ -640,7 +640,7 @@ impl AxisMode { fn show_axes( key_input: Res>, mut mode: ResMut, - mut axis_query: Query<&mut Visibility, (With, With)>, + mut axis_query: Query<&mut Visibility, (With, With)>, ) { if key_input.just_pressed(KeyCode::KeyS) { mode.toggle(); diff --git a/src/screenshot.rs b/src/screenshot.rs index d08e19d..30b9222 100644 --- a/src/screenshot.rs +++ b/src/screenshot.rs @@ -13,7 +13,7 @@ use bevy::{ asset::{io::Reader, LoadContext}, prelude::*, }; -use bevy_prototype_lyon::prelude::{Fill, Path, Stroke}; +use bevy_prototype_lyon::prelude::{Fill, Shape, Stroke}; use image::ImageFormat; use serde::Deserialize; @@ -143,7 +143,7 @@ fn save_svg_file( fonts_storage: Res, raw_fonts: Res>, path_query: Query<( - &Path, + &Shape, Option<&Fill>, Option<&Stroke>, &Transform, diff --git a/src/tests.rs b/src/tests.rs index 280a615..8b6f6c1 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -5,7 +5,7 @@ use crate::gui::{file_drop, ActiveData, UiState}; use crate::{data, escher, geom, info}; use bevy::prelude::*; use bevy::time::TimePlugin; -use bevy_prototype_lyon::prelude::{GeometryBuilder, Path, PathBuilder, ShapeBundle, Stroke}; +use bevy_prototype_lyon::prelude::{GeometryBuilder, PathBuilder, Shape, Stroke}; use bevy::tasks::IoTaskPool; @@ -43,11 +43,8 @@ fn gy_dist_aes_spaws_xaxis_spawns_hist() { let path_builder = PathBuilder::new(); let line = path_builder.build(); app.world_mut().spawn(( - ShapeBundle { - path: GeometryBuilder::build_as(&line), - transform: Transform::from_xyz(1., 1., 1.), - ..default() - }, + GeometryBuilder::build_as(&line), + Transform::from_xyz(1., 1., 1.), Stroke::new(Color::srgb(51. / 255., 78. / 255., 101. / 255.), 10.0), escher::ArrowTag { id: String::from("a"), @@ -79,7 +76,7 @@ fn gy_dist_aes_spaws_xaxis_spawns_hist() { app.update(); assert!(app .world_mut() - .query::<(&HistTag, &Path)>() + .query::<(&HistTag, &Shape)>() .iter(&app.world()) .next() .is_some()); @@ -106,11 +103,8 @@ fn point_dist_aes_spaws_box_axis_spawns_box() { let path_builder = PathBuilder::new(); let line = path_builder.build(); app.world_mut().spawn(( - ShapeBundle { - path: GeometryBuilder::build_as(&line), - transform: Transform::from_xyz(1., 1., 1.), - ..default() - }, + GeometryBuilder::build_as(&line), + Transform::from_xyz(1., 1., 1.), Stroke::new(Color::srgb(51. / 255., 78. / 255., 101. / 255.), 10.0), escher::ArrowTag { id: String::from("a"), @@ -142,7 +136,7 @@ fn point_dist_aes_spaws_box_axis_spawns_box() { assert!(app .world_mut() - .query::<(&HistTag, &Unscale, &Path)>() + .query::<(&HistTag, &Unscale, &Shape)>() .iter(&app.world()) .next() .is_some());