Esempio n. 1
0
        private void addRandomPolynomial()
        {
            int[] multipliers = new int[5];
            Point[] points = new Point[500];

            for (int i = 0; i < multipliers.Length; i++)
                multipliers[i] = (int)((random.NextDouble() - 0.5) * 200);

            double step = (double)(10) / points.Length;
            for (int i = 0; i < points.Length; i++)
            {
                points[i].X = -5 + (step * i);
                points[i].Y = Math.Pow(points[i].X, 5) +
                    multipliers[0] * Math.Pow(points[i].X, 4) +
                    multipliers[1] * Math.Pow(points[i].X, 3) +
                    multipliers[2] * Math.Pow(points[i].X, 2) +
                    multipliers[3] * points[i].X +
                    multipliers[4];
            }

            var dataSource = points.AsDataSource<Point>();
            dataSource.SetXYMapping(point => point);


            LineGraph polinom = new LineGraph(dataSource,
                multipliers[0]+" "+multipliers[1]+" "+multipliers[2]+" "+multipliers[3]+" "+multipliers[4]);
            
            mainPlotter.Children.Add(polinom);
        }
        public MainWindow()
        {
            InitializeComponent();

            // Create first source
            source1 = new ObservableDataSource<Point>();
            // Set identity mapping of point in collection to point on plot
            source1.SetXYMapping(p => p);

            source2 = new ObservableDataSource<Point>();
            source2.SetXYMapping(p => p);

            source3 = new ObservableDataSource<Point>();
            source3.SetXYMapping(p => p);

            source4 = new ObservableDataSource<Point>();
            source4.SetXYMapping(p => p);

            source5 = new ObservableDataSource<Point>();
            source5.SetXYMapping(p => p);

            // Add all three graphs. Colors are not specified and chosen random
            graphT = plotterT.AddLineGraph(source1, Colors.Red, 2, "TEMP");
            graphH = plotterH.AddLineGraph(source2, Colors.Green, 2, "HUM");
            graphD = plotterD.AddLineGraph(source3, Colors.Blue, 2, "DUST");
            graphP = plotterP.AddLineGraph(source4, Colors.DarkSeaGreen, 2, "PRESS");
            graphACC = plotterACC.AddLineGraph(source5, Colors.CadetBlue, 2, "ACC");

            //timer.Tick += new EventHandler(timer_Tick);//Alarm Signal lamp flicker
            //timer.Interval = new TimeSpan(1000);
        }
 private void ReloadData()
 {
     if (mainPlotter != null)
     {
         mainPlotter.RemoveAllGraphs();
         linegraphs.Clear();
         string location = (comboboxLocation.SelectedItem as ContentControl).Content as string;
         AllergologySample.DataProvider dataProvider = new DataProvider(location + ".xml");
         mainPlotter.HorizontalAxis = new HorizontalDateTimeAxis();
         try
         {
             dataProvider.Load(checkBoxGroupAlergens.IsChecked == true);
             foreach (string alergen in dataProvider.GetAlergens())
             {
                 var xs = dataProvider.GetXcomponents(alergen).AsXDataSource();
                 xs.SetXMapping(d => (mainPlotter.HorizontalAxis as HorizontalDateTimeAxis).ConvertToDouble(d));
                 var ys = dataProvider.GetYcomponents(alergen).AsYDataSource();
                 CompositeDataSource dataSource = xs.Join(ys);
                 LineGraph linegraph = new LineGraph(dataSource, alergen);
                 linegraphs.Add(linegraph);
                 mainPlotter.Children.Add(linegraph);
             }
             mainPlotter.FitToView();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message + " " + ex.StackTrace);
         }
     }
 }
Esempio n. 4
0
        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            #region Data preparation
            const int N = 200;

            int[] thiknesses = new int[10];

            for(int i=0;i<10;i++)
                thiknesses[i] = i+1;

            Point[] points = new Point[N];
            double step = 10 / (double)N;

            for(int i=0;i<N;i++) {
                points[i].X = -5 + i*step;
                points[i].Y = Math.Exp(points[i].X);
            }

            EnumerableDataSource<Point> dataSource = points.AsDataSource<Point>();
            dataSource.SetXYMapping(point => point);
            #endregion

            graph = new LineGraph(dataSource, "Graph Description");
            graph.LineThickness = 3;
            graph.LineColor = Colors.Red;

            
            MainPlotter.Children.Add(graph);
            MainPlotter.FitToView();

            TextBoxDescription.Text = graph.Description;
            if (MainPlotter.Legend != null)
                TextBoxDescriptionLength.Text = MainPlotter.Legend.AllowedDescriptionLength.ToString();
        }
Esempio n. 5
0
		private void Window1_Loaded(object sender, RoutedEventArgs e)
		{
			//plotter.Viewport.Visible = new DataRect(-1, -1.1, 200, 2.2);

			const int count = 14000;
			Point[] pts = new Point[count];

			for (int i = 0; i < count; i++)
			{
				double x = i / 20.0 - 1000;
				pts[i] = new Point(x, Math.Sin(x));
			}

#if !old
			var ds = pts.AsDataSource();

			LineChart chart = new LineChart { DataSource = ds };
			//chart.Filters.Clear();

			//InclinationFilter filter = new InclinationFilter();
			//BindingOperations.SetBinding(filter, InclinationFilter.CriticalAngleProperty, new Binding { Path = new PropertyPath("Value"), Source = slider });
			//chart.Filters.Add(filter);
			plotter.Children.Add(chart);

			//plotter.Children.Add(new LineChart { DataSource = new FunctionalDataSource { Function = x => Math.Atan(x) } });
			//plotter.Children.Add(new LineChart { DataSource = new FunctionalDataSource { Function = x => Math.Tan(x) } });
#else
			var ds2 = new Microsoft.Research.DynamicDataDisplay.DataSources.RawDataSource(pts);
			lineGraph = plotter.AddLineGraph(ds2);
#endif

			((NumericAxis)plotter.MainHorizontalAxis).TicksProvider = new CustomBaseNumericTicksProvider(Math.PI);
			((NumericAxis)plotter.MainHorizontalAxis).LabelProvider = new CustomBaseNumericLabelProvider(Math.PI, "π");
		}
Esempio n. 6
0
        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            const int N = 200;
            
            double step = Math.PI * 2 / N;

            #region CompositeDataSource
            double[] x = new double[N];
            double[] y = new double[N];
            
            for (int i = 0; i < N; i++)
            {
                x[i] = i *step;
                y[i] = Math.Sin(x[i]);
            }

            var xDataSource = x.AsXDataSource();
            var yDataSource = y.AsYDataSource();

            CompositeDataSource compositeDataSource = xDataSource.Join(yDataSource);

            sin = new LineGraph(compositeDataSource, "sin(x)");

            PlotterMain.Children.Add(sin);
            #endregion

            #region RawDataSource
            Point[] points = new Point[N];

            for (int i = 0; i < N; i++) { 
                points[i] = new Point(i*step, (0.7 * Math.Cos(x[i] * 3) + 3) + (1.5 * Math.Sin(x[i] / 2 + 4)));
            }

            RawDataSource rawDataSource = points.AsDataSource();
            
            cos = new LineGraph(rawDataSource, "(0.7 * Cos(3x)+3)+(1.5*Sin(x/2+4))");
            
            PlotterMain.Children.Add(cos);
            #endregion

            #region EnumerableDataSource and Custom Graph Settings
            
            MyClass[] myObjects = new MyClass[N];
            for (int i = 0; i < N; i++)
                myObjects[i] = new MyClass() { A = 0.1 + i * step };

            EnumerableDataSource<MyClass> enumDataSource = myObjects.AsDataSource<MyClass>();
            enumDataSource.SetXYMapping(o => new Point(o.A,o.B));

            LineGraphSettings settings = new LineGraphSettings();
            settings.LineColor = Colors.Magenta;
            settings.LineThickness = Math.PI;
            settings.Description = "Log10";
            log = new LineGraph(enumDataSource, settings);
            PlotterMain.Children.Add(log);

            #endregion

            PlotterMain.FitToView();
        }
        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            #region Prepering arrays with data

            const int N = 200;
            DateTime[] x = new DateTime[N];
            double[] y = new double[N];

            TimeSpan step = new TimeSpan(11, 21, 31);

            x[0] = DateTime.Now;
            y[0] = 0;

            for (int i = 1; i < N; i++)
            {
                x[i] = x[i - 1] + step;
                y[i] = (Int32)(y[i - 1] + Math.E) % 37;
            }
            #endregion

            //Here we replace default numeric axis with DateTime Axis
            dateAxis = new HorizontalDateTimeAxis();
            plotter.HorizontalAxis =dateAxis;

            //Now we should set xMapping using ConvertToDouble method
            var xDataSource = x.AsXDataSource();
            xDataSource.SetXMapping(d => dateAxis.ConvertToDouble(d));
            var yDataSource = y.AsYDataSource();

            CompositeDataSource compositeDataSource = xDataSource.Join(yDataSource);
            LineGraph line = new LineGraph(compositeDataSource,"Graph depends on DateTime");

            plotter.Children.Add(line);
            plotter.FitToView();
        }
Esempio n. 8
0
		public Window1()
		{
			InitializeComponent();

#if MULTIPLE
			for (int ix = 0; ix < colNum; ix++)
			{
				content.ColumnDefinitions.Add(new ColumnDefinition());
			}
			for (int iy = 0; iy < rowNum; iy++)
			{
				content.RowDefinitions.Add(new RowDefinition());
			}

			for (int ix = 0; ix < colNum; ix++)
			{
				for (int iy = 0; iy < rowNum; iy++)
				{
					ChartPlotter plotter = new ChartPlotter();
					plotter.MainHorizontalAxis = null;
					plotter.MainVerticalAxis = null;
					plotter.BorderThickness = new Thickness(1);
					Grid.SetColumn(plotter, ix);
					Grid.SetRow(plotter, iy);
					content.Children.Add(plotter);
					plotter.LegendVisibility = Visibility.Hidden;
					plotter.Legend.AutoShowAndHide = false;

					AnimatedDataSource ds = new AnimatedDataSource();
					data.Add(ds);

					LineGraph line = new LineGraph(ds.DataSource);
					line.Stroke = BrushHelper.CreateBrushWithRandomHue();
					line.StrokeThickness = 2;
					line.Filters.Add(new FrequencyFilter());
					plotter.Children.Add(line);
				}
			}
#else
			ChartPlotter plotter = new ChartPlotter();
			plotter.HorizontalAxis = null;
			plotter.VerticalAxis = null;

			content.Children.Add(plotter);
			for (int i = 0; i < rowNum * colNum; i++)
			{
				AnimatedDataSource ds = new AnimatedDataSource();
				data.Add(ds);

				LineGraph line = new LineGraph(ds.DataSource);
				line.LineBrush = BrushHelper.CreateBrushWithRandomHue();
				line.LineThickness = 1;
				line.Filters.Add(new FrequencyFilter());
				plotter.Children.Add(line);
			}
#endif

			Loaded += new RoutedEventHandler(Window1_Loaded);
		}
Esempio n. 9
0
		void Window1_Loaded(object sender, RoutedEventArgs e)
		{
			var ds = new Point[] { new Point(0, 0), new Point(1, 1) }.AsDataSource();
			graph = plotter.AddLineGraph(ds);

			// hiding new unfinished legend
			plotter.NewLegend.Visibility = Visibility.Collapsed;
		}
Esempio n. 10
0
		void Window1_Loaded(object sender, RoutedEventArgs e)
		{
			double[] xs = new double[] { 1, 2, 3 };
			double[] ys = new double[] { 0.1, 0.4, 0.2 };

			var ds = xs.AsXDataSource().Join(ys.AsYDataSource());

			chart = plotter.AddLineGraph(ds, "Chart1"); 
		}
Esempio n. 11
0
		private void AddTwoSampleCharts()
		{
			var xs = Enumerable.Range(0, 800).Select(i => i * 0.01);
			var xds = xs.AsXDataSource();
			var yds1 = xs.Select(x => Math.Cos(x)).AsYDataSource();
			var yds2 = xs.Select(x => Math.Sin(x)).AsYDataSource();

			first = plotter.AddLineGraph(xds.Join(yds1), Colors.Red, 5);
			second = plotter.AddLineGraph(xds.Join(yds2), Colors.Blue, 5);
		}
Esempio n. 12
0
        public Series(ChartPlotter plotter, string descr, double thick, Color color)
        {
            DataSource = new ObservableDataSource<Point>();
              DataSource.SetXYMapping(pt => pt);

              plotter.Dispatcher.Invoke((Action)
            delegate()
            {
              Graph = plotter.AddLineGraph(DataSource, color, thick, descr);
            }
              );
        }
Esempio n. 13
0
		private void MainWindow_Loaded(object sender, RoutedEventArgs e)
		{
			// Prepare data in arrays
			const int N = 100;
			double[] x = new double[N];
			double[] y = new double[N];

			for (int i = 0; i < N; i++)
			{
				x[i] = i * 0.1;
				y[i] = Math.Cos(x[i]);
			}

			// Add data sources:
			var yDataSource = new EnumerableDataSource<double>(y);
			yDataSource.SetYMapping(Y => Y);
			yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty,
				Y => string.Format("Value is {0}", Y));

			var xDataSource = new EnumerableDataSource<double>(x);
			xDataSource.SetXMapping(X => X);


			CompositeDataSource compositeDataSource = new CompositeDataSource(xDataSource, yDataSource);

			Matrix m = Matrix.Identity;
			m.RotateAt(45, 10, 10);
			line = new LineGraph
			{
				Stroke = Brushes.Green,
				StrokeThickness = 2,
				DataTransform =
					//new MatrixDataTransform(m) 
				new RotateDataTransform(45.0.DegreesToRadians())
			};
			line.DataSource = compositeDataSource;
			line.AddToPlotter(plotter);

			plotter.Viewport.Constraints.Add(new PhysicalProportionsConstraint { ProportionRatio = 1 });


			// adding graph to plotter
			plotter.AddLineGraph(compositeDataSource,
				new Pen(Brushes.Goldenrod, 3),
				new SampleMarker(),
				new PenDescription("Cosine"));

			//plotter.Viewport.FitToViewRestrictions.Add(new FollowDataWidthRestriction { Width = 1 });

			plotter.PreviewKeyDown += plotter_KeyDown;
		}
        public MainPage()
        {
            InitializeComponent();

            double[] x = new double[200];
            for (int i = 0; i < x.Length; i++)
                x[i] = 3.1415 * i / (x.Length - 1);

            for (int i = 0; i < 25; i++)
            {
                var lg = new LineGraph();
                lines.Children.Add(lg);
                lg.Stroke = new SolidColorBrush(Color.FromArgb(255, 0, (byte)(i * 10), 0));
                lg.Description = String.Format("Data series {0}", i + 1);
                lg.StrokeThickness = 2;
                lg.Plot(x, x.Select(v => Math.Sin(v + i / 10.0)).ToArray());
            }
        }
Esempio n. 15
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var x = new LineGraph(ViewModel.X)
            {
                LinePen = new Pen(new SolidColorBrush(Colors.Red), 1),
                Description = new PenDescription("X")
            };
            plotter.Children.Add(x);
            var y = new LineGraph(ViewModel.Y)
            {
                LinePen = new Pen(new SolidColorBrush(Colors.Green), 1),
                Description = new PenDescription("Y")
            };
            plotter.Children.Add(y);
            var z = new LineGraph(ViewModel.Z)
            {
                LinePen = new Pen(new SolidColorBrush(Colors.Blue), 1),
                Description = new PenDescription("Z")
            };
            plotter.Children.Add(z);

            var alpha = new LineGraph(ViewModel.Alpha)
            {
                LinePen = new Pen(new SolidColorBrush(Colors.DarkGoldenrod), 1),
                Description = new PenDescription("Roll")
            };
            plotter.Children.Add(alpha);

            var beta = new LineGraph(ViewModel.Beta)
            {
                LinePen = new Pen(new SolidColorBrush(Colors.Violet), 1),
                Description = new PenDescription("Yaw")
            };
            plotter.Children.Add(beta);

            var gamma = new LineGraph(ViewModel.Gamma)
            {
                LinePen = new Pen(new SolidColorBrush(Colors.DarkCyan), 1),
                Description = new PenDescription("Pitch")
            };
            plotter.Children.Add(gamma);
        }
Esempio n. 16
0
        private void run()
        {
            var lens = new LensCompiler();

            var currX = getDouble(StartPos, -10);
            var endX = getDouble(EndPos, 10);
            var currY = 0.0;
            var step = getDouble(Step, 0.1);

            var obs = new ObservableDataSource<Point>();
            obs.SetXYMapping(p => p);

            if (m_PreviousGraph != null)
                m_PreviousGraph.Remove();

            m_PreviousGraph = Chart.AddLineGraph(obs, Colors.Green, 2, "Graph");

            lens.RegisterProperty("x", () => currX);
            lens.RegisterProperty("y", () => currY, y => currY = y);

            try
            {
                var fx = lens.Compile(Func.Text);

                while (currX < endX)
                {
                    fx();
                    obs.AppendAsync(Chart.Dispatcher, new Point(currX, currY));
                    currX += step;
                }
            }
            catch (LensCompilerException ex)
            {
                MessageBox.Show(
                    ex.FullMessage,
                    "Compilation Error",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error
                );
            }
        }
Esempio n. 17
0
		public PolarWindow()
		{
			InitializeComponent();

			grid.Children.Add(plotter);

			const int N = 100;
			var rs = Enumerable.Range(0, N).Select(i => (double)1);
			var phis = Enumerable.Range(0, N).Select(i => (i * (360.0 / (N - 1)).DegreesToRadians()));

			EnumerableDataSource<double> xs = new EnumerableDataSource<double>(rs);
			xs.SetXMapping(x => x);
			EnumerableDataSource<double> ys = new EnumerableDataSource<double>(phis);
			ys.SetYMapping(y => y);
			CompositeDataSource ds = new CompositeDataSource(xs, ys);

			LineGraph line = new LineGraph();
			line.DataTransform = new CompositeDataTransform(new PolarToRectTransform(), new RotateDataTransform(0.5, new Point(3, 0)));
			line.Stroke = Brushes.Blue;
			line.StrokeThickness = 1;
			line.DataSource = ds;
			plotter.Children.Add(line);
		}
Esempio n. 18
0
        private LineGraph _UpdateLine(LineGraph line, double[] x, double[] y, Color color, string description)
        {
            lock (chart)
            {
                if (line != null)
                {
                    chart.Children.Remove(line);
                }

                var xData = x.AsXDataSource();
                var yData = y.AsYDataSource();

                CompositeDataSource compositeDataSource = xData.Join(yData);
                // adding graph to plotter
                LineGraph newLine = chart.AddLineGraph(compositeDataSource, color, 2, description);

                // Force evertyhing plotted to be visible
                chart.FitToView();

                return newLine;

            }
        }
Esempio n. 19
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 18 "..\..\..\Chronogramme\EssaiChrono.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.Quit_Click);

            #line default
            #line hidden
                return;

            case 2:
                this.p = ((Microsoft.Research.DynamicDataDisplay.ChartPlotter)(target));
                return;

            case 3:
                this.chrono = ((Microsoft.Research.DynamicDataDisplay.LineGraph)(target));
                return;
            }
            this._contentLoaded = true;
        }
Esempio n. 20
0
        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < animatedX.Length; i++)
            {
                animatedX[i] = 2 * Math.PI * i / animatedX.Length;
                animatedY[i] = Math.Sin(animatedX[i]);
            }
            EnumerableDataSource<double> xSrc = new EnumerableDataSource<double>(animatedX);
            xSrc.SetXMapping(x => x);
            animatedDataSource = new EnumerableDataSource<double>(animatedY);
            animatedDataSource.SetYMapping(y => y);

            // Adding graph to plotter
            LineGraph graph = new LineGraph(new CompositeDataSource(xSrc, animatedDataSource), "Sin(x + phase)");
            plotter.Children.Add(graph);

            timer.Interval = TimeSpan.FromMilliseconds(10);
            timer.Tick += AnimatedPlot_Timer;
            timer.Start();

            // Force evertyhing plotted to be visible
            plotter.FitToView();
        }
Esempio n. 21
0
 private void UpdateLine(LineGraph line, double[] x, double[] y, Color color, string description, out LineGraph newLine)
 {
     ChartUpdater cup = new ChartUpdater(_UpdateLine);
     object _line = this.Dispatcher.Invoke(cup, line, x, y, color, description);
     newLine = _line as LineGraph;
 }
 /// <summary>
 /// 
 /// draw signer
 /// </summary>
 /// <param name="split"></param>
 /// <param name="min"></param>
 /// <param name="max"></param>
 public void DrawSigner(int split, double min, double max)
 {
     if (lastSigner != null)
     {
         lastSigner.Remove();
     }
     lastSigner = AddSplitLine(split, 1, min, max, SegmentType.NotSegment, Colors.Black);
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            List<Point> list = new List<Point>();

            Random rnd = new Random();
            for (int i = 0; i < 300; i++)
            {
                list.Add(new Point(i, rnd.Next(50)));
            }
            EnumerableDataSource<Point> edc;
            edc = new EnumerableDataSource<Point>(list);
            edc.SetXMapping(x => x.X);
            edc.SetYMapping(y => Convert.ToDouble(y.Y));
            edc.AddMapping(CircleElementPointMarker.ToolTipTextProperty, s => String.Format("Y-Data : {0}\nX-Data : {1}", s.Y, s.X));

            LineGraph line =new LineGraph(edc);
            plotter.Children.Add(line);
            //,
            line.LinePen = new Pen(Brushes.Transparent, 3);
            //line. new CircleElementPointMarker
            //{
            //    Size = 15,
            //    Brush = border,
            //    Fill = c2
            //};
            //                null
            //                ));
        }
Esempio n. 24
0
		public static LineGraph AddLineGraph(this Plotter2D plotter, IPointDataSource pointSource, Pen linePen, Description description)
		{
			if (pointSource == null)
				throw new ArgumentNullException("pointSource");
			if (linePen == null)
				throw new ArgumentNullException("linePen");

			LineGraph graph = new LineGraph
			{
				DataSource = pointSource,
				LinePen = linePen
			};
			if (description != null)
			{
				graph.Description = description;
			}
			graph.Filters.Add(new InclinationFilter());
			graph.Filters.Add(new FrequencyFilter());
			//graph.Filters.Add(new CountFilter());
			plotter.Children.Add(graph);
			return graph;
		}
        private void m_unsynchronizedSubscriber_NewMeasurements(object sender, EventArgs<ICollection<IMeasurement>> e)
        {
            if (0 == Interlocked.Exchange(ref m_processingUnsynchronizedMeasurements, 1))
            {
                try
                {
                    foreach (IMeasurement measurement in e.Argument)
                    {
                        double tempValue = measurement.AdjustedValue;

                        if (!double.IsNaN(tempValue) && !double.IsInfinity(tempValue)) // Process data only if it is not NaN or infinity.
                        {
                            ChartPlotterDynamic.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate
                                {
                                    if (m_yAxisDataCollection.Count == 0)
                                    {
                                        for (int i = 0; i < m_numberOfPointsToPlot; i++)
                                            m_yAxisDataCollection.Enqueue(tempValue);

                                        m_yAxisBindingCollection = new EnumerableDataSource<double>(m_yAxisDataCollection);
                                        m_yAxisBindingCollection.SetYMapping(y => y);

                                        m_lineGraph = ChartPlotterDynamic.AddLineGraph(new CompositeDataSource(m_xAxisBindingCollection, m_yAxisBindingCollection), Color.FromArgb(255, 25, 25, 200), 1, "");

                                    }
                                    else
                                    {
                                        double oldValue;
                                        if (m_yAxisDataCollection.TryDequeue(out oldValue))
                                            m_yAxisDataCollection.Enqueue(tempValue);
                                    }
                                    m_yAxisBindingCollection.RaiseDataChanged();
                                });
                        }
                    }
                }
                finally
                {
                    Interlocked.Exchange(ref m_processingUnsynchronizedMeasurements, 0);
                }
            }
        }
Esempio n. 26
0
        private void btnResetConfirm_Click(object sender, RoutedEventArgs e)
        {
            List<ushort> address = new List<ushort>();
            List<ushort> value = new List<ushort>();
            address.Add(0x300);
            value.Add(0x05);//IMU_reset
            byte[] xmtData = sp3.GenerateFrame(GenerateAddressValuePair(address, value));
            if (sp.IsOpen)
            {
                sp.Write(xmtData, 0, xmtData.Length);
            }
            Run r = new Run(BitConverter.ToString(xmtData));
            paraConsole.Inlines.Add(r);
            paraConsole.Inlines.Add(new LineBreak());
            //滚动到当前光标处
            rtbConsole.ScrollToEnd();

            //clear the screen
            plotterIMU1.Children.Remove(graphEulerX1);
            plotterIMU1.Children.Remove(graphEulerY1);
            plotterIMU1.Children.Remove(graphEulerZ1);
            plotterIMU2.Children.Remove(graphEulerX2);
            plotterIMU2.Children.Remove(graphEulerY2);
            plotterIMU2.Children.Remove(graphEulerZ2);
            plotterIMU3.Children.Remove(graphEulerX3);
            plotterIMU3.Children.Remove(graphEulerY3);
            plotterIMU3.Children.Remove(graphEulerZ3);
            //timer.IsEnabled = true;
            EulerX1 = new ObservableDataSource<Point>();//draw curve
            EulerY1 = new ObservableDataSource<Point>();
            EulerZ1 = new ObservableDataSource<Point>();
            EulerX2 = new ObservableDataSource<Point>();//draw curve
            EulerY2 = new ObservableDataSource<Point>();
            EulerZ2 = new ObservableDataSource<Point>();
            EulerX3 = new ObservableDataSource<Point>();//draw curve
            EulerY3 = new ObservableDataSource<Point>();
            EulerZ3 = new ObservableDataSource<Point>();
            time = 0;
            graphEulerX1 = plotterIMU1.AddLineGraph(EulerX1, Colors.Green, 2, "X");//add new curve
            graphEulerY1 = plotterIMU1.AddLineGraph(EulerY1, Colors.Red, 2, "Y");
            graphEulerZ1 = plotterIMU1.AddLineGraph(EulerZ1, Colors.Blue, 2, "Z");
            graphEulerX2 = plotterIMU2.AddLineGraph(EulerX2, Colors.Green, 2, "X");//add new curve
            graphEulerY2 = plotterIMU2.AddLineGraph(EulerY2, Colors.Red, 2, "Y");
            graphEulerZ2 = plotterIMU2.AddLineGraph(EulerZ2, Colors.Blue, 2, "Z");
            graphEulerX3 = plotterIMU3.AddLineGraph(EulerX3, Colors.Green, 2, "X");//add new curve
            graphEulerY3 = plotterIMU3.AddLineGraph(EulerY3, Colors.Red, 2, "Y");
            graphEulerZ3 = plotterIMU3.AddLineGraph(EulerZ3, Colors.Blue, 2, "Z");
        }
        /// <summary>
        /// draw split line
        /// </summary>
        /// <param name="split"></param>
        /// <param name="stroke"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public LineGraph AddSplitLine(int split, double stroke, double min, double max, SegmentType segType, Color color)
        {
            var tempPoints = new TwoDimensionViewPointCollection();
            var v_right = new EnumerableDataSource<TwoDimensionViewPoint>(tempPoints);
            v_right.SetXMapping(x => x.TimeStamp);
            v_right.SetYMapping(y => y.Value);
            tempPoints.Add(new TwoDimensionViewPoint(max, split));
            tempPoints.Add(new TwoDimensionViewPoint(min, split));

            LineGraph newSplit;
            if (segType == SegmentType.NotSegment)
            {
                newSplit = chart.AddLineGraph(v_right, color, stroke, "seg line");
            }
            else
            {
                newSplit = new LineGraph(v_right);
                newSplit.LinePen = new Pen(new SolidColorBrush(color), stroke);
            }
            if (segType == SegmentType.AccSegment)
            {
                _accSegLineList.Add(newSplit);
            }
            if (segType == SegmentType.VelSegment)
            {
                _velSegLineList.Add(newSplit);
            }
            if (segType == SegmentType.AngSegment)
            {
                _angSegLineList.Add(newSplit);
            }

            return newSplit;
        }
Esempio n. 28
0
		public static LineAndMarker<ElementMarkerPointsGraph> AddLineGraph(this Plotter2D plotter, IPointDataSource pointSource,
				Pen linePen, ElementPointMarker marker, Description description)
		{
			if (pointSource == null)
				throw new ArgumentNullException("pointSource");

			var res = new LineAndMarker<ElementMarkerPointsGraph>();



			if (linePen != null) // We are requested to draw line graphs
			{
				LineGraph graph = new LineGraph
				{
					DataSource = pointSource,
					LinePen = linePen
				};
				if (description != null)
				{
					graph.Description = description;
				}
				if (marker == null)
				{
					// Add inclination filter only to graphs without markers
					graph.Filters.Add(new InclinationFilter());
				}

				graph.Filters.Add(new FrequencyFilter());
				//graph.Filters.Add(new CountFilter());

				res.LineGraph = graph;

				plotter.Children.Add(graph);
			}

			if (marker != null) // We are requested to draw marker graphs
			{
				ElementMarkerPointsGraph markerGraph = new ElementMarkerPointsGraph
				{
					DataSource = pointSource,
					Marker = marker
				};

				res.MarkerGraph = markerGraph;

				plotter.Children.Add(markerGraph);
			}

			return res;
		}
Esempio n. 29
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // 设置串口参数
            sp.PortName = "COM9";
            sp.BaudRate = 115200;
            sp.Parity = Parity.None;
            sp.DataBits = 8;
            sp.StopBits = StopBits.One;
            sp.ReceivedBytesThreshold = 1;
            sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);

            btnPowerOn.DataContext = this;
            tbStatusBar.DataContext = this;

            //my code for plotting
            graphEulerX1 = plotterIMU1.AddLineGraph(EulerX1, Colors.Green, 2, "X");//add new curve
            graphEulerY1 = plotterIMU1.AddLineGraph(EulerY1, Colors.Red, 2, "Y");
            graphEulerZ1 = plotterIMU1.AddLineGraph(EulerZ1, Colors.Blue, 2, "Z");
            graphEulerX2 = plotterIMU2.AddLineGraph(EulerX2, Colors.Green, 2, "X");//add new curve
            graphEulerY2 = plotterIMU2.AddLineGraph(EulerY2, Colors.Red, 2, "Y");
            graphEulerZ2 = plotterIMU2.AddLineGraph(EulerZ2, Colors.Blue, 2, "Z");
            graphEulerX3 = plotterIMU3.AddLineGraph(EulerX3, Colors.Green, 2, "X");//add new curve
            graphEulerY3 = plotterIMU3.AddLineGraph(EulerY3, Colors.Red, 2, "Y");
            graphEulerZ3 = plotterIMU3.AddLineGraph(EulerZ3, Colors.Blue, 2, "Z");

            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += new EventHandler(timer_Tick);
            timer.IsEnabled = true;

            plotterIMU1.Viewport.FitToView();
            plotterIMU2.Viewport.FitToView();
            plotterIMU3.Viewport.FitToView();

            //senior's code for plotting
            /*
            timer.Interval = TimeSpan.FromSeconds(0.1);
            timer.Tick += new EventHandler(timer_Tick);

            plotterMotorVelocity.AddLineGraph(velocity, Colors.Green, 2, "Velocity");
            */
            robotStatus = FindResource("RobotStatus") as RobotStatus;
        }
        public Chart GetChart(Chart chart)
        {
            if (String.IsNullOrEmpty(chart.Expression))
            {
                return chart;
            }

            if (!chart.Expression.ToLower().Contains('x'))
            {
                return chart;
            }

            if (chart.MaxX - chart.MinX <= 0)
            {
                return chart;
            }

            if (chart.MaxY - chart.MinY <= 0)
            {
                return chart;
            }

            if (chart.Width <= 0 || chart.Height <= 0)
            {
                return chart;
            }

            Func<Double, Double> expressionEvaluator = this.CreateExpressionEvaluator(chart.Expression.Replace(",", "."));

            if (expressionEvaluator == null)
            {
                return chart;
            }

            OperationContext operationContext = OperationContext.Current;

            Thread thread = new Thread(new ThreadStart(delegate
            {
                using (new OperationContextScope(operationContext))
                {
                    ChartPlotter chartProtter = new ChartPlotter();
                    chartProtter.Width = chart.Width;
                    chartProtter.Height = chart.Height;

                    List<EnumerableDataSource<Double>> pointDataSources = this.CreatePointDataSources(chart, expressionEvaluator);

                    foreach (EnumerableDataSource<Double> pointDataSource in pointDataSources)
                    {
                        LineGraph lineGraph = new LineGraph(pointDataSource);
                        lineGraph.LinePen = new System.Windows.Media.Pen(lineGraph.LinePen.Brush, 2.0);
                        chartProtter.Children.Add(lineGraph);
                    }

                    chartProtter.LegendVisible = false;

                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        chartProtter.SaveScreenshotToStream(memoryStream, "png");
                        chart.ImageBytes = memoryStream.ToArray();
                    }
                }
            }));

            thread.SetApartmentState(System.Threading.ApartmentState.STA);
            thread.Start();
            thread.Join();

            return chart;
        }
        private void yieldTestBtn_Click(object sender, RoutedEventArgs e)
        {
            //Excel_irCurveSymbolViewModel test = new Excel_irCurveSymbolViewModel();

            //test.Symbol_ = "111000";

            //DataBaseConnectManager.DBConnection_
            //    = DataBaseConnectManager.ConnectionFactory(EnvironmentVariable.MarketDataDBFile_,"RMS");

            //test.dataLoad(new DateTime(2014, 10, 24));

            CurveManager cm = new CurveManager();

            cm.load("111000", ProgramVariable.ReferenceDate_);

            //QLNet.YieldTermStructure ts = cm.yieldTS();
            QLNet.YieldTermStructure ts = cm.yieldTSBuild();

            double[] sumY = Enumerable.Repeat<double>(0.0, 100).ToArray<double>();
            double[] x = Enumerable.Range(0, 200).Select(i => i / 100.0).ToArray();
            double[] y = new double[x.Length];

            for (int i = 0; i < x.Length; i++)
            {
                y[i] = ts.zeroRate(x[i], QLNet.Compounding.Compounded).value();
            }

            ChartPlotter cp = new ChartPlotter();

            var xData = x.AsXDataSource();
            var yData = y.AsYDataSource();

            CompositeDataSource compositeDataSource = xData.Join(yData);

            LineGraph lineG = new LineGraph(compositeDataSource);

            lineG.Description = new PenDescription("합계");
            cp.Children.Add(lineG);

            //this.chartGrid_.Children.Add(cp);

            Window w = new Window();
            w.Content = cp;
            w.ShowDialog();

        }