Represents a line annotation.
Inheritance: OxyPlot.Annotations.TextualAnnotation
Ejemplo n.º 1
1
        private async Task AddCrossHairAnnotation(double x, double y, CancellationToken cancellationToken)
        {
            await this.Dispatcher.InvokeAsync(() => Diagram.Model.Annotations.Clear(), System.Windows.Threading.DispatcherPriority.Background);

            await Task.Run(() =>
            {
                var vannotation = new OxyPlot.Annotations.LineAnnotation
                {
                    X         = x,
                    Y         = 0,
                    Type      = LineAnnotationType.Vertical,
                    Color     = OxyColors.Gainsboro,
                    LineStyle = LineStyle.Dash
                };


                var hannotation = new OxyPlot.Annotations.LineAnnotation
                {
                    X         = 0,
                    Y         = y,
                    Type      = LineAnnotationType.Horizontal,
                    Color     = OxyColors.Gainsboro,
                    LineStyle = LineStyle.Dash
                };


                return(vannotation, hannotation);
            }, cancellationToken).ContinueWith(async a =>
            {
                var result = await a;
                Diagram.Model.Annotations.Add(result.vannotation);
                Diagram.Model.Annotations.Add(result.hannotation);
                Diagram.Model.InvalidatePlot(true);
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
        public LineSeriesControl()
        {
            InitializeComponent();
            Plot.Model = new OxyPlot.PlotModel();
            Plot.Dock = DockStyle.Fill;

            var linearAxis1 = new LinearAxis();
            linearAxis1.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139);
            linearAxis1.MajorGridlineStyle = LineStyle.Solid;
            linearAxis1.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139);
            linearAxis1.MinorGridlineStyle = LineStyle.Solid;
            linearAxis1.Position = AxisPosition.Bottom;
            linearAxis1.Title = "Position";
            linearAxis1.Unit = "mm";
            Plot.Model.Axes.Add(linearAxis1);
            var linearAxis2 = new OxyPlot.Axes.LinearAxis();
            linearAxis2.MajorGridlineColor = OxyColor.FromArgb(40, 0, 0, 139);
            linearAxis2.MajorGridlineStyle = LineStyle.Solid;
            linearAxis2.MinorGridlineColor = OxyColor.FromArgb(20, 0, 0, 139);
            linearAxis2.MinorGridlineStyle = LineStyle.Solid;
            linearAxis2.Title = "Intensity";
            linearAxis2.Unit = YAxisUnits[YUnitsToUse.GetHashCode()];
            Plot.Model.Axes.Add(linearAxis2);

            Plot.Model.Background = OxyColor.FromRgb(255, 255, 255);
            AddNewLockinDataSeries();
            var cursorX = new LineAnnotation()
            {
                Type = LineAnnotationType.Vertical,
                Color = OxyColors.Green,
                ClipByYAxis = false,
                X = 0,
                StrokeThickness = 2
            };
            var cursorY = new LineAnnotation()
            {
                Type = LineAnnotationType.Horizontal,
                Color = OxyColors.Green,
                ClipByXAxis = false,
                Y = 0,
                StrokeThickness = 2,
            };
            Plot.Model.Annotations.Add(cursorX);
            Plot.Model.Annotations.Add(cursorY);
            Plot.Model.Padding = new OxyThickness(2);
            Controls.Add(Plot);
        }
Ejemplo n.º 3
0
        public static List <OxyPlot.Annotations.RectangleAnnotation> DefineSupportResistanceZones(List <TradingPeriod> T)
        {
            List <OxyPlot.Annotations.RectangleAnnotation> SAR = new List <OxyPlot.Annotations.RectangleAnnotation>();

            /// Get Support

            List <TradingPeriod> LowPivots = new List <TradingPeriod>(T.Where(x => x.IsPivotLow[0]));

            for (int i = LowPivots.Count; i >= 0; i--)
            {
                int VolaTilityRange;
                if (i > 20)
                {
                    VolaTilityRange = 20;
                }
                else
                {
                    VolaTilityRange = i;
                }

                double STDev = Accord.Statistics.Measures.StandardDeviation(T.GetRange(T.IndexOf(LowPivots[i]) - VolaTilityRange, VolaTilityRange).Select(x => x.Close).ToArray());

                double yOne = T[i].Close + T[i].Close * 0.1 * STDev;
                double yTwo = T[i].Close - T[i].Close * 0.1 * STDev;

                List <TradingPeriod> Temps = new List <TradingPeriod>(T.Where(x => x.Close > yTwo && x.Close < yOne).ToList());

                if (Temps.Count > 2)
                {
                    OxyPlot.Annotations.LineAnnotation temp = new OxyPlot.Annotations.LineAnnotation();
                    temp.MinimumX = Temps.Min(x => x.Day.Ticks);
                    temp.MinimumY = Temps.Min(x => x.Close);
                    temp.MaximumX = Temps.Max(x => x.Day.Ticks);
                    temp.MaximumY = Temps.Max(x => x.Close);
                    temp.Color    = OxyPlot.OxyColors.CornflowerBlue;
                }
            }

            /// Get Resistance

            //for (int i = T.Count; i >= 0 )



            return(SAR);
        }
Ejemplo n.º 4
0
        private void GeothermsPlotView_OnLoaded(object sender, RoutedEventArgs e)
        {
            // oceanicFunc = y => MathNet.Numerics.SpecialFunctions.Erf((y/(2*Math.Sqrt(1e-6*t*365*24*60*60))))*tm;

            //// oceanicFunc = y => MathNet.Numerics.SpecialFunctions.Erfc(y);

            // Func<double, double> yFunc = d => d;
            // //oceanicSerie = new FunctionSeries(oceanicFunc, 0, 300000, 1000);
            // oceanicSerie = new FunctionSeries(oceanicFunc, yFunc, 0, MAX_DEPTH, 1000, "Океаническая кривая (" + (t/1e6).ToString("0.#") + " Ma)" );
            // oceanicSerie.Color = OxyColor.FromRgb(0,255,0);
            // oceanicSerie.StrokeThickness = 3;
            // //oceanicSerie.XAxisKey = "xAxis";
            // //oceanicSerie.YAxisKey = "yAxis";
            oceanicSerie = new FunctionSeries();
            AdjustGeothermToMantle();

            // model.Series.Add(oceanicSerie);
            model.Series.Add(mantleSeries);
            model.Series.Add(_continentalCrustSeries);
            model.Series.Add(_continentalSeries);


            var lithTermBoundary = new LineAnnotation
            {
                Type = LineAnnotationType.Vertical,
                X    = 1300
            };

            _continentalLithosphere = new LineAnnotation
            {
                Type = LineAnnotationType.Horizontal,
                Y    = 160000
            };

            model.Annotations.Add(lithTermBoundary);
            model.Annotations.Add(_continentalLithosphere);

            ContinueContinentToAdiabate();

            //model.InvalidatePlot(false);
        }
Ejemplo n.º 5
0
        public static PlotModel LineAnnotation()
        {
            var model = new PlotModel { Title = "LineAnnotation", Subtitle = "Click and drag the annotation line." };
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80 });
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 });
            var la = new LineAnnotation { Type = LineAnnotationType.Vertical, X = 4 };
            la.MouseDown += (s, e) =>
                {
                    if (e.ChangedButton != OxyMouseButton.Left)
                    {
                        return;
                    }

                    la.StrokeThickness *= 5;
                    model.InvalidatePlot(false);
                    e.Handled = true;
                };

            // Handle mouse movements (note: this is only called when the mousedown event was handled)
            la.MouseMove += (s, e) =>
                {
                    la.X = la.InverseTransform(e.Position).X;
                    model.InvalidatePlot(false);
                    e.Handled = true;
                };
            la.MouseUp += (s, e) =>
                {
                    la.StrokeThickness /= 5;
                    model.InvalidatePlot(false);
                    e.Handled = true;
                };
            model.Annotations.Add(la);
            return model;
        }
Ejemplo n.º 6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //定义model
            _myPlotModel = new PlotModel()
            {
                Title             = "Temp & Humi",
                LegendTitle       = "Legend",
                LegendOrientation = LegendOrientation.Horizontal,
                LegendPlacement   = LegendPlacement.Inside,
                LegendPosition    = LegendPosition.TopRight,
                LegendBackground  = OxyColor.FromAColor(200, OxyColors.Beige),
                LegendBorder      = OxyColors.Black
            };
            //X轴
            _dateAxis = new DateTimeAxis()
            {
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineStyle = LineStyle.Dot,
                IntervalLength     = 80,
                IsZoomEnabled      = false,
                IsPanEnabled       = false
            };
            _myPlotModel.Axes.Add(_dateAxis);

            //Y轴
            _valueAxis = new LinearAxis()
            {
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineStyle = LineStyle.Dot,
                IntervalLength     = 80,
                Angle         = 60,
                IsZoomEnabled = false,
                IsPanEnabled  = false,
                Maximum       = 100,
                Minimum       = -1
            };
            _myPlotModel.Axes.Add(_valueAxis);

            //添加标注线,温度上下限和湿度上下限
            var lineTempMaxAnnotation = new OxyPlot.Annotations.LineAnnotation()
            {
                Type      = LineAnnotationType.Horizontal,
                Color     = OxyColors.Red,
                LineStyle = LineStyle.Solid,
                Y         = 10,
                Text      = "Temp MAX:10"
            };

            _myPlotModel.Annotations.Add(lineTempMaxAnnotation);

            var lineTempMinAnnotation = new LineAnnotation()
            {
                Type      = LineAnnotationType.Horizontal,
                Y         = 30,
                Text      = "Temp Min:30",
                Color     = OxyColors.Red,
                LineStyle = LineStyle.Solid
            };

            _myPlotModel.Annotations.Add(lineTempMinAnnotation);

            var lineHumiMaxAnnotation = new OxyPlot.Annotations.LineAnnotation()
            {
                Type      = LineAnnotationType.Horizontal,
                Color     = OxyColors.Red,
                LineStyle = LineStyle.Solid,
                //lineMaxAnnotation.MaximumX = 0.8;
                Y    = 75,
                Text = "Humi MAX:75"
            };

            _myPlotModel.Annotations.Add(lineHumiMaxAnnotation);

            var lineHumiMinAnnotation = new LineAnnotation()
            {
                Type      = LineAnnotationType.Horizontal,
                Y         = 35,
                Text      = "Humi Min:35",
                Color     = OxyColors.Red,
                LineStyle = LineStyle.Solid
            };

            _myPlotModel.Annotations.Add(lineHumiMinAnnotation);

            //添加两条曲线
            var series = new LineSeries()
            {
                Color           = OxyColors.Green,
                StrokeThickness = 2,
                MarkerSize      = 3,
                MarkerStroke    = OxyColors.DarkGreen,
                MarkerType      = MarkerType.Diamond,
                Title           = "Temp",
                Smooth          = true
            };

            _myPlotModel.Series.Add(series);
            series = new LineSeries()
            {
                Color           = OxyColors.Blue,
                StrokeThickness = 2,
                MarkerSize      = 3,
                MarkerStroke    = OxyColors.BlueViolet,
                MarkerType      = MarkerType.Star,
                Title           = "Humi",
                Smooth          = true
            };
            _myPlotModel.Series.Add(series);


            plotView1.Model = _myPlotModel;

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    var date = DateTime.Now;
                    _myPlotModel.Axes[0].Maximum = DateTimeAxis.ToDouble(date.AddSeconds(1));

                    var lineSer = plotView1.Model.Series[0] as LineSeries;
                    lineSer.Points.Add(new DataPoint(DateTimeAxis.ToDouble(date), rand.Next(100, 300) / 10.0));
                    if (lineSer.Points.Count > 100)
                    {
                        lineSer.Points.RemoveAt(0);
                    }

                    lineSer = plotView1.Model.Series[1] as LineSeries;
                    lineSer.Points.Add(new DataPoint(DateTimeAxis.ToDouble(date), rand.Next(350, 750) / 10.0));
                    if (lineSer.Points.Count > 100)
                    {
                        lineSer.Points.RemoveAt(0);
                    }

                    _myPlotModel.InvalidatePlot(true);

                    Thread.Sleep(1000);
                }
            });
        }
Ejemplo n.º 7
0
        static void GenerateGraph(ImagePlot plot)
        {
            
            PlotModel model = new PlotModel { Title = plot.name };
            
            model.LegendTitle = "Descriptor";
            if (arguments.Flip)
                model.LegendTitle = "Image";

            float maxPrecision = 0;
            int colorIndex = 0;

            foreach(DescriptorData data in plot.descriptors)
            {

                String title = data.descriptor;
                if (arguments.Flip)
                    title = data.image;

                title += " (" + data.correctMatches + "/" + data.totalMatches + ")";

                
                LineSeries line = new LineSeries { Title = title, Color = colors[colorIndex++ % colors.Length] };
                for (int i = 0; i < data.pointData.Count; i++ )
                {
                    maxPrecision = Math.Max(maxPrecision, data.pointData[i].precision);
                    line.Points.Add(new DataPoint(data.pointData[i].precision, data.pointData[i].recall));
                }
                model.Series.Add(line);
            }

            // If global scale is on, we'll use that instead.
            if (arguments.GlobalScale)
                maxPrecision = globalScaleMax;

            // Add some padding
            maxPrecision = (float)Math.Min(maxPrecision + (maxPrecision * .2), 1.2f);

            // If we aren't scaling, just set it to 1.0
            if (!arguments.Scale && !arguments.GlobalScale)
                maxPrecision = 1.0f;

            LineAnnotation max = new LineAnnotation { Type = LineAnnotationType.Vertical, X = 1.0, Color = OxyColors.LightGray, LineStyle = OxyPlot.LineStyle.Dash };

            model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 0.0, Maximum = maxPrecision, Title = "Recall" });
            model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = 0.0, Maximum = 1.05, Title = "Precision" });
            model.Annotations.Add(max);

            plot.plot = model;

        }
Ejemplo n.º 8
0
        public void PlotSpectra(MSFeatureLight feature, IEnumerable<XYData> spectrum)
        {
            var series = new StemSeries
            {
                Color = OxyColors.Black
            };

            var minimumMz = double.MaxValue;
            var maximumMz = double.MinValue;
            var maxAbundance = double.MinValue;

            if (spectrum.Count() < 1)
                return;

            foreach (var peak in spectrum)
            {
                minimumMz = Math.Min(peak.X, minimumMz);
                maximumMz = Math.Max(peak.X, maximumMz);
                maxAbundance = Math.Max(maxAbundance, peak.Y);

                series.Points.Add(new DataPoint(peak.X, peak.Y));
            }

            var maxAbundanceTop = maxAbundance*.5;

            Model.Axes[0].AbsoluteMinimum = minimumMz;
            Model.Axes[0].AbsoluteMaximum = maximumMz;

            Model.Series.Add(series);

            // Add in the monoisotopic peak
            var colors = new ColorTypeIterator();
            var chargeColor = colors.GetColor(feature.ChargeState);
            var msFeature = new StemSeries
            {
                Color = chargeColor
            };
            msFeature.Points.Add(new DataPoint(feature.Mz, feature.Abundance));
            Model.Series.Add(msFeature);

            // Add in the rest of the isotopes
            var alphaColor = OxyColor.FromAColor(100, OxyColors.Red);
            var charge = feature.ChargeState;
            var mz = feature.Mz;
            var abundance = Convert.ToDouble(feature.Abundance);
            var monoPeakAnnotation = new LineAnnotation
            {
                Type = LineAnnotationType.Vertical,
                X = mz,
                Color = alphaColor,
                TextColor = alphaColor,
                Text = string.Format("mono peak: {0} m/z",
                    mz.ToString("F3"))
            };
            Model.Annotations.Add(monoPeakAnnotation);

            var lastMz = mz;
            var spacing = 1.0/charge;
            while (mz < maximumMz && abundance > 1)
            {
                mz = mz + (1.0/charge);
                abundance *= .75;
                var peakAnnotation = new LineAnnotation
                {
                    Type = LineAnnotationType.Vertical,
                    X = mz,
                    Color = alphaColor,
                    TextColor = alphaColor,
                    Text = string.Format("{0} m/z",
                        mz.ToString("F3"))
                };

                var spaceAnnotation = new LineAnnotation
                {
                    Type = LineAnnotationType.Horizontal,
                    Color = alphaColor,
                    TextColor = alphaColor,
                    TextHorizontalAlignment = HorizontalAlignment.Center,
                    TextVerticalAlignment = VerticalAlignment.Top,
                    TextPosition = new DataPoint(.5, 0),
                    MinimumX = lastMz,
                    MaximumX = mz,
                    Text = string.Format("d={0}", spacing.ToString("F2")),
                    Y = maxAbundance*.75
                };
                maxAbundance *= .75;
                lastMz = mz;
                Model.Annotations.Add(spaceAnnotation);
                Model.Annotations.Add(peakAnnotation);
            }

            if (feature.ParentFeature != null)
            {
                var features = feature.ParentFeature.Features;
                foreach (var subFeature in features)
                {
                    var msms =
                        subFeature.MSnSpectra.Where(x => x.PrecursorMz > minimumMz && x.PrecursorMz < maximumMz);
                    foreach (var fragmentation  in msms)
                    {
                        var spaceAnnotation = new LineAnnotation
                        {
                            Type = LineAnnotationType.Vertical,
                            Color = OxyColors.Gray,
                            TextColor = OxyColors.Gray,
                            FontWeight = 3,
                            TextVerticalAlignment = VerticalAlignment.Top,
                            TextPosition = new DataPoint(1, 0),
                            StrokeThickness = 2,
                            Text =
                                string.Format("msms {0} - scan {1}", fragmentation.PrecursorMz.ToString("F2"),
                                    fragmentation.Scan),
                            X = fragmentation.PrecursorMz
                        };
                        Model.Annotations.Add(spaceAnnotation);

                        var lowerMz = new LineAnnotation
                        {
                            Type = LineAnnotationType.Horizontal,
                            Color = OxyColors.LightGray,
                            TextColor = OxyColors.LightGray,
                            FontWeight = 3,
                            TextVerticalAlignment = VerticalAlignment.Top,
                            TextPosition = new DataPoint(1, 0),
                            StrokeThickness = 2,
                            Y = maxAbundanceTop,
                            Text = string.Format("{0} m/z", MsmsDistanceLower.ToString("F2")),
                            MinimumX = fragmentation.PrecursorMz - MsmsDistanceLower,
                            MaximumX = fragmentation.PrecursorMz
                        };

                        var upperMz = new LineAnnotation
                        {
                            Type = LineAnnotationType.Horizontal,
                            Color = OxyColors.LightGray,
                            TextColor = OxyColors.LightGray,
                            FontWeight = 3,
                            TextVerticalAlignment = VerticalAlignment.Top,
                            TextPosition = new DataPoint(1, 0),
                            StrokeThickness = 2,
                            Text = string.Format("{0} m/z", MsmsDistanceUpper.ToString("F2")),
                            Y = maxAbundanceTop,
                            MinimumX = fragmentation.PrecursorMz,
                            MaximumX = fragmentation.PrecursorMz + MsmsDistanceUpper
                        };

                        Model.Annotations.Add(upperMz);
                        Model.Annotations.Add(lowerMz);
                    }
                }
            }
        }
        private void SetPlotModel()
        {
            if (oxyMainPlot.Model != null)
                oxyMainPlot.Model = null;
            PlotModel l_PlotModel = new PlotModel("Remote CTrader chart");
            l_PlotModel.PlotAreaBorderColor = OxyColor.FromRgb(0, 0, 0);

            CandleStickSeries l_CandleSticks = new CandleStickSeries();
            l_CandleSticks.DataFieldClose = "Close";
            l_CandleSticks.DataFieldOpen = "Open";
            l_CandleSticks.DataFieldHigh = "Max";
            l_CandleSticks.DataFieldLow = "Min";
            l_CandleSticks.DataFieldX = "Time";

            l_CandleSticks.CandleWidth = 5;

            l_CandleSticks.Background = OxyColor.FromRgb(0, 0, 0);

            if (m_SelectedRobot > 0)
            {
                m_MarketData = m_PipeProxy.GetMarketDataByLength(m_SelectedRobot, 100);
                m_AdditionalData = m_PipeProxy.GetAdditionalData(m_SelectedRobot);
            }
            l_CandleSticks.ItemsSource = m_MarketData;
            l_PlotModel.Series.Add(l_CandleSticks);

            #region Bottom Axis setup
            DateTimeAxis l_BottomAxis = new DateTimeAxis();
            l_BottomAxis.StringFormat = "yy-MM-dd hh:mm";
            l_BottomAxis.IntervalType = DateTimeIntervalType.Auto;
            l_BottomAxis.FontSize = 8;
            l_PlotModel.Axes.Add(l_BottomAxis);
            l_BottomAxis.AxisChanged += l_BottomAxis_AxisChanged;
            #endregion

            #region Side Axis setup
            LinearAxis l_SideAxis = new LinearAxis();
            l_PlotModel.Axes.Add(l_SideAxis);
            l_SideAxis.AxisChanged += l_SideAxis_AxisChanged;
            #endregion

            #region Initialize top line
            m_TopLine = new LineAnnotation();
            m_TopLine.Color = OxyColor.FromRgb(125, 230, 125);
            m_TopLine.LineStyle = LineStyle.Solid;
            m_TopLine.StrokeThickness = 3;
            m_TopLine.Type = LineAnnotationType.Horizontal;
            m_TopLine.Selectable = true;
            m_TopLine.TextColor = m_TopLine.Color;
            m_TopLine.Y = m_MarketData.Last().Close;
            m_TopLine.Text = m_TopLine.Y.ToString("N4");

            l_PlotModel.Annotations.Add(m_TopLine);
            #endregion

            #region Initialize bottom line
            m_BottomLine = new LineAnnotation();
            m_BottomLine.Color = OxyColor.FromRgb(230, 125, 125);
            m_BottomLine.LineStyle = LineStyle.Solid;
            m_BottomLine.StrokeThickness = 3;
            m_BottomLine.Type = LineAnnotationType.Horizontal;
            m_BottomLine.Selectable = true;
            m_BottomLine.Y = m_MarketData.Last().Close;
            m_BottomLine.TextColor = m_BottomLine.Color;
            m_BottomLine.Text = m_BottomLine.Y.ToString("N4");
            l_PlotModel.Annotations.Add(m_BottomLine);
            #endregion

            #region Initialize pending order line
            m_PendingLine = new LineAnnotation();
            m_PendingLine.Color = OxyColor.FromRgb(125, 125, 230);
            m_PendingLine.LineStyle = LineStyle.Solid;
            m_PendingLine.StrokeThickness = 3;
            m_PendingLine.Type = LineAnnotationType.Horizontal;
            m_PendingLine.Selectable = true;
            m_PendingLine.Y = m_MarketData.Last().Close;
            m_PendingLine.TextColor = m_PendingLine.Color;
            m_PendingLine.Text = m_PendingLine.Y.ToString("N4");
            if(chbPEnabled.IsEnabled)
                l_PlotModel.Annotations.Add(m_PendingLine);
            #endregion

            oxyMainPlot.Model = l_PlotModel;
            l_PlotModel.Updated += l_PlotModel_Updated;
        }
Ejemplo n.º 10
0
		public PlotModel LineSeries (TrendbarJson[] data)
		{
			var model = new PlotModel { Title = "LineSeries", LegendSymbolLength = 24 };
			var s1 = new OxyPlot.Series.LineSeries {
				Title = currentSymbol.SymbolName,
				Color = OxyColors.Orange,
			};
			foreach (TrendbarJson item in data) {
				s1.Points.Add (new DataPoint (item.Timestamp, item.Close));
			}

			model.Series.Add (s1);
			model.Axes.Add (new LinearAxis { Position = AxisPosition.Left, MaximumPadding = 0.3, MinimumPadding = 0.3 });
			model.Axes.Add (new LinearAxis { Position = AxisPosition.Bottom, MaximumPadding = 0.03, MinimumPadding = 0.03 });

			var arrowAnnotation = new LineAnnotation {
				Type = LineAnnotationType.Horizontal,
				Color = OxyColors.Red,
				Y = data[data.Length - 1].Close,
				Text = data[data.Length - 1].Close.ToString(),
				TextColor = OxyColors.White
			};
			model.Annotations.Add(arrowAnnotation);
			return model;
		}
Ejemplo n.º 11
0
        public void DrawLine(
            object x1,
            object y1,
            object x2,
            object y2,
            Models.Graph.LineType type,
            Models.Graph.LineThicknessType thickness,
            Color colour)
        {
            OxyPlot.Annotations.LineAnnotation annotation = new OxyPlot.Annotations.LineAnnotation();

            double x1Position = 0.0;

            if (x1 is DateTime)
            {
                x1Position = DateTimeAxis.ToDouble(x1);
            }
            else
            {
                x1Position = Convert.ToDouble(x1);
            }
            double y1Position = 0.0;

            if ((double)y1 == double.MinValue)
            {
                y1Position = AxisMinimum(Models.Graph.Axis.AxisType.Left);
            }
            else if ((double)y1 == double.MaxValue)
            {
                y1Position = AxisMaximum(Models.Graph.Axis.AxisType.Left);
            }
            else
            {
                y1Position = (double)y1;
            }
            double x2Position = 0.0;

            if (x2 is DateTime)
            {
                x2Position = DateTimeAxis.ToDouble(x2);
            }
            else
            {
                x2Position = Convert.ToDouble(x2);
            }
            double y2Position = 0.0;

            if ((double)y2 == double.MinValue)
            {
                y2Position = AxisMinimum(Models.Graph.Axis.AxisType.Left);
            }
            else if ((double)y2 == double.MaxValue)
            {
                y2Position = AxisMaximum(Models.Graph.Axis.AxisType.Left);
            }
            else
            {
                y2Position = (double)y2;
            }

            annotation.X        = x1Position;
            annotation.Y        = y1Position;
            annotation.MinimumX = x1Position;
            annotation.MinimumY = y1Position;
            annotation.MaximumX = x2Position;
            annotation.MaximumY = y2Position;
            annotation.Type     = LineAnnotationType.Vertical;
            annotation.Color    = OxyColor.FromArgb(colour.A, colour.R, colour.G, colour.B);

            // Line type.
            // LineStyle oxyLineType;
            // if (Enum.TryParse<LineStyle>(type.ToString(), out oxyLineType))
            //    annotation.LineStyle = oxyLineType;

            // Line thickness
            if (thickness == LineThicknessType.Thin)
            {
                annotation.StrokeThickness = 0.5;
            }
            this.plot1.Model.Annotations.Add(annotation);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     Plots the UMC's
        /// </summary>
        /// <param name="features"></param>
        private void PlotFeatures(IEnumerable<UMCLight> features)
        {
            var markerIterator = new MarkerTypeIterator();
            m_colorIterator = new ColorTypeIterator();

            var i = 0;

            m_scanAnnotation = new LineAnnotation
            {
                X = 0,
                TextColor = OxyColors.Gray,
                Text = "0",
                TextOrientation = AnnotationTextOrientation.Vertical,
                LineStyle = LineStyle.Dash,
                Type = LineAnnotationType.Vertical,
            };

            Model.Annotations.Add(m_scanAnnotation);

            foreach (var feature in features)
            {
                var chargeMap = feature.CreateChargeMap();

                foreach (var charge in chargeMap.Keys)
                {
                    var msFeatures = chargeMap[charge];
                    msFeatures = msFeatures.OrderBy(x => x.Scan).ToList();
                    var mz = msFeatures[0].Mz;

                    var newSeries = new LineSeries
                    {
                        Color = m_colorIterator.GetColor(charge),
                        MarkerFill = m_colorIterator.GetColor(charge),
                        MarkerSize = 3,
                        MarkerStroke = OxyColors.White,
                        MarkerStrokeThickness = 1.5,
                        MarkerType = markerIterator.GetMarker(i++),
                        Title = string.Format("{0} m/z  - Charge {1}",
                            mz.ToString("F3"),
                            charge)
                    };

                    double abundance = 0;
                    MSFeatureLight bestFeature = null;

                    foreach (var msFeature in msFeatures)
                    {
                        if (abundance < msFeature.Abundance)
                        {
                            bestFeature = msFeature;
                            abundance = msFeature.Abundance;
                        }

                        foreach (var msms in msFeature.MSnSpectra)
                        {
                            var peptideSequence = "";
                            if (msms.Peptides.Count > 0)
                                peptideSequence = msms.Peptides[0].Sequence;

                            var msmsAnnotation = new LineAnnotation
                            {
                                Type = LineAnnotationType.Vertical,
                                X = msms.Scan,
                                Y = msFeature.Abundance,
                                StrokeThickness = 2,
                                Color = m_colorIterator.GetColor(msFeature.ChargeState),
                                TextColor = m_colorIterator.GetColor(msFeature.ChargeState),
                                Text = string.Format("{2} - {0} m/z {1}",
                                    msms.PrecursorMz.ToString("F3"),
                                    peptideSequence,
                                    msms.CollisionType)
                            };
                            Model.Annotations.Add(msmsAnnotation);
                        }
                        newSeries.Points.Add(new DataPoint(msFeature.Scan, msFeature.Abundance));
                    }

                    newSeries.Tag = charge;

                    if (bestFeature != null)
                    {
                        ScanAnnotationX = bestFeature.Scan;
                        SelectedCharge = charge;
                    }
                    Model.Series.Add(newSeries);
                }
            }
        }
Ejemplo n.º 13
0
        public static List <OxyPlot.Annotations.LineAnnotation> DefineSupportResistanceZonesPivots(Stock T, Stock.Interval Period)
        {
            List <OxyPlot.Annotations.LineAnnotation> SAR = new List <OxyPlot.Annotations.LineAnnotation>();
            List <TradingPeriod> TList = new List <TradingPeriod>();
            int    VolaTilityRange     = 0;
            int    min = 0;
            double AnnualisationFactor = 0;

            switch (Period)
            {
            case Stock.Interval.Hour:
                TList               = T.HourlyHist;
                VolaTilityRange     = 120;
                AnnualisationFactor = 252 * 6;
                min = 10;
                break;

            case Stock.Interval.Day:
                TList               = T.DailyHist;
                VolaTilityRange     = 21;
                AnnualisationFactor = 252;
                min = 10;
                break;

            case Stock.Interval.Week:
                TList               = T.WeeklyHist;
                VolaTilityRange     = 4;
                AnnualisationFactor = 52;
                min = 3;
                break;

            case Stock.Interval.Month:
                TList               = T.MonthlyHist;
                VolaTilityRange     = 1;
                AnnualisationFactor = 12;
                min = 3;
                break;
            }

            /// Get Support
            /// Adam Grimes formula


            List <TradingPeriod> LowPivots = new List <TradingPeriod>(TList.Where(x => x.IsPivotLow[0]));

            for (int i = LowPivots.Count - 1; i >= 0; i--)
            {
                if (i < VolaTilityRange)
                {
                    VolaTilityRange = i;
                }

                List <double> LogReturns = new List <double>();
                List <double> Prices     = TList.GetRange(TList.IndexOf(LowPivots[i]) - VolaTilityRange, VolaTilityRange).Select(x => x.AdjClose).ToList();
                for (int MN = 1; MN < VolaTilityRange; MN++)
                {
                    double Temp = Math.Log(Prices[MN] / Prices[MN - 1]);
                    LogReturns.Add(Temp);
                }
                double STDev = Accord.Statistics.Measures.StandardDeviation(LogReturns.ToArray()) * Math.Sqrt(AnnualisationFactor);



                //double STDev = Accord.Statistics.Measures.StandardDeviation(TList.GetRange(TList.IndexOf(LowPivots[i]) - VolaTilityRange, VolaTilityRange).Select(x => x.ReturnSeries).ToArray()) * Math.Sqrt(AnnualisationFactor);

                //double yOne = LowPivots[i].AdjClose + STDev;
                //double yTwo = LowPivots[i].AdjClose - STDev;

                double yOne = Math.Abs(LowPivots[i].Close * (1 + Math.Pow(STDev, 2)));
                double yTwo = Math.Abs(LowPivots[i].Close * (1 - Math.Pow(STDev, 2)));

                List <TradingPeriod> Temps = new List <TradingPeriod>();

                for (int x = i; x >= 0; x--)
                {
                    if (LowPivots[x].Close > yTwo && LowPivots[x].Close < yOne)
                    {
                        Temps.Add(LowPivots[x]);
                    }
                    else
                    {
                        break;
                    }
                }

                for (int x = i; x < LowPivots.Count - 1; x++)
                {
                    if (LowPivots[x].Close > yTwo && LowPivots[x].Close < yOne)
                    {
                        Temps.Add(LowPivots[x]);
                    }
                    else
                    {
                        break;
                    }
                }

                if (Temps.Count > min)
                {
                    OxyPlot.Annotations.LineAnnotation temp  = new OxyPlot.Annotations.LineAnnotation();
                    OxyPlot.Annotations.LineAnnotation temp2 = new OxyPlot.Annotations.LineAnnotation();

                    temp.Type     = LineAnnotationType.Horizontal;
                    temp.MinimumX = Temps.Min(x => x.Index);
                    temp.MaximumX = Temps.Max(x => x.Index);
                    //if (Period != Stock.Interval.Week) temp.Y = Temps.OrderBy(x => x.Close).Take(2).Last().Close;
                    //else temp.Y = Temps.Min(x => x.Close);
                    temp.Y     = Temps.Min(x => x.Close);
                    temp.Color = OxyColors.Red;

                    temp2.Type     = LineAnnotationType.Horizontal;
                    temp2.MinimumX = Temps.Min(x => x.Index);
                    temp2.MaximumX = Temps.Max(x => x.Index);
                    //if (Period != Stock.Interval.Week) temp2.Y = Temps.OrderByDescending(x => x.Close).Take(2).Last().Close;
                    //else temp2.Y = Temps.Max(x => x.Close);
                    temp2.Y     = Temps.Max(x => x.Close);
                    temp2.Color = OxyColors.Red;


                    //double High1 = Math.Abs(temp.Y * (1 + Math.Pow(STDev, 2)));
                    //double Low1 = Math.Abs(temp.Y * (1 - Math.Pow(STDev, 2)));
                    //double High2 = Math.Abs(temp2.Y * (1 + Math.Pow(STDev, 2)));
                    //double Low2 = Math.Abs(temp2.Y * (1 - Math.Pow(STDev, 2)));
                    //List<OxyPlot.Annotations.LineAnnotation> MoreTemps1 = new List<LineAnnotation>();
                    //List<OxyPlot.Annotations.LineAnnotation> MoreTemps2 = new List<LineAnnotation>();

                    //MoreTemps1 = SAR.Where(x => x.Y < High1 && x.Y > Low1).ToList();
                    //MoreTemps2 = SAR.Where(x => x.Y < High2 && x.Y > Low2).ToList();

                    //if (MoreTemps1.Count > 0)
                    //{
                    //    temp.MinimumX = MoreTemps1.Min(x => x.MinimumX);
                    //    temp.MaximumX = MoreTemps1.Max(x => x.MaximumX);
                    //    temp.Y = MoreTemps1.Average(x => x.Y);
                    //    //foreach (var v in MoreTemps1)
                    //    //{
                    //    //    SAR.Remove(v);
                    //    //}
                    //    SAR.Add(temp);

                    //}
                    //else SAR.Add(temp);

                    //if (MoreTemps2.Count > 0)
                    //{
                    //    temp2.MinimumX = MoreTemps2.Min(x => x.MinimumX);
                    //    temp2.MaximumX = MoreTemps2.Max(x => x.MaximumX);
                    //    temp2.Y = MoreTemps2.Average(x => x.Y);
                    //    //foreach (var c in MoreTemps2)
                    //    //{
                    //    //    SAR.Remove(c);
                    //    //}
                    //    SAR.Add(temp2);
                    //}
                    //else SAR.Add(temp2);

                    SAR.Add(temp);
                    SAR.Add(temp2);
                }


                foreach (var t in Temps)
                {
                    i--;

                    TList.Remove(TList.Last());
                }
            }

            /// Get Resistance
            ///
            switch (Period)
            {
            case Stock.Interval.Hour:
                TList               = T.HourlyHist;
                VolaTilityRange     = 120;
                AnnualisationFactor = 252 * 6;
                min = 10;
                break;

            case Stock.Interval.Day:
                TList               = T.DailyHist;
                VolaTilityRange     = 21;
                AnnualisationFactor = 252;
                min = 10;
                break;

            case Stock.Interval.Week:
                TList               = T.WeeklyHist;
                VolaTilityRange     = 4;
                AnnualisationFactor = 52;
                min = 2;
                break;

            case Stock.Interval.Month:
                TList               = T.MonthlyHist;
                VolaTilityRange     = 1;
                AnnualisationFactor = 12;
                min = 1;
                break;
            }

            List <TradingPeriod> HighPivots = new List <TradingPeriod>(TList.Where(x => x.IsPivotHigh[0]));


            for (int i = HighPivots.Count - 1; i >= 0; i--)
            {
                if (i < VolaTilityRange)
                {
                    VolaTilityRange = i;
                }


                List <double> LogReturns = new List <double>();
                List <double> Prices     = TList.GetRange(TList.IndexOf(HighPivots[i]) - VolaTilityRange, VolaTilityRange).Select(x => x.AdjClose).ToList();
                for (int MN = 1; MN < VolaTilityRange; MN++)
                {
                    double Temp = Math.Log(Prices[MN] / Prices[MN - 1]);
                    LogReturns.Add(Temp);
                }
                double STDev = Accord.Statistics.Measures.StandardDeviation(LogReturns.ToArray()) * Math.Sqrt(AnnualisationFactor);



                //double STDev = Accord.Statistics.Measures.StandardDeviation(TList.GetRange(TList.IndexOf( HighPivots[i]) - VolaTilityRange, VolaTilityRange).Select(x => x.ReturnSeries).ToArray()) * Math.Sqrt(AnnualisationFactor);

                double yOne = Math.Abs(HighPivots[i].Close * (1 + Math.Pow(STDev, 2)));
                double yTwo = Math.Abs(HighPivots[i].Close * (1 - Math.Pow(STDev, 2)));

                //double yOne = HighPivots[i].AdjClose + STDev;
                //double yTwo = HighPivots[i].AdjClose - STDev;

                List <TradingPeriod> Temps = new List <TradingPeriod>();

                for (int x = i; x >= 0; x--)
                {
                    if (HighPivots[x].High > yTwo && HighPivots[x].High < yOne)
                    {
                        Temps.Add(HighPivots[x]);
                    }
                    else
                    {
                        break;
                    }
                }


                for (int x = i; x < HighPivots.Count - 1; x++)
                {
                    if (HighPivots[x].High > yTwo && HighPivots[x].High < yOne)
                    {
                        Temps.Add(HighPivots[x]);
                    }
                    else
                    {
                        break;
                    }
                }

                if (Temps.Count > min)
                {
                    OxyPlot.Annotations.LineAnnotation temp  = new OxyPlot.Annotations.LineAnnotation();
                    OxyPlot.Annotations.LineAnnotation temp2 = new OxyPlot.Annotations.LineAnnotation();

                    temp.Type     = LineAnnotationType.Horizontal;
                    temp.MinimumX = Temps.Min(x => x.Index);
                    temp.MaximumX = Temps.Max(x => x.Index);
                    //if (Period != Stock.Interval.Week) temp2.Y = Temps.OrderByDescending(x => x.Close).Take(2).Last().Close;
                    //else temp2.Y = Temps.Max(x => x.Close);
                    temp2.Y    = Temps.Max(x => x.Close);
                    temp.Color = OxyColors.LawnGreen;

                    temp2.Type     = LineAnnotationType.Horizontal;
                    temp2.MinimumX = Temps.Min(x => x.Index);
                    temp2.MaximumX = Temps.Max(x => x.Index);
                    //if (Period != Stock.Interval.Week) temp.Y = Temps.OrderBy(x => x.Close).Take(2).Last().Close;
                    //else temp.Y = Temps.Min(x => x.Close);
                    temp.Y      = Temps.Min(x => x.Close);
                    temp2.Color = OxyColors.LawnGreen;

                    SAR.Add(temp);
                    SAR.Add(temp2);
                }
                foreach (var t in Temps)
                {
                    i--;

                    TList.Remove(HighPivots.Last());
                }
            }

            return(SAR);
        }
Ejemplo n.º 14
0
        public AreaSeriesViewModel()
        {
            var pnls = new List<Pnl>();

            var random = new Random(31);
            var dateTime = DateTime.Today.Add(TimeSpan.FromHours(9));
            for (var pointIndex = 0; pointIndex < 50; pointIndex++)
            {
                pnls.Add(new Pnl
                {
                    Time = dateTime,
                    Value = -200 + random.Next(1000),
                });
                dateTime = dateTime.AddMinutes(1);
            }

            var minimum = pnls.Min(x => x.Value);
            var maximum = pnls.Max(x => x.Value);

            var plotModel = this.PlotModel;
            plotModel.Title = "Area Series Animation Demo";

            var series = new AreaSeries
            {
                Title = "P & L",
                ItemsSource = pnls,
                DataFieldX = "Time",
                DataFieldY = "Value",
                Color = OxyColor.Parse("#4CAF50"),
                Fill = OxyColor.Parse("#454CAF50"),
                MarkerSize = 3,
                MarkerFill = OxyColor.Parse("#FFFFFFFF"),
                MarkerStroke = OxyColor.Parse("#4CAF50"),
                MarkerStrokeThickness = 1.5,
                MarkerType = MarkerType.Circle,
                StrokeThickness = 1,
            };
            plotModel.Series.Add(series);

            var annotation = new LineAnnotation
            {
                Type = LineAnnotationType.Horizontal,
                Y = 0
            };
            plotModel.Annotations.Add(annotation);

            var dateTimeAxis = new DateTimeAxis
            {
                Position = AxisPosition.Bottom,
                IntervalType = DateTimeIntervalType.Hours,
                IntervalLength = 50
            };
            plotModel.Axes.Add(dateTimeAxis);

            var margin = (maximum - minimum) * 0.05;

            var valueAxis = new LinearAxis
            {
                Position = AxisPosition.Left,
                Minimum = minimum - margin,
                Maximum = maximum + margin,
            };
            plotModel.Axes.Add(valueAxis);
        }
Ejemplo n.º 15
0
        private void Plot(string filename, double[,] impact, int numEvents, bool plotMarketNeutral, bool plotEvents, bool plotErrorBars)
        {
            Console.WriteLine("Plotting Graph");

            var plotModel1 = new PlotModel();

            if (plotMarketNeutral)
            {
                plotModel1.Title = "market relative mean of " + numEvents + " events";
            }
            else
            {
                plotModel1.Title = "mean of " + numEvents + " events";
            }

            var horizAxis = new LinearAxis
                                {
									Position = AxisPosition.Bottom,
                                    Minimum = studyRange.Min() - 1,
                                    Maximum = studyRange.Max() + 1,
                                    Title = "Days"
                                };
            plotModel1.Axes.Add(horizAxis);

            var vertAxis = new LinearAxis
                               {
								   Position = AxisPosition.Left,
                                   Minimum = Math.Min(studyStat.Min(), 0.5),
                                   Maximum = Math.Max(studyStat.Max(), 1.2),
                                   Title = "Cumulative Abnormal Returns"
                               };
            plotModel1.Axes.Add(vertAxis);

            var meanLineSeries = new LineSeries { Color = OxyColor.FromArgb(255, 00, 00, 255) };
            meanLineSeries.MarkerFill = meanLineSeries.Color;
            meanLineSeries.MarkerStroke = meanLineSeries.Color;
            meanLineSeries.MarkerType = MarkerType.Plus;
            meanLineSeries.StrokeThickness = 4;
            meanLineSeries.Title = "Mean";

            IEnumerator<int> x = studyRange.GetEnumerator();
            var y = studyStat.GetEnumerator();

            while (x.MoveNext() && y.MoveNext())
                meanLineSeries.Points.Add(new DataPoint(x.Current, y.Current));

            plotModel1.Series.Add(meanLineSeries);

            if (plotEvents)
            {
                // draw a line for each event
                var eventLineSeries = new LineSeries { Color = OxyColor.FromArgb(255, 255, 00, 00), StrokeThickness = 1 };

                x = studyRange.GetEnumerator();
                for (int i = 0; x.MoveNext() && i < impact.GetLength(0); i++)
                    foreach (int j in Enumerable.Range(0, impact.GetLength(1)))
                        eventLineSeries.Points.Add(new DataPoint(x.Current, impact[i, j]));
            }

            // draw a horizontal line at Y = 1.0
            var lineAnnotation = new LineAnnotation
                                     {
                                         Type = LineAnnotationType.Horizontal,
                                         Y = 1.0,
                                         Color = OxyColors.Black
                                     };
            plotModel1.Annotations.Add(lineAnnotation);

			if (plotErrorBars)
			{
				// draw errorbars if user wants them
				var errorSeries = new ErrorSeries
				{
					Color = OxyColor.FromArgb(255, 0xAA, 0xAA, 0xFF)
				};

				for (int i = lookbackDays; i < studyStd.Count; i++)
				{
					errorSeries.Points.Add(new ErrorItem(i - lookbackDays, studyStat[i], 0, studyStd[i] * 2));
				}

				plotModel1.Series.Add(errorSeries);
			}

			using (var fileStream = new System.IO.FileStream (filename, System.IO.FileMode.Create)) 
			{
				OxyPlot.PdfExporter.Export(plotModel1, fileStream, 1000, 800);
			}
        }
Ejemplo n.º 16
0
        public static PlotModel LineAnnotation()
        {
            var model = new PlotModel("LineAnnotation", "Click and drag the annotation line.");
            model.Axes.Add(new LinearAxis(AxisPosition.Bottom, -20, 80));
            model.Axes.Add(new LinearAxis(AxisPosition.Left, -10, 10));
            var la = new LineAnnotation { Type = LineAnnotationType.Vertical, X = 4 };
            la.MouseDown += (s, e) =>
                {
                    if (e.ChangedButton != OxyMouseButton.Left)
                    {
                        return;
                    }

                    la.StrokeThickness *= 5;
                    model.RefreshPlot(false);
                    e.Handled = true;
                };

            // Handle mouse movements (note: this is only called when the mousedown event was handled)
            la.MouseMove += (s, e) =>
                {
                    la.X = la.InverseTransform(e.Position).X;
                    model.RefreshPlot(false);
                    e.Handled = true;
                };
            la.MouseUp += (s, e) =>
                {
                    la.StrokeThickness /= 5;
                    model.RefreshPlot(false);
                    e.Handled = true;
                };
            model.Annotations.Add(la);
            return model;
        }
Ejemplo n.º 17
0
        public Example GenerateGraph(Stock Stck, Stock.Interval Period)
        {
            int    length    = 0;
            double startPost = 0;
            double endPOs    = 0;
            List <TradingPeriod> TradingList = new List <TradingPeriod>();

            switch (Period)
            {
            case Stock.Interval.Hour:
                length      = Stck.HourlyHist.Count;
                TradingList = Stck.HourlyHist;
                startPost   = length + 6;
                endPOs      = length - 50;
                break;

            case Stock.Interval.Day:
                length      = Stck.DailyHist.Count;
                TradingList = Stck.DailyHist;
                startPost   = length + 6;
                endPOs      = length - 110;
                break;

            case Stock.Interval.Week:
                length      = Stck.WeeklyHist.Count;
                TradingList = Stck.WeeklyHist;
                startPost   = length + 6;
                endPOs      = length - 80;
                break;

            case Stock.Interval.Month:
                length      = Stck.MonthlyHist.Count;
                TradingList = Stck.MonthlyHist;
                startPost   = length + 3;
                endPOs      = length - 48;
                break;
            }

            VolumeStyle style    = VolumeStyle.Combined;
            bool        naturalY = false;
            bool        naturalV = false;

            var pm = new PlotModel {
            };

            var series = new CandleStickAndVolumeSeries
            {
                PositiveColor      = OxyColors.DarkGreen,
                NegativeColor      = OxyColors.Red,
                PositiveHollow     = false,
                NegativeHollow     = false,
                SeparatorColor     = OxyColors.Gray,
                SeparatorLineStyle = LineStyle.Dash,
                VolumeStyle        = VolumeStyle.Combined
            };


            // create bars
            foreach (var v in TradingList)
            {
                OhlcvItem Temp = new OhlcvItem();
                Temp.BuyVolume = (v.Volume);
                Temp.Close     = v.Close;
                Temp.High      = v.High;
                Temp.Low       = v.Low;
                Temp.Open      = v.Open;
                Temp.X         = v.Index;

                series.Append(Temp);
            }

            // create visible window
            var Istart = length - 10;
            var Iend   = length - 1;
            var Ymin   = series.Items.Skip((int)endPOs).Take((int)startPost - (int)endPOs + 1).Select(x => x.Low).Min();
            var Ymax   = series.Items.Skip((int)endPOs).Take((int)startPost - (int)endPOs + 1).Select(x => x.High).Max();

            // setup axes
            var timeAxis = new OxyPlot.Axes.DateTimeAxis
            {
                Position = AxisPosition.Bottom,
                Minimum  = endPOs,
                Maximum  = startPost,

                //StartPosition = Xmax - TimeSpan.FromDays(180).Ticks,
                //EndPosition = Xmax,
            };

            var barAxis = new OxyPlot.Axes.LogarithmicAxis()
            {
                Position      = AxisPosition.Left,
                Key           = series.BarAxisKey,
                StartPosition = 0.15,
                EndPosition   = 1.0,
                Minimum       = naturalY ? double.NaN : Ymin,
                Maximum       = naturalY ? double.NaN : Ymax,
            };
            var volAxis = new OxyPlot.Axes.LinearAxis()
            {
                Position      = AxisPosition.Left,
                Key           = series.VolumeAxisKey,
                StartPosition = 0.0,
                EndPosition   = 0.15,
                Minimum       = naturalV ? double.NaN : 0,
                Maximum       = naturalV ? double.NaN : TradingList.Max(x => x.Volume)
            };

            switch (style)
            {
            case VolumeStyle.None:
                barAxis.Key           = null;
                barAxis.StartPosition = 0.0;
                pm.Axes.Add(timeAxis);
                pm.Axes.Add(barAxis);
                break;

            case VolumeStyle.Combined:
            case VolumeStyle.Stacked:
                pm.Axes.Add(timeAxis);
                pm.Axes.Add(barAxis);
                pm.Axes.Add(volAxis);
                break;

            case VolumeStyle.PositiveNegative:
                volAxis.Minimum = naturalV ? double.NaN : -5000;
                pm.Axes.Add(timeAxis);
                pm.Axes.Add(barAxis);
                pm.Axes.Add(volAxis);
                break;
            }

            pm.Series.Add(series);



            if (naturalY == false)
            {
                timeAxis.AxisChanged += (sender, e) => AdjustYExtent(series, timeAxis, barAxis);
                //timeAxis.AxisChanged += (sender, e) => AdjustYExtent(series, timeAxis, volAxis);
            }

            ///Adding Pivot Annotation
            ///
            Stck.GetPivots(Period);

            var ResistanceLines   = new List <OxyPlot.Annotations.LineAnnotation>();
            var FirstOrderPivots  = new List <OxyPlot.Annotations.PointAnnotation>();
            var SecondOrderPivots = new List <OxyPlot.Annotations.PointAnnotation>();
            var ThirdOrderPivots  = new List <OxyPlot.Annotations.PointAnnotation>();

            foreach (var f in TradingList)
            {
                if (f.IsPivotHigh[0])
                {
                    FirstOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation()
                    {
                        Fill = OxyColors.LawnGreen, X = f.Index, Y = f.High
                    });
                }
                if (f.IsPivotHigh[1])
                {
                    SecondOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation()
                    {
                        Fill = OxyColors.Green, X = f.Index, Y = f.High
                    });
                }
                if (f.IsPivotHigh[2])
                {
                    ThirdOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation()
                    {
                        Fill = OxyColors.DarkGreen, X = f.Index, Y = f.High
                    });
                }
                if (f.IsPivotLow[0])
                {
                    FirstOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation()
                    {
                        Fill = OxyColors.Pink, X = f.Index, Y = f.Low
                    });
                }
                if (f.IsPivotLow[1])
                {
                    SecondOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation()
                    {
                        Fill = OxyColors.Red, X = f.Index, Y = f.Low
                    });
                }
                if (f.IsPivotLow[2])
                {
                    ThirdOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation()
                    {
                        Fill = OxyColors.DarkRed, X = f.Index, Y = f.Low
                    });
                }
            }
            ResistanceLines = MarketStructure.DefineSupportResistanceZonesPivots(Stck, Period);

            GraphOverlays FOP   = new GraphOverlays();
            GraphOverlays SOP   = new GraphOverlays();
            GraphOverlays TOP   = new GraphOverlays();
            GraphOverlays Lines = new GraphOverlays();

            FOP.Name   = "First Order Pivot";
            SOP.Name   = "Second Order Pivot";
            TOP.Name   = "Third Order Pivot";
            Lines.Name = "Resistance Lines";

            FOP.Overlay   = FirstOrderPivots;
            SOP.Overlay   = SecondOrderPivots;
            TOP.Overlay   = ThirdOrderPivots;
            Lines.Overlay = ResistanceLines;

            FOP.Period   = Period;
            SOP.Period   = Period;
            TOP.Period   = Period;
            Lines.Period = Period;

            CurrentOverlays.Add(FOP);
            CurrentOverlays.Add(SOP);
            CurrentOverlays.Add(TOP);
            CurrentOverlays.Add(Lines);
            ///Adding line annotation...


            var la = new OxyPlot.Annotations.LineAnnotation {
                Type = LineAnnotationType.Horizontal, Y = TradingList.Last().Close
            };

            la.MouseDown += (s, e) =>
            {
                if (e.ChangedButton != OxyMouseButton.Left)
                {
                    return;
                }

                la.StrokeThickness *= 5;
                pm.InvalidatePlot(false);
                e.Handled = true;
            };

            // Handle mouse movements (note: this is only called when the mousedown event was handled)
            la.MouseMove += (s, e) =>
            {
                la.Y    = la.InverseTransform(e.Position).Y;
                la.Text = string.Format("{0:0.###}", la.Y);
                pm.InvalidatePlot(false);
                e.Handled = true;
            };
            la.MouseUp += (s, e) =>
            {
                la.StrokeThickness /= 5;
                pm.InvalidatePlot(false);
                e.Handled = true;
            };
            pm.Annotations.Add(la);

            OxyPlot.Annotations.ArrowAnnotation tmp = null;

            pm.MouseDown += (s, e) =>
            {
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    // Create a new arrow annotation
                    tmp            = new OxyPlot.Annotations.ArrowAnnotation();
                    tmp.HeadLength = 0;
                    tmp.StartPoint = tmp.EndPoint = timeAxis.InverseTransform(e.Position.X, e.Position.Y, barAxis);
                    pm.Annotations.Add(tmp);
                    e.Handled = true;
                }
                if (e.ChangedButton == OxyMouseButton.Middle)
                {
                    //delete old arrow annotation
                    if (e.HitTestResult != null)
                    {
                        if (e.HitTestResult.Element.GetType() == typeof(OxyPlot.Annotations.ArrowAnnotation))
                        {
                            tmp = (OxyPlot.Annotations.ArrowAnnotation)e.HitTestResult.Element;
                            pm.Annotations.Remove(tmp);
                            e.Handled = true;
                        }
                    }
                }
            };

            // Handle mouse movements (note: this is only called when the mousedown event was handled)
            pm.MouseMove += (s, e) =>
            {
                if (tmp != null)
                {
                    // Modify the end point
                    tmp.EndPoint   = timeAxis.InverseTransform(e.Position.X, e.Position.Y, barAxis);
                    tmp.FontWeight = FontWeights.Bold;
                    tmp.Text       = string.Format("{0:0.##}%", ((tmp.StartPoint.Y - tmp.EndPoint.Y) * -100) / tmp.StartPoint.Y);

                    // Redraw the plot
                    pm.InvalidatePlot(false);
                    e.Handled = true;
                }
            };

            pm.MouseUp += (s, e) =>
            {
                if (tmp != null)
                {
                    tmp       = null;
                    e.Handled = true;
                }
            };
            pm.Title = Stck.StockName;

            var controller = new PlotController();

            //controller.UnbindAll();
            //controller.BindMouseDown(OxyMouseButton.Middle, PlotCommands);
            //controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt);
            //controller.BindMouseDown(OxyMouseButton.Middle,  );

            return(new Example(pm, controller));
        }
Ejemplo n.º 18
0
        public void DrawLine(
            object x1,
            object y1,
            object x2,
            object y2,
            Models.Graph.LineType type,
            Models.Graph.LineThicknessType thickness,
            Color colour)
        {
            OxyPlot.Annotations.LineAnnotation annotation = new OxyPlot.Annotations.LineAnnotation();

            double x1Position = 0.0;
            if (x1 is DateTime)
                x1Position = DateTimeAxis.ToDouble(x1);
            else
                x1Position = Convert.ToDouble(x1);
            double y1Position = 0.0;
            if ((double)y1 == double.MinValue)
                y1Position = AxisMinimum(Models.Graph.Axis.AxisType.Left);
            else if ((double)y1 == double.MaxValue)
                y1Position = AxisMaximum(Models.Graph.Axis.AxisType.Left);
            else
                y1Position = (double)y1;
            double x2Position = 0.0;
            if (x2 is DateTime)
                x2Position = DateTimeAxis.ToDouble(x2);
            else
                x2Position = Convert.ToDouble(x2);
            double y2Position = 0.0;
            if ((double)y2 == double.MinValue)
                y2Position = AxisMinimum(Models.Graph.Axis.AxisType.Left);
            else if ((double)y2 == double.MaxValue)
                y2Position = AxisMaximum(Models.Graph.Axis.AxisType.Left);
            else
                y2Position = (double)y2;

            annotation.X = x1Position;
            annotation.Y = y1Position;
            annotation.MinimumX = x1Position;
            annotation.MinimumY = y1Position;
            annotation.MaximumX = x2Position;
            annotation.MaximumY = y2Position;
            annotation.Type = LineAnnotationType.Vertical;
            annotation.Color = OxyColor.FromArgb(colour.A, colour.R, colour.G, colour.B);

            // Line type.
            // LineStyle oxyLineType;
            // if (Enum.TryParse<LineStyle>(type.ToString(), out oxyLineType))
            //    annotation.LineStyle = oxyLineType;

            // Line thickness
            if (thickness == LineThicknessType.Thin)
                annotation.StrokeThickness = 0.5;
            this.plot1.Model.Annotations.Add(annotation);
        }
Ejemplo n.º 19
0
        public static PlotModel DefaultAnnotationLayer()
        {
            var plotModel1 = new PlotModel { Title = "Annotations should be drawn on top by default", Subtitle = "The line annotation should be on top!" };
            var areaSeries1 = new AreaSeries();
            areaSeries1.Points.Add(new DataPoint(0, 50));
            areaSeries1.Points.Add(new DataPoint(10, 40));
            areaSeries1.Points.Add(new DataPoint(20, 60));
            areaSeries1.Points2.Add(new DataPoint(0, 60));
            areaSeries1.Points2.Add(new DataPoint(5, 80));
            areaSeries1.Points2.Add(new DataPoint(20, 70));
            areaSeries1.Color = OxyColors.Red;
            areaSeries1.Color2 = OxyColors.Blue;
            areaSeries1.Fill = OxyColors.Yellow;

            plotModel1.Series.Add(areaSeries1);
            var lineAnnotation = new LineAnnotation
            {
                Type = LineAnnotationType.Vertical,
                Layer = AnnotationLayer.AboveSeries,
                X = 6
            };

            plotModel1.Annotations.Add(lineAnnotation);
            return plotModel1;
        }
Ejemplo n.º 20
0
		public PlotModel CandleStickSeries (TrendbarJson[] data)
		{
			var model = new PlotModel { 
				Title = "CandleStickSeries",
				LegendSymbolLength = 24,
			};
			var s1 = new OxyPlot.Series.CandleStickSeries {
				Title = currentSymbol.SymbolName,
				Color = OxyColors.Black,
			};
			foreach (TrendbarJson item in data) {
				s1.Items.Add (new HighLowItem (item.Timestamp, item.High, item.Low, item.Open, item.Close));
			}

			model.Series.Add (s1);
			model.Axes.Add (new LinearAxis { Position = AxisPosition.Left, MaximumPadding = 0.3, MinimumPadding = 0.3 });
			model.Axes.Add (new LinearAxis { Position = AxisPosition.Bottom, MaximumPadding = 0.03, MinimumPadding = 0.03 });

			var arrowAnnotation = new LineAnnotation {
				Type = LineAnnotationType.Horizontal,
				Y = data[data.Length - 1].Close,
				Text = data[data.Length - 1].Close.ToString()
			};
			model.Annotations.Add(arrowAnnotation);
			return model;
		}