/// <summary> /// Initializes a new instance of the <see cref="ErrorColumnItem"/> class. /// </summary> /// <param name="value"> /// The value. /// </param> /// <param name="error"> /// The error. /// </param> /// <param name="categoryIndex"> /// Index of the category. /// </param> /// <param name="color"> /// The color. /// </param> public ErrorColumnItem(double value, double error, int categoryIndex = -1, OxyColor color = null) { this.Value = value; this.Error = error; this.CategoryIndex = categoryIndex; this.Color = color; }
/// <summary> /// Exports the specified plot model to a file. /// </summary> /// <param name="model">The model to export.</param> /// <param name="fileName">The file name.</param> /// <param name="width">The width of the output bitmap.</param> /// <param name="height">The height of the output bitmap.</param> /// <param name="background">The background color. The default value is <c>null</c>.</param> /// <param name="resolution">The resolution (resolution). The default value is 96.</param> public static void Export(PlotModel model, string fileName, int width, int height, OxyColor background, int resolution = 96) { using (var s = File.Create(fileName)) { Export(model, s, width, height, background, resolution); } }
public void DrawLine(IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased) { var e = new Polyline(); if (stroke != null && thickness > 0) { e.Stroke = GetCachedBrush(stroke); switch (lineJoin) { case OxyPenLineJoin.Round: e.StrokeLineJoin = PenLineJoin.Round; break; case OxyPenLineJoin.Bevel: e.StrokeLineJoin = PenLineJoin.Bevel; break; // The default StrokeLineJoin is Miter } if (thickness != 1) // default values is 1 e.StrokeThickness = thickness; if (dashArray != null) e.StrokeDashArray = new DoubleCollection(dashArray); } // pl.Fill = null; if (aliased) e.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased); var pc = new PointCollection(points.Count); foreach (var p in points) pc.Add(ToPoint(p)); e.Points = pc; Add(e); }
/// <summary> /// Export the specified plot model to an xaml string. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> /// <returns>A xaml string.</returns> public static string ExportToString(PlotModel model, double width, double height, OxyColor background = null) { var g = new Grid(); if (background != null) { g.Background = background.ToBrush(); } var c = new Canvas(); g.Children.Add(c); var size = new Size(width, height); g.Measure(size); g.Arrange(new Rect(0, 0, width, height)); g.UpdateLayout(); var rc = new ShapesRenderContext(c) { UseStreamGeometry = false }; model.Update(); model.Render(rc, width, height); var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true }); XamlWriter.Save(c, xw); } return sb.ToString(); }
/// <summary> /// Draws an ellipse. /// </summary> /// <param name="rect">The rectangle.</param> /// <param name="fill">The fill color.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The thickness.</param> public override void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness) { this.SetAlias(false); var convertedRectangle = rect.Convert(); if (fill.IsVisible()) { this.SetFill(fill); using (var path = new CGPath()) { path.AddEllipseInRect(convertedRectangle); this.gctx.AddPath(path); } this.gctx.DrawPath(CGPathDrawingMode.Fill); } if (stroke.IsVisible() && thickness > 0) { this.SetStroke(stroke, thickness); using (var path = new CGPath()) { path.AddEllipseInRect(convertedRectangle); this.gctx.AddPath(path); } this.gctx.DrawPath(CGPathDrawingMode.Stroke); } }
public HighLowSeries(OxyColor color, double strokeThickness = 1, string title = null) : this() { this.Color = color; this.StrokeThickness = strokeThickness; this.Title = title; }
/// <summary> /// Exports the specified plot model to a xaml file. /// </summary> /// <param name="model">The model.</param> /// <param name="fileName">Name of the file.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> public static void Export(PlotModel model, string fileName, double width, double height, OxyColor background) { using (var w = new StreamWriter(fileName)) { w.Write(ExportToString(model, width, height, background)); } }
/// <summary> /// Initializes a new instance of the <see cref="IntervalBarItem"/> class. /// </summary> /// <param name="start"> /// The start. /// </param> /// <param name="end"> /// The end. /// </param> /// <param name="title"> /// The title. /// </param> /// <param name="color"> /// The color. /// </param> public IntervalBarItem(double start, double end, string title = null, OxyColor color = null) { this.Start = start; this.End = end; this.Title = title; this.Color = color; }
/// <summary> /// Exports the specified plot model to an xps file. /// </summary> /// <param name="model">The model.</param> /// <param name="fileName">The file name.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background color.</param> public static void Export(IPlotModel model, string fileName, double width, double height, OxyColor background) { using (var xpsPackage = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite)) { using (var doc = new XpsDocument(xpsPackage)) { var canvas = new Canvas { Width = width, Height = height, Background = background.ToBrush() }; canvas.Measure(new Size(width, height)); canvas.Arrange(new Rect(0, 0, width, height)); var rc = new ShapesRenderContext(canvas); #if !NET35 rc.TextFormattingMode = TextFormattingMode.Ideal; #endif model.Update(true); model.Render(rc, width, height); canvas.UpdateLayout(); var xpsdw = XpsDocument.CreateXpsDocumentWriter(doc); xpsdw.Write(canvas); } } }
/// <summary> /// Initializes a new instance of the <see cref="ScatterSeries"/> class. /// </summary> /// <param name="title"> /// The title. /// </param> /// <param name="markerFill"> /// The marker fill color. /// </param> /// <param name="markerSize"> /// Size of the markers (If ScatterPoint.Size is set, this value will be overridden). /// </param> public ScatterSeries(string title, OxyColor markerFill = null, double markerSize = 5) : this() { this.MarkerFill = markerFill; this.MarkerSize = markerSize; this.Title = title; }
/// <summary> /// Exports the specified plot model to a xaml file. /// </summary> /// <param name="model">The model.</param> /// <param name="fileName">Name of the file.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> public static void Export(PlotModel model, string fileName, double width, double height, OxyColor background) { using (var sw = new StreamWriter(fileName)) { var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true }); Export(model, xw, width, height, background); } }
/// <summary> /// Exports the specified plot model to an xps file. /// </summary> /// <param name="model">The model.</param> /// <param name="fileName">The file name.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background color.</param> public static void Export(IPlotModel model, string fileName, double width, double height, OxyColor background) { using (var stream = File.Open(fileName, FileMode.Create, FileAccess.ReadWrite)) { var exporter = new XpsExporter { Width = width, Height = height, Background = background }; exporter.Export(model, stream); } }
/// <summary> /// Exports the specified plot model to a stream. /// </summary> /// <param name="model">The model.</param> /// <param name="stream">The stream.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> /// <param name="resolution">The resolution.</param> public static void Export(PlotModel model, Stream stream, int width, int height, OxyColor background = null, int resolution = 96) { var bmp = ExportToBitmap(model, width, height, background); var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bmp)); encoder.Save(stream); }
/// <summary> /// Initializes a new instance of the <see cref="RectangleBarItem"/> class. /// </summary> /// <param name="x0"> /// The x0. /// </param> /// <param name="y0"> /// The y0. /// </param> /// <param name="x1"> /// The x1. /// </param> /// <param name="y1"> /// The y1. /// </param> /// <param name="title"> /// The title. /// </param> /// <param name="color"> /// The color. /// </param> public RectangleBarItem(double x0, double y0, double x1, double y1, string title = null, OxyColor color = null) { this.X0 = x0; this.Y0 = y0; this.X1 = x1; this.Y1 = y1; this.Title = title; this.Color = color; }
/// <summary> /// Export the specified plot model to an xaml string. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> /// <returns>A xaml string.</returns> public static string ExportToString(IPlotModel model, double width, double height, OxyColor background) { var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true }); Export(model, xw, width, height, background); } return sb.ToString(); }
/// <summary> /// Initializes a new instance of the <see cref="PdfRenderContext" /> class. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background color.</param> public PdfRenderContext(double width, double height, OxyColor background) { this.RendersToScreen = false; this.doc = new PdfDocument(); var page = new PdfPage { Width = new XUnit(width), Height = new XUnit(height) }; this.doc.AddPage(page); this.g = XGraphics.FromPdfPage(page); if (background.IsVisible()) { this.g.DrawRectangle(ToBrush(background), 0, 0, width, height); } }
/// <summary> /// Initializes a new instance of the <see cref="TornadoBarItem"/> class. /// </summary> /// <param name="minimum"> /// The minimum. /// </param> /// <param name="maximum"> /// The maximum. /// </param> /// <param name="baseValue"> /// The base value. /// </param> /// <param name="minimumColor"> /// The minimum color. /// </param> /// <param name="maximumColor"> /// The maximum color. /// </param> public TornadoBarItem( double minimum, double maximum, double baseValue = double.NaN, OxyColor minimumColor = null, OxyColor maximumColor = null) { this.Minimum = minimum; this.Maximum = maximum; this.BaseValue = baseValue; this.MinimumColor = minimumColor; this.MaximumColor = maximumColor; }
public void Create_SmallImageToBmp() { var data = new OxyColor[2, 4]; data[1, 0] = OxyColors.Blue; data[1, 1] = OxyColors.Green; data[1, 2] = OxyColors.Red; data[1, 3] = OxyColors.White; data[0, 0] = OxyColor.FromAColor(127, OxyColors.Yellow); data[0, 1] = OxyColor.FromAColor(127, OxyColors.Orange); data[0, 2] = OxyColor.FromAColor(127, OxyColors.Pink); data[0, 3] = OxyColors.Transparent; var img = OxyImage.Create(data, ImageFormat.Bmp, new BmpEncoderOptions()); var bytes = img.GetData(); File.WriteAllBytes(@"Imaging\SmallImage.bmp", bytes); }
public void FromArgbX() { var data = new OxyColor[2, 4]; data[1, 0] = OxyColors.Blue; data[1, 1] = OxyColors.Green; data[1, 2] = OxyColors.Red; data[1, 3] = OxyColors.White; data[0, 0] = OxyColors.Yellow.ChangeAlpha(127); data[0, 1] = OxyColors.Orange.ChangeAlpha(127); data[0, 2] = OxyColors.Pink.ChangeAlpha(127); data[0, 3] = OxyColors.Transparent; var img = OxyImage.FromArgbX(data); var bytes = img.GetData(); File.WriteAllBytes("FromArgbX.bmp", bytes); }
public void PngFromArgb2() { int w = 266; int h = 40; var data = new OxyColor[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { data[i, j] = OxyColor.FromHsv((double)j / w, 1, 1); } } var img = OxyImage.PngFromArgb(data); var bytes = img.GetData(); File.WriteAllBytes("PngFromArgb2.png", bytes); }
public void Create_LargeImageToPng() { int w = 266; int h = 40; var data = new OxyColor[w, h]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { data[x, y] = OxyColor.FromHsv((double)x / w, 1, 1); } } var img = OxyImage.Create(data, ImageFormat.Png); var bytes = img.GetData(); File.WriteAllBytes(@"Imaging\LargeImage.png", bytes); }
public void DrawLines(IEnumerable<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased) { var startPoint = new ScreenPoint(); bool first = true; foreach (var p in points) { if (!first) { Add(new Line { X1 = startPoint.X, Y1 = startPoint.Y, X2 = p.X, Y2 = p.Y }); } else { startPoint = p; } first = !first; } }
/// <summary> /// Saves the PlotView as a bitmap. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> public void SaveBitmap(string fileName, int width, int height, OxyColor background) { if (width <= 0) { width = (int)this.ActualWidth; } if (height <= 0) { height = (int)this.ActualHeight; } if (!background.IsVisible()) { background = this.Background.ToOxyColor(); } PngExporter.Export(this.ActualModel, fileName, width, height, background); }
/// <summary> /// Draws an ellipse. /// </summary> /// <param name="rect">The rectangle defining the ellipse.</param> /// <param name="fill">The fill.</param> /// <param name="stroke">The stroke.</param> /// <param name="thickness">The thickness.</param> public void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness) { var el = new Ellipse(); if (stroke.IsVisible()) { el.Stroke = stroke.ToBrush(); el.StrokeThickness = thickness; } if (fill.IsVisible()) { el.Fill = fill.ToBrush(); } el.Width = rect.Width; el.Height = rect.Height; Canvas.SetLeft(el, rect.Left); Canvas.SetTop(el, rect.Top); this.Add(el, rect.Left, rect.Top); }
public void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness = 1) { using (var paint = new Paint()) { paint.AntiAlias = true; paint.StrokeWidth = (float)thickness; if (fill != null) { paint.SetStyle(Paint.Style.Fill); paint.Color = stroke.ToColor(); canvas.DrawOval(rect.ToRectF(), paint); } if (stroke != null) { paint.SetStyle(Paint.Style.Stroke); paint.Color = stroke.ToColor(); canvas.DrawOval(rect.ToRectF(), paint); } } }
/// <summary> /// Draws an ellipse. /// </summary> /// <param name="rect">The rectangle.</param> /// <param name="fill">The fill color.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The thickness.</param> public override void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness) { // center of ellipse var ex = rect.Left + (rect.Width / 2.0); var ey = rect.Top + (rect.Height / 2.0); // ellipse dimensions var ew = rect.Width; var eh = rect.Height; if (fill.IsVisible()) { this.g.Save(); this.g.Translate(ex, ey); // make (ex, ey) == (0, 0) this.g.Scale(ew / 2.0, eh / 2.0); // for width: ew / 2.0 == 1.0, eh / 2.0 == 1.0 this.g.Arc(0.0, 0.0, 1.0, 0.0, 2.0 * Math.PI); // 'circle' centered at (0, 0) this.g.ClosePath(); this.g.SetSourceColor(fill); this.g.Fill(); this.g.Restore(); } if (stroke.IsVisible() && thickness > 0) { this.g.Save(); // g.SmoothingMode = SmoothingMode.HighQuality; // TODO this.g.Translate(ex, ey); // make (ex, ey) == (0, 0) this.g.Scale(ew / 2.0, eh / 2.0); // for width: ew / 2.0 == 1.0 // for height: eh / 2.0 == 1.0 this.g.Arc(0.0, 0.0, 1.0, 0.0, 2.0 * Math.PI); // 'circle' centered at (0, 0) this.g.SetSourceColor(stroke); this.g.LineWidth = thickness * 2.0 / ew; this.g.Stroke(); this.g.Restore(); } }
public void DrawLine(IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { var pen = CreatePen(stroke, thickness, dashArray, lineJoin); // todo: alias line // if (aliased) // .SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased); var lp = new Point(); int i = 0; foreach (var point in points) { var p = point.ToPoint(); if (i > 0) { dc.DrawLine(pen, lp, p); } i++; lp = p; } }
private static Pen CreatePen(OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin = LineJoin.Miter) { if (stroke == null) return null; var pen = new Pen(stroke.ToBrush(), thickness); if (dashArray != null) { pen.DashStyle = new DashStyle(dashArray, 0); } switch (lineJoin) { case LineJoin.Round: pen.LineJoin = PenLineJoin.Round; break; case LineJoin.Bevel: pen.LineJoin = PenLineJoin.Bevel; break; // The default LineJoin is Miter } return pen; }
/// <summary> /// Exports the specified plot model to a xml writer. /// </summary> /// <param name="model">The model.</param> /// <param name="writer">The xml writer.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> private static void Export(IPlotModel model, XmlWriter writer, double width, double height, OxyColor background) { var c = new Canvas(); if (background.IsVisible()) { c.Background = background.ToBrush(); } c.Measure(new Size(width, height)); c.Arrange(new Rect(0, 0, width, height)); var rc = new CanvasRenderContext(c) { UseStreamGeometry = false }; rc.TextFormattingMode = TextFormattingMode.Ideal; model.Update(true); model.Render(rc, width, height); c.UpdateLayout(); XamlWriter.Save(c, writer); }
public void FromIndexed8() { var data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; var data2 = new byte[,] { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } }; var palette = new OxyColor[8]; palette[4] = OxyColors.Blue; palette[5] = OxyColors.Green; palette[6] = OxyColors.Red; palette[7] = OxyColors.White; palette[0] = OxyColors.Yellow.ChangeAlpha(127); palette[1] = OxyColors.Orange.ChangeAlpha(127); palette[2] = OxyColors.Pink.ChangeAlpha(127); palette[3] = OxyColors.Transparent; var img = OxyImage.FromIndexed8(4, 2, data, palette); var bytes = img.GetData(); File.WriteAllBytes("FromIndexed8.bmp", bytes); var img2 = OxyImage.FromIndexed8(data2, palette); var bytes2 = img2.GetData(); File.WriteAllBytes("FromIndexed8_2.bmp", bytes2); }
public void addNode(MainWindow window, double x, double y, string s, double markerSize, OxyColor color) { LineSeries series = new LineSeries(); series.MarkerType = OxyPlot.MarkerType.Circle; series.Color = color; series.MarkerSize = markerSize; series.Points.Add(new DataPoint(x, y)); series.TrackerFormatString = s; window.plotModel.Series.Add(series); }
void IRenderContext.DrawEllipse(OxyRect extents, OxyColor fill, OxyColor stroke, double thickness) { throw new NotImplementedException(); }
void IRenderContext.DrawRectangles(IList <OxyRect> rectangles, OxyColor fill, OxyColor stroke, double thickness) { throw new NotImplementedException(); }
public override void Render(IRenderContext rc, PlotModel model1) { PlotModel model = this.PlotModel; if (Theme != null) { OxyColor color = Convertor.ConvertColorToOxyColor(Theme.GetThemeColor()); this.FillColor = color; } //base.Render(rc, model); UpdateValidData(); this.ActualBarRectangles = new List <OxyRect>(); if (this.ValidItems == null || this.ValidItems.Count == 0) { return; } var clippingRect = this.GetClippingRect(); var categoryAxis = this.GetCategoryAxis(); var actualBarWidth = this.GetActualBarWidth(); var stackIndex = this.IsStacked ? categoryAxis.GetStackIndex(this.StackGroup) : 0; for (var i = 0; i < this.ValidItems.Count; i++) { var item = this.ValidItems[i]; var categoryIndex = this.ValidItems[i].CategoryIndex; if (categoryIndex < 0) { continue; } var value = item.Value; // Get base- and topValue var baseValue = double.NaN; if (this.IsStacked) { baseValue = categoryAxis.GetCurrentBaseValue(stackIndex, categoryIndex, value < 0); } if (double.IsNaN(baseValue)) { baseValue = this.BaseValue; } var topValue = this.IsStacked ? baseValue + value : value; // Calculate offset double categoryValue; if (this.IsStacked) { categoryValue = categoryAxis.GetCategoryValue(categoryIndex, stackIndex, actualBarWidth); } else { categoryValue = categoryIndex - 0.5 + categoryAxis.GetCurrentBarOffset(categoryIndex); } if (this.IsStacked) { categoryAxis.SetCurrentBaseValue(stackIndex, categoryIndex, value < 0, topValue); } var rect = this.GetRectangle(baseValue, topValue, categoryValue, categoryValue + actualBarWidth); this.ActualBarRectangles.Add(rect); this.RenderItem(rc, clippingRect, topValue, categoryValue, actualBarWidth, item, rect); if (this.LabelFormatString != null) { this.RenderLabel(rc, clippingRect, rect, value, i); } if (!this.IsStacked) { categoryAxis.IncreaseCurrentBarOffset(categoryIndex, actualBarWidth); } } }
public static void Plot3SeriaKolumnowy(string xTitle, string yTitle, OxyColor color1, OxyColor color2, OxyColor color3, int[,] histogramValues, string label1, string label2, string label3, PlotModel histogramModel, bool chkR, bool chkG, bool chkB) { histogramModel.Series.Clear(); histogramModel.Axes.Clear(); var l = histogramValues.Length / 3; var categoryAxisRGB = new CategoryAxis { GapWidth = 0, IsAxisVisible = false, IsZoomEnabled = false, MinorStep = 1 }; var s1 = new ColumnSeries { Title = label1, StrokeColor = color1, FillColor = color1, StrokeThickness = 1 }; for (int i = 0; i < l; i++) { int y_val = histogramValues[i, 0]; categoryAxisRGB.Labels.Add(i.ToString()); s1.Items.Add(new ColumnItem { Value = y_val, Color = color1 }); } var s2 = new ColumnSeries { Title = label2, StrokeColor = color2, FillColor = color2, StrokeThickness = 1 }; for (int i = 0; i < l; i++) { int y_val = histogramValues[i, 1]; s2.Items.Add(new ColumnItem { Value = y_val, Color = color2 }); } var s3 = new ColumnSeries { Title = label3, StrokeColor = color3, FillColor = color3, StrokeThickness = 1 }; for (int i = 0; i < l; i++) { int y_val = histogramValues[i, 2]; s3.Items.Add(new ColumnItem { Value = y_val, Color = color3 }); } var linearAxisRGB1 = new LinearAxis { Maximum = l, Minimum = 0, IsZoomEnabled = false, Position = AxisPosition.Bottom, Title = xTitle }; var linearAxisRGB2 = new LinearAxis { AbsoluteMinimum = 0, MinimumPadding = 0, IsZoomEnabled = false, Title = yTitle }; histogramModel.Axes.Add(categoryAxisRGB); histogramModel.Axes.Add(linearAxisRGB1); histogramModel.Axes.Add(linearAxisRGB2); if (chkR) { histogramModel.Series.Add(s1); } if (chkG) { histogramModel.Series.Add(s2); } if (chkB) { histogramModel.Series.Add(s3); } histogramModel.InvalidatePlot(true); }
/// <summary> /// Export the specified plot model to an xaml string. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="background">The background.</param> /// <returns>A xaml string.</returns> public static string ExportToString(IPlotModel model, double width, double height, OxyColor background) { var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true }); Export(model, xw, width, height, background); } return(sb.ToString()); }
/// <summary> /// Draws the line using the MaxPolylinesPerLine and MinPointsPerPolyline properties. /// </summary> /// <param name="points">The points.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The thickness.</param> /// <param name="dashArray">The dash array. Use <c>null</c> to get a solid line.</param> /// <param name="lineJoin">The line join.</param> /// <param name="aliased">Render aliased if set to <c>true</c>.</param> /// <remarks>See <a href="https://oxyplot.codeplex.com/discussions/456679">discussion</a>.</remarks> private void DrawLineBalanced(IList <ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { // balance the number of points per polyline and the number of polylines var numPointsPerPolyline = Math.Max(points.Count / MaxPolylinesPerLine, MinPointsPerPolyline); var polyline = this.CreateAndAdd <Polyline>(); this.SetStroke(polyline, stroke, thickness, lineJoin, dashArray, 0, aliased); var pc = new PointCollection(numPointsPerPolyline); var n = points.Count; double lineLength = 0; var dashPatternLength = (dashArray != null) ? dashArray.Sum() : 0; var last = new Point(); for (int i = 0; i < n; i++) { var p = aliased ? this.ToPixelAlignedPoint(points[i]) : this.ToPoint(points[i]); pc.Add(p); // alt. 1 if (dashArray != null) { if (i > 0) { var delta = p - last; var dist = Math.Sqrt((delta.X * delta.X) + (delta.Y * delta.Y)); lineLength += dist; } last = p; } // use multiple polylines with limited number of points to improve WPF performance if (pc.Count >= numPointsPerPolyline) { polyline.Points = pc; if (i < n - 1) { // alt.2 ////if (dashArray != null) ////{ //// lineLength += this.GetLength(polyline); ////} // start a new polyline at last point so there is no gap (it is not necessary to use the % operator) var dashOffset = dashPatternLength > 0 ? lineLength / thickness : 0; polyline = this.CreateAndAdd <Polyline>(); this.SetStroke(polyline, stroke, thickness, lineJoin, dashArray, dashOffset, aliased); pc = new PointCollection(numPointsPerPolyline) { pc.Last() }; } } } if (pc.Count > 1 || n == 1) { polyline.Points = pc; } }
/// <summary> /// Initializes a new instance of the <see cref="BarItem"/> class. /// </summary> /// <param name="value"> /// The value. /// </param> /// <param name="categoryIndex"> /// Index of the category. /// </param> /// <param name="color"> /// The color. /// </param> public BarItem(double value, int categoryIndex = -1, OxyColor color = null) { this.Value = value; this.CategoryIndex = categoryIndex; this.Color = color; }
private static void AddHLThresholdsAnnotation() { PolygonAnnotation profoundHL = new PolygonAnnotation(); profoundHL.Text = AnnotationText.ProfoundHL; profoundHL.TextPosition = new DataPoint(AudiogramAxes.FreqAxisMinHz + AnnotationText.AnnotationTextOffset, HLThreshold.ProfoundHLdB + AnnotationText.AnnotationTextOffset); profoundHL.TextHorizontalAlignment = HorizontalAlignment.Left; profoundHL.Layer = AnnotationLayer.BelowAxes; profoundHL.Fill = OxyColor.FromRgb(ProfoundHLFill.Red, ProfoundHLFill.Green, ProfoundHLFill.Blue); profoundHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMinHz, AudiogramAxes.PowerAxisMaxdB)); profoundHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMaxHz, AudiogramAxes.PowerAxisMaxdB)); profoundHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMaxHz, HLThreshold.ProfoundHLdB)); profoundHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMinHz, HLThreshold.ProfoundHLdB)); PolygonAnnotation severeHL = new PolygonAnnotation(); severeHL.Text = AnnotationText.SevereHL; severeHL.TextPosition = new DataPoint(AudiogramAxes.FreqAxisMinHz + AnnotationText.AnnotationTextOffset, HLThreshold.SevereHLdB + AnnotationText.AnnotationTextOffset); severeHL.TextHorizontalAlignment = HorizontalAlignment.Left; severeHL.Layer = AnnotationLayer.BelowAxes; severeHL.Fill = OxyColor.FromRgb(SevereHLFill.Red, SevereHLFill.Green, SevereHLFill.Blue); severeHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMinHz, HLThreshold.ProfoundHLdB)); severeHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMaxHz, HLThreshold.ProfoundHLdB)); severeHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMaxHz, HLThreshold.SevereHLdB)); severeHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMinHz, HLThreshold.SevereHLdB)); PolygonAnnotation moderateHL = new PolygonAnnotation(); moderateHL.Text = AnnotationText.ModerateHL; moderateHL.TextPosition = new DataPoint(AudiogramAxes.FreqAxisMinHz + AnnotationText.AnnotationTextOffset, HLThreshold.ModerateHLdB + AnnotationText.AnnotationTextOffset); moderateHL.TextHorizontalAlignment = HorizontalAlignment.Left; moderateHL.Layer = AnnotationLayer.BelowAxes; moderateHL.Fill = OxyColor.FromRgb(ModerateHLFill.Red, ModerateHLFill.Green, ModerateHLFill.Blue); moderateHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMinHz, HLThreshold.SevereHLdB)); moderateHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMaxHz, HLThreshold.SevereHLdB)); moderateHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMaxHz, HLThreshold.ModerateHLdB)); moderateHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMinHz, HLThreshold.ModerateHLdB)); PolygonAnnotation mildHL = new PolygonAnnotation(); mildHL.Text = AnnotationText.MildHL; mildHL.TextPosition = new DataPoint(AudiogramAxes.FreqAxisMinHz + AnnotationText.AnnotationTextOffset, HLThreshold.MildHLdB + AnnotationText.AnnotationTextOffset); mildHL.TextHorizontalAlignment = HorizontalAlignment.Left; mildHL.Layer = AnnotationLayer.BelowAxes; mildHL.Fill = OxyColor.FromRgb(MildHLFill.Red, MildHLFill.Green, MildHLFill.Blue); mildHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMinHz, HLThreshold.ModerateHLdB)); mildHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMaxHz, HLThreshold.ModerateHLdB)); mildHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMaxHz, HLThreshold.MildHLdB)); mildHL.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMinHz, HLThreshold.MildHLdB)); PolygonAnnotation normal = new PolygonAnnotation(); normal.Text = AnnotationText.NormalHL; normal.TextPosition = new DataPoint(AudiogramAxes.FreqAxisMinHz + AnnotationText.AnnotationTextOffset, HLThreshold.NormalHLdB + AnnotationText.AnnotationTextOffset); normal.TextHorizontalAlignment = HorizontalAlignment.Left; normal.Layer = AnnotationLayer.BelowAxes; normal.Fill = OxyColor.FromRgb(NormalFill.Red, NormalFill.Green, NormalFill.Blue); normal.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMinHz, HLThreshold.MildHLdB)); normal.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMaxHz, HLThreshold.MildHLdB)); normal.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMaxHz, HLThreshold.NormalHLdB)); normal.Points.Add(new DataPoint(AudiogramAxes.FreqAxisMinHz, HLThreshold.NormalHLdB)); PlotModel.Annotations.Add(normal); PlotModel.Annotations.Add(mildHL); PlotModel.Annotations.Add(moderateHL); PlotModel.Annotations.Add(severeHL); PlotModel.Annotations.Add(profoundHL); }
public BuySellSeries() { mainSeries = new LineSeries { Title = "Operations", Color = OxyColor.FromRgb(55, 55, 55), }; openPositionsCirclesSeries = new ScatterSeries { Title = "Open position (arrow down - short postion)", MarkerType = MarkerType.Circle, MarkerSize = 8, MarkerFill = OxyColor.FromRgb(40, 40, 40), }; closePositionsGreenCirclesSeries = new ScatterSeries { Title = "Profitable trade", MarkerType = MarkerType.Circle, MarkerSize = 8, MarkerFill = OxyColor.FromRgb(121, 229, 112), MarkerStroke = OxyColor.FromRgb(40, 40, 40), MarkerStrokeThickness = 2, }; closePositionsRedCirclesSeries = new ScatterSeries { Title = "Unprofitable trade", MarkerType = MarkerType.Circle, MarkerSize = 8, MarkerFill = OxyColor.FromRgb(214, 107, 107), MarkerStroke = OxyColor.FromRgb(40, 40, 40), MarkerStrokeThickness = 2, }; openPositionsUpShapesSeries = new ScatterSeries { MarkerType = MarkerType.Custom, MarkerOutline = ShapesPaths.arrowUp, MarkerSize = 16, MarkerFill = OxyColor.FromRgb(255, 255, 255), }; openPositionsDownShapesSeries = new ScatterSeries { MarkerType = MarkerType.Custom, MarkerOutline = ShapesPaths.arrowDown, MarkerSize = 16, MarkerFill = OxyColor.FromRgb(255, 255, 255), }; closePositionsPlusShapesSeries = new ScatterSeries { MarkerType = MarkerType.Custom, MarkerOutline = ShapesPaths.plus, MarkerSize = 16, MarkerFill = OxyColor.FromRgb(55, 55, 55), }; closePositionsMinusShapesSeries = new ScatterSeries { MarkerType = MarkerType.Custom, MarkerOutline = ShapesPaths.minus, MarkerSize = 16, MarkerFill = OxyColor.FromRgb(55, 55, 55), }; scatterSeries = new ScatterSeries[] { closePositionsGreenCirclesSeries, closePositionsRedCirclesSeries, closePositionsPlusShapesSeries, closePositionsMinusShapesSeries, openPositionsCirclesSeries, openPositionsUpShapesSeries, openPositionsDownShapesSeries, }; }
private void SetAttributes(OxyColor fill, OxyColor stroke, double thickness) { gctx.SetLineWidth((float)thickness); SetFill(fill); SetStroke(stroke); }
private UIColor ToColor(OxyColor c) { return(UIColor.FromRGBA(c.R, c.G, c.B, c.A)); }
/// <summary> /// Inicializa uma nova instancia de <see cref="T:SchedulerSharp.Models.PlotableProcess"/> . /// </summary> /// <param name="process">Processo base.</param> /// <param name="execTime">Tempo em que foi executado.</param> public PlotableProcess(EscalonableProcess process, int execTime) : base(process.name, process.arrivalTime, process.runtime) { ExecTime = execTime; attColor = WaitingColor; }
/// <summary> /// Draws a collection of polygons, where all polygons have the same stroke and fill. /// This performs better than calling DrawPolygon multiple times. /// </summary> /// <param name="polygons">The polygons.</param> /// <param name="fill">The fill color. If set to <c>OxyColors.Undefined</c>, the polygons will not be filled.</param> /// <param name="stroke">The stroke color. If set to <c>OxyColors.Undefined</c>, the polygons will not be stroked.</param> /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param> /// <param name="dashArray">The dash array (in device independent units, 1/96 inch).</param> /// <param name="lineJoin">The line join type.</param> /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param> public void DrawPolygons( IList <IList <ScreenPoint> > polygons, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { var usg = this.UseStreamGeometry; Path path = null; StreamGeometry streamGeometry = null; StreamGeometryContext sgc = null; PathGeometry pathGeometry = null; int count = 0; foreach (var polygon in polygons) { if (path == null) { path = this.CreateAndAdd <Path>(); this.SetStroke(path, stroke, thickness, lineJoin, dashArray, 0, aliased); if (!fill.IsUndefined()) { path.Fill = this.GetCachedBrush(fill); } if (usg) { streamGeometry = new StreamGeometry { FillRule = FillRule.Nonzero }; sgc = streamGeometry.Open(); } else { pathGeometry = new PathGeometry { FillRule = FillRule.Nonzero }; } } PathFigure figure = null; bool first = true; foreach (var p in polygon) { var point = aliased ? this.ToPixelAlignedPoint(p) : this.ToPoint(p); if (first) { if (usg) { sgc.BeginFigure(point, !fill.IsUndefined(), true); } else { figure = new PathFigure { StartPoint = point, IsFilled = !fill.IsUndefined(), IsClosed = true }; pathGeometry.Figures.Add(figure); } first = false; } else { if (usg) { sgc.LineTo(point, !stroke.IsUndefined(), true); } else { figure.Segments.Add(new LineSegment(point, !stroke.IsUndefined()) { IsSmoothJoin = true }); } } } count++; // Must limit the number of figures, otherwise drawing errors... if (count > MaxFiguresPerGeometry) { if (usg) { sgc.Close(); path.Data = streamGeometry; } else { path.Data = pathGeometry; } path = null; count = 0; } } if (path != null) { if (usg) { sgc.Close(); path.Data = streamGeometry; } else { path.Data = pathGeometry; } } }
public static PlotModel ScatterSeries10225() { var plotModel1 = new PlotModel { Title = "Issue 10225", PlotMargins = new OxyThickness(50, 5, 5, 50), Padding = new OxyThickness(0), PlotAreaBorderThickness = new OxyThickness(1, 1, 1, 1), PlotAreaBorderColor = OxyColors.Black, TextColor = OxyColors.Black, LegendOrientation = LegendOrientation.Horizontal, LegendPosition = LegendPosition.TopRight, LegendMargin = 0 }; plotModel1.Axes.Add(new LinearAxis { IsAxisVisible = true, Title = "X", Position = AxisPosition.Bottom, TickStyle = TickStyle.Outside, TicklineColor = OxyColors.Black, Minimum = 0, MaximumPadding = 0.05 }); plotModel1.Axes.Add(new LogarithmicAxis { MinimumPadding = 0.05, MaximumPadding = 0.1, Title = "Y", Position = AxisPosition.Left, TickStyle = TickStyle.Outside, TicklineColor = OxyColors.Black, MajorGridlineColor = OxyColors.Black, MajorGridlineStyle = LineStyle.Solid }); var referenceCurve = new LineSeries { Title = "Reference", Smooth = true, Color = OxyColor.FromArgb(255, 89, 128, 168) }; var upperBoundary = new LineSeries { LineStyle = LineStyle.Dot, Color = OxyColors.LightGray, Smooth = true, Title = string.Empty }; var lowerBoundary = new LineSeries { LineStyle = LineStyle.Dot, Color = OxyColors.LightGray, Smooth = true, Title = "+/- 15 %" }; // Series that holds and formats points inside of the boundary var inBoundaryResultLine = new ScatterSeries { Title = "actual", MarkerFill = OxyColors.Black, MarkerSize = 4, MarkerStroke = OxyColors.White, MarkerType = MarkerType.Circle }; // Series that holds and formats points outside of the boundary var outBoundaryResultLine = new ScatterSeries { Title = "not permissible deviation", MarkerFill = OxyColors.Red, MarkerSize = 4, MarkerStroke = OxyColors.White, MarkerType = MarkerType.Circle }; // Just some random data to fill the series: var referenceValues = new[] { double.NaN, 0.985567558024852, 0.731704530257957, 0.591109071735532, 0.503627816316065, 0.444980686815776, 0.403576666032678, 0.373234299823915, 0.350375591667333, 0.332795027566349, 0.319063666439909, 0.30821748743148, 0.299583943726489, 0.292680371378706, 0.287151885046283, 0.282732008216725, 0.279216923371711, 0.276557880999918 }; var actualValues = new[] { double.NaN, 0.33378346040897, 1.09868427497967, 0.970771068054048, 0.739778217457323, 0.582112938330166, 0.456962500853806, 0.37488740614826, 0.330272509496142, 0.334461549522006, 0.30989175806678, 0.286944862053553, 0.255895385950234, 0.231850970296068, 0.217579897050944, 0.217113227224437, 0.164759946945322, 0.0459134254747994 }; for (var index = 0; index <= 17; index++) { var referenceValue = referenceValues[index]; var lowerBound = referenceValue - (referenceValue * 0.15); var upperBound = referenceValue + (referenceValue * 0.15); referenceCurve.Points.Add(new DataPoint(index, referenceValue)); lowerBoundary.Points.Add(new DataPoint(index, lowerBound)); upperBoundary.Points.Add(new DataPoint(index, upperBound)); var actualValue = actualValues[index]; if (actualValue > lowerBound && actualValue < upperBound) { inBoundaryResultLine.Points.Add(new ScatterPoint(index, actualValue)); } else { outBoundaryResultLine.Points.Add(new ScatterPoint(index, actualValue)); } } plotModel1.Series.Add(referenceCurve); plotModel1.Series.Add(lowerBoundary); plotModel1.Series.Add(upperBoundary); plotModel1.Series.Add(outBoundaryResultLine); plotModel1.Series.Add(inBoundaryResultLine); return(plotModel1); }
/// <summary> /// Draws text. /// </summary> /// <param name="p">The position.</param> /// <param name="text">The text.</param> /// <param name="fill">The text color.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontSize">Size of the font (in device independent units, 1/96 inch).</param> /// <param name="fontWeight">The font weight.</param> /// <param name="rotate">The rotation angle.</param> /// <param name="halign">The horizontal alignment.</param> /// <param name="valign">The vertical alignment.</param> /// <param name="maxSize">The maximum size of the text (in device independent units, 1/96 inch).</param> public void DrawText( ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize, double fontWeight, double rotate, HorizontalAlignment halign, VerticalAlignment valign, OxySize?maxSize) { var tb = this.CreateAndAdd <TextBlock>(); tb.Text = text; tb.Foreground = this.GetCachedBrush(fill); if (fontFamily != null) { tb.FontFamily = this.GetCachedFontFamily(fontFamily); } if (fontSize > 0) { tb.FontSize = fontSize; } if (fontWeight > 0) { tb.FontWeight = GetFontWeight(fontWeight); } TextOptions.SetTextFormattingMode(tb, this.TextFormattingMode); double dx = 0; double dy = 0; if (maxSize != null || halign != HorizontalAlignment.Left || valign != VerticalAlignment.Top) { tb.Measure(new Size(1000, 1000)); var size = tb.DesiredSize; if (maxSize != null) { if (size.Width > maxSize.Value.Width + 1e-3) { size.Width = Math.Max(maxSize.Value.Width, 0); } if (size.Height > maxSize.Value.Height + 1e-3) { size.Height = Math.Max(maxSize.Value.Height, 0); } tb.Width = size.Width; tb.Height = size.Height; } if (halign == HorizontalAlignment.Center) { dx = -size.Width / 2; } if (halign == HorizontalAlignment.Right) { dx = -size.Width; } if (valign == VerticalAlignment.Middle) { dy = -size.Height / 2; } if (valign == VerticalAlignment.Bottom) { dy = -size.Height; } } var transform = new TransformGroup(); transform.Children.Add(new TranslateTransform(dx, dy)); if (Math.Abs(rotate) > double.Epsilon) { transform.Children.Add(new RotateTransform(rotate)); } transform.Children.Add(new TranslateTransform(p.X, p.Y)); tb.RenderTransform = transform; if (tb.Clip != null) { tb.Clip.Transform = tb.RenderTransform.Inverse as Transform; } tb.SetValue(RenderOptions.ClearTypeHintProperty, ClearTypeHint.Enabled); }
public LinearBarViewModel() { 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 = "Linear Bar Series Animation Demo"; var series = new LinearBarSeries { Title = "P & L", ItemsSource = pnls, DataFieldX = "Time", DataFieldY = "Value", FillColor = OxyColor.Parse("#454CAF50"), StrokeColor = OxyColor.Parse("#4CAF50"), StrokeThickness = 1, BarWidth = 5 }; 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); }
public async Task <PlotModel> Generate() { var responses = metrics.ToDictionary(x => x, x => cloudWatch.GetMetricStatisticsAsync(new GetMetricStatisticsRequest { Namespace = x.Namespace, MetricName = x.Name, Period = (int)x.Period.TotalSeconds, StartTime = metricStartTime, Dimensions = x.Dimensions, EndTime = metricEndTime, Statistics = x.StatisticType.GetRequestStatistics(), ExtendedStatistics = x.StatisticType.GetRequestExtendedStatistics() })); await Task.WhenAll(responses.Select(x => x.Value)); var model = new PlotModel { Title = title, Subtitle = subtitle, Padding = new OxyThickness(20d), LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.BottomLeft, LegendOrientation = LegendOrientation.Horizontal, DefaultColors = GraphConstants.Colors, PlotAreaBorderThickness = new OxyThickness(0d, 0d, 0d, 1d), PlotAreaBorderColor = OxyColor.FromRgb(204, 204, 204) }; var dataRanges = new List <Tuple <StandardUnit, double> >(); foreach (var response in responses.Where(x => x.Value.Result.Datapoints.Any())) { IEnumerable <Datapoint> orderedData = response.Value.Result.Datapoints.OrderByDescending(i => i.StatisticTypeValue(response.Key.StatisticType)); Datapoint highestDataPoint = orderedData.First(); Datapoint lowestDataPoint = orderedData.Last(); dataRanges.Add(Tuple.Create(highestDataPoint.Unit, highestDataPoint.StatisticTypeValue(response.Key.StatisticType))); dataRanges.Add(Tuple.Create(lowestDataPoint.Unit, lowestDataPoint.StatisticTypeValue(response.Key.StatisticType))); Series series = seriesBuilder.BuildSeries(response.Key, response.Value.Result.Datapoints); model.Series.Add(series); } var aAxis = new DateTimeAxis { Position = AxisPosition.Bottom, TicklineColor = OxyColor.FromRgb(238, 238, 238), Minimum = DateTimeAxis.ToDouble(metricStartTime), Maximum = DateTimeAxis.ToDouble(metricEndTime) }; if (metrics.All(x => x.GraphType != GraphType.Total)) { model.Axes.Add(InferYAxis(dataRanges)); model.Axes.Add(aAxis); } return(model); }
void IRenderContext.DrawText(ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize, double fontWeight, double rotation, OxyPlot.HorizontalAlignment horizontalAlignment, OxyPlot.VerticalAlignment verticalAlignment, OxySize?maxSize) { throw new NotImplementedException(); }
public static void Plot3Serie(string xTitle, string yTitle, OxyColor color1, OxyColor color2, OxyColor color3, string label1, string label2, string label3, PlotModel plotModel, int[,] histogramValues) { plotModel.Series.Clear(); plotModel.Axes.Clear(); plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = xTitle }); plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = yTitle }); var l = histogramValues.Length / 3; var plotR_Series = new LineSeries { Title = label1, StrokeThickness = 2, MarkerSize = 2, Color = color1 }; for (int i = 0; i < l; i++) { int y_val = histogramValues[i, 0]; plotR_Series.Points.Add(new DataPoint(i, y_val)); } plotModel.Series.Add(plotR_Series); var plotG_Series = new LineSeries { Title = label2, StrokeThickness = 2, MarkerSize = 2, Color = color2 }; for (int i = 0; i < l; i++) { int y_val = histogramValues[i, 1]; plotG_Series.Points.Add(new DataPoint(i, y_val)); } plotModel.Series.Add(plotG_Series); var plotB_Series = new LineSeries { Title = label3, StrokeThickness = 2, MarkerSize = 2, Color = color3 }; for (int i = 0; i < l; i++) { int y_val = histogramValues[i, 2]; plotB_Series.Points.Add(new DataPoint(i, y_val)); } plotModel.Series.Add(plotB_Series); plotModel.InvalidatePlot(true); }
void IRenderContext.DrawPolygons(IList <IList <ScreenPoint> > polygons, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { throw new NotImplementedException(); }
/// <summary> /// Draws the rectangle. /// </summary> /// <param name="rect">The rectangle.</param> /// <param name="fill">The fill color.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The stroke thickness.</param> public override void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness) { this.WriteRectangle(rect.Left, rect.Top, rect.Width, rect.Height, this.CreateStyle(fill, stroke, thickness)); }
private void UpdatePlot() { var pm = new PlotModel { Title = this.year.ToString(), Subtitle = "data from gapminder.org", LegendPosition = LegendPosition.RightBottom }; var ss = new ScatterSeries { MarkerType = MarkerType.Circle, MarkerFill = OxyColors.Transparent, MarkerStroke = OxyColors.Blue, MarkerStrokeThickness = 1 }; var piX = typeof(Statistics).GetProperty("GdpPerCapitaPpp"); var piY = typeof(Statistics).GetProperty("LifeExpectancyAtBirth"); var piSize = typeof(Statistics).GetProperty("Population"); var piColor = typeof(Statistics).GetProperty("GeographicRegion"); foreach (var kvp in Countries) { Country country = kvp.Value; double x = country.FindValue(year, piX); double y = country.FindValue(year, piY); double size = country.FindValue(year, piSize); if (double.IsNaN(x) || double.IsNaN(y)) { continue; } ss.Points.Add(new ScatterPoint(x, y, double.NaN, double.NaN, country.Name)); //double radius = 4; //if (!double.IsNaN(size)) // radius = Math.Sqrt(size)*0.1; //if (radius < 4) radius = 4; //if (radius > 40) radius = 40; //ss.MarkerSizes.Add(radius); // Debug.WriteLine(countryName+": "+stats.Population); } pm.Series.Add(ss); if (SelectedCountry != null) { var ls = new LineSeries { Title = SelectedCountry.Name }; ls.LineJoin = OxyPenLineJoin.Bevel; foreach (var p in SelectedCountry.Statistics) { if (double.IsNaN(p.GdpPerCapitaPpp) || double.IsNaN(p.LifeExpectancyAtBirth)) { continue; } ls.Points.Add(new DataPoint(p.GdpPerCapitaPpp, p.LifeExpectancyAtBirth)); } pm.Series.Add(ls); var ss2 = new ScatterSeries(); double x = SelectedCountry.FindValue(year, piX); double y = SelectedCountry.FindValue(year, piY); ss2.Points.Add(new ScatterPoint(x, y, 10)); ss2.MarkerFill = OxyColor.FromAColor(120, OxyColors.Red); ss2.MarkerType = MarkerType.Circle; pm.Series.Add(ss2); } pm.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 19, Maximum = 87, Title = "Life expectancy (years)" }); pm.Axes.Add(new LogarithmicAxis { Position = AxisPosition.Bottom, Title = "Income per person (GDP/capita, PPP$ inflation-adjusted)", Minimum = 200, Maximum = 90000 }); PlotModel = pm; }
/// <summary> /// Draws the text. /// </summary> /// <param name="p">The p.</param> /// <param name="text">The text.</param> /// <param name="c">The c.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="fontWeight">The font weight.</param> /// <param name="rotate">The rotate.</param> /// <param name="halign">The horizontal alignment.</param> /// <param name="valign">The vertical alignment.</param> /// <param name="maxSize">Size of the max.</param> public override void DrawText( ScreenPoint p, string text, OxyColor c, string fontFamily, double fontSize, double fontWeight, double rotate, HorizontalAlignment halign, VerticalAlignment valign, OxySize?maxSize) { if (string.IsNullOrEmpty(text)) { return; } var lines = Regex.Split(text, "\r\n"); var textSize = this.MeasureText(text, fontFamily, fontSize, fontWeight); var lineHeight = textSize.Height / lines.Length; var lineOffset = new ScreenVector(-Math.Sin(rotate / 180.0 * Math.PI) * lineHeight, +Math.Cos(rotate / 180.0 * Math.PI) * lineHeight); if (this.UseVerticalTextAlignmentWorkaround) { // offset the position, and set the valign to neutral value of `Bottom` double offsetRatio = valign == VerticalAlignment.Bottom ? (1.0 - lines.Length) : valign == VerticalAlignment.Top ? 1.0 : (1.0 - (lines.Length / 2.0)); valign = VerticalAlignment.Bottom; p += lineOffset * offsetRatio; foreach (var line in lines) { var size = this.MeasureText(line, fontFamily, fontSize, fontWeight); this.WriteText(p, line, c, fontFamily, fontSize, fontWeight, rotate, halign, valign); p += lineOffset; } } else { if (valign == VerticalAlignment.Bottom) { for (var i = lines.Length - 1; i >= 0; i--) { var line = lines[i]; _ = this.MeasureText(line, fontFamily, fontSize, fontWeight); this.WriteText(p, line, c, fontFamily, fontSize, fontWeight, rotate, halign, valign); p -= lineOffset; } } else { foreach (var line in lines) { var size = this.MeasureText(line, fontFamily, fontSize, fontWeight); this.WriteText(p, line, c, fontFamily, fontSize, fontWeight, rotate, halign, valign); p += lineOffset; } } } }
public void addLine(MainWindow window, double x1, double y1, double x2, double y2, OxyColor color) { LineSeries series1 = new LineSeries { Color = color }; series1.Points.Add(new DataPoint(x1, y1)); series1.Points.Add(new DataPoint(x2, y2)); series1.TrackerKey = "InvisibleTracker"; window.plotModel.Series.Add(series1); }
/// <summary> /// Writes text. /// </summary> /// <param name="position">The position.</param> /// <param name="text">The text.</param> /// <param name="fill">The text color.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontSize">The font size (in user units).</param> /// <param name="fontWeight">The font weight.</param> /// <param name="rotate">The rotation angle.</param> /// <param name="halign">The horizontal alignment.</param> /// <param name="valign">The vertical alignment.</param> public void WriteText( ScreenPoint position, string text, OxyColor fill, string fontFamily = null, double fontSize = 10, double fontWeight = FontWeights.Normal, double rotate = 0, HorizontalAlignment halign = HorizontalAlignment.Left, VerticalAlignment valign = VerticalAlignment.Top) { // http://www.w3.org/TR/SVG/text.html this.WriteStartElement("text"); // WriteAttributeString("x", position.X); // WriteAttributeString("y", position.Y); string baselineAlignment = "hanging"; if (valign == VerticalAlignment.Middle) { baselineAlignment = "middle"; } if (valign == VerticalAlignment.Bottom) { baselineAlignment = "baseline"; } this.WriteAttributeString("dominant-baseline", baselineAlignment); string textAnchor = "start"; if (halign == HorizontalAlignment.Center) { textAnchor = "middle"; } if (halign == HorizontalAlignment.Right) { textAnchor = "end"; } this.WriteAttributeString("text-anchor", textAnchor); string fmt = "translate({0:" + this.NumberFormat + "},{1:" + this.NumberFormat + "})"; string transform = string.Format(CultureInfo.InvariantCulture, fmt, position.X, position.Y); if (Math.Abs(rotate) > 0) { transform += string.Format(CultureInfo.InvariantCulture, " rotate({0})", rotate); } this.WriteAttributeString("transform", transform); if (fontFamily != null) { this.WriteAttributeString("font-family", fontFamily); } if (fontSize > 0) { this.WriteAttributeString("font-size", fontSize); } if (fontWeight > 0) { this.WriteAttributeString("font-weight", fontWeight); } if (fill.IsInvisible()) { this.WriteAttributeString("fill", "none"); } else { this.WriteAttributeString("fill", this.ColorToString(fill)); if (fill.A != 0xFF) { this.WriteAttributeString("fill-opacity", fill.A / 255.0); } } this.WriteClipPathAttribute(); // WriteAttributeString("style", style); this.WriteString(text); this.WriteEndElement(); }
public override void DrawText(ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize, double fontWeight, double rotate, HorizontalAlignment halign, VerticalAlignment valign, OxySize?maxSize) { if (string.IsNullOrEmpty(text)) { return; } fontFamily = GetDefaultFont(fontFamily); if (fontWeight >= 700) { //fs = FontStyle.Bold; } if (maxSize != null) { // if (size.Width > maxSize.Value.Width) // { // size.Width = (float)maxSize.Value.Width; // } // // if (size.Height > maxSize.Value.Height) // { // size.Height = (float)maxSize.Value.Height; // } } gctx.SaveState(); gctx.SelectFont(fontFamily, (float)fontSize, CGTextEncoding.MacRoman); ToColor(fill).SetFill(); gctx.SetTextDrawingMode(CGTextDrawingMode.Fill); var tfont = UIFont.FromName(fontFamily, (float)fontSize); NSString nsstr = new NSString(text); SizeF sz = nsstr.StringSize(tfont); float y = (float)(p.Y); float x = (float)(p.X); switch (halign) { case HorizontalAlignment.Left: x = (float)(p.X); break; case HorizontalAlignment.Right: x = (float)(p.X - sz.Width); break; case HorizontalAlignment.Center: x = (float)(p.X - (sz.Width / 2)); break; } switch (valign) { case VerticalAlignment.Bottom: y -= (float)sz.Height; break; case VerticalAlignment.Top: //y += (float)fontSize; break; case VerticalAlignment.Middle: y -= (float)(sz.Height / 2); break; } RectangleF rect = new RectangleF(x, y, sz.Width, sz.Height); nsstr.DrawString(rect, tfont); gctx.RestoreState(); //Console.WriteLine("X:{0:###} Y:{1:###} HA:{2}:{3:###} VA:{4}:{5:###} TW:{6:###} - {7}", p.X, p.Y, halign, x, valign, y, textSize.Width, text); }
public GraphDataCat(TimeSpan startTime, string title, ChartConfig chartConfig, CatSelection catSelection) { _startTime = startTime; this.Title = title; _clipMax = chartConfig.ClipMax; X = new LineSeries() { Title = "X", LineStyle = LineStyle.Solid, Color = OxyColor.FromRgb(0xff, 0, 0), }; Y = new LineSeries() { Title = "Y", LineStyle = LineStyle.Solid, Color = OxyColor.FromRgb(0, 0xff, 0), }; Z = new LineSeries() { Title = "Z", LineStyle = LineStyle.Solid, Color = OxyColor.FromRgb(0, 0, 0xff), }; switch (catSelection) { case CatSelection.GroupByLinearAcceleration: Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = chartConfig.LinearAccelerationMin, Maximum = chartConfig.LinearAccelerationMax, }); break; case CatSelection.GroupByAngularVelocity: Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = chartConfig.AngularVelocityMin, Maximum = chartConfig.AngularVelocityMax, }); break; case CatSelection.GroupByAngle: Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = chartConfig.AngleMin, Maximum = chartConfig.AngleMax, }); break; } this.IsLegendVisible = true; this.Series.Add(X); this.Series.Add(Y); this.Series.Add(Z); //this.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)")); }