default_x_bounds does not set "reset" bounds

Aperta
#123 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust

Direzione di ricerca

Inizia leggendo l’implementazione e la documentazione di Plot.default_x_bounds e Plot.default_y_bounds, quindi traccia il modo in cui il grafico gestisce i limiti iniziali e il comportamento di ripristino con doppio clic. Riproduci l’esempio del cerchio fornito con egui_plot 0.32.1 e confronta il movimento interattivo con il comportamento di ripristino. Il lavoro è completato quando i limiti forniti dall’utente rimangono utilizzabili e vengono ripristinati con un doppio clic.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Rust
Stelle
494
Fork
110
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di emilk/egui_plot

Tutte le issue di emilk/egui_plot

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.