Skip to content

Commit

Permalink
feat: plot nav improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
strasdat committed Oct 10, 2023
1 parent 89520c0 commit 4df90cd
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 105 deletions.
3 changes: 2 additions & 1 deletion rs/plotting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4", features = ["derive"] }
eframe = "0.22"
eframe = "0.23"
egui_plot = "0.23"
prost = "0.12"
tokio = { version = "1", features = ["full"] }
tonic = "0.10.2"
Expand Down
6 changes: 4 additions & 2 deletions rs/plotting/src/actors/grpc_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ impl ActorNode for ActiveGrpcSourceNodeImpl {
.add_service(PlottingWidgetServer::new(server))
.serve(address.parse().unwrap());
match server_future.await {
Ok(_) =>{}
Err(e) =>{panic!("{}", e);}
Ok(_) => {}
Err(e) => {
panic!("{}", e);
}
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions rs/plotting/src/actors/plotter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ use hollywood::core::*;
use hollywood::macros::actor_inputs;
use tokio::select;

#[derive(Clone, Debug)]
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct PlotterProp {}



/// Inbound message for the Plotter actor.
#[derive(Clone, Debug)]
#[actor_inputs(PlotterInbound, {PlotterProp, PlotterState, NullOutbound})]
Expand Down
42 changes: 26 additions & 16 deletions rs/plotting/src/bin/plotter_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub use hollywood::core::*;
use hollywood::macros::*;

use plotting::actors::plotter::{run_on_main_thread, PlotterActor, PlotterProp, PlotterState};
use plotting::graphs::common::{Bounds, OrdinateBounds};
use plotting::graphs::packets::PlottingPacket;
use plotting::graphs::packets::PlottingPackets;

Expand Down Expand Up @@ -37,25 +38,34 @@ impl OnMessage for GraphGeneratorMessage {
) {
match &self {
GraphGeneratorMessage::ClockTick(time_in_seconds) => {
let mut packets = vec![];
packets.push(PlottingPacket::append_to_curve(
("graph", "sin"),
plotting::graphs::common::Color::red(),
(*time_in_seconds, time_in_seconds.sin()),
10.0,
));
packets.push(PlottingPacket::append_to_vec3_curve(
("graph2", "sins"),
(
*time_in_seconds,
let packets = vec![
PlottingPacket::append_to_curve(
("trig0", "sin"),
plotting::graphs::common::Color::red(),
(*time_in_seconds, time_in_seconds.sin()),
1000.0,
Bounds {
x_bounds: OrdinateBounds::from_len_and_max(2.0, None),
y_bounds: OrdinateBounds::from_len_and_max(2.0, Some(1.0)),
},
),
PlottingPacket::append_to_vec3_curve(
("trig1", "sin/cos/tan"),
(
time_in_seconds.cos(),
(2.0 * time_in_seconds).cos(),
(3.0 * time_in_seconds).cos(),
*time_in_seconds,
(
time_in_seconds.sin(),
time_in_seconds.cos(),
time_in_seconds.tan(),
),
),
1000.0,
Bounds {
x_bounds: OrdinateBounds::from_len_and_max(2.0, None),
y_bounds: OrdinateBounds::from_len_and_max(2.0, Some(1.0)),
},
),
10.0,
));
];
outbound.packets.send(packets);
}
}
Expand Down
28 changes: 28 additions & 0 deletions rs/plotting/src/graphs/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ impl Color {
}
}

#[derive(Clone, Debug, Copy)]
pub struct RegionF64 {
pub min: f64,
pub max: f64,
}
#[derive(Clone, Debug, Copy)]
pub struct OrdinateBounds {
pub largest: f64,
pub len: f64,
pub data_driven: bool,
}

impl OrdinateBounds {
pub fn from_len_and_max(len: f64, max: Option<f64>) -> Self {
OrdinateBounds {
largest: max.unwrap_or_default(),
len,
data_driven: max.is_none(),
}
}
}

#[derive(Clone, Debug, Copy)]
pub struct Bounds {
pub x_bounds: OrdinateBounds,
pub y_bounds: OrdinateBounds,
}

#[derive(Clone, Debug, Default)]
pub enum LineType {
#[default]
Expand Down
8 changes: 5 additions & 3 deletions rs/plotting/src/graphs/packets.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@


use super::{
common::{Color, LineType, ResetPredicate},
common::{Bounds, Color, LineType, ResetPredicate},
scalar_curve::{NamedScalarCurve, ScalarCurve},
vec3_curve::{NamedVec3Curve, Vec3Curve},
};
Expand All @@ -20,6 +18,7 @@ impl PlottingPacket {
color: Color,
(x, y): (f64, f64),
history_length: f64,
bounds: Bounds,
) -> PlottingPacket {
let curve = NamedScalarCurve {
plot_name: plot.into(),
Expand All @@ -31,6 +30,7 @@ impl PlottingPacket {
clear_x_smaller_than: ResetPredicate {
clear_x_smaller_than: Some(x - history_length),
},
bounds,
},
};

Expand All @@ -41,6 +41,7 @@ impl PlottingPacket {
(plot, graph): (S, S),
(x, y): (f64, (f64, f64, f64)),
history_length: f64,
bounds: Bounds,
) -> PlottingPacket {
let curve = NamedVec3Curve {
plot_name: plot.into(),
Expand All @@ -52,6 +53,7 @@ impl PlottingPacket {
clear_x_smaller_than: ResetPredicate {
clear_x_smaller_than: Some(x - history_length),
},
bounds,
},
};

Expand Down
9 changes: 7 additions & 2 deletions rs/plotting/src/graphs/scalar_curve.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::graphs::common::{Color, LineType, ResetPredicate};

#[derive(Clone, Debug, Default)]
use super::common::Bounds;

#[derive(Clone, Debug)]
pub struct ScalarCurve {
pub data: Vec<(f64, f64)>,
pub color: Color,
pub curve_type: LineType,
pub clear_x_smaller_than: ResetPredicate,
pub bounds: Bounds,
}

impl ScalarCurve {
Expand All @@ -14,12 +17,14 @@ impl ScalarCurve {
color: Color,
curve_type: LineType,
f: ResetPredicate,
bounds: Bounds,
) -> Self {
ScalarCurve {
data,
color,
curve_type,
clear_x_smaller_than: f,
bounds,
}
}

Expand Down Expand Up @@ -52,7 +57,7 @@ impl ScalarCurve {
}
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
pub struct NamedScalarCurve {
pub plot_name: String,
pub graph_name: String,
Expand Down
9 changes: 7 additions & 2 deletions rs/plotting/src/graphs/vec3_curve.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::graphs::common::{Color, LineType, ResetPredicate};

#[derive(Clone, Debug, Default)]
use super::common::Bounds;

#[derive(Clone, Debug)]
pub struct Vec3Curve {
pub data: Vec<(f64, (f64, f64, f64))>,
pub color: [Color; 3],
pub curve_type: LineType,
pub clear_x_smaller_than: ResetPredicate,
pub bounds: Bounds,
}

impl Vec3Curve {
Expand All @@ -14,12 +17,14 @@ impl Vec3Curve {
color: [Color; 3],
curve_type: LineType,
f: ResetPredicate,
bounds: Bounds,
) -> Self {
Vec3Curve {
data,
color,
curve_type,
clear_x_smaller_than: f,
bounds,
}
}

Expand Down Expand Up @@ -52,7 +57,7 @@ impl Vec3Curve {
}
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
pub struct NamedVec3Curve {
pub plot_name: String,
pub graph_name: String,
Expand Down
26 changes: 25 additions & 1 deletion rs/plotting/src/grpc/proto.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::mem::size_of;

use crate::graphs::common::{LineType, ResetPredicate};
use crate::graphs::common::{Bounds, LineType, OrdinateBounds, ResetPredicate};
use crate::graphs::packets::{PlottingPacket, PlottingPackets};
use crate::graphs::scalar_curve::{NamedScalarCurve, ScalarCurve};
use crate::graphs::vec3_curve::{NamedVec3Curve, Vec3Curve};
Expand Down Expand Up @@ -89,6 +89,18 @@ pub fn from_proto(m: Messages) -> PlottingPackets {
clear_x_smaller_than: reset_predicate_from_proto(
proto_curve.reset.unwrap(),
),
bounds: Bounds {
x_bounds: OrdinateBounds {
largest: 0.0,
len: 100.0,
data_driven: true,
},
y_bounds: OrdinateBounds {
largest: 0.0,
len: 100.0,
data_driven: true,
},
},
},
}));
}
Expand Down Expand Up @@ -143,6 +155,18 @@ pub fn from_proto(m: Messages) -> PlottingPackets {
clear_x_smaller_than: reset_predicate_from_proto(
proto_curve3.reset.unwrap(),
),
bounds: Bounds {
x_bounds: OrdinateBounds {
largest: 0.0,
len: 100.0,
data_driven: true,
},
y_bounds: OrdinateBounds {
largest: 0.0,
len: 100.0,
data_driven: true,
},
},
},
}));
}
Expand Down
Loading

0 comments on commit 4df90cd

Please sign in to comment.