default_x_bounds does not set "reset" bounds
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- rust
调研方向
先阅读 Plot.default_x_bounds 和 Plot.default_y_bounds 的实现与文档,然后跟踪绘图如何处理初始边界和双击重置行为。使用 egui_plot 0.32.1 重现所提供的圆形示例,并比较交互式移动与重置行为。当用户提供的边界仍可用,并且能够在双击时恢复时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
egui_plot 0.32.1
I'm trying to accomplish the following behavior:
- Set my own X/Y bounds for a plot. Ignore contained data for bounds.
- Allow user to move/zoom/... the plot
- On double-click, make the plot go back to my own X/Y bounds
This seems like a reasonable behavior to me.
Judging by the comment, Plot.default_x_bounds seem to do exactly that, as the comment states that it /// Overwrite the starting and reset bounds used for the x axis. However, in practice,
1. If I do a simple
Plot::new("circle_plot")
.default_x_bounds(-0.5, 0.5)
.default_y_bounds(-0.3, 0.3)
.show(ui, |plot_ui| {
plot_ui.line(Line::new("circle", PlotPoints::Owned(points)));
});
the user can't control the plot, the bounds always come back to the defaults
2. If I set bounds only once on start
it works better, but double-clicking does NOT reset the plot to my bounds (as suggested by the comment "Overwrite the starting and reset bounds used for the x axis"), but in such a way as to contain all the data.
let plot = Plot::new("circle_plot");
let plot = if self.first_time {
plot.default_x_bounds(-0.5, 0.5).default_y_bounds(-0.3, 0.3)
} else {
plot
};
plot.show(ui, |plot_ui| {
plot_ui.line(Line::new("circle", PlotPoints::Owned(points)).width(3.));
});
I want double-click to reset to my bounds. How can I achieve my objective?
The whole example:
use eframe::egui;
use egui_plot::{Line, Plot, PlotPoint, PlotPoints};
struct MyApp {
first_time: bool,
}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
let points: Vec<PlotPoint> = (0..100).map(|i| {
let angle = (i as f64) * std::f64::consts::TAU / 100.0;
PlotPoint { x: angle.cos(), y: angle.sin() }
}).collect();
let plot = Plot::new("circle_plot");
let plot = if self.first_time {
plot.default_x_bounds(-0.5, 0.5).default_y_bounds(-0.3, 0.3)
} else {
plot
};
plot.show(ui, |plot_ui| {
plot_ui.line(Line::new("circle", PlotPoints::Owned(points)).width(3.));
});
});
self.first_time = false;
}
}
fn main() {
let native_options = eframe::NativeOptions::default();
let _ = eframe::run_native(
"My XY Circle Plot",
native_options,
Box::new(|_cc| Ok(Box::new(MyApp { first_time: true }))),
);
}
- 主要语言
- Rust
- 星标
- 494
- 派生
- 110
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
emilk/egui_plot 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
-
bug
难度 1/5 1 小时以内 新手友好度 90/100
-
难度 3/5 1-2 天 新手友好度 66/100
-
难度 4/5 3-5 天 新手友好度 48/100
-
难度 4/5 3-5 天 新手友好度 45/100
相似的 Issue
-
chat compiler P1
难度 2/5 1-3 小时 新手友好度 76/100
HerringtonDarkholme/hd-lang#2793 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
security-advisory
难度 2/5 1-3 小时 新手友好度 78/100
MinBZK/regelrecht#2173 ·
-
ci
难度 2/5 1-3 小时 新手友好度 88/100
jonathanong/no-mistakes#5804 ·
-
triage: failed
难度 2/5 1-3 小时 新手友好度 68/100
oxc-project/tsrs#1277 · 1 条评论 ·
维护者通常 1 天内回复