default_x_bounds does not set "reset" bounds

オープン
#123 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

emilk/egui_plot のほかの issue

emilk/egui_plot の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。