default_x_bounds does not set "reset" bounds

Đang mở
#123 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
data-visualization

Hướng nghiên cứu

Bắt đầu bằng cách đọc phần triển khai và tài liệu của Plot.default_x_bounds và Plot.default_y_bounds, sau đó theo dõi cách biểu đồ xử lý các giới hạn ban đầu và hành vi đặt lại khi nhấp đúp. Tái hiện ví dụ hình tròn được cung cấp bằng egui_plot 0.32.1 và so sánh chuyển động tương tác với hành vi đặt lại. Hoàn thành khi các giới hạn do người dùng cung cấp vẫn có thể sử dụng được và được khôi phục khi nhấp đúp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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 }))),
    );
}

Ngôn ngữ chính
Rust
Star
494
Fork
110
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của emilk/egui_plot

Tất cả issue của emilk/egui_plot

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.