Skip to content

Commit

Permalink
chore: update bevy_prototype_lyon to a later commit for require funct…
Browse files Browse the repository at this point in the history
…ionality
  • Loading branch information
carrascomj committed Dec 30, 2024
1 parent 2a2a478 commit da8f8bb
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 77 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
51 changes: 19 additions & 32 deletions src/aesthetics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<UiState>,
mut query: Query<(&mut Path, &CircleTag)>,
mut query: Query<(&mut Shape, &CircleTag)>,
mut aes_query: Query<(&Point<f32>, &Aesthetics), (With<Gsize>, With<GeomMetabolite>)>,
) {
for (sizes, aes) in aes_query.iter_mut() {
Expand Down Expand Up @@ -214,7 +213,7 @@ pub fn plot_metabolite_size(
fn restore_geoms<T: Tag>(
mut restore_event: EventReader<RestoreEvent>,
mut query: ParamSet<(
Query<(&mut Fill, &mut Path), With<T>>,
Query<(&mut Fill, &mut Shape), With<T>>,
Query<&mut Stroke, (With<T>, Without<Fill>)>,
)>,
) {
Expand All @@ -241,7 +240,7 @@ fn restore_geoms<T: Tag>(
/// 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<f32>, &Aesthetics, &mut GeomHist),
(With<Gy>, Without<PopUp>),
Expand Down Expand Up @@ -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<Gy>, Without<PopUp>, With<Point<f32>>),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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.),
)
Expand All @@ -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.),
)
Expand Down Expand Up @@ -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::<Text2d>(this_dist, 600., font.clone(), 12.);
commands
Expand Down Expand Up @@ -717,7 +704,7 @@ fn normalize_histogram_height(
mut query: Query<
(
&mut Transform,
&mut Path,
&mut Shape,
&mut Fill,
&HistTag,
&VisCondition,
Expand Down Expand Up @@ -753,10 +740,10 @@ fn change_color(
ui_state: Res<UiState>,
mut query: Query<(&mut Fill, &HistTag, &ColorListener), With<Stroke>>,
) {
let mut gradients: HashMap<Side, colorgrad::Gradient> = 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,
Expand Down
14 changes: 4 additions & 10 deletions src/escher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
));
Expand Down
26 changes: 11 additions & 15 deletions src/funcplot.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<Path> {
pub fn plot_kde(samples: &[f32], n: u32, size: f32, xlimits: (f32, f32)) -> Option<Shape> {
let center = size / 2.;
let anchors = linspace(-center, center, n);
if center.is_nan() {
Expand Down Expand Up @@ -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<Path> {
pub fn plot_hist(samples: &[f32], bins: u32, size: f32, xlimits: (f32, f32)) -> Option<Shape> {
let center = size / 2.;
// a bin should not be less than a data point
let bins = u32::min(samples.len() as u32 / 2, bins);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -229,17 +228,14 @@ impl<T: TextRoot> ScaleBundle<T> {
}
}

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),
)
}
Expand Down Expand Up @@ -267,7 +263,7 @@ pub fn plot_scales<T: TextRoot>(
)
}

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()
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -640,7 +640,7 @@ impl AxisMode {
fn show_axes(
key_input: Res<ButtonInput<KeyCode>>,
mut mode: ResMut<AxisMode>,
mut axis_query: Query<&mut Visibility, (With<Xaxis>, With<Path>)>,
mut axis_query: Query<&mut Visibility, (With<Xaxis>, With<Shape>)>,
) {
if key_input.just_pressed(KeyCode::KeyS) {
mode.toggle();
Expand Down
4 changes: 2 additions & 2 deletions src/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -143,7 +143,7 @@ fn save_svg_file(
fonts_storage: Res<RawFontStorage>,
raw_fonts: Res<Assets<RawAsset>>,
path_query: Query<(
&Path,
&Shape,
Option<&Fill>,
Option<&Stroke>,
&Transform,
Expand Down
20 changes: 7 additions & 13 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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());
Expand All @@ -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"),
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit da8f8bb

Please sign in to comment.