LoginSignup
1
2

More than 5 years have passed since last update.

[廃版] Visual Studio | WPF > OxyPlot > zoomingやpanningの効果を解除 > _PlotModel.ResetAllAxes(); > マウス操作で可能だった: 真ん中wheelをダブルクリック

Last updated at Posted at 2017-11-27
動作環境
Windows 8.1 Pro (64bit)
Microsoft Visual Studio 2017 Community
OxyPlot.Wpf v1.0.0
Sublime Text 2

OxyPlotにてzoomingやpanningをした後に、その効果を解除する(元の状態に戻す)方法がマウス操作では用意されていないようだ。
(追記: 用意されていた)。

コードでの実装としては以下の情報がある。
https://github.com/oxyplot/oxyplot/issues/748

tibel commented on 27 Jan 2016
Axis.Reset() and then PlotModel.InvalidatePlot(false) should do what you want to reset the axis to default behavior.

試したところ、InvalidatePlot(false)の方は不要であった。
と思ったが、1秒タイマーなどでInvalidatePlot(true)などしてないときにはInvalidatePlot(false)がないと、効果が解除されないようだ。

code

MainWindow.xaml
<Window x:Class="_171127_t1530_tooManyPoints.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:_171127_t1530_tooManyPoints"
        xmlns:oxy="http://oxyplot.org/wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel>
            <Button Height="30" Content="default" Name="B_default" Click="B_default_Click"/>
            <oxy:PlotView Model="{Binding _PlotModel, Mode=OneWay}" Height="250"/>
        </StackPanel>
    </Grid>
</Window>
MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
// 以下を追加した
using OxyPlot;
using OxyPlot.Series;
using System.Windows.Threading;

namespace _171127_t1530_tooManyPoints
{
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        private DispatcherTimer myTimer;
        private LineSeries mySeries;
        private Random randGen;
        private int pos = 0;
        public PlotModel _PlotModel { get; private set; } = new PlotModel() { Title = "LineSeries" };

        public MainWindow()
        {
            InitializeComponent();

            // 1. 1秒タイマーの設定
            myTimer = new DispatcherTimer(DispatcherPriority.Normal);
            myTimer.Interval = new TimeSpan(0, 0, 1);
            myTimer.Tick += myTimer_Tick;

            randGen = new Random();

            graph_init();

            myTimer.Start();
        }

        private void graph_init()
        {
            mySeries = new LineSeries
            {
                StrokeThickness = 0.5,
            };

            graph_add_series_addEach();
            _PlotModel.Series.Add(mySeries);
            this.DataContext = this;
        }

        static readonly int kNumAddPoint = 5000;
        static readonly int kMaxPoint = 200000;

        private void graph_add_series_addEach()
        {
            for (int idx=0; idx < kNumAddPoint; idx++)
            {
                var yval = randGen.NextDouble() * 10.0;
                mySeries.Points.Add(new DataPoint(pos, yval));
                pos++;
            }
        }

        void myTimer_Tick(object sender, EventArgs e)
        {
            if (pos > kMaxPoint)
            {
                return;
            }

            graph_add_series_addEach();
            _PlotModel.InvalidatePlot(true);
        }

        private void B_default_Click(object sender, RoutedEventArgs e)
        {
            _PlotModel.ResetAllAxes();
            _PlotModel.InvalidatePlot(false);
        }
    }
}

実行例

zoomingとpanning使用
qiita.png

Defaultボタン押下後
qiita2.png

マウス操作で可能だった

(追記)

  • zooming
    • マウス真ん中のwheel上下: 拡大縮小
    • マウス真ん中のwheelにて範囲選択: 指定範囲での拡大
  • panning: マウス右クリックでドラッグ
  • zoomingとpanningの解除: マウス真ん中のwheelダブルクリック
  • 値表示: マウス左クリック

以下に関連情報を見つけた。上記外にもいくつかあるようだ。
http://docs.oxyplot.org/en/latest/controllers/

1
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2