Quantcast
Channel: OxyPlot (moved to GitHub)
Viewing all articles
Browse latest Browse all 2061

New Post: WPF performance

$
0
0
Below code is currently set to use OxyPlot.WindowsForms control in a WPF application. Change the XAML to use OxyPlot.WPF for comparison. I was unable to retrieve any insight using either SharpDevelop or SlimTune profilers. Perhaps someone else can make sense of the data.

XAML:
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"
        xmlns:oxy2="clr-namespace:OxyPlot.WindowsForms;assembly=OxyPlot.WindowsForms"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded" WindowState="Maximized">
  <!-- Comment/Uncomment the plot variant to use: WPF/WF -->
  <!--<oxy:Plot x:Name="MyPlot" />-->
  <WindowsFormsHost>
    <oxy2:Plot x:Name="MyPlot" />
  </WindowsFormsHost>
</Window>
Code behind:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
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;

namespace WpfApplication1 {
  /// <summary>
  /// Interaction logic for MainWindow.xaml
  /// </summary>
  public partial class MainWindow : Window {
    public MainWindow() {
      InitializeComponent();
      InitPlot();
      // initialize plot data points
      for(int i = 0; i < TOTAL_AXES; i++) {
        _SeriesIndex[i] = 0;
        sbyte _DataValue = 0;
        for(int j = 0; j < TOTAL_POINTS/2; j++) {
          _SeriesData[i].Add(new OxyPlot.DataPoint(_SeriesData[i].Count, _DataValue));
          _SeriesData[i].Add(new OxyPlot.DataPoint(_SeriesData[i].Count, -_DataValue));
          _DataValue++;
        }
      }
      // set up refresh timer for ~30fps
      _PlotRefresh.Interval = new TimeSpan(0, 0, 0, 0, 33);
      _PlotRefresh.Tick += new EventHandler(Timer_Tick);
    }

    private void InitPlot() {
      OxyPlot.Series.LineSeries srs = null;
      OxyPlot.Axes.LinearAxis axisBottom =
        new OxyPlot.Axes.LinearAxis(OxyPlot.Axes.AxisPosition.Bottom);
      OxyPlot.Axes.LinearAxis axisLeft = null;
      double wfpos = 1.0;

      MyPlot.Model = new OxyPlot.PlotModel();
      MyPlot.Model.Padding = new OxyPlot.OxyThickness(0);
      // single bottom axis
      axisBottom.MajorGridlineStyle = OxyPlot.LineStyle.Solid;
      axisBottom.MinorGridlineStyle = OxyPlot.LineStyle.Solid;
      axisBottom.MinimumPadding = 0;
      axisBottom.MaximumPadding = 0;
      MyPlot.Model.Axes.Add(axisBottom);

      for(int i = 0; i < TOTAL_AXES; i++) {
        // initialize each left axis
        axisLeft = new OxyPlot.Axes.LinearAxis();
        axisLeft.Position = OxyPlot.Axes.AxisPosition.Left;
        axisLeft.MajorGridlineStyle = OxyPlot.LineStyle.Solid;
        axisLeft.MinorGridlineStyle = OxyPlot.LineStyle.Solid;
        axisLeft.Minimum = -128;
        axisLeft.Maximum = 127;
        axisLeft.MinimumPadding = 0;
        axisLeft.MaximumPadding = 0;
        axisLeft.EndPosition = wfpos;
        wfpos -= ((1.0 / TOTAL_AXES) - 0.01);
        axisLeft.StartPosition = wfpos;
        wfpos -= 0.01;
        axisLeft.Key = "AxisKey" + i.ToString();
        MyPlot.Model.Axes.Add(axisLeft);
        // initialize each series for the axis
        _SeriesData.Add(new List<OxyPlot.IDataPoint>(TOTAL_POINTS));
        srs = new OxyPlot.Series.LineSeries();
        srs.CanTrackerInterpolatePoints = false;
        srs.StrokeThickness = 1;
        srs.Points = _SeriesData[i];
        srs.YAxisKey = axisLeft.Key;
        MyPlot.Model.Series.Add(srs);
      }
    }
    private void Window_Loaded(object sender, RoutedEventArgs e) {
      _PlotRefresh.Start();
    }
    private void Timer_Tick(object sender, EventArgs e) {
      // this is meant for use with dynamic data/series, but the effects
      // are similar using static data for testing
      MyPlot.RefreshPlot(true);
    }

    private const int TOTAL_AXES = 4;
    private const int TOTAL_POINTS = 512;
    private List<IList<OxyPlot.IDataPoint>> _SeriesData =
      new List<IList<OxyPlot.IDataPoint>>(TOTAL_AXES);
    private int[] _SeriesIndex = new int[TOTAL_AXES];
    private System.Windows.Threading.DispatcherTimer _PlotRefresh =
      new System.Windows.Threading.DispatcherTimer();
  }
}

Viewing all articles
Browse latest Browse all 2061

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>