Example #1
0
        private void Model_MouseUp(object sender, OxyMouseEventArgs e)
        {
            isPanBar = false;

            if (RectangleUI != null && isSelected)
            {
                if (Math.Abs(RectangleUI.X1 - RectangleUI.X0) < 10)
                {
                    ClearBar();
                    SelectedData.Clear();
                }
                else
                {
                    double min = RectangleUI.X0 < RectangleUI.X1 ? RectangleUI.X0 : RectangleUI.X1;
                    double max = RectangleUI.X0 > RectangleUI.X1 ? RectangleUI.X0 : RectangleUI.X1;
                    RectangleUI       = new RectangleBarItem(min, Int16.MinValue, max, Int16.MaxValue);
                    RectangleUI.Color = OxyColor.FromArgb(100, 250, 0, 0);
                    Bar.Items.Add(RectangleUI);
                    Bar.Items.RemoveAt(0);
                    Line.Points.Where(point => point.X > min && point.X < max).ToList().ForEach(p =>
                    {
                        SelectedData.Add(new Complex(p.Y, 0));
                    });
                    LastX = (int)min;
                    Debug.WriteLine(SelectedData.Count());
                }
            }
            isSelected = false;
        }
Example #2
0
        private void Model_MouseMove(object sender, OxyMouseEventArgs e)
        {
            X = (int)(OxyPlot.Axes.Axis.InverseTransform(e.Position, Model.Axes[0], Model.Axes[1]).X);
            if (isSelected)
            {
                if (RectangleUI == null)
                {
                    startX            = X;
                    RectangleUI       = new RectangleBarItem(startX, Int16.MinValue, X, Int16.MaxValue);
                    RectangleUI.Color = OxyColor.FromArgb(100, 0, 0, 250);
                    Bar.Items.Add(RectangleUI);
                }
                else
                {
                    RectangleUI.X1 = X;
                }

                Model.InvalidatePlot(true);
            }

            if (isPanBar && RectangleUI != null)
            {
                int offset = X - LastX;
                RectangleUI.X0 += offset;
                RectangleUI.X1 += offset;
                //Process2((int)RectangleUI.X0, (int)RectangleUI.X1);
                ProcessFFT();

                LastX = X;
                Model.InvalidatePlot(true);
            }
        }
Example #3
0
        private void PlotResults()
        {
            try
            {
                var model = new PlotModel
                {
                    Title          = "Bytes frequency histogram", LegendPlacement = LegendPlacement.Outside,
                    LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical
                };
                OxyPlot.Series.RectangleBarSeries bars = new RectangleBarSeries();

                if (_plotScale == PlotScale.Log)
                {
                    throw new NotImplementedException("Logarithmic scale");

                    /*Axis yAxis = new LogarithmicAxis();
                     * model.Axes.Add(yAxis);
                     * yAxis.AbsoluteMinimum = 0;
                     * yAxis.Minimum = 0;*/
                }

                for (int i = 0; i < _results.Length; i++)
                {
                    double height = GetHeight(i);

                    //HighLowItem chartItem = new HighLowItem(i, height, 0);
                    RectangleBarItem item = new RectangleBarItem(i, 0, i + 1, height);

                    bars.Items.Add(item);
                }

                model.Series.Add(bars);

                //model.Axes.Add(yAxis);

                HistogramDrawer.Model = model;

                HistogramDrawer.Visible = true;

                EntropyValueLabel.Text = _results.Entropy.ToString("0.00000");


                ProcessUi();
            }
            catch (NotImplementedException e)
            {
                MessageBox.Show("This feature is not implemented: " + e.Message);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                throw;
            }
        }
Example #4
0
        private void Model_MouseUp(object sender, OxyMouseEventArgs e)
        {
            isPanBar = false;

            if (RectangleUI != null && isSelected)
            {
                if (Math.Abs(RectangleUI.X1 - RectangleUI.X0) < 10)
                {
                    ClearBar();
                    SelectedData.Clear();
                }
                else
                {
                    double[] func = FFTHelper.WindowFunc(SelectedWindowFunc, 512);
                    double   min  = RectangleUI.X0 < RectangleUI.X1 ? RectangleUI.X0 : RectangleUI.X1;
                    double   max  = RectangleUI.X0 > RectangleUI.X1 ? RectangleUI.X0 : RectangleUI.X1;
                    RectangleUI       = new RectangleBarItem(min, Int16.MinValue, max, Int16.MaxValue);
                    RectangleUI.Color = OxyColor.FromArgb(100, 0, 0, 250);
                    Bar.Items.Add(RectangleUI);
                    Bar.Items.RemoveAt(0);
                    int func_i = 0;
                    Line.Points.Where(point => point.X > min && point.X < max).ToList().ForEach(p =>
                    {
                        SelectedData.Add(new Complex(p.Y * func[func_i], 0));

                        if (func_i == 511)
                        {
                            func_i = 0;
                        }
                        else
                        {
                            func_i++;
                        }
                    });
                    LastX = (int)min;

                    if (!IsMagnitude)
                    {
                        Process2((int)RectangleUI.X0, (int)RectangleUI.X1);
                        // Process((int)RectangleUI.X0, (int)RectangleUI.X1);
                    }
                    else
                    {
                        Morphing();
                    }
                }
            }
            isSelected = false;
        }
Example #5
0
        private void Model_MouseMove(object sender, OxyMouseEventArgs e)
        {
            X = (int)(OxyPlot.Axes.Axis.InverseTransform(e.Position, Model.Axes[0], Model.Axes[1]).X);

            if (isSelected)
            {
                if (RectangleUI == null)
                {
                    startX            = X;
                    RectangleUI       = new RectangleBarItem(startX, Int16.MinValue, X, Int16.MaxValue);
                    RectangleUI.Color = OxyColor.FromArgb(100, 250, 0, 0);
                    Bar.Items.Add(RectangleUI);
                }
                else
                {
                    double min = RectangleUI.X0 < RectangleUI.X1 ? RectangleUI.X0 : RectangleUI.X1;
                    double max = RectangleUI.X0 > RectangleUI.X1 ? RectangleUI.X0 : RectangleUI.X1;
                    // Debug.WriteLine(((int)max - (int)min));
                    if (((int)max - (int)min) >= WindowWidth)
                    {
                        RectangleUI.X1 = RectangleUI.X0 < RectangleUI.X1 ? startX + (WindowWidth + 1) : startX - (WindowWidth + 1);
                    }
                    else
                    {
                        RectangleUI.X1 = X;
                    }
                }

                Model.InvalidatePlot(true);
            }

            if (isPanBar && RectangleUI != null)
            {
                WindowPositionChanged?.Invoke(X - LastX);
                int offset = X - LastX;
                RectangleUI.X0 += offset;
                RectangleUI.X1 += offset;
                ProcessFFT();

                LastX = X;
                Model.InvalidatePlot(true);
            }
        }
Example #6
0
        private void CreateBarSeries(LinearAxis linearAxis2, PlotModel plotModel)
        {
            var barSeries = new RectangleBarSeries {StrokeThickness = 0};

            var dif = GetDiff(Data.Grouping);
            foreach (var p in Data.GetGroupedDataSet()[0])
            {
                var r = new RectangleBarItem(p.Key, 0, p.Key + dif, p.Value, color: OxyColors.Blue);
                barSeries.Items.Add(r);
            }
            plotModel.Series.Add(barSeries);
        }
Example #7
0
File: Plot.cs Project: zrolfs/mzLib
        /// <summary>
        /// Adds a histogram. The data X value is used to bin the data.
        /// </summary>
        public void AddHistogram(IEnumerable <Datum> data, int numBins, OxyColor?borderColor = null, OxyColor?fillColor = null,
                                 double borderThickness      = 1, string xAxisLabel = null, string chartTitle = null, string chartSubtitle = null,
                                 bool refreshAfterAddingData = true)
        {
            SetCommonChartProperties(chartTitle, chartSubtitle);

            if (!data.Any())
            {
                return;
            }

            double min = data.Min(p => p.X);
            double max = data.Max(p => p.X);

            double binWidth        = (max - min) / numBins;
            var    histogramSeries = new RectangleBarSeries();

            double binFloor = min;

            for (int i = 0; i < numBins; i++)
            {
                var binData = data.Where(p => p.X >= binFloor && p.X < binFloor + binWidth);

                var bin = new RectangleBarItem(binFloor, 0, binFloor + binWidth, binData.Count());
                histogramSeries.Items.Add(bin);

                binFloor += binWidth;
            }

            histogramSeries.StrokeThickness = borderThickness;

            if (fillColor.HasValue)
            {
                histogramSeries.FillColor = fillColor.Value;
            }
            if (borderColor.HasValue)
            {
                histogramSeries.StrokeColor = borderColor.Value;
            }

            var xAxis = new LinearAxis()
            {
                MajorStep     = binWidth,
                Position      = AxisPosition.Bottom,
                StringFormat  = "F2",
                MinorTickSize = 0,
                Title         = xAxisLabel
            };

            var yAxis = new LinearAxis()
            {
                Position = AxisPosition.Left, MinorTickSize = 0, Title = "Count"
            };

            if (!Model.Axes.Any())
            {
                Model.Axes.Add(xAxis);
                Model.Axes.Add(yAxis);
            }

            Model.Series.Add(histogramSeries);

            if (refreshAfterAddingData)
            {
                RefreshChart();
            }
        }
Example #8
0
        public void Redraw()
        {
            Plot = new PlotModel();
            Plot.DefaultFontSize = Model.DefaultFontSize;
            Plot.LegendFontSize  = Model.LegendFontSize;
            Plot.Title           = Model.Title;
            if (Model.ShowLegend)
            {
                switch (Model.LegendPosition)
                {
                case OpenFMSL.Contracts.Infrastructure.Reporting.LegendPosition.TopRight:
                    Plot.LegendPosition = OxyPlot.LegendPosition.RightTop;
                    break;

                case OpenFMSL.Contracts.Infrastructure.Reporting.LegendPosition.TopLeft:
                    Plot.LegendPosition = OxyPlot.LegendPosition.TopLeft;
                    break;

                case OpenFMSL.Contracts.Infrastructure.Reporting.LegendPosition.BottomLeft:
                    Plot.LegendPosition = OxyPlot.LegendPosition.BottomLeft;
                    break;

                case OpenFMSL.Contracts.Infrastructure.Reporting.LegendPosition.BottomRight:
                    Plot.LegendPosition = OxyPlot.LegendPosition.BottomRight;
                    break;

                default:
                    Plot.LegendPosition = OxyPlot.LegendPosition.RightTop;
                    break;
                }

                Plot.IsLegendVisible = true;
            }

            Plot.Axes.Clear();

            LinearAxis yAxis = new LinearAxis {
                Position = AxisPosition.Left, Title = Model.YAxisTitle, AxisTitleDistance = 10
            };

            if (Model.IsReversedYAxis)
            {
                yAxis.StartPosition = 1;
                yAxis.EndPosition   = 0;
            }

            Plot.Axes.Add(yAxis);

            LinearAxis xAxis = new LinearAxis {
                Position = AxisPosition.Bottom, Title = Model.XAxisTitle, AxisTitleDistance = 10
            };

            Plot.Axes.Add(xAxis);

            if (!Model.AutoScaleX)
            {
                xAxis.Minimum = Model.XMin;
                xAxis.Maximum = Model.XMax;
            }

            if (!Model.AutoScaleY)
            {
                yAxis.Minimum = Model.YMin;
                yAxis.Maximum = Model.YMax;
            }

            Plot.Series.Clear();

            foreach (var series in Model.Series)
            {
                switch (series.Type)
                {
                case SeriesType.StackedBar100:
                {
                    var line = new BarSeries();
                    line.IsStacked = true;
                    line.Title     = series.Name;
                    for (int i = 0; i < series.X.Count; i++)
                    {
                        var item = new BarItem(series.X[i]);

                        line.Items.Add(item);
                    }
                    if (series.ShowInLegend)
                    {
                        line.RenderInLegend = true;
                    }
                    else
                    {
                        line.RenderInLegend = false;
                    }

                    Plot.Series.Add(line);
                    break;
                }

                case SeriesType.Line:
                {
                    var line = new LineSeries();
                    line.MarkerType      = OxyPlot.MarkerType.Circle;
                    line.Title           = series.Name;
                    line.StrokeThickness = series.Thickness;

                    if (series.Color != "Auto")
                    {
                        var seriesColor = System.Drawing.Color.FromName(series.Color);
                        line.Color = OxyColor.FromArgb(seriesColor.A, seriesColor.R, seriesColor.G, seriesColor.B);
                    }


                    switch (series.DashPattern)
                    {
                    case DashPattern.Dash:
                        //line.BrokenLineStyle = LineStyle.Dash;
                        line.LineStyle = LineStyle.Dash;
                        //line.BrokenLineColor = OxyColors.Transparent;
                        //line.BrokenLineThickness = series.Thickness;
                        break;

                    case DashPattern.AlternatingDash:
                        //line.BrokenLineStyle = LineStyle.LongDash;
                        //line.BrokenLineColor = OxyColors.Transparent;
                        //line.BrokenLineThickness = series.Thickness;
                        line.LineStyle = LineStyle.LongDashDot;
                        break;

                    case DashPattern.DashDot:
                        //line.BrokenLineStyle = LineStyle.DashDot;
                        //line.BrokenLineColor = OxyColors.Transparent;
                        //line.BrokenLineThickness = series.Thickness;
                        line.LineStyle = LineStyle.DashDot;
                        break;

                    case DashPattern.Dotted:
                        //line.BrokenLineStyle = LineStyle.Dot;
                        //line.BrokenLineColor = OxyColors.Transparent;
                        //line.BrokenLineThickness = series.Thickness;
                        line.LineStyle = LineStyle.Dot;
                        break;

                    default:
                        line.LineStyle = LineStyle.Solid;
                        //line.BrokenLineStyle = LineStyle.Solid;
                        //line.BrokenLineThickness = 0;
                        break;
                    }


                    for (int i = 0; i < series.X.Count; i++)
                    {
                        var item = new DataPoint(series.X[i], series.Y[i]);

                        line.Points.Add(item);
                    }
                    if (series.ShowMarker)
                    {
                        line.MarkerSize = 2 * series.Thickness;
                        line.MarkerFill = line.Color;
                    }

                    if (series.ShowInLegend)
                    {
                        line.RenderInLegend = true;
                    }
                    else
                    {
                        line.RenderInLegend = false;
                    }

                    Plot.Series.Add(line);
                    break;
                }

                case SeriesType.Scatter:
                {
                    var line = new ScatterSeries();
                    line.Title = series.Name;
                    switch (series.Marker)
                    {
                    case OpenFMSL.Contracts.Infrastructure.Reporting.MarkerType.Circle:
                        line.MarkerType = OxyPlot.MarkerType.Circle;
                        break;

                    case OpenFMSL.Contracts.Infrastructure.Reporting.MarkerType.Diamond:
                        line.MarkerType = OxyPlot.MarkerType.Diamond;
                        break;

                    case OpenFMSL.Contracts.Infrastructure.Reporting.MarkerType.Square:
                        line.MarkerType = OxyPlot.MarkerType.Square;
                        break;

                    default:
                        line.MarkerType = OxyPlot.MarkerType.Cross;
                        break;
                    }

                    if (series.Color != "Auto")
                    {
                        var seriesColor = System.Drawing.Color.FromName(series.Color);
                        line.MarkerFill = OxyColor.FromArgb(seriesColor.A, seriesColor.R, seriesColor.G, seriesColor.B);
                    }

                    for (int i = 0; i < series.X.Count; i++)
                    {
                        var item = new ScatterPoint(series.X[i], series.Y[i]);

                        line.Points.Add(item);
                    }

                    if (series.ShowInLegend)
                    {
                        line.RenderInLegend = true;
                    }
                    else
                    {
                        line.RenderInLegend = false;
                    }

                    Plot.Series.Add(line);
                    break;
                }

                case SeriesType.JacobianStructure:
                {
                    var line = new OxyPlot.Series.RectangleBarSeries();

                    LinearAxis XAxisReversed = new LinearAxis {
                        Position = AxisPosition.Bottom, Title = "Variables", IntervalLength = 15, StartPosition = 0, EndPosition = 1
                    };
                    Plot.Axes.Add(XAxisReversed);

                    // Y2 Axis
                    LinearAxis YAxisReversed = new LinearAxis {
                        Position = AxisPosition.Left, Title = "Equations", IntervalLength = 15, StartPosition = 1, EndPosition = 0
                    };
                    Plot.Axes.Add(YAxisReversed);


                    double currentX = 0;
                    double currentY = 0;
                    line.Title = "Jacobian Structure";
                    //line.TrackerFormatString = "{0}\n{1}: {2} {3}\n{4}: {5} {6}";

                    for (int i = 0; i < series.X.Count; i++)
                    {
                        var item = new RectangleBarItem {
                            X0 = currentX, X1 = currentX + series.X[i], Y0 = currentY, Y1 = currentY + series.Y[i]
                        };
                        line.Items.Add(item);
                        currentX += series.X[i];
                        currentY += series.Y[i];


                        if (series.X[i] != series.Y[i])
                        {
                            item.Color = OxyColors.OrangeRed;
                        }
                        else
                        {
                            item.Color = OxyColors.DodgerBlue;
                        }
                    }
                    Plot.Series.Add(line);
                }
                break;

                default:
                {
                    var line = new LineSeries();
                }
                break;
                }
            }
        }