aboutsummaryrefslogtreecommitdiff
path: root/src/ui/graph.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/graph.rs')
-rw-r--r--src/ui/graph.rs81
1 files changed, 51 insertions, 30 deletions
diff --git a/src/ui/graph.rs b/src/ui/graph.rs
index 198c020..725c0dc 100644
--- a/src/ui/graph.rs
+++ b/src/ui/graph.rs
@@ -85,8 +85,14 @@ impl GraphState {
self.map_to_step((frame.height() / self.scale) + 2.0 * step as f32, step),
);
let p = Point::new(
- self.map_to_step(-self.center.x / self.scale - s.width / 2.0 - step as f32, step),
- self.map_to_step(-self.center.y / self.scale - s.height / 2.0 - step as f32, step),
+ self.map_to_step(
+ -self.center.x / self.scale - s.width / 2.0 - step as f32,
+ step,
+ ),
+ self.map_to_step(
+ -self.center.y / self.scale - s.height / 2.0 - step as f32,
+ step,
+ ),
);
Rectangle::new(p, s)
}
@@ -192,35 +198,50 @@ impl canvas::Program<Message, Renderer> for GraphCanvas {
);
frame.with_save(|frame| {
- for x in (rect.x as i64 + 2 * step as i64..x_end).step_by(step) {
- let p = Point::new(x as f32, 0.0);
- frame.fill(&Path::circle(p, 10.0 / state.scale), zcolor);
- frame.fill_text(Text {
- content: x.to_string(),
- position: p,
- horizontal_alignment: iced::alignment::Horizontal::Center,
- vertical_alignment: iced::alignment::Vertical::Center,
- color: Color::WHITE,
- ..Text::default()
- });
- }
+ frame.with_clip(
+ Rectangle {
+ x: 0.0,
+ y: 0.0,
+ width: frame.width(),
+ height: frame.height(),
+ },
+ |frame| {
+ frame.translate(Vector {
+ x: frame.center().x + state.center.x,
+ y: frame.center().y + state.center.y,
+ });
+ frame.scale(state.scale);
+ for x in (rect.x as i64..x_end).step_by(step) {
+ let p = Point::new(x as f32, 0.0);
+ frame.fill(&Path::circle(p, 10.0 / state.scale), zcolor);
+ frame.fill_text(Text {
+ content: x.to_string(),
+ position: p,
+ horizontal_alignment: iced::alignment::Horizontal::Center,
+ vertical_alignment: iced::alignment::Vertical::Center,
+ color: Color::WHITE,
+ ..Text::default()
+ });
+ }
- for y in (rect.y as i64..y_end).step_by(step) {
- if y == 0 {
- continue;
- }
+ for y in (rect.y as i64..y_end).step_by(step) {
+ if y == 0 {
+ continue;
+ }
- let p = Point::new(0.0, y as f32);
- frame.fill(&Path::circle(p, 10.0 / state.scale), zcolor);
- frame.fill_text(Text {
- content: (-y).to_string(),
- position: p,
- horizontal_alignment: iced::alignment::Horizontal::Center,
- vertical_alignment: iced::alignment::Vertical::Center,
- color: Color::WHITE,
- ..Text::default()
- });
- }
+ let p = Point::new(0.0, y as f32);
+ frame.fill(&Path::circle(p, 10.0 / state.scale), zcolor);
+ frame.fill_text(Text {
+ content: (-y).to_string(),
+ position: p,
+ horizontal_alignment: iced::alignment::Horizontal::Center,
+ vertical_alignment: iced::alignment::Vertical::Center,
+ color: Color::WHITE,
+ ..Text::default()
+ });
+ }
+ },
+ )
});
let step = (step / 10).max(1);
@@ -294,7 +315,7 @@ impl canvas::Program<Message, Renderer> for GraphCanvas {
} else {
state.scale *= 1.1;
}
- state.scale = state.scale.max(0.000001);
+ state.scale = state.scale.max(0.0000000001);
return (event::Status::Captured, Some(Message::RefreshGraphCanvas));
}
_ => {}