public void SetDistAnnotation(List <LevelAndValue> seriesList, double percent) { this.PlotModel.Annotations.Clear(); int indexMin = this.EnergyHistogramDatum.HistogramData .FindIndex(a => a.Level == seriesList.Min(b => b.Level)); int indexMax = this.EnergyHistogramDatum.HistogramData .FindIndex(a => a.Level == seriesList.Max(b => b.Level)); RectangleAnnotation rectAannotation = new RectangleAnnotation(); rectAannotation.Fill = OxyColor.FromArgb(100, OxyColors.Orange.R, OxyColors.Orange.G, OxyColors.Orange.B); rectAannotation.MinimumX = indexMin - 0.5; rectAannotation.MaximumX = indexMax + 0.5; rectAannotation.Layer = AnnotationLayer.BelowSeries; this.PlotModel.Annotations.Add(rectAannotation); var textAnnotation = new TextAnnotation(); textAnnotation.TextPosition = new DataPoint((float)(indexMax + indexMin) / 2, this.PlotModel.Axes[1].ActualMaximum / 2); textAnnotation.Text = String.Format("{0:f1}%", percent); textAnnotation.TextColor = OxyColors.Orange; textAnnotation.FontSize = 50; textAnnotation.FontWeight = FontWeights.Bold; textAnnotation.Stroke = OxyColors.Transparent; this.PlotModel.Annotations.Add(textAnnotation); this.PlotModel.InvalidatePlot(true); }
/// <summary> /// 创建RectangleAnnotation图像,NaN表示值由显示的高度或宽度决定 /// </summary> /// <param name="markText">标注文字</param> /// <param name="minX">起始X</param> /// <param name="minY">起始Y</param> /// <param name="maxX">结束X</param> /// <param name="maxY">结束Y</param> /// <param name="markerSize">标注的大小</param> /// <param name="borderColor">边框颜色</param> /// <param name="fillColor">填充颜色</param> /// <param name="lineWidth">线宽</param> /// <returns></returns> public static RectangleAnnotation CreateRectangleAnnotation(string markText, double minX = double.NaN, double maxX = double.NaN, double minY = double.NaN, double maxY = double.NaN, double markerSize = 5.0, SolidColorBrush borderColor = null, SolidColorBrush fillColor = null, double lineWidth = 1.0) { if (borderColor == null) { borderColor = Brushes.Black; } if (fillColor == null) { fillColor = Brushes.Transparent; } RectangleAnnotation annotation = new RectangleAnnotation() { MinimumX = minX, MaximumX = maxX, MinimumY = minY, MaximumY = maxY, Stroke = ChartCommonMethod.ToOxyColor(borderColor), StrokeThickness = lineWidth, Fill = ChartCommonMethod.ToOxyColor(fillColor), Text = markText }; return(annotation); }
//TODO dorobić ciągłe rysowanie jak jest łączenie public void ConnectionStatusChanged(object sender, ConnectionStatusChangedArgs e) { DateTime now = DateTime.Now; switch (e.Actual) { case ConnectionStatusEnum.CONNECTED: Console.WriteLine("Połączono" + now); if (connectionRefusedAreas.Count > 0) { connectionRefusedAreas.Last().MaximumX = DateTimeAxis.ToDouble(now); } break; case ConnectionStatusEnum.CONNECTION_LOST: case ConnectionStatusEnum.DISCONNECTING: Console.WriteLine("Połączenie utracone " + now); RectangleAnnotation ra = new RectangleAnnotation { MinimumX = DateTimeAxis.ToDouble(now), MaximumX = DateTimeAxis.ToDouble(now), Fill = OxyColor.FromAColor(80, OxyColors.Red) }; connectionRefusedAreas.Add(ra); break; } }
private DataPoint CalcTextPoint(RectangleAnnotation anno) { return(new DataPoint( anno.MinimumX + (model.Axes[0].ActualMaximum - model.Axes[0].ActualMinimum) * 0.007, model.Axes[1].ActualMaximum - (model.Axes[1].ActualMaximum - model.Axes[1].ActualMinimum) * 0.009 * anno.Text.Length - (model.Axes[1].ActualMaximum - model.Axes[1].ActualMinimum) * 0.01 )); }
private void Plot_MouseDown(object sender, OxyMouseDownEventArgs e) { if (e.ChangedButton == OxyMouseButton.Left) { MouseMoveState = MoveState.None; } if (!CanCreateRanges || e.ChangedButton != OxyMouseButton.Left || SetRanges.Count == RangeLimit) { return; } _clickStartX = PlotSeries.InverseTransform(e.Position).X; if (Ranges.Count <= SetRanges.Count) { _activeRange = CreateRange(); } else { _activeRange = Ranges[SetRanges.Count]; } SetRanges.Add(_activeRange); _activeRange.MinimumX = _clickStartX; _activeRange.MaximumX = _clickStartX; Model.InvalidatePlot(false); e.Handled = true; MouseMoveState = MoveState.CreatingRange; }
public void RectangleAnnotation() { var s1 = new RectangleAnnotation(); var s2 = new Annotations.RectangleAnnotation(); OxyAssert.PropertiesAreEqual(s2, s1); }
public static PlotModel RectangleAnnotationClick() { var plotModel = new PlotModel { Title = "RectangleAnnotation click" }; plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom }); plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left }); var annotation = new RectangleAnnotation() { MinimumX = 10, MaximumX = 60, MinimumY = 10, MaximumY = 20 }; plotModel.Annotations.Add(annotation); int i = 0; annotation.MouseDown += (s, e) => { annotation.Text = "Clicked " + (++i) + " times."; plotModel.InvalidatePlot(false); }; return(plotModel); }
private void Range_MouseDown(object sender, OxyMouseDownEventArgs e) { _clickedRange = (RectangleAnnotation)sender; if (e.ChangedButton == OxyMouseButton.Left && e.IsControlDown) { RemoveRange(_clickedRange); MouseMoveState = MoveState.None; e.Handled = true; return; } if (!CanChangeRanges || e.ChangedButton != OxyMouseButton.Left) { return; } var x = PlotSeries.InverseTransform(e.Position).X; _moveStartX = _clickedRange.MinimumX; _clickStartXOffset = -(x - _clickedRange.MinimumX); e.Handled = true; MouseMoveState = MoveState.MovingRange; }
private void txtCtDropper_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.' && e.KeyChar != '-') { e.Handled = true; } if (e.KeyChar == '.' && (sender as RadTextBox).Text.IndexOf('.') > -1 && (sender as RadTextBox).Text.IndexOf('-') > -1) { e.Handled = true; } if (e.KeyChar == '\r') { if (!this.bIsTreSholdLoaded) { return; } if (this.txtCtDropper.Text.ToString().Trim() != "" && this.txtCtDropper.Text.ToString().Trim() != "-") { if (Convert.ToDouble(this.txtCtDropper.Text) > Convert.ToDouble(this.txtCtGrower.Text) || Convert.ToDouble(this.txtCtDropper.Text) < Convert.ToDouble(this.txtCtStopper.Text)) { MessageBox.Show("Dropper value cannot be higher than grower or less than stopper"); return; } this.VADropper.X = Convert.ToDouble(this.txtCtDropper.Text); this.RADropper.X = this.VADropper.X - this.RADropper.Width / 2; RectangleAnnotation rADropper = this.RADropper; double num = Math.Round(this.VADropper.X, 2); rADropper.Text = num.ToString(); this.RAGrower.X = this.VAGrower.X - this.RAGrower.Width / 2; this.txtCtFlat.Text = string.Concat(this.txtCtDropper.Text, " - +", this.txtCtGrower.Text); this.trkBarvalues(); } } }
private void fnStprAnnotation() { try { this.CA = this.chartThreshold.ChartAreas[0]; this.VAStopper.AxisX = this.CA.AxisX; this.VAStopper.AllowMoving = true; this.VAStopper.IsInfinitive = true; this.VAStopper.ClipToChartArea = this.CA.Name; this.VAStopper.Name = "stopper"; this.VAStopper.LineColor = Color.Red; this.VAStopper.LineWidth = 1; this.RAStopper.AxisX = this.chartThreshold.ChartAreas[0].AxisX; this.RAStopper.IsSizeAlwaysRelative = false; this.RAStopper.Width = 0.1; this.RAStopper.Height = this.Ymax / 10; this.RAStopper.LineColor = Color.Navy; this.RAStopper.BackColor = Color.Red; this.RAStopper.AxisY = this.chartThreshold.ChartAreas[0].AxisY; this.RAStopper.Y = -this.RAStopper.Height; this.RAStopper.X = this.VAStopper.X - this.RAStopper.Width / 2; RectangleAnnotation rAStopper = this.RAStopper; double num = Math.Round(this.VAStopper.X, 2); rAStopper.Text = num.ToString(); this.RAStopper.ForeColor = Color.White; this.RAStopper.Font = new Font("Arial", 8f); this.chartThreshold.AnnotationPositionChanged += new EventHandler(this.chartThreshold_AnnotationPositionChanged); this.chartThreshold.Annotations.Add(this.VAStopper); this.chartThreshold.Annotations.Add(this.RAStopper); } catch (Exception exception) { throw exception; } }
private static RectangleAnnotation CreateAnomalyZoneForAxis(Axis axis, double start, double end, string name) { RectangleAnnotation annotation = new RectangleAnnotation { Stroke = OxyColors.Transparent, StrokeThickness = 0, ClipByYAxis = false, ClipByXAxis = false }; if ((axis.Position == AxisPosition.Bottom) || (axis.Position == AxisPosition.Top)) { annotation.MinimumX = start; annotation.MaximumX = end; annotation.TextRotation = -90; annotation.XAxisKey = axis.Key; } else { annotation.MinimumY = start; annotation.MaximumY = end; annotation.YAxisKey = axis.Key; } annotation.Text = name; return(annotation); }
//TODO dorobić ciągłe rysowanie jak jest łączenie public void ConnectionStatusChanged(object sender, ConnectionStatusChangedArgs e) { DateTime now = DateTime.Now; Console.WriteLine($"ConnectionStatusChanged {e.Actual} {now}"); switch (e.Actual) { case ConnectionStatusEnum.CONNECTED: case ConnectionStatusEnum.DISCONNECTED: if (connectionRefusedAreas.Count > 0) { connectionRefusedAreas.Last().MaximumX = DateTimeAxis.ToDouble(now); } break; case ConnectionStatusEnum.CONNECTION_LOST: RectangleAnnotation ra = new RectangleAnnotation { MinimumX = DateTimeAxis.ToDouble(now), MaximumX = DateTimeAxis.ToDouble(now), Fill = OxyColor.FromAColor(80, OxyColors.Red) }; connectionRefusedAreas.Add(ra); break; } ChartMove(); Plot.InvalidatePlot(true); }
private void RenderAnno() { model.Annotations.Clear(); int indexAnno = 0; for (int i = 0; i < stages.Count; i++) { if (stages[i].IsChecked && !stages[i].IsSecond) { RectangleAnnotation anno = new RectangleAnnotation(); anno.Layer = AnnotationLayer.BelowSeries; anno.Text = stages[i].Text; anno.TextRotation = -90; anno.MinimumX = DateTimeAxis.ToDouble(stages[i].DateTime); Stage second = FindSecondStage(stages[i].ID); if (second != null) { anno.MaximumX = DateTimeAxis.ToDouble(second.DateTime); } else { anno.MaximumX = model.Axes[0].ActualMaximum; } anno.TextPosition = CalcTextPoint(anno); anno.Fill = (indexAnno++ % 2 == 1) ? OxyColor.FromRgb(225, 225, 225) : OxyColor.FromRgb(240, 240, 240); anno.MouseDown += Stage_MouseDown; anno.FontSize = TextFontSize; anno.TextColor = OxyColors.Black; anno.Tag = stages[i].ID; model.Annotations.Add(anno); } } plotter.InvalidatePlot(false); }
private void RemoveRange(RectangleAnnotation range) { SetRanges.Remove(range); RangeRemoved?.Invoke(_activeRange, _activeRange.MinimumX, _activeRange.MaximumX); range.MinimumX = 0; range.MaximumX = 0; Model.InvalidatePlot(false); }
private void SetAnnotationStyle2() { if (AnnotationStyle2 == null || AnnotationStyle2.SelectedIndex == -1) { return; } if (Annotation.SelectedItem.Value == "Line") { LineAnnotation annotation = (LineAnnotation)Chart1.Annotations[0]; annotation.EndCap = (LineAnchorCapStyle)LineAnchorCapStyle.Parse(typeof(LineAnchorCapStyle), AnnotationStyle2.SelectedItem.Value); } else if (Annotation.SelectedItem.Value == "Vertical Line") { VerticalLineAnnotation annotation = (VerticalLineAnnotation)Chart1.Annotations[0]; annotation.EndCap = (LineAnchorCapStyle)LineAnchorCapStyle.Parse(typeof(LineAnchorCapStyle), AnnotationStyle2.SelectedItem.Value); } else if (Annotation.SelectedItem.Value == "Horizontal Line") { HorizontalLineAnnotation annotation = (HorizontalLineAnnotation)Chart1.Annotations[0]; annotation.EndCap = (LineAnchorCapStyle)LineAnchorCapStyle.Parse(typeof(LineAnchorCapStyle), AnnotationStyle2.SelectedItem.Value); } else if (Annotation.SelectedItem.Value == "Polyline") { PolylineAnnotation annotation = (PolylineAnnotation)Chart1.Annotations[0]; annotation.EndCap = (LineAnchorCapStyle)LineAnchorCapStyle.Parse(typeof(LineAnchorCapStyle), AnnotationStyle2.SelectedItem.Value); } else if (Annotation.SelectedItem.Value == "Rectangle") { RectangleAnnotation annotation = (RectangleAnnotation)Chart1.Annotations[0]; annotation.LineDashStyle = (ChartDashStyle)ChartDashStyle.Parse(typeof(ChartDashStyle), AnnotationStyle2.SelectedItem.Value); } else if (Annotation.SelectedItem.Value == "Ellipse") { EllipseAnnotation annotation = (EllipseAnnotation)Chart1.Annotations[0]; annotation.LineDashStyle = (ChartDashStyle)ChartDashStyle.Parse(typeof(ChartDashStyle), AnnotationStyle2.SelectedItem.Value); } else if (Annotation.SelectedItem.Value == "Polygon") { PolygonAnnotation annotation = (PolygonAnnotation)Chart1.Annotations[0]; annotation.LineDashStyle = (ChartDashStyle)ChartDashStyle.Parse(typeof(ChartDashStyle), AnnotationStyle2.SelectedItem.Value); } }
/// <summary> /// Initialises the chart /// </summary> private void InitChart() { _mainChartArea.AxisX.ScaleView.Zoomable = true; _mainChartArea.AxisY.ScaleView.Zoomable = true; _mainChartArea.CursorX.AutoScroll = true; _mainChartArea.CursorY.AutoScroll = true; //_mainChartArea.AxisY2.Enabled = AxisEnabled.True; _priceAnnotation = new RectangleAnnotation(); _priceAnnotation.ForeColor = Color.Black; _priceAnnotation.Font = new Font("Arial", 9);; _priceAnnotation.LineWidth = 1; _priceAnnotation.BackColor = Color.LemonChiffon; chartCtrl.Annotations.Add(_priceAnnotation); _maxPriceAnnotation = new CalloutAnnotation(); _maxPriceAnnotation.ForeColor = Color.Black; _maxPriceAnnotation.Font = new Font("Arial", 9);; _maxPriceAnnotation.LineWidth = 1; _maxPriceAnnotation.CalloutStyle = CalloutStyle.SimpleLine; _maxPriceAnnotation.AnchorAlignment = ContentAlignment.BottomRight; chartCtrl.Annotations.Add(_maxPriceAnnotation); _minPriceAnnotation = new CalloutAnnotation(); _minPriceAnnotation.ForeColor = Color.Black; _minPriceAnnotation.Font = new Font("Arial", 9);; _minPriceAnnotation.LineWidth = 1; _minPriceAnnotation.CalloutStyle = CalloutStyle.SimpleLine; _minPriceAnnotation.AnchorAlignment = ContentAlignment.MiddleRight; _minPriceAnnotation.AxisX = _mainChartArea.AxisX; _minPriceAnnotation.AxisY = _mainChartArea.AxisY; chartCtrl.Annotations.Add(_minPriceAnnotation); _currentPriceAnnotation = new ArrowAnnotation(); _currentPriceAnnotation.ForeColor = Color.Black; _currentPriceAnnotation.Font = new Font("Arial", 9); _currentPriceAnnotation.LineWidth = 1; _currentPriceAnnotation.Width = 1; _currentPriceAnnotation.Height = 1; _currentPriceAnnotation.ArrowSize = 1; _currentPriceAnnotation.AxisX = _mainChartArea.AxisX; _currentPriceAnnotation.AxisY = _mainChartArea.AxisY; _currentPriceAnnotation.ArrowSize = 3; _currentPriceAnnotation.Height = 0; _currentPriceAnnotation.AnchorAlignment = ContentAlignment.MiddleLeft; //_currentPriceAnnotation.AnchorAlignment = ContentAlignment.MiddleRight; chartCtrl.Annotations.Add(_currentPriceAnnotation); // _mainChartArea.BackSecondaryColor = _mainChartArea.BackColor = Color.Black; chartCtrl.Series[Constants.PriceSerieName]["PriceUpColorUp"] = "Green"; }
/// <summary> /// Initializes a new instance of the <see cref="AnnotationDefaults"/> class. /// </summary> public AnnotationDefaults() { _table = new Hashtable { { AnnotationType.Ellipse, new EllipseAnnotation(new AnnotationBrush(Color.Red), new AnnotationPen(Color.Red)) }, { AnnotationType.EmbeddedImage, new EmbeddedImageAnnotation() }, { AnnotationType.Freehand, new FreehandAnnotation(new AnnotationPen(Color.Blue, 4)) }, { AnnotationType.Lines, new LinesAnnotation() }, { AnnotationType.Polygon, new PolygonAnnotation(new AnnotationPen(Color.Black), new AnnotationBrush(Color.Green)) }, { AnnotationType.Rectangle, new RectangleAnnotation(new AnnotationBrush(Color.Orange), new AnnotationPen(Color.Silver)) }, { AnnotationType.ReferencedImage, new ReferencedImageAnnotation() }, { AnnotationType.Text, new TextAnnotation(string.Empty, new AnnotationFont("Arial", 12), new AnnotationBrush(Color.Black), new AnnotationBrush(Color.Gainsboro), new AnnotationPen(Color.Black)) }, { AnnotationType.Redaction, new RectangleAnnotation(new AnnotationBrush(Color.Black), null) } }; // Callout var leader = new AnnotationPen(Color.Black, 2); leader.EndCap = new AnnotationLineCap(AnnotationLineCapStyle.Arrow, new SizeF(15, 15)); _table.Add(AnnotationType.Callout, new CalloutAnnotation(string.Empty, new AnnotationFont("Times New Roman", 12), new AnnotationBrush(Color.Black), 4, new AnnotationBrush(Color.White), new AnnotationPen(Color.Black, 2), leader, 10)); // Line var textOutline = new AnnotationPen(Color.Black); textOutline.EndCap = new AnnotationLineCap(AnnotationLineCapStyle.FilledArrow, new SizeF(15, 15)); _table.Add(AnnotationType.Line, new LineAnnotation(textOutline)); // Rubberstamp var stamp = new RubberStampAnnotation(); stamp.Data.Size = new SizeF(400, 110); stamp.Data.CanMirror = false; stamp.Text = "DRAFT"; _table.Add(AnnotationType.RubberStamp, stamp); // Sticky Note var sticky = new TextAnnotation(string.Empty, new AnnotationFont("Arial", 12), new AnnotationBrush(Color.Black), new AnnotationBrush(SystemColors.Info), new AnnotationPen(Color.Black, 1)); sticky.Data.Size = new SizeF(200, 120); sticky.Shadow = new AnnotationBrush(Color.FromArgb(120, Color.Silver)); sticky.ShadowOffset = new PointF(5, 5); _table.Add(AnnotationType.StickyNote, sticky); // Rectangle Highlighter var rc = new RectangleAnnotation(new AnnotationBrush(Color.Yellow), null); rc.Translucent = true; _table.Add(AnnotationType.RectangleHighlighter, rc); // Freehand Highlighter var fh = new FreehandAnnotation(new AnnotationPen(Color.Yellow, 20)); fh.Translucent = true; fh.LineType = FreehandLineType.Curves; _table.Add(AnnotationType.FreehandHighlighter, fh); }
private void AnnotationStyle2_SelectedIndexChanged(object sender, System.EventArgs e) { if (Annotation.SelectedItem.ToString() == "Line") { LineAnnotation annotation = (LineAnnotation)Chart1.Annotations[0]; annotation.EndCap = (LineAnchorCapStyle)LineAnchorCapStyle.Parse(typeof(LineAnchorCapStyle), AnnotationStyle2.SelectedItem.ToString()); } else if (Annotation.SelectedItem.ToString() == "Vertical Line") { VerticalLineAnnotation annotation = (VerticalLineAnnotation)Chart1.Annotations[0]; annotation.EndCap = (LineAnchorCapStyle)LineAnchorCapStyle.Parse(typeof(LineAnchorCapStyle), AnnotationStyle2.SelectedItem.ToString()); } else if (Annotation.SelectedItem.ToString() == "Horizontal Line") { HorizontalLineAnnotation annotation = (HorizontalLineAnnotation)Chart1.Annotations[0]; annotation.EndCap = (LineAnchorCapStyle)LineAnchorCapStyle.Parse(typeof(LineAnchorCapStyle), AnnotationStyle2.SelectedItem.ToString()); } else if (Annotation.SelectedItem.ToString() == "Polyline") { PolylineAnnotation annotation = (PolylineAnnotation)Chart1.Annotations[0]; annotation.EndCap = (LineAnchorCapStyle)LineAnchorCapStyle.Parse(typeof(LineAnchorCapStyle), AnnotationStyle2.SelectedItem.ToString()); } else if (Annotation.SelectedItem.ToString() == "Rectangle") { RectangleAnnotation annotation = (RectangleAnnotation)Chart1.Annotations[0]; annotation.LineDashStyle = (ChartDashStyle)ChartDashStyle.Parse(typeof(ChartDashStyle), AnnotationStyle2.SelectedItem.ToString()); } else if (Annotation.SelectedItem.ToString() == "Ellipse") { EllipseAnnotation annotation = (EllipseAnnotation)Chart1.Annotations[0]; annotation.LineDashStyle = (ChartDashStyle)ChartDashStyle.Parse(typeof(ChartDashStyle), AnnotationStyle2.SelectedItem.ToString()); } else if (Annotation.SelectedItem.ToString() == "Polygon") { PolygonAnnotation annotation = (PolygonAnnotation)Chart1.Annotations[0]; annotation.LineDashStyle = (ChartDashStyle)ChartDashStyle.Parse(typeof(ChartDashStyle), AnnotationStyle2.SelectedItem.ToString()); } }
public static PlotModel SelectRange() { var model = new PlotModel("Select range", "Left click and drag to select a range."); model.Series.Add(new FunctionSeries(Math.Cos, 0, 40, 0.1)); RectangleAnnotation range = null; double startx = double.NaN; model.MouseDown += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { if (range == null) { // Create and add the annotation to the plot range = new RectangleAnnotation { Fill = OxyColors.SkyBlue.ChangeAlpha(120) }; model.Annotations.Add(range); model.RefreshPlot(true); } startx = range.InverseTransform(e.Position).X; range.MinimumX = startx; range.MaximumX = startx; model.RefreshPlot(true); e.Handled = true; } }; model.MouseMove += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left && !double.IsNaN(startx)) { var x = range.InverseTransform(e.Position).X; range.MinimumX = Math.Min(x, startx); range.MaximumX = Math.Max(x, startx); range.Text = string.Format("∫ cos(x) dx = {0:0.00}", Math.Sin(range.MaximumX) - Math.Sin(range.MinimumX)); model.Subtitle = string.Format("Integrating from {0:0.00} to {1:0.00}", range.MinimumX, range.MaximumX); model.RefreshPlot(true); e.Handled = true; } }; model.MouseUp += (s, e) => { startx = double.NaN; }; return(model); }
public static Example ClickingOnAnAnnotation() { var plotModel = new PlotModel { Title = "Clicking on an annotation", Subtitle = "Click on the rectangles" }; plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom }); plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left }); var annotation1 = new RectangleAnnotation { Fill = OxyColors.Green, Text = "RectangleAnnotation 1", MinimumX = 25, MaximumX = 75, MinimumY = 20, MaximumY = 40 }; plotModel.Annotations.Add(annotation1); var annotation2 = new RectangleAnnotation { Fill = OxyColors.SkyBlue, Text = "RectangleAnnotation 2", MinimumX = 25, MaximumX = 75, MinimumY = 60, MaximumY = 80 }; plotModel.Annotations.Add(annotation2); EventHandler <OxyMouseDownEventArgs> handleMouseClick = (s, e) => { plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)s).Text; plotModel.InvalidatePlot(false); }; annotation1.MouseDown += handleMouseClick; annotation2.MouseDown += handleMouseClick; var controller = new PlotController(); var handleClick = new DelegatePlotCommand <OxyMouseDownEventArgs>( (v, c, e) => { var args = new HitTestArguments(e.Position, 10); var firstHit = v.ActualModel.HitTest(args).FirstOrDefault(x => x.Element is RectangleAnnotation); if (firstHit != null) { e.Handled = true; plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)firstHit.Element).Text; plotModel.InvalidatePlot(false); } }); controller.Bind(new OxyMouseDownGesture(OxyMouseButton.Left), handleClick); return(new Example(plotModel, controller)); }
/// <summary> /// Put an annotation on the layer that highlights the rectangle in the color passed in /// </summary> /// <param name="layer">The layer on which to put the annotation</param> /// <param name="imageBox">The bounds of the annotation</param> /// <param name="hiColor">The color of the annotation</param> private void CreateHighlightAnnotation(LayerAnnotation layer, RectangleF imageBox, Color hiColor) { RectangleAnnotation ra = new RectangleAnnotation(imageBox, new AnnotationBrush(hiColor), null) { Translucent = true }; ra.Data.CanMove = false; ra.Data.CanResize = false; ra.Data.CanSelect = false; ra.Data.CanRotate = false; layer.Items.Add(ra); }
public void SetCompAnnotation(double low, double high, bool isAbsolute) { this.PlotModel.Annotations.Clear(); int indexLow = this.TimeHistogramDatum.HistogramData .FindIndex(v => v.Level == Math.Ceiling(low / this.TimeHistogramDatum.ClassWidth) * this.TimeHistogramDatum.ClassWidth); int indexHigh = this.TimeHistogramDatum.HistogramData .FindIndex(v => v.Level == Math.Ceiling(high / this.TimeHistogramDatum.ClassWidth) * this.TimeHistogramDatum.ClassWidth); RectangleAnnotation rectAannotationMin = new RectangleAnnotation(); rectAannotationMin.Fill = OxyColor.FromArgb(100, OxyColors.Orange.R, OxyColors.Orange.G, OxyColors.Orange.B); rectAannotationMin.MinimumX = indexLow - 0.5; rectAannotationMin.MaximumX = indexLow + 0.5; rectAannotationMin.Layer = AnnotationLayer.BelowSeries; this.PlotModel.Annotations.Add(rectAannotationMin); RectangleAnnotation rectAannotationMax = new RectangleAnnotation(); rectAannotationMax.Fill = OxyColor.FromArgb(100, OxyColors.Orange.R, OxyColors.Orange.G, OxyColors.Orange.B); rectAannotationMax.MinimumX = indexHigh - 0.5; rectAannotationMax.MaximumX = indexHigh + 0.5; rectAannotationMax.Layer = AnnotationLayer.BelowSeries; this.PlotModel.Annotations.Add(rectAannotationMax); var textAnnotation = new TextAnnotation(); textAnnotation.TextPosition = new DataPoint((float)(indexHigh + indexLow) / 2, this.PlotModel.Axes[1].ActualMaximum / 2); if (isAbsolute) { textAnnotation.Text = String.Format("{0:f0}s", high - low); } else { textAnnotation.Text = String.Format("{0:f0}%", high * 100 / low); } textAnnotation.TextColor = OxyColors.Orange; textAnnotation.FontSize = 50; textAnnotation.FontWeight = FontWeights.Bold; textAnnotation.Stroke = OxyColors.Transparent; this.PlotModel.Annotations.Add(textAnnotation); this.PlotModel.InvalidatePlot(true); }
private RectangleAnnotation CreateRange() { var range = new RectangleAnnotation { Fill = OxyColor.FromAColor(120, OxyColors.SkyBlue), MinimumX = 0, MaximumX = 0 }; Ranges.Add(range); range.MouseDown += Range_MouseDown; range.MouseUp += Range_MouseUp; Model.Annotations.Add(range); return(range); }
public void SetLevelAnnotation(double level) { this.PlotModel.Annotations.Clear(); int index = this.TimeHistogramDatum.HistogramData .FindIndex(v => v.Level == (int)(Math.Ceiling((level + 0.0f) / this.TimeHistogramDatum.ClassWidth) * this.TimeHistogramDatum.ClassWidth)); Console.WriteLine("CLASS_WIDTH: " + this.TimeHistogramDatum.ClassWidth); Console.WriteLine("LEVEL: " + this.TimeHistogramDatum.HistogramData[0].Level); Console.WriteLine("VALUE: " + (int)(Math.Ceiling((level + 0.0f) / this.TimeHistogramDatum.ClassWidth) * this.TimeHistogramDatum.ClassWidth)); RectangleAnnotation rectAannotation = new RectangleAnnotation(); rectAannotation.Fill = OxyColor.FromArgb(100, OxyColors.Orange.R, OxyColors.Orange.G, OxyColors.Orange.B); rectAannotation.MinimumX = index - 0.5; rectAannotation.MaximumX = index + 0.5; rectAannotation.Layer = AnnotationLayer.BelowSeries; this.PlotModel.Annotations.Add(rectAannotation); // TODO アルゴリズム考えよう int x; if (index < 2) { x = 2; } else if (index > 8) { x = 8; } else { x = index; } var textAnnotation = new TextAnnotation(); textAnnotation.TextPosition = new DataPoint(x, this.PlotModel.Axes[1].ActualMaximum / 2); textAnnotation.Text = String.Format("{0:f0}s", level); textAnnotation.TextColor = OxyColors.Orange; textAnnotation.FontSize = 50; textAnnotation.FontWeight = FontWeights.Bold; textAnnotation.Stroke = OxyColors.Transparent; this.PlotModel.Annotations.Add(textAnnotation); this.PlotModel.InvalidatePlot(true); }
public static PlotModel AnnotationLayers() { var model = new PlotModel { Title = "AnnotationLayers" }; var a1 = new RectangleAnnotation { MinimumX = 10, MaximumX = 20, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.BelowAxes }; var a2 = new RectangleAnnotation { MinimumX = 30, MaximumX = 40, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.BelowSeries }; var a3 = new RectangleAnnotation { MinimumX = 50, MaximumX = 60, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.AboveSeries }; model.Annotations.Add(a1); model.Annotations.Add(a2); model.Annotations.Add(a3); var s1 = new FunctionSeries(Math.Sin, 0, 100, 0.01); model.Series.Add(s1); a1.MouseDown += (s, e) => { model.Subtitle = "Clicked annotation below axes"; model.InvalidatePlot(true); e.Handled = true; }; a2.MouseDown += (s, e) => { model.Subtitle = "Clicked annotation below series"; model.InvalidatePlot(true); e.Handled = true; }; a3.MouseDown += (s, e) => { model.Subtitle = "Clicked annotation above series"; model.InvalidatePlot(true); e.Handled = true; }; s1.MouseDown += (s, e) => { model.Subtitle = "Clicked series"; model.InvalidatePlot(true); e.Handled = true; }; return(model); }
public PlotModelRangeSelectionHandler(PlotModel model) { _model = model; _range = new RectangleAnnotation { Fill = OxyColor.FromAColor(120, OxyColors.SkyBlue) }; // Create and add the annotation to the plot _model.InvalidatePlot(true); _startx = double.NaN; _model.MouseDown += OnModelOnMouseDown; _model.MouseMove += OnModelOnMouseMove; _model.MouseUp += OnModelOnMouseUp; }
private void CreateAnnotations() { m_chart.Annotations.Clear(); if (Path == null || !Path.HasSegments) { TextAnnotation txt = new TextAnnotation(); if (Path == null) { txt.Text = "No path selected"; } else { txt.Text = "Generating detailed path data ..."; } txt.AnchorX = 50; txt.AnchorY = 50; txt.Font = new Font(FontFamily.GenericSansSerif, 24.0f); m_chart.Annotations.Add(txt); } else { m_line = new VerticalLineAnnotation(); m_line.LineColor = Color.Black; m_line.LineDashStyle = ChartDashStyle.Dash; m_line.AxisX = m_chart.ChartAreas[0].AxisX; m_line.IsInfinitive = true; m_line.ClipToChartArea = m_chart.ChartAreas[0].Name; m_line.LineWidth = 3; m_line.AnchorX = m_time; m_line.AllowMoving = true; m_chart.Annotations.Add(m_line); m_chart.AnnotationPositionChanging += TimeBarChangedByUser; m_rect = new RectangleAnnotation(); m_rect.ForeColor = Color.White; m_rect.BackColor = Color.Blue; m_rect.Width = 10; m_rect.Height = 4; m_rect.Width = 2.5; m_rect.AnchorY = 0.0; m_rect.AnchorX = m_time; m_rect.AxisY = m_chart.ChartAreas[0].AxisY; m_rect.AxisX = m_chart.ChartAreas[0].AxisX; m_rect.ClipToChartArea = null; m_chart.Annotations.Add(m_rect); } }
public static PlotModel SelectRange() { var model = new PlotModel { Title = "Select range", Subtitle = "Left click and drag to select a range." }; model.Series.Add(new FunctionSeries(Math.Cos, 0, 40, 0.1)); var range = new RectangleAnnotation { Fill = OxyColor.FromAColor(120, OxyColors.SkyBlue), MinimumX = 0, MaximumX = 0 }; model.Annotations.Add(range); double startx = double.NaN; model.MouseDown += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { startx = range.InverseTransform(e.Position).X; range.MinimumX = startx; range.MaximumX = startx; model.InvalidatePlot(true); e.Handled = true; } }; model.MouseMove += (s, e) => { if (!double.IsNaN(startx)) { var x = range.InverseTransform(e.Position).X; range.MinimumX = Math.Min(x, startx); range.MaximumX = Math.Max(x, startx); range.Text = string.Format("∫ cos(x) dx = {0:0.00}", Math.Sin(range.MaximumX) - Math.Sin(range.MinimumX)); model.Subtitle = string.Format("Integrating from {0:0.00} to {1:0.00}", range.MinimumX, range.MaximumX); model.InvalidatePlot(true); e.Handled = true; } }; model.MouseUp += (s, e) => { startx = double.NaN; }; return(model); }
private void Ranges_RangeCreated(RectangleAnnotation range, double start, double end) { var frames = PLog.GetFramesInRange(start, end); if (frames.Count == 0) { NodeList = new List <PerfNodeStats>(); range.ToolTip = "No Frames!"; return; } range.ToolTip = $"{frames.Count} frames, Span {(end-start)/1000:F3}s, Avg: {frames.Average(f => f.Time):F2}Ms Peak {frames.MaxBy(f=> f.Time).Time:F2}Ms"; NodeList = PLog.GetStatsForRange(frames.Start, frames.End). OrderByDescending(p => p.AvgExclusiveTime). ToList(); }
/// <summary>Get scatter points for MS features and a rectangle annotation for the LCMS feature.</summary> /// <param name="feature">An LCMS feature.</param> /// <param name="dataset">The dataset that the LCMS feature comes from.</param> /// <returns>The tuple containing the LCMS feature annotation and the MS feature scatter points..</returns> private Tuple <RectangleAnnotation, IEnumerable <ScatterPoint> > GetMsFeaturesAndAnnotations(FeaturePoint feature, DatasetInformation dataset) { var msdataPoints = new List <ScatterPoint> { Capacity = feature.UMCLight.MsFeatures.Count }; var minNet = double.PositiveInfinity; var maxNet = 0.0; var minMass = double.PositiveInfinity; var maxMass = 0.0; foreach (var msfeature in feature.UMCLight.MsFeatures) { var net = this.GetNet(dataset, msfeature.Scan); minNet = Math.Min(minNet, net); maxNet = Math.Max(maxNet, net); minMass = Math.Min(minMass, msfeature.MassMonoisotopic); maxMass = Math.Max(maxMass, msfeature.MassMonoisotopic); msdataPoints.Add(new ScatterPoint(net, msfeature.MassMonoisotopic, 0.8)); } var netRange = maxNet - minNet; netRange = netRange.Equals(0.0) ? 0.01 : netRange; var massRange = maxMass - minMass; massRange = Math.Max(1.0, massRange); minNet = minNet - (0.25 * netRange); maxNet = maxNet + (0.25 * netRange); minMass = Math.Max(minMass - (massRange * 0.5), 0); maxMass = maxMass + (massRange * 0.5); var annotation = new RectangleAnnotation { MinimumX = minNet, MaximumX = maxNet, MinimumY = minMass, MaximumY = maxMass, Fill = OxyColors.Transparent, StrokeThickness = 1.0, }; return(new Tuple <RectangleAnnotation, IEnumerable <ScatterPoint> >(annotation, msdataPoints)); }
public static PlotModel AnnotationLayers() { var model = new PlotModel { Title = "AnnotationLayers" }; var a1 = new RectangleAnnotation { MinimumX = 10, MaximumX = 20, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.BelowAxes }; var a2 = new RectangleAnnotation { MinimumX = 30, MaximumX = 40, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.BelowSeries }; var a3 = new RectangleAnnotation { MinimumX = 50, MaximumX = 60, MinimumY = -1, MaximumY = 1, Layer = AnnotationLayer.AboveSeries }; model.Annotations.Add(a1); model.Annotations.Add(a2); model.Annotations.Add(a3); var s1 = new FunctionSeries(Math.Sin, 0, 100, 0.01); model.Series.Add(s1); a1.MouseDown += (s, e) => { model.Subtitle = "Clicked annotation below axes"; model.InvalidatePlot(true); e.Handled = true; }; a2.MouseDown += (s, e) => { model.Subtitle = "Clicked annotation below series"; model.InvalidatePlot(true); e.Handled = true; }; a3.MouseDown += (s, e) => { model.Subtitle = "Clicked annotation above series"; model.InvalidatePlot(true); e.Handled = true; }; s1.MouseDown += (s, e) => { model.Subtitle = "Clicked series"; model.InvalidatePlot(true); e.Handled = true; }; return model; }
public static Example ClickingOnAnAnnotation() { // https://oxyplot.codeplex.com/discussions/543975 var plotModel = new PlotModel { Title = "Clicking on an annotation", Subtitle = "Click on the rectangles" }; plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom }); plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left }); var annotation1 = new RectangleAnnotation { Fill = OxyColors.Green, Text = "RectangleAnnotation 1", MinimumX = 25, MaximumX = 75, MinimumY = 20, MaximumY = 40 }; plotModel.Annotations.Add(annotation1); var annotation2 = new RectangleAnnotation { Fill = OxyColors.SkyBlue, Text = "RectangleAnnotation 2", MinimumX = 25, MaximumX = 75, MinimumY = 60, MaximumY = 80 }; plotModel.Annotations.Add(annotation2); EventHandler<OxyMouseDownEventArgs> handleMouseClick = (s, e) => { plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)s).Text; plotModel.InvalidatePlot(false); }; annotation1.MouseDown += handleMouseClick; annotation2.MouseDown += handleMouseClick; var controller = new PlotController(); var handleClick = new DelegatePlotCommand<OxyMouseDownEventArgs>( (v, c, e) => { var args = new HitTestArguments(e.Position, 10); var firstHit = v.ActualModel.HitTest(args).FirstOrDefault(x => x.Element is RectangleAnnotation); if (firstHit != null) { plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)firstHit.Element).Text; plotModel.InvalidatePlot(false); } }); controller.Bind(new OxyMouseDownGesture(OxyMouseButton.Left), handleClick); return new Example(plotModel, controller); }
public void SetLevelAnnotation(double level) { this.PlotModel.Annotations.Clear(); int index = this.EnergyHistogramDatum.HistogramData .FindIndex(v => v.Level == Math.Ceiling(level / this.EnergyHistogramDatum.ClassWidth) * this.EnergyHistogramDatum.ClassWidth); RectangleAnnotation rectAannotation = new RectangleAnnotation(); rectAannotation.Fill = OxyColor.FromArgb(100, OxyColors.Orange.R, OxyColors.Orange.G, OxyColors.Orange.B); rectAannotation.MinimumX = index - 0.5; rectAannotation.MaximumX = index + 0.5; rectAannotation.Layer = AnnotationLayer.BelowSeries; this.PlotModel.Annotations.Add(rectAannotation); // TODO アルゴリズム考えよう int x; if (index < 2) { x = 2; } else if (index > 8) { x = 8; } else { x = index; } var textAnnotation = new TextAnnotation(); textAnnotation.TextPosition = new DataPoint(x, this.PlotModel.Axes[1].ActualMaximum / 2); textAnnotation.Text = String.Format("{0:f3}kWh", level); textAnnotation.TextColor = OxyColors.Orange; textAnnotation.FontSize = 50; textAnnotation.FontWeight = FontWeights.Bold; textAnnotation.Stroke = OxyColors.Transparent; this.PlotModel.Annotations.Add(textAnnotation); this.PlotModel.InvalidatePlot(true); }
public void SetDistAnnotation(List<LevelAndValue> seriesList, double percent) { this.PlotModel.Annotations.Clear(); int indexMin = this.EnergyHistogramDatum.HistogramData .FindIndex(a => a.Level == seriesList.Min(b => b.Level)); int indexMax = this.EnergyHistogramDatum.HistogramData .FindIndex(a => a.Level == seriesList.Max(b => b.Level)); RectangleAnnotation rectAannotation = new RectangleAnnotation(); rectAannotation.Fill = OxyColor.FromArgb(100, OxyColors.Orange.R, OxyColors.Orange.G, OxyColors.Orange.B); rectAannotation.MinimumX = indexMin - 0.5; rectAannotation.MaximumX = indexMax + 0.5; rectAannotation.Layer = AnnotationLayer.BelowSeries; this.PlotModel.Annotations.Add(rectAannotation); var textAnnotation = new TextAnnotation(); textAnnotation.TextPosition = new DataPoint((float)(indexMax + indexMin) / 2, this.PlotModel.Axes[1].ActualMaximum / 2); textAnnotation.Text = String.Format("{0:f1}%", percent); textAnnotation.TextColor = OxyColors.Orange; textAnnotation.FontSize = 50; textAnnotation.FontWeight = FontWeights.Bold; textAnnotation.Stroke = OxyColors.Transparent; this.PlotModel.Annotations.Add(textAnnotation); this.PlotModel.InvalidatePlot(true); }
public static PlotModel ClickingOnAnAnnotation() { var plotModel = new PlotModel { Title = "Clicking on an annotation", Subtitle = "Click on the rectangles" }; plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom }); plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left }); var annotation1 = new RectangleAnnotation { Fill = OxyColors.Green, Text = "RectangleAnnotation 1", MinimumX = 25, MaximumX = 75, MinimumY = 20, MaximumY = 40 }; plotModel.Annotations.Add(annotation1); var annotation2 = new RectangleAnnotation { Fill = OxyColors.SkyBlue, Text = "RectangleAnnotation 2", MinimumX = 25, MaximumX = 75, MinimumY = 60, MaximumY = 80 }; plotModel.Annotations.Add(annotation2); EventHandler<OxyMouseDownEventArgs> handleMouseClick = (s, e) => { plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)s).Text; plotModel.InvalidatePlot(false); }; annotation1.MouseDown += handleMouseClick; annotation2.MouseDown += handleMouseClick; return plotModel; }
public static PlotModel RectangleAnnotationClick() { var plotModel = new PlotModel { Title = "RectangleAnnotation click" }; plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom }); plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left }); var annotation = new RectangleAnnotation() { MinimumX = 10, MaximumX = 60, MinimumY = 10, MaximumY = 20 }; plotModel.Annotations.Add(annotation); int i = 0; annotation.MouseDown += (s, e) => { annotation.Text = "Clicked " + (++i) + " times."; plotModel.InvalidatePlot(false); }; return plotModel; }
public static PlotModel SelectRange() { var model = new PlotModel { Title = "Select range", Subtitle = "Left click and drag to select a range." }; model.Series.Add(new FunctionSeries(Math.Cos, 0, 40, 0.1)); var range = new RectangleAnnotation { Fill = OxyColor.FromAColor(120, OxyColors.SkyBlue), MinimumX = 0, MaximumX = 0 }; model.Annotations.Add(range); double startx = double.NaN; model.MouseDown += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { startx = range.InverseTransform(e.Position).X; range.MinimumX = startx; range.MaximumX = startx; model.InvalidatePlot(true); e.Handled = true; } }; model.MouseMove += (s, e) => { if (!double.IsNaN(startx)) { var x = range.InverseTransform(e.Position).X; range.MinimumX = Math.Min(x, startx); range.MaximumX = Math.Max(x, startx); range.Text = string.Format("∫ cos(x) dx = {0:0.00}", Math.Sin(range.MaximumX) - Math.Sin(range.MinimumX)); model.Subtitle = string.Format("Integrating from {0:0.00} to {1:0.00}", range.MinimumX, range.MaximumX); model.InvalidatePlot(true); e.Handled = true; } }; model.MouseUp += (s, e) => { startx = double.NaN; }; return model; }
public void ChopperWorker() { int[] ChopperSpectrum = CAEN_x730.GetHistogram(7); var areaSeries = (AreaSeries)ChopperPlot.Series.FirstOrDefault(); areaSeries.Points.Clear(); areaSeries.Points2.Clear(); int maxDisplayChannelNumber = ChopperSpectrum.Count() - 1; while (ChopperSpectrum[maxDisplayChannelNumber] == 0) { maxDisplayChannelNumber -= 1; if (maxDisplayChannelNumber < 100) return; } for (int i = 50; i < maxDisplayChannelNumber; i++) { areaSeries.Points.Add(new DataPoint(i, ChopperSpectrum[i])); areaSeries.Points2.Add(new DataPoint(i, 0)); } ChopperPlot.Annotations.Clear(); var yAxis = ChopperPlot.Axes.FirstOrDefault(x => x.Position == AxisPosition.Left); var IntegrationInterval = new RectangleAnnotation { MinimumY = 0, MaximumY = 10000, MinimumX = chopperConfig.LeftIntervalChannel, MaximumX = chopperConfig.RightIntervalChannel, Fill = OxyColor.FromAColor(20, OxyColors.Blue), }; ChopperPlot.Annotations.Add(IntegrationInterval); ChopperPlot.InvalidatePlot(true); }
/// <summary> /// Draw a rectangle on chart. /// </summary> /// <param name="sender">Source Chart.</param> /// <param name="x">XAxis value</param> /// <param name="y">YAxis value</param> /// <param name="width">rectangle width using XAis value.</param> /// <param name="height">rectangle height using YAis value.</param> /// <param name="lineColor">Outline color.</param> /// <param name="name">Annotation name.</param> /// <param name="lineWidth">Line width</param> /// <param name="lineStyle">Line style</param> /// <param name="chartArea">Target ChartArea where annotation should be displayed. Default to first ChartArea if not defined.</param> public static Annotation DrawRectangle(this Chart sender, double x, double y, double width, double height, Drawing.Color lineColor, string name = "", int lineWidth = 1, ChartDashStyle lineStyle = ChartDashStyle.Solid, ChartArea chartArea = null) { RectangleAnnotation rect = new RectangleAnnotation(); ChartArea ptrChartArea = (chartArea == null) ? sender.ChartAreas[0] : chartArea; string chartAreaName = ptrChartArea.Name; rect.ClipToChartArea = chartAreaName; rect.AxisXName = chartAreaName + "\\rX"; rect.YAxisName = chartAreaName + "\\rY"; rect.BackColor = Drawing.Color.Transparent; rect.ForeColor = Drawing.Color.Transparent; rect.IsSizeAlwaysRelative = false; rect.LineColor = lineColor; rect.LineWidth = lineWidth; rect.LineDashStyle = lineStyle; //Limit rectangle within chart area Axis ptrAxis = ptrChartArea.AxisX; if (x < ptrAxis.Minimum) { width = width - (ptrAxis.Minimum - x); x = ptrAxis.Minimum; } else if (x > ptrAxis.Maximum) { width = width - (x - ptrAxis.Maximum); x = ptrAxis.Maximum; } if ((x + width) > ptrAxis.Maximum) width = ptrAxis.Maximum - x; ptrAxis = ptrChartArea.AxisY; if (y < ptrAxis.Minimum) { height = height - (ptrAxis.Minimum - y); y = ptrAxis.Minimum; } else if (y > ptrAxis.Maximum) { height = height - (y - ptrAxis.Maximum); y = ptrAxis.Maximum; } if ((y + height) > ptrAxis.Maximum) height = ptrAxis.Maximum - y; rect.X = x; rect.Y = y; rect.Width = width; rect.Height = height; rect.LineColor = lineColor; sender.Annotations.Add(rect); if (!string.IsNullOrEmpty(name)) rect.Name = name; return rect; }
public void SetCompAnnotation(double low, double high, bool isAbsolute) { this.PlotModel.Annotations.Clear(); int indexLow = this.EnergyHistogramDatum.HistogramData .FindIndex(v => v.Level == Math.Ceiling(low / this.EnergyHistogramDatum.ClassWidth) * this.EnergyHistogramDatum.ClassWidth); int indexHigh = this.EnergyHistogramDatum.HistogramData .FindIndex(v => v.Level == Math.Ceiling(high / this.EnergyHistogramDatum.ClassWidth) * this.EnergyHistogramDatum.ClassWidth); RectangleAnnotation rectAannotationMin = new RectangleAnnotation(); rectAannotationMin.Fill = OxyColor.FromArgb(100, OxyColors.Orange.R, OxyColors.Orange.G, OxyColors.Orange.B); rectAannotationMin.MinimumX = indexLow - 0.5; rectAannotationMin.MaximumX = indexLow + 0.5; rectAannotationMin.Layer = AnnotationLayer.BelowSeries; this.PlotModel.Annotations.Add(rectAannotationMin); RectangleAnnotation rectAannotationMax = new RectangleAnnotation(); rectAannotationMax.Fill = OxyColor.FromArgb(100, OxyColors.Orange.R, OxyColors.Orange.G, OxyColors.Orange.B); rectAannotationMax.MinimumX = indexHigh - 0.5; rectAannotationMax.MaximumX = indexHigh + 0.5; rectAannotationMax.Layer = AnnotationLayer.BelowSeries; this.PlotModel.Annotations.Add(rectAannotationMax); var textAnnotation = new TextAnnotation(); textAnnotation.TextPosition = new DataPoint((float)(indexHigh + indexLow) / 2, this.PlotModel.Axes[1].ActualMaximum / 2); if (isAbsolute) textAnnotation.Text = String.Format("{0:f3}kWh", high - low); else textAnnotation.Text = String.Format("{0:f0}%", high * 100 / low); textAnnotation.TextColor = OxyColors.Orange; textAnnotation.FontSize = 50; textAnnotation.FontWeight = FontWeights.Bold; textAnnotation.Stroke = OxyColors.Transparent; this.PlotModel.Annotations.Add(textAnnotation); this.PlotModel.InvalidatePlot(true); }
public void RectangleAnnotation() { var s1 = new RectangleAnnotation(); var s2 = new Annotations.RectangleAnnotation(); OxyAssert.PropertiesAreEqual(s1, s2); }
private void SetAnnotationType() { Chart1.Annotations.Clear(); if(Annotation.SelectedItem.Value == "Line") { LineAnnotation annotation = new LineAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[2]; annotation.Height = -25; annotation.Width = -25; annotation.LineWidth = 2; Chart1.Annotations.Add(annotation); } else if(Annotation.SelectedItem.Value == "Vertical Line") { VerticalLineAnnotation annotation = new VerticalLineAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[2]; annotation.Height = -25; annotation.LineWidth = 2; Chart1.Annotations.Add(annotation); } else if(Annotation.SelectedItem.Value == "Horizontal Line") { HorizontalLineAnnotation annotation = new HorizontalLineAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[2]; annotation.Width = -25; annotation.LineWidth = 2; Chart1.Annotations.Add(annotation); } else if(Annotation.SelectedItem.Value == "Polyline") { PolylineAnnotation annotation = new PolylineAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[2]; // explicitly set the relative height and width annotation.Height = 50; annotation.Width = 30; PointF [] points = new PointF[5]; points[0].X = 0; points[0].Y = 0; points[1].X = 100; points[1].Y = 0; points[2].X = 0; points[2].Y = 100; points[3].X = 100; points[3].Y = 100; points[4].X = 0; points[4].Y = 50; annotation.GraphicsPath.AddPolygon(points); Chart1.Annotations.Add(annotation); } else if(Annotation.SelectedItem.Value == "Text") { TextAnnotation annotation = new TextAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[2]; annotation.Text = "I am a TextAnnotation"; annotation.ForeColor = Color.Black; annotation.Font = new Font("Arial", 12);; Chart1.Annotations.Add(annotation); } else if(Annotation.SelectedItem.Value == "Rectangle") { RectangleAnnotation annotation = new RectangleAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[2]; annotation.Text = "I am a\nRectangleAnnotation"; annotation.ForeColor = Color.Black; annotation.Font = new Font("Arial", 12);; annotation.LineWidth = 2; Chart1.Annotations.Add(annotation); } else if(Annotation.SelectedItem.Value == "Ellipse") { EllipseAnnotation annotation = new EllipseAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[2]; annotation.Text = "I am an EllipseAnnotation"; annotation.ForeColor = Color.Black; annotation.Font = new Font("Arial", 12);; annotation.LineWidth = 2; annotation.Height = 35; annotation.Width = 60; Chart1.Annotations.Add(annotation); } else if(Annotation.SelectedItem.Value == "Arrow") { ArrowAnnotation annotation = new ArrowAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[2]; annotation.Height = -25; annotation.Width = -25; annotation.LineWidth = 2; Chart1.Annotations.Add(annotation); } else if(Annotation.SelectedItem.Value == "Border3D") { Border3DAnnotation annotation = new Border3DAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[2]; annotation.Text = "I am a Border3DAnnotation"; annotation.ForeColor = Color.Black; annotation.Font = new Font("Arial", 12);; annotation.Height = 40; annotation.Width = 50; Chart1.Annotations.Add(annotation); } else if(Annotation.SelectedItem.Value == "Callout") { CalloutAnnotation annotation = new CalloutAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[1]; annotation.Text = "I am a\nCalloutAnnotation"; annotation.ForeColor = Color.Black; annotation.Font = new Font("Arial", 10);; annotation.Height = 35; annotation.Width = 50; Chart1.Annotations.Add(annotation); } else if(Annotation.SelectedItem.Value == "Polygon") { PolygonAnnotation annotation = new PolygonAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[2]; // explicitly set the relative height and width annotation.Height = 50; annotation.Width = 30; annotation.BackColor = Color.FromArgb(128, Color.Orange); // define relative value points for a polygon PointF [] points = new PointF[5]; points[0].X = 0; points[0].Y = 0; points[1].X = 100; points[1].Y = 0; points[2].X = 100; points[2].Y = 100; points[3].X = 0; points[3].Y = 100; points[4].X = 50; points[4].Y = 50; annotation.GraphicsPath.AddPolygon(points); Chart1.Annotations.Add(annotation); } else if(Annotation.SelectedItem.Value == "Image") { if (Chart1.Images.IndexOf("MyBmp") < 0) { Bitmap Bmp = new Bitmap(200, 75); Graphics g = Graphics.FromImage(Bmp); g.FillRectangle(new SolidBrush(Color.Transparent), 0, 0, Bmp.Width, Bmp.Height); g.FillRectangle(new SolidBrush(Color.PaleGoldenrod), Bmp.Width/2, 0, Bmp.Width/2, Bmp.Height); g.FillRectangle(new SolidBrush(Color.PaleVioletRed), 0, 0, Bmp.Width/2, Bmp.Height); g.FillRectangle(new SolidBrush(Color.FromArgb(128, Color.DarkOrange)), 0, Bmp.Height/2, Bmp.Width, Bmp.Height/2); g.DrawString("I am an ImageAnnotation", new Font("Arial", 12), new SolidBrush(Color.Black), new Rectangle( 0, 0, Bmp.Width, Bmp.Height)); g.Dispose(); Chart1.Images.Add(new NamedImage("MyBmp", Bmp)); } ImageAnnotation annotation = new ImageAnnotation(); annotation.AnchorDataPoint = Chart1.Series[0].Points[2]; annotation.Image = "MyBmp"; Chart1.Annotations.Add(annotation); } }