default_x_bounds does not set "reset" bounds

未关闭
#123 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
rust

调研方向

先阅读 Plot.default_x_bounds 和 Plot.default_y_bounds 的实现与文档,然后跟踪绘图如何处理初始边界和双击重置行为。使用 egui_plot 0.32.1 重现所提供的圆形示例,并比较交互式移动与重置行为。当用户提供的边界仍可用,并且能够在双击时恢复时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug

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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

emilk/egui_plot 的其他 Issue

查看 emilk/egui_plot 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。