/// <summary>
 /// Creates an example linear bar series with negative values.
 /// </summary>
 /// <returns>A linear bar series containing random points.</returns>
 private static LinearBarSeries CreateExampleLinearBarSeriesWithNegativeValues()
 {
     var linearBarSeries = new LinearBarSeries();
     var r = new Random(31);
     for (int x = 0; x <= 50; x++)
     {
         var y = -200 + r.Next(1000);
         linearBarSeries.Points.Add(new DataPoint(x, y));
     }
     return linearBarSeries;
 }
 /// <summary>
 /// Creates an example linear bar series.
 /// </summary>
 /// <returns>A linear bar series containing random points.</returns>
 private static LinearBarSeries CreateExampleLinearBarSeries()
 {
     var linearBarSeries = new LinearBarSeries();
     var r = new Random(31);
     var y = r.Next(10, 30);
     for (int x = 0; x <= 50; x++)
     {
         linearBarSeries.Points.Add(new DataPoint(x, y));
         y += r.Next(-5, 5);
     }
     return linearBarSeries;
 }
Example #3
0
 private static void SetPlotData(PlotModel IncomePlot, 
     Transaction data, OxyColor barColor, int number)
 {
     var barSeries = new LinearBarSeries
     {
         StrokeThickness = 1,
         FillColor = barColor,
         Title = data.Description
     };
     barSeries.Points.Add(new DataPoint(DateTimeAxis.ToDouble(data.TimeStamp),
         double.Parse((number * data.Amount).ToString())));
     IncomePlot.Series.Add(barSeries);
 }
Example #4
0
        private async Task<PlotModel> CompareSpeedHelium(Double step)
        {
            var sp = new PerformanceComputing.SpeedParticle(0, 1100000, Environment.ProcessorCount);
            var plotModel = new PlotModel { Title = "Общая скорость гелия" };
            TextBlock item = (TextBlock)ViewSpeed.SelectedItem;
            var selectedItem = item?.Text;

            if (selectedItem != null && selectedItem.Equals("Общая"))
            {
                //await sp.SpeedHeliumsAsync(Dimensionless.IsChecked != null && (bool)Dimensionless.IsChecked);

                await
                    sp.DecompositionSpeedHeliumsAsync(Dimensionless.IsChecked != null && (bool)Dimensionless.IsChecked);

                var speed = sp.HeliumsDecompositionSpeed;

                //var speed = new List<double>(sp.HeliumsFullSpeed);
                //speed.Sort();
                //List<Double> _sp = new List<Double>();

                //var h = (speed[speed.Count - 1] - speed[0]) / 100;

                //for (int i = 0; i < 100; i++)
                //{
                //    var Ai = speed[0] + ((i + 1) - 1) * h;
                //    var Bi = speed[0] + ((i + 2) - 1) * h;
                //    _sp.Add(speed.FindAll(x => x > Ai && x < Bi).Count / (speed.Count * h));
                //}

                var lineSerie = new LinearBarSeries
                {
                    FillColor = OxyColor.FromArgb(69, 76, 175, 80),
                    StrokeThickness = 1,
                    StrokeColor = OxyColor.FromArgb(255, 76, 175, 80),
                    Title = "Распределение Vx"
                };

                var lineSerie2 = new LinearBarSeries
                {
                    FillColor = OxyColor.FromArgb(69, 255, 255, 0),
                    StrokeThickness = 1,
                    StrokeColor = OxyColor.FromArgb(255, 76, 175, 80),
                    Title = "Распределение Vy"
                };

                var lineSerie3 = new LinearBarSeries
                {
                    FillColor = OxyColor.FromArgb(69, 72, 118, 255),
                    StrokeThickness = 1,
                    StrokeColor = OxyColor.FromArgb(255, 76, 175, 80),
                    Title = "Распределение Vx"
                };

                Int32 k = 0;
                for (var i = 0; i < speed.Count; i += 11000)
                {
                    lineSerie.Points.Add(new DataPoint(k++, speed[i].Vx));
                    //lineSerie2.Points.Add(new DataPoint(k++, speed[i].Vy));
                    //lineSerie3.Points.Add(new DataPoint(k++, speed[i].Vz));
                }
                for (var i = 0; i < speed.Count; i += 11000)
                {
                    lineSerie2.Points.Add(new DataPoint(k++, speed[i].Vy));
                }
                for (var i = 0; i < speed.Count; i += 11000)
                {
                    lineSerie3.Points.Add(new DataPoint(k++, speed[i].Vz));
                }


                //var lineSerie = new LineSeries
                //{
                //    StrokeThickness = 2,
                //    MarkerSize = 3,
                //    Title = "Значения скоростей для частиц"
                //};

                //Int32 k = 0;
                //for (var i = 0; i < speed.Count; i += 11000)
                //{
                //    lineSerie.Points.Add(new DataPoint(k++, speed[i]));
                //}

                plotModel.Series.Add(lineSerie);
                plotModel.Series.Add(lineSerie2);
                plotModel.Series.Add(lineSerie3);

            }
            return plotModel;
        }
Example #5
0
        private async Task<PlotModel> CompareSpeedElectron(Double step)
        {
            var sp = new PerformanceComputing.SpeedParticle(0, 1100000, Environment.ProcessorCount);
            var plotModel = new PlotModel { Title = "Общая скорость электронов" };
            TextBlock item = (TextBlock)ViewSpeed.SelectedItem;
            var selectedItem = item?.Text;

            if (selectedItem != null && selectedItem.Equals("Общая"))
            {
                await
                    sp.DecompositionSpeedElectronsAsync(Dimensionless.IsChecked != null && (bool)Dimensionless.IsChecked);

                var speed = sp.ElectronsDecompositionSpeed;

                var lineSerie = new LinearBarSeries
                {
                    FillColor = OxyColor.FromArgb(69, 76, 175, 80),
                    StrokeThickness = 1,
                    StrokeColor = OxyColor.FromArgb(255, 76, 175, 80),
                    Title = "Распределение Vx"
                };

                var lineSerie2 = new LinearBarSeries
                {
                    FillColor = OxyColor.FromArgb(69, 255, 255, 0),
                    StrokeThickness = 1,
                    StrokeColor = OxyColor.FromArgb(255, 76, 175, 80),
                    Title = "Распределение Vy"
                };

                var lineSerie3 = new LinearBarSeries
                {
                    FillColor = OxyColor.FromArgb(69, 72, 118, 255),
                    StrokeThickness = 1,
                    StrokeColor = OxyColor.FromArgb(255, 76, 175, 80),
                    Title = "Распределение Vz"
                };

                Int32 k = 0;
                for (var i = 0; i < speed.Count; i += 11000)
                {
                    lineSerie.Points.Add(new DataPoint(k++, speed[i].Vx));
                    lineSerie2.Points.Add(new DataPoint(k++, speed[i].Vy));
                    lineSerie3.Points.Add(new DataPoint(k++, speed[i].Vz));
                }
                //for (var i = 0; i < speed.Count; i += 11000)
                //{
                //    lineSerie2.Points.Add(new DataPoint(k++, speed[i].Vy));
                //}
                //for (var i = 0; i < speed.Count; i += 11000)
                //{
                //    lineSerie3.Points.Add(new DataPoint(k++, speed[i].Vz));
                //}

                plotModel.Series.Add(lineSerie);
                plotModel.Series.Add(lineSerie2);
                plotModel.Series.Add(lineSerie3);

            }
            return plotModel;
        }
Example #6
0
        private async Task<PlotModel> CompareSpeedCarbon(Double step)
        {
            var sp = new PerformanceComputing.SpeedParticle(0, 1100000, Environment.ProcessorCount);
            var plotModel = new PlotModel { Title = "Общая скорость частиц углерода" };
            TextBlock item = (TextBlock)ViewSpeed.SelectedItem;
            var selectedItem = item?.Text;

            if (selectedItem != null && selectedItem.Equals("Общая"))
            {
                Stopwatch st = new Stopwatch();
                st.Start();
                await
                    sp.DecompositionSpeedCarbonsAsync(Dimensionless.IsChecked != null && (bool)Dimensionless.IsChecked);
                st.Stop();
                var speed = new List<Particle>(sp.CarbonsDecompositionSpeed);

                Compare(speed);

                var savePicker = new Windows.Storage.Pickers.FileSavePicker();
                savePicker.SuggestedStartLocation =
                    Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
                savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
                // Default file name if the user does not type one in or select a file to replace
                savePicker.SuggestedFileName = "Распределение скорости карбона";

                Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();
                if (file != null)
                {
                    //StringBuilder text = new StringBuilder();

                    //foreach (var particle in speed)
                    //{
                    //    text.AppendLine(particle.Vx.ToString());
                    //    text.AppendLine(particle.Vy.ToString());
                    //    text.AppendLine(particle.Vz.ToString());
                    //}

                    StringBuilder text = new StringBuilder();
                    text.AppendLine(st.ElapsedMilliseconds.ToString());
                    text.AppendLine(speed[0].x.ToString());
                    text.AppendLine(speed[0].y.ToString());
                    text.AppendLine(speed[0].z.ToString());


                    await Windows.Storage.FileIO.WriteTextAsync(file, text.ToString());

                    Windows.Storage.Provider.FileUpdateStatus status =
                        await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);
                    Windows.Storage.CachedFileManager.DeferUpdates(file);
                    // write to file

                }

                var lineSerie = new LinearBarSeries
                {
                    FillColor = OxyColor.FromArgb(69, 76, 175, 80),
                    StrokeThickness = 1,
                    StrokeColor = OxyColor.FromArgb(255, 76, 175, 80),
                    Title = "Распределение Vx"
                };

                var lineSerie2 = new LinearBarSeries
                {
                    FillColor = OxyColor.FromArgb(69, 255, 255, 0),
                    StrokeThickness = 1,
                    StrokeColor = OxyColor.FromArgb(255, 76, 175, 80),
                    Title = "Распределение Vy"
                };

                var lineSerie3 = new LinearBarSeries
                {
                    FillColor = OxyColor.FromArgb(69, 72, 118, 255),
                    StrokeThickness = 1,
                    StrokeColor = OxyColor.FromArgb(255, 76, 175, 80),
                    Title = "Распределение Vz"
                };

                Int32 k = 0;
                for (var i = 0; i < speed.Count; i += 100)
                {
                    lineSerie.Points.Add(new DataPoint(k++, speed[i].Vx));
                }
                for (var i = 0; i < speed.Count; i += 100)
                {
                    lineSerie2.Points.Add(new DataPoint(k++, speed[i].Vy));
                }
                for (var i = 0; i < speed.Count; i += 100)
                {
                    lineSerie3.Points.Add(new DataPoint(k++, speed[i].Vz));
                }

                plotModel.Series.Add(lineSerie);
                plotModel.Series.Add(lineSerie2);
                plotModel.Series.Add(lineSerie3);

            }
            return plotModel;
        }
        public static async Task AnimateSeriesAsync(
            this PlotModel plotModel,
            LinearBarSeries series,
            AnimationSettings settings)
        {
            var points = series.GetAnimatablePoints();
            if (points.Count == 0)
            {
                return;
            }

            var duration = settings.Duration;
            if (duration == default(TimeSpan))
            {
                duration = TimeSpan.FromMilliseconds(DefaultAnimationDuration);
            }

            var easingFunction = settings.EasingFunction;
            if (easingFunction == null)
            {
                easingFunction = DefaultEasingFunction;
            }

            var animationFrameDurationInMs = (int)settings.FrameDuration.TotalMilliseconds;
            var minimumValue = settings.MinimumValue;

            var animationFrames = new List<AnimationFrame>();

            // Animation assumptions:
            // 
            //   - Total duration: 300ms (in this example)
            //   - At least animate each horizontal value separately
            //   - First animate from left => right (70 % of the time)
            //   - Second animate from center => end (30 % of the time)
            // 
            // |                                                  ^
            // |                                                  |
            // |               ___                                |
            // |               | |                                |  30 % of time
            // |   ___         | |                                |     90 ms
            // |   | |         | |                                |
            // |   | |   ___   | |                                |
            // |   | |   | |   | |                                |
            // |___|_|___|_|___|_|_____________________________   ^
            // 
            // <---------------- 70 % of time ---------------->
            //                     (210 ms)

            var horizontalDuration = duration.TotalMilliseconds / 100 * settings.HorizontalPercentage;
            var verticalDuration = duration.TotalMilliseconds / 100 * settings.VerticalPercentage;

            var animationFrameCount = (int)(duration.TotalMilliseconds / animationFrameDurationInMs);
            var animationFrameDuration = TimeSpan.FromMilliseconds(animationFrameDurationInMs);

            if (!minimumValue.HasValue)
            {
                minimumValue = 0d;

                var defaultYAxis = plotModel.DefaultYAxis;
                if (defaultYAxis != null)
                {
                    if (defaultYAxis.Minimum > 0d)
                    {
                        minimumValue = defaultYAxis.Minimum;
                    }
                }
            }

            var minX = (from point in points orderby point.X select point.X).Min();
            var maxX = (from point in points orderby point.X select point.X).Max();
            var deltaX = maxX - minX;

            for (var i = 0; i < animationFrameCount; i++)
            {
                var animationFrame = new AnimationFrame
                {
                    Duration = animationFrameDuration
                };

                var currentTime = animationFrameDurationInMs * i;
                var percentage = i * 100d / animationFrameCount;

                var horizontalPercentage = currentTime * 100d / horizontalDuration;
                if (horizontalPercentage > 100d)
                {
                    horizontalPercentage = 100d;
                }

                var currentDeltaX = deltaX / 100d * horizontalPercentage;
                var currentX = minX + currentDeltaX;

                // Get the last visible point. It should not be based on the index (can be really different), but on the X position
                // since we want to draw a smooth animation
                var lastVisibleHorizontalPoint = 0;
                for (int j = 0; j < points.Count; j++)
                {
                    var x = points[j].FinalX;
                    if (x > currentX)
                    {
                        break;
                    }

                    lastVisibleHorizontalPoint = j;
                }

                for (var j = 0; j < points.Count; j++)
                {
                    var point = points[j];

                    var isVisible = false;
                    var x = point.FinalX;
                    var y = 0d;

                    if (j <= lastVisibleHorizontalPoint)
                    {
                        isVisible = true;
                        y = point.FinalY;

                        // We know how long an y animation takes. We only have to calculate if this start time of this x animation
                        // is longer than verticalDuration ago
                        var localDeltaX = point.FinalX - minX;
                        var localPercentageX = localDeltaX * 100d / deltaX;
                        var startTime = horizontalDuration / 100 * localPercentageX;
                        var endTime = startTime + verticalDuration;

                        if (endTime > currentTime)
                        {
                            var timeDeltaTotal = endTime - startTime;
                            var timeDeltaCurrent = currentTime - startTime;
                            var subPercentage = timeDeltaCurrent * 100d / timeDeltaTotal;

                            // This bar is part of the current animation, calculate the Y relative to 30 % of the time based on the current index
                            // Calculate the % that offset is based on totalTimeDelta

                            // Calculate point to animate from
                            var maxY = point.FinalY;
                            var minY = minimumValue.Value;
                            var deltaY = maxY - minY;

                            // We need to ease against percentage (between 0 and 1)
                            var ease = easingFunction.Ease(subPercentage / 100);
                            var currentDeltaY = deltaY * ease;

                            y = minY + currentDeltaY;
                        }
                    }

                    animationFrame.AnimationPoints.Add(new AnimationPoint
                    {
                        IsVisible = isVisible,
                        X = x,
                        Y = y
                    });
                }

                animationFrames.Add(animationFrame);
            }

            animationFrames.InsertDelayAnimationFrame(settings.Delay);

            await plotModel.AnimateSeriesAsync(series, animationFrames);
        }
        private async Task<PlotModel> ComparePdfElectron(Double step)
        {
            //var sp = new PerformanceComputing.SpeedParticle(0, 1100000, Environment.ProcessorCount);
            //await sp.DecompositionSpeedAsync();

            //var t = sp.Electrons;

            //List<double> tempList = new List<double>(970303);

            //foreach (Particle particle in t)
            //{
            //    var speed = particle.Vx + particle.Vy + particle.Vz;
            //    tempList.Add(speed);
            //}

            //tempList.Sort();

            var maxwell = new MaxwellParticleDistribution(0, 1100000, Environment.ProcessorCount);

            await maxwell.DistributionParticleAsync();
            var distributionElectrons = maxwell.ElectronsPdf();



            var plotModel = new PlotModel { Title = "Распределение электронов" };
            var linearBarSeries = new LinearBarSeries
            {
                FillColor = OxyColor.FromArgb(69, 76, 175, 80),
                StrokeThickness = 1,
                StrokeColor = OxyColor.FromArgb(255, 76, 175, 80),
                Title = "ElectronPDF"
            };
            var categoryAxis = new CategoryAxis
            {
                TickStyle = TickStyle.Outside,
                MajorStep = step,
                Title = "Скорость частиц",
                Unit = "м/с",
                TitleFontSize = 15
            };
            var k = 0;
            for (var i = 0; i < 1100000; i += 11000)
            {
                linearBarSeries.Points.Add(new DataPoint(k++, distributionElectrons[i]));
                categoryAxis.ActualLabels.Add(i.ToString());
            }

            plotModel.Axes.Add(categoryAxis);
            plotModel.Series.Add(linearBarSeries);
            return plotModel;
        }
        private PlotModel ComparePdfHelium(Double step)
        {
            var maxwell = new MaxwellParticleDistribution(0, 7000, Environment.ProcessorCount);
            var distributionElectrons = maxwell.HeliumsPdf();

            var plotModel = new PlotModel { Title = "Распределение частиц гелия" };
            var linearBarSeries = new LinearBarSeries
            {
                FillColor = OxyColor.FromArgb(69, 76, 175, 80),
                StrokeThickness = 1,
                StrokeColor = OxyColor.FromArgb(255, 76, 175, 80),
                Title = "HeliumPDF"
            };
            var categoryAxis = new CategoryAxis
            {
                TickStyle = TickStyle.Outside,
                MajorStep = step,
                Title = "Скорость частиц",
                Unit = "м/с",
                TitleFontSize = 15
            };
            var k = 0;
            for (int i = 0; i < 7000; i += 100)
            {
                linearBarSeries.Points.Add(new DataPoint(k++, distributionElectrons[i]));
                categoryAxis.ActualLabels.Add(i.ToString());
            }
            plotModel.Axes.Add(categoryAxis);
            plotModel.Series.Add(linearBarSeries);
            return plotModel;
        }