public void AddLine(DataPoint[] data)
 {
     var lineSeries = new LineSeries();
     lineSeries.ItemsSource = data;
     Plot.Series.Add(lineSeries);
     var x = data.Select(d => d.X);
     _xAxis = new LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom }; //, Minimum = x.Min(), Maximum = x.Max() };
     Plot.Axes.Add(_xAxis);
 }
Exemple #2
1
        private void HandleNewStockPrice(StockPriceMessage message)
        {
            if (_series.ContainsKey(message.StockSymbol))
            {
                var seriesToUpdate = _series[message.StockSymbol];

                var newDataPoint = new DataPoint(DateTimeAxis.ToDouble(message.Date),
                    Axis.ToDouble(message.StockPrice));

                if (seriesToUpdate.Points.Count > 10)
                {
                    seriesToUpdate.Points.RemoveAt(0);
                }

                seriesToUpdate.Points.Add(newDataPoint);

                RefreshChart();
            }
        }
Exemple #3
0
        public async Task <List <DataPoint> > FetchData(DateTime startTime, DateTime endTime)
        {
            List <DataPoint> dataPoints = new List <DataPoint>();

            // using data layer for fetching data
            ConfigurationManagerJSON configManager = new ConfigurationManagerJSON();

            configManager.Initialize();
            PspDataAdapter adapter = new PspDataAdapter {
                ConfigurationManager = configManager
            };
            Dictionary <string, List <PspDataLayer.DataPoint> > res = await adapter.GetDataAsync(startTime, endTime, MeasLabel);

            // check if result has one key since we queried for only one key
            if (res.Keys.Count == 1)
            {
                // todo check the measId also

                List <PspDataLayer.DataPoint> dataResults = res.Values.ElementAt(0);
                for (int resIter = 0; resIter < dataResults.Count; resIter++)
                {
                    DateTime dataTime = dataResults[resIter].Time;
                    // convert the time from utc to local
                    //dataTime = DateTime.SpecifyKind((TimeZoneInfo.ConvertTime(dataTime, TimeZoneInfo.Utc, TimeZoneInfo.Local)), DateTimeKind.Local);
                    DataPoint dataPoint = new DataPoint(DateTimeAxis.ToDouble(dataTime), dataResults[resIter].Value);
                    dataPoints.Add(dataPoint);
                }

                // Create dataPoints based on the fetch strategy and max Resolution
                dataPoints = FetchHelper.GetDataPointsWithGivenMaxSampleInterval(dataPoints, MaxResolution, SamplingStrategy, DateTimeAxis.ToDouble(startTime));
            }
            return(dataPoints);
        }
Exemple #4
0
 private void Plot_model_MouseDown(object sender, OxyMouseDownEventArgs e)
 {
     if (e.ChangedButton == OxyMouseButton.Right)
     {
         mouse_point = new DataPoint(e.Position.X, e.Position.Y);
     }
 }
Exemple #5
0
        public void AddPoint(int i, DataPoint dataPoint)
        {
            _series[i].Points.Add(dataPoint);

            // Axes are created automatically if they are not defined
            // Set the Model property, the INotifyPropertyChanged event will make the WPF Plot control update its content
            Model = _tmp;
        }
Exemple #6
0
 public TrackerHitResult(Series.Series series, DataPoint dp, ScreenPoint sp, object item = null, double index = -1, string text = null)
 {
     this.DataPoint = dp;
     this.Position = sp;
     this.Item = item;
     this.Index = index;
     this.Series = series;
     this.Text = text;
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     int[] v = value as int[];
     DataPoint[] ret = new DataPoint[v.Length];
     for (int i = 0; i < v.Length; i++)
     {
         ret[i] = new DataPoint(i, v[i]);
     }
     return ret;
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     IList<double> v = value as IList<double>;
     DataPoint[] ret = new DataPoint[v.Count()];
     Console.WriteLine(ret.Length);
     for(int x=0; x<v.Count(); x++)
     {
         ret[x] = new DataPoint(x, v[x]);
     }
     return ret;
 }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     IntHistogram hist = value as IntHistogram;
     Debug.WriteLine("Beeeeee {0}", hist == null);
     if (hist == null) return null;
     DataPoint[] ret = new DataPoint[hist.NBins];
     for (int i = 0; i < hist.NBins; i++)
     {
         ret[i] = new DataPoint(i, hist.Channel[i]);
     }
     Debug.WriteLine(ret.Length);
     return ret;
 }
        public void PushSample(double sample)
        {
            // remove the oldest item if we have filled our buffer
            if (Points.Count >= MaxPoints)
            {
                Points.RemoveAt(0);// remove oldest item
            }

            // adjust everyone's time
            for (int i = 0; i < Points.Count; i++)
            {
                var point = Points[i];
                Points[i] = new DataPoint(point.X - SampleRate, point.Y);
            }

            // add new point
            Points.Add(sample == UNDEFINED_SAMPLE
                        ? DataPoint.Undefined
                        : new DataPoint(0, sample));
        }
 public void ShowMovingAverage(pres.TimeFrame timeFrame, IList<StockIntervalData> candelSeries)
 {
     Average.Points.Clear();
     foreach (Worker.Average c in worker.movingAverage(candelSeries, 50))
     {
         DataPoint p = new DataPoint(OxyPlot.Axes.DateTimeAxis.ToDouble(c.date),(double)c.valueAverage);
         Average.Points.Add(p);
     }
 }
 private static Series CreateRandomLineSeries(int n, string title, MarkerType markerType)
 {
     var s1 = new LineSeries { Title = title, MarkerType = markerType, MarkerStroke = OxyColors.Black, MarkerStrokeThickness = 1.0 };
     double x = 0;
     double y = 0;
     for (int i = 0; i < n; i++)
     {
         x += 2 + Randomizer.NextDouble() * 10;
         y += 1 + Randomizer.NextDouble();
         var p = new DataPoint(x, y);
         s1.Points.Add(p);
     }
     return s1;
 }
        /// <summary>
        /// Gets the point on the series that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">Interpolate the series if this flag is set to <c>true</c>.</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            var points = this.Points;

            if (points == null)
            {
                return null;
            }

            var spn = default(ScreenPoint);
            var dpn = default(DataPoint);
            double index = -1;

            double minimumDistance = double.MaxValue;

            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                var p1 = points[i];
                var p2 = points[i + 1];
                if (!this.IsValidPoint(p1) || !this.IsValidPoint(p2))
                {
                    continue;
                }

                var sp1 = this.Transform(p1);
                var sp2 = this.Transform(p2);

                // Find the nearest point on the line segment.
                var spl = ScreenPointHelper.FindPointOnLine(point, sp1, sp2);

                if (ScreenPoint.IsUndefined(spl))
                {
                    // P1 && P2 coincident
                    continue;
                }

                double l2 = (point - spl).LengthSquared;

                if (l2 < minimumDistance)
                {
                    double u = (spl - sp1).Length / (sp2 - sp1).Length;
                    dpn = new DataPoint(p1.X + (u * (p2.X - p1.X)), p1.Y + (u * (p2.Y - p1.Y)));
                    spn = spl;
                    minimumDistance = l2;
                    index = i + u;
                }
            }

            if (minimumDistance < double.MaxValue)
            {
                return new TrackerHitResult
                {
                    Series = this,
                    DataPoint = dpn,
                    Position = spn,
                    Item = this.GetItem((int)index),
                    Index = index
                };
            }

            return null;
        }
Exemple #14
0
        void ConstuctPlot(DataPointCollection dataPointCollection)
        {
            // function to filter the results if we're not auto-scaling
            Func <DataPoint, bool> isWithinAxes = p => (AutoScaleX || (p.X <= MaxXValue && p.X >= MinXValue)) && (AutoScaleY || (p.Y <= MaxYValue && p.Y >= MinYValue));

            // function to filter out any invalid data points
            Func <DataPoint, bool> isValidDataPoint = p => !double.IsInfinity(Math.Abs(p.X)) && !double.IsNaN(p.X) && !double.IsInfinity(Math.Abs(p.Y)) && !double.IsNaN(p.Y);

            //check if any normalization is selected
            var normToCurve = PlotNormalizationTypeOptionVM.SelectedValue == PlotNormalizationType.RelativeToCurve && DataSeriesCollection.Count > 1;
            var normToMax   = PlotNormalizationTypeOptionVM.SelectedValue == PlotNormalizationType.RelativeToMax && DataSeriesCollection.Count > 0;

            var tempPointArrayA = new List <Point>();
            var tempPointArrayB = new List <Point>();

            double x;
            double y;
            var    lineSeriesA = new LineSeries();
            var    lineSeriesB = new LineSeries(); //we need B for complex

            if (dataPointCollection.DataPoints[0] is ComplexDataPoint)
            {
                // normalization calculations
                var max = 1.0;
                if (normToMax)
                {
                    var points = dataPointCollection.DataPoints.Cast <ComplexDataPoint>().ToArray();
                    max = points.Select(p => p.Y.Real).Max();
                }
                double[] tempY = null;
                if (normToCurve)
                {
                    tempY = (from ComplexDataPoint dp in DataSeriesCollection[0].DataPoints select dp.Y.Real).ToArray();
                }

                var curveIndex = 0;
                foreach (var dp in dataPointCollection.DataPoints.Cast <ComplexDataPoint>())
                {
                    x = XAxisSpacingOptionVM.SelectedValue == ScalingType.Log ? Math.Log10(dp.X) : dp.X;
                    switch (PlotToggleTypeOptionVM.SelectedValue)
                    {
                    case PlotToggleType.Phase:
                        y = -(dp.Y.Phase * (180 / Math.PI));
                        break;

                    case PlotToggleType.Amp:
                        y = dp.Y.Magnitude;
                        break;

                    default:     // case PlotToggleType.Complex:
                        y = dp.Y.Real;
                        switch (PlotNormalizationTypeOptionVM.SelectedValue)
                        {
                        case PlotNormalizationType.RelativeToCurve:
                            var curveY = normToCurve && tempY != null ? tempY[curveIndex] : 1.0;
                            y = y / curveY;
                            break;

                        case PlotNormalizationType.RelativeToMax:
                            y = y / max;
                            break;
                        }
                        y = YAxisSpacingOptionVM.SelectedValue == ScalingType.Log ? Math.Log10(y) : y;
                        var p = new DataPoint(x, y);
                        if (isValidDataPoint(p) && isWithinAxes(p))
                        {
                            lineSeriesB.Points.Add(p);
                            //Add the data to the tempPointArray to add to the PlotSeriesCollection
                            tempPointArrayB.Add(new Point(x, y));
                        }
                        y = dp.Y.Imaginary;
                        break;
                    }
                    switch (PlotNormalizationTypeOptionVM.SelectedValue)
                    {
                    case PlotNormalizationType.RelativeToCurve:
                        var curveY = normToCurve && tempY != null ? tempY[curveIndex] : 1.0;
                        y = y / curveY;
                        break;

                    case PlotNormalizationType.RelativeToMax:
                        y = y / max;
                        break;
                    }
                    y = YAxisSpacingOptionVM.SelectedValue == ScalingType.Log ? Math.Log10(y) : y;
                    var point = new DataPoint(x, y);
                    if (isValidDataPoint(point) && isWithinAxes(point))
                    {
                        lineSeriesA.Points.Add(point);
                        //Add the data to the tempPointArray to add to the PlotSeriesCollection
                        tempPointArrayA.Add(new Point(x, y));
                    }
                    curveIndex += 1;
                }
                ShowComplexPlotToggle = true; // right now, it's all or nothing - assume all plots are ComplexDataPoints
            }
            else
            {
                // normalization calculations
                var max = 1.0;
                if (normToMax)
                {
                    var points = dataPointCollection.DataPoints.Cast <DoubleDataPoint>().ToArray();
                    max = points.Select(p => p.Y).Max();
                }
                double[] tempY = null;
                if (normToCurve)
                {
                    tempY = (from DoubleDataPoint dp in DataSeriesCollection[0].DataPoints select dp.Y).ToArray();
                }

                var curveIndex = 0;
                foreach (var dp in dataPointCollection.DataPoints.Cast <DoubleDataPoint>())
                {
                    x = XAxisSpacingOptionVM.SelectedValue == ScalingType.Log ? Math.Log10(dp.X) : dp.X;
                    switch (PlotNormalizationTypeOptionVM.SelectedValue)
                    {
                    case PlotNormalizationType.RelativeToCurve:
                        var curveY = normToCurve && tempY != null ? tempY[curveIndex] : 1.0;
                        y = dp.Y / curveY;
                        break;

                    case PlotNormalizationType.RelativeToMax:
                        y = dp.Y / max;
                        break;

                    default:
                        y = dp.Y;
                        break;
                    }
                    y = YAxisSpacingOptionVM.SelectedValue == ScalingType.Log ? Math.Log10(y) : y;
                    var point = new DataPoint(x, y);
                    if (isValidDataPoint(point) && isWithinAxes(point))
                    {
                        lineSeriesA.Points.Add(point);
                        //Add the data to the tempPointArray to add to the PlotSeriesCollection
                        tempPointArrayA.Add(new Point(x, y));
                    }
                    curveIndex += 1;
                }
            }
            if (ShowComplexPlotToggle)
            {
                switch (PlotToggleTypeOptionVM.SelectedValue)
                {
                case PlotToggleType.Complex:
                    lineSeriesA.Title      = dataPointCollection.Title + " (imag)";
                    lineSeriesB.Title      = dataPointCollection.Title + " (real)";
                    lineSeriesB.MarkerType = MarkerType.Circle;
                    PlotModel.Series.Add(lineSeriesB);
                    PlotSeriesCollection.Add(tempPointArrayB.ToArray());
                    break;

                case PlotToggleType.Phase:
                    lineSeriesA.Title = dataPointCollection.Title + " (phase)";
                    break;

                case PlotToggleType.Amp:
                    lineSeriesA.Title = dataPointCollection.Title + " (amp)";
                    break;
                }
                lineSeriesA.MarkerType = MarkerType.Circle;
                PlotModel.Series.Add(lineSeriesA);
                PlotModel.Title = PlotTitles[PlotTitles.Count - 1];
                PlotSeriesCollection.Add(tempPointArrayA.ToArray());
            }
            else
            {
                lineSeriesA.Title      = dataPointCollection.Title;
                lineSeriesA.MarkerType = MarkerType.Circle;
                PlotModel.Series.Add(lineSeriesA);
                PlotModel.Title = PlotTitles[PlotTitles.Count - 1];
                PlotSeriesCollection.Add(tempPointArrayA.ToArray());
            }
        }
        protected bool GetNearestPointInternal(
            IEnumerable<IDataPoint> points, ScreenPoint point, out DataPoint dpn, out ScreenPoint spn, out int index)
        {
            spn = default(ScreenPoint);
            dpn = default(DataPoint);
            index = -1;

            double minimumDistance = double.MaxValue;
            int i = 0;
            foreach (DataPoint p in points)
            {
                ScreenPoint sp = AxisBase.Transform(p, this.XAxis, this.YAxis);
                double dx = sp.x - point.x;
                double dy = sp.y - point.y;
                double d2 = dx * dx + dy * dy;

                if (d2 < minimumDistance)
                {
                    dpn = p;
                    spn = sp;
                    minimumDistance = d2;
                    index = i;
                }
                i++;
            }

            return minimumDistance < double.MaxValue;
        }
Exemple #16
0
		public void DrawLine(DataPoint start, double angle, double length, LineStyle style = LineStyle.Solid)
	    {
			var a = Math.Sin(DegreeToRadian(angle)) * length;
			var b = Math.Cos(DegreeToRadian(angle)) * length;
			DrawLine(start, new DataPoint(start.X + b, start.Y + a), style);
	    }
 protected virtual string GetSelectedPointInfo(LineSeries lineSeries, DataPoint point)
 {
     return string.Format("{0}{1}{2}: {3}{1}{4}: {5}",
         lineSeries.Title, Environment.NewLine,
         lineSeries.XAxis.Title, point.X,
         lineSeries.YAxis.Title, point.Y);
 }
        /// <summary>
        /// CTOR
        /// </summary>
        public CPUCoreWorkloadChartUserControl()
        {
            InitializeComponent();

            this.CPUCoreWorkloadPlot = new PlotModel();

            this.CPUCoreWorkloadPlot.Axes.Add(new LinearAxis()
            {
                IsZoomEnabled = false,
                Maximum = 102,
                Minimum = 0,
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineStyle = LineStyle.Dot,
                Position = AxisPosition.Left
            });

            this.CPUCoreWorkloadPlot.Axes.Add(new LinearAxis()
            {
                IsZoomEnabled = false,
                Maximum = 102,
                Minimum = 0,
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineStyle = LineStyle.Dot,
                Position = AxisPosition.Right
            });

            this.CPUCoreWorkloadPlot.Axes.Add(new LinearAxis()
            {
                IsZoomEnabled = false,
                Position = AxisPosition.Bottom,
                TickStyle = TickStyle.None,
                IsAxisVisible = false
            });

            var areaSeries = new LineSeries()
            {
                StrokeThickness = 1,
                LineStyle = OxyPlot.LineStyle.Solid,
                Color = OxyColors.Blue,
            //    Color2 = OxyColors.Transparent,
            //    Fill = OxyColor.FromRgb(214, 231, 242),
            //    DataFieldX = "X",
            //    DataFieldY = "Y",
            //    DataFieldX2 = "X"
            };

            for (int i = 0; i < 60; i++)
            {
                var dp = new DataPoint(i, 0);
                areaSeries.Points.Add(dp);
            }

            this.CPUCoreWorkloadPlot.Series.Add(areaSeries);
        }
        /// <summary>
        /// This is a non-static version of the dep. property changed event
        /// </summary>
        /// <param name="args"></param>
        void CurrentCoreWorkloadChangedPropertyCallback(DependencyPropertyChangedEventArgs args)
        {
            var areaSeries = (LineSeries)this.CPUCoreWorkloadPlot.Series[0];

            if (areaSeries.Points.Count > 60)
                areaSeries.Points.RemoveAt(0);

            double x = areaSeries.Points.Count > 0 ? areaSeries.Points[areaSeries.Points.Count - 1].X + 1 : 0;

            var dp = new DataPoint(x, Convert.ToDouble(args.NewValue));
            areaSeries.Points.Add(dp);

            if (this.CurrentCpuWorkloadSeries != null && this.CurrentCpuWorkloadSeries.Count == 0)
            {
                this.CurrentCpuWorkloadSeries.Add(new ChartDataPoint() { Name = "Workload", Value = Convert.ToDouble(args.NewValue) });
            }
            else
            {
                this.CurrentCpuWorkloadSeries.FirstOrDefault().Value = Convert.ToDouble(args.NewValue);
            }

            this.CPUCoreWorkloadPlot.InvalidatePlot(true);
        }
 /// <summary>
 /// Transforms the specified point to screen coordinates.
 /// </summary>
 /// <param name="p">
 /// The point.
 /// </param>
 /// <param name="xaxis">
 /// The x axis.
 /// </param>
 /// <param name="yaxis">
 /// The y axis.
 /// </param>
 /// <returns>
 /// The transformed point.
 /// </returns>
 public static ScreenPoint Transform(DataPoint p, Axis xaxis, Axis yaxis)
 {
     return xaxis.Transform(p.x, p.y, yaxis);
 }
        /// <summary>
        /// Gets the point on the series that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">Interpolate the series if this flag is set to <c>true</c>.</param>
        /// <returns>
        /// A TrackerHitResult for the current hit.
        /// </returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (interpolate)
            {
                return null;
            }

            TrackerHitResult result = null;

            // http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/
            double minimumDistance = double.MaxValue;
            var points = this.Points;

            for (int i = 0; i < points.Count; i++)
            {
                var p1 = points[i];
                var basePoint = new DataPoint(p1.X, this.Base);
                var sp1 = this.Transform(p1);
                var sp2 = this.Transform(basePoint);
                var u = ScreenPointHelper.FindPositionOnLine(point, sp1, sp2);

                if (double.IsNaN(u))
                {
                    continue;
                }

                if (u < 0 || u > 1)
                {
                    continue; // outside line
                }

                var sp = sp1 + ((sp2 - sp1) * u);
                double distance = (point - sp).LengthSquared;

                if (distance < minimumDistance)
                {
                    result = new TrackerHitResult(
                        this,
                        new DataPoint(p1.X, p1.Y),
                        new ScreenPoint(sp1.x, sp1.y),
                        this.GetItem(i));
                    minimumDistance = distance;
                }
            }

            return result;
        }
        private static IList<IDataPoint> CreateRandomPoints(int n)
        {
            var points = new List<IDataPoint>();
            for (int i = 0; i < n; i++)
            {
                double x = Randomizer.NextDouble() * 10;
                double y = Randomizer.NextDouble() * 10;
                var p = new DataPoint(x, y);
                points.Add(p);
            }

            return points;
        }
Exemple #23
0
	    public void DrawLine(DataPoint start, DataPoint end, LineStyle style = LineStyle.Solid)
	    {
			var line = new LineSeries
			{
				StrokeThickness = 2,
				Smooth = true,
				Color = OxyColor.FromRgb(0, 0, 0),
				LineStyle = style,
				Points = new List<IDataPoint>()
			};
		    var deltaX = Math.Abs(start.X - end.X);
			var deltaY = Math.Abs(start.Y - end.Y);
		    var k = deltaY / deltaX;
		    if (start.Y > end.Y)
			    k = -k;
			var i = 0.0;
			while (i <= deltaX)
			{
				var x = i;
				if (start.X > end.X)
					x = -i;
				line.Points.Add(new DataPoint(start.X + x, (start.Y + k*i)));
				i += Opt.Step;
			}
			//Shit for vertical line
		    if ((int)start.X == (int)end.X)
		    {
			    var startY = start.Y < end.Y ? start : end;
			    for (var j = startY.Y; j < startY.Y + deltaY; j += Opt.Step)
				    line.Points.Add(new DataPoint(start.X, j));
		    }
			_mainPlot.Series.Add(line);
	    }
		public PointInfo(DataPoint point, string label = null, bool isVisible = true)
		{
			Point = point;
			Label = label;
			IsPointVisible = isVisible;
		}
        /// <summary>
        /// Gets the point on the curve that is nearest the specified point.
        /// </summary>
        /// <param name = "point">The point.</param>
        /// <param name = "dpn">The nearest point (data coordinates).</param>
        /// <param name = "spn">The nearest point (screen coordinates).</param>
        /// <returns></returns>
        protected bool GetNearestInterpolatedPointInternal(
            IList<IDataPoint> points, ScreenPoint point, out DataPoint dpn, out ScreenPoint spn, out int index)
        {
            spn = default(ScreenPoint);
            dpn = default(DataPoint);
            index = -1;

            // http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/
            double minimumDistance = double.MaxValue;

            for (int i = 0; i + 1 < points.Count; i++)
            {
                IDataPoint p1 = points[i];
                IDataPoint p2 = points[i + 1];
                ScreenPoint sp1 = AxisBase.Transform(p1, this.XAxis, this.YAxis);
                ScreenPoint sp2 = AxisBase.Transform(p2, this.XAxis, this.YAxis);

                double sp21X = sp2.x - sp1.x;
                double sp21Y = sp2.y - sp1.y;
                double u1 = (point.x - sp1.x) * sp21X + (point.y - sp1.y) * sp21Y;
                double u2 = sp21X * sp21X + sp21Y * sp21Y;
                double ds = sp21X * sp21X + sp21Y * sp21Y;

                if (ds < 4)
                {
                    // if the points are very close, we can get numerical problems, just use the first point...
                    u1 = 0;
                    u2 = 1;
                }

                if (u2 < double.Epsilon && u2 > -double.Epsilon)
                {
                    continue; // P1 && P2 coincident
                }

                double u = u1 / u2;
                if (u < 0) u = 0;
                if (u > 1) u = 1;

                double sx = sp1.x + u * sp21X;
                double sy = sp1.y + u * sp21Y;

                double dx = point.x - sx;
                double dy = point.y - sy;
                double distance = dx * dx + dy * dy;

                if (distance < minimumDistance)
                {
                    double px = p1.X + u * (p2.X - p1.X);
                    double py = p1.Y + u * (p2.Y - p1.Y);
                    dpn = new DataPoint(px, py);
                    spn = new ScreenPoint(sx, sy);
                    minimumDistance = distance;
                    index = i;
                }
            }

            return minimumDistance < double.MaxValue;
        }
		public void Drawing()
		{
			var options = new GraphOptions(null, null, 0.01, new GraphSize(0, 720, -40, _sizeY), new SvgFileSize((int)(_sizeY * 3.4 * 2.2 * 4), (int)(_sizeY * 3.4 * 4)), AppDomain.CurrentDomain.BaseDirectory + @"\Graph\Temp\gr2.tmp", "");
			options.PosX = App.CurrentEngineType == EngineType.Petrol ? 3000 : 4000;
			options.PosY = 400;
			Graph = new Graph(InitPlot(options), options);
			Graph.DrawLine(new DataPoint(180, _sizeY), new DataPoint(180, -30), LineStyle.Dash);
			Graph.DrawLine(new DataPoint(360, _sizeY), new DataPoint(360, -30), LineStyle.Dash);
			Graph.DrawLine(new DataPoint(540, _sizeY), new DataPoint(540, -30), LineStyle.Dash);
			Graph.DrawLine(new DataPoint(720, _sizeY), new DataPoint(720, -30), LineStyle.Dash);
			//Inlet
			var mainLine1Start = new DataPoint(0, -_p0);
			var mainLine1End = new DataPoint(180, -_p0);
			Graph.DrawLine(mainLine1Start, mainLine1End);
			//Outlet
			var mainLine2Start = new DataPoint(540, _p0);
			var mainLine2End = new DataPoint(720, _p0);
			Graph.DrawLine(mainLine2Start, mainLine2End);
			//Compression and Working stroke lines
			var pointsCompression = CompressionCurve();
			_pointsCompression = pointsCompression;
			Graph.DrawCurve(pointsCompression);
			var pointsWorkingStroke = WorkingStrokeCurve();
			_pointsWorkingStroke = pointsWorkingStroke;
			Graph.DrawCurve(pointsWorkingStroke);
			//Connection line between compression and working stroke lines
			var connectionLineStart = new DataPoint(360, pointsCompression[pointsCompression.Count - 1].Y);
			var connectionLineEnd = new DataPoint(360, pointsWorkingStroke[0].Y);
			Graph.DrawLine(connectionLineStart, connectionLineEnd);

			Graph.DrawLine(new DataPoint(0, _sizeY - _sizeY * 0.05), new DataPoint(720, _sizeY - _sizeY * 0.05));
			//Pj line
			PjCurve();
			//Ro line
			if (App.CurrentEngineType == EngineType.Diesel)
				Graph.DrawLine(new DataPoint(360, pointsWorkingStroke[0].Y),
					new DataPoint(360 + _data["Ro"].Val, pointsWorkingStroke[0].Y));
		}
 private static DataPoint[] Fractalise(DataPoint[] data, DataPoint[] detail)
 {
     var result = new DataPoint[(data.Length - 1) * detail.Length + 1];
     int j = 0;
     for (int i = 0; i + 1 < data.Length; i++)
     {
         double dx = data[i + 1].X - data[i].X;
         double dy = data[i + 1].Y - data[i].Y;
         foreach (var uv in detail)
             result[j++] = new DataPoint(data[i].X + dx * uv.X + dy * uv.Y, data[i].Y + dy * uv.X - dx * uv.Y);
     }
     result[j] = data.Last();
     return result;
 }
		private List<DataPoint> CompressionCurve()
		{
			var list = new List<DataPoint>();
			var step = 180.0 / _sizeX;
			//Compression
			for (var i = 0; i < _mainCurve2X.Count; i++)
			{
				list.Add(new DataPoint(360 - (_mainCurve2X[_mainCurve2X.Count - i - 1] - _sc) * step, _mainCurve2Y[_mainCurve2Y.Count - i - 1] - _p0));
			}
			//Some necessary correction
			list[0] = new DataPoint(180, -_p0);
			list[1] = new DataPoint(210, 0);
			var y = list.Select(dataPoint => dataPoint.Y).ToList();
			var x = list.Select(dataPoint => dataPoint.X).ToList();
			var interpolation = CubicSpline.InterpolateAkima(x, y);
			list = new List<DataPoint>();
			for (var i = 180; i <= 360; i += 30)
				list.Add(new DataPoint(i, interpolation.Interpolate(i)));
			//Some necessary correction
			var scaleY = _data["MaxPressure"].Val < 5 ? 0.025 :
			_data["MaxPressure"].Val > 8 ? 0.05 : 0.04;
			list[list.Count - 1] = new DataPoint(360, _data["PressureCompression"].Val / scaleY);
			return list;
		}
		private List<DataPoint> WorkingStrokeCurve()
		{
			var list = new List<DataPoint>();
			double step;
			if (App.CurrentEngineType == EngineType.Petrol)
				step = 180.0 / _sizeX;
			else
				step = (180.0 - _data["Ro"].Val) / _sizeX;
			//Working stroke
			var scaleX = _data["PistonStroke"].Val > 80 ? 1 : 0.5;
			for (var i = 0; i < _mainCurve1X.Count; i++)
			{
				list.Add(App.CurrentEngineType == EngineType.Petrol
					? new DataPoint((_mainCurve1X[i] - _sc) * step + 360, _mainCurve1Y[i] - _p0)
					: new DataPoint((_mainCurve1X[i] - _sc - _data["Sigma"].Val / scaleX) * step + 360, _mainCurve1Y[i] - _p0));
			}
			var shitY = list[0].Y;
			if (App.CurrentEngineType == EngineType.Diesel)
			{
				//Just must be!
				list[list.Count - 1] = new DataPoint(540, list[list.Count - 1].Y);

				var len = 180;
				var newLen = len - _data["Ro"].Val;
				for (var i = 0; i < list.Count; i++)
				{
					var newX = (len - (list[list.Count - i - 1].X - 360)) * newLen / len;
					var a = len - (list[list.Count - i - 1].X - 360) - newX;
					list[list.Count - i - 1] = new DataPoint(list[list.Count - i - 1].X + a, list[list.Count - i - 1].Y);
				}
			}
			var y = list.Select(dataPoint => dataPoint.Y).ToList();
			var x = list.Select(dataPoint => dataPoint.X).ToList();
			var interpolation = CubicSpline.InterpolateAkima(x, y);
			list = new List<DataPoint>();
			for (var i = 360; i <= 540; i += 30)
				if (i != 450)
					list.Add(new DataPoint(i, interpolation.Interpolate(i)));
			if (App.CurrentEngineType == EngineType.Diesel)
				list[0] = new DataPoint(360 + _data["Ro"].Val, shitY);
			list[list.Count - 1] = new DataPoint(540, list[list.Count - 1].Y - _p0);
			return list;
		}
		private void PSumCurve()
		{
			var line = new List<DataPoint>();
			for (var i = 0; i < 12; i++)
			{
				line.Add(new DataPoint(i * 30, _data["OrdinatesSpecificSummaryForces" + i].Val));
			}
			var scaleY = _data["MaxPressure"].Val < 5 ? 0.025 :
			_data["MaxPressure"].Val > 8 ? 0.05 : 0.04;
			line.Add(new DataPoint(12 * 30, _data["PressureCompression"].Val / scaleY));
			Graph.DrawCurve(line, null, LineStyle.Dot);
			line = new List<DataPoint>();
			for (var i = 13; i < 20; i++)
			{
				line.Add(new DataPoint((i-1) * 30, _data["OrdinatesSpecificSummaryForces" + i].Val));
			}
			if (App.CurrentEngineType == EngineType.Diesel)
			{
				line[0] = new DataPoint(360 + _data["Ro"].Val, line[0].Y);
				Graph.DrawLine(new DataPoint(360, line[0].Y), line[0], LineStyle.Dot);
			}
			Graph.DrawCurve(line, null, LineStyle.Dot);
			line = new List<DataPoint>();
			for (var i = 20; i < 27; i++)
			{
				line.Add(new DataPoint((i - 2) * 30, _data["OrdinatesSpecificSummaryForces" + i].Val));
			}
			Graph.DrawCurve(line, null, LineStyle.Dot);
		}
 public void ShowSlider(DataSeries s, DataPoint dp)
 {
 }
        /// <summary>
        /// Gets the point in the dataset that is nearest the specified point.
        /// </summary>
        /// <param name="point">
        /// The point.
        /// </param>
        /// <param name="interpolate">
        /// The interpolate.
        /// </param>
        /// <returns>
        /// A TrackerHitResult for the current hit.
        /// </returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            for (int i = 0; i < this.ActualBarRectangles.Count; i++)
            {
                var r = this.ActualBarRectangles[i];
                if (r.Contains(point))
                {
                    var item = (IntervalBarItem)this.GetItem(this.ValidItemsIndexInversion[i]);
                    var categoryIndex = item.GetCategoryIndex(i);
                    double value = (this.ValidItems[i].Start + this.ValidItems[i].End) / 2;
                    var dp = new DataPoint(categoryIndex, value);
                    var text = StringHelper.Format(
                        this.ActualCulture,
                        this.TrackerFormatString,
                        item,
                        this.Items[i].Start,
                        this.Items[i].End,
                        this.Items[i].Title);
                    return new TrackerHitResult(this, dp, point, item, i, text);
                }
            }

            return null;
        }
Exemple #33
0
 public void Update()
 {
     if (series > 3)
         series = 0;
     var points = new DataPoint[NumberOfPoints];
     for (int i = 0; i < _xs.Length; i++)
     {
         points[i] = new DataPoint(_xs[i], _yss[series][i]);
     }
     series++;
     _lineSeries.ItemsSource = points;
     PlotModel.InvalidatePlot(true);
 }
Exemple #34
0
        /// <summary>
        /// Gets the point on the curve that is nearest the specified point.
        /// </summary>
        /// <param name = "point">The point.</param>
        /// <param name = "dpn">The nearest point (data coordinates).</param>
        /// <param name = "spn">The nearest point (screen coordinates).</param>
        /// <returns></returns>
        protected bool GetNearestInterpolatedPointInternal(
            IList <IDataPoint> points, ScreenPoint point, out DataPoint dpn, out ScreenPoint spn, out int index)
        {
            spn   = default(ScreenPoint);
            dpn   = default(DataPoint);
            index = -1;

            // http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/
            double minimumDistance = double.MaxValue;

            for (int i = 0; i + 1 < points.Count; i++)
            {
                IDataPoint  p1  = points[i];
                IDataPoint  p2  = points[i + 1];
                ScreenPoint sp1 = AxisBase.Transform(p1, this.XAxis, this.YAxis);
                ScreenPoint sp2 = AxisBase.Transform(p2, this.XAxis, this.YAxis);

                double sp21X = sp2.x - sp1.x;
                double sp21Y = sp2.y - sp1.y;
                double u1    = (point.x - sp1.x) * sp21X + (point.y - sp1.y) * sp21Y;
                double u2    = sp21X * sp21X + sp21Y * sp21Y;
                double ds    = sp21X * sp21X + sp21Y * sp21Y;

                if (ds < 4)
                {
                    // if the points are very close, we can get numerical problems, just use the first point...
                    u1 = 0;
                    u2 = 1;
                }

                if (u2 < double.Epsilon && u2 > -double.Epsilon)
                {
                    continue; // P1 && P2 coincident
                }

                double u = u1 / u2;
                if (u < 0)
                {
                    u = 0;
                }
                if (u > 1)
                {
                    u = 1;
                }

                double sx = sp1.x + u * sp21X;
                double sy = sp1.y + u * sp21Y;

                double dx       = point.x - sx;
                double dy       = point.y - sy;
                double distance = dx * dx + dy * dy;

                if (distance < minimumDistance)
                {
                    double px = p1.X + u * (p2.X - p1.X);
                    double py = p1.Y + u * (p2.Y - p1.Y);
                    dpn             = new DataPoint(px, py);
                    spn             = new ScreenPoint(sx, sy);
                    minimumDistance = distance;
                    index           = i;
                }
            }

            return(minimumDistance < double.MaxValue);
        }