Neuerstellung

- Quelle: https://github.com/oxyplot/oxyplot
This commit is contained in:
2023-09-02 09:24:59 +02:00
commit 9520c1fa4a
810 changed files with 117869 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
[Examples("Annotations"), Tags("Annotations")]
public static class AnnotationExamples
{
[Example("Tool tips")]
public static PlotModel ToolTips()
{
var model = new PlotModel { Title = "Tool tips" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
model.Annotations.Add(new LineAnnotation { Slope = 0.1, Intercept = 1, Text = "LineAnnotation", ToolTip = "This is a tool tip for the LineAnnotation" });
model.Annotations.Add(new RectangleAnnotation { MinimumX = 20, MaximumX = 70, MinimumY = 10, MaximumY = 40, TextRotation = 10, Text = "RectangleAnnotation", ToolTip = "This is a tooltip for the RectangleAnnotation", Fill = OxyColor.FromAColor(99, OxyColors.Blue), Stroke = OxyColors.Black, StrokeThickness = 2 });
model.Annotations.Add(new EllipseAnnotation { X = 20, Y = 60, Width = 20, Height = 15, Text = "EllipseAnnotation", ToolTip = "This is a tool tip for the EllipseAnnotation", TextRotation = 10, Fill = OxyColor.FromAColor(99, OxyColors.Green), Stroke = OxyColors.Black, StrokeThickness = 2 });
model.Annotations.Add(new PointAnnotation { X = 50, Y = 50, Text = "P1", ToolTip = "This is a tool tip for the PointAnnotation" });
model.Annotations.Add(new ArrowAnnotation { StartPoint = new DataPoint(8, 4), EndPoint = new DataPoint(0, 0), Color = OxyColors.Green, Text = "ArrowAnnotation", ToolTip = "This is a tool tip for the ArrowAnnotation" });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(60, 60), Text = "TextAnnotation", ToolTip = "This is a tool tip for the TextAnnotation" });
return model;
}
}
}

View File

@@ -0,0 +1,97 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ArrowAnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using System;
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
[Examples("ArrowAnnotation"), Tags("Annotations")]
public static class ArrowAnnotationExamples
{
[Example("ArrowAnnotation")]
public static PlotModel ArrowAnnotation()
{
var model = new PlotModel { Title = "ArrowAnnotations" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -40, Maximum = 60 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 });
model.Annotations.Add(
new ArrowAnnotation
{
StartPoint = new DataPoint(8, 4),
EndPoint = new DataPoint(0, 0),
Color = OxyColors.Green,
Text = "StartPoint and EndPoint"
});
model.Annotations.Add(
new ArrowAnnotation
{
ArrowDirection = new ScreenVector(30, 70),
EndPoint = new DataPoint(40, -3),
Color = OxyColors.Blue,
Text = "ArrowDirection and EndPoint"
});
model.Annotations.Add(
new ArrowAnnotation
{
ArrowDirection = new ScreenVector(30, -70),
EndPoint = new DataPoint(10, -3),
HeadLength = 14,
HeadWidth = 6,
Veeness = 4,
Color = OxyColors.Red,
Text = "HeadLength = 20, HeadWidth = 10, Veeness = 4"
});
return model;
}
[Example("Rotations")]
public static PlotModel Rotations()
{
var model = new PlotModel { Title = "ArrowAnnotation Rotations" };
model.Axes.Add(
new LinearAxis
{
Position = AxisPosition.Bottom,
Minimum = -5,
Maximum = 45,
MajorGridlineStyle = LineStyle.Solid
});
model.Axes.Add(
new LinearAxis
{
Position = AxisPosition.Left,
StartPosition = 1,
EndPosition = 0,
Minimum = -1,
Maximum = 8,
MajorGridlineStyle = LineStyle.Solid
});
for (var i = 0; i < 360; i += 5)
{
var rad = i / 360d * Math.PI * 2;
model.Annotations.Add(
new ArrowAnnotation
{
EndPoint = new DataPoint(i % 45, i / 45),
Text = $"{i}°",
ArrowDirection = new ScreenVector(Math.Cos(rad), Math.Sin(rad)) * 25,
HeadLength = 5
});
}
return model;
}
}
}

View File

@@ -0,0 +1,30 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="EllipseAnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
[Examples("EllipseAnnotation"), Tags("Annotations")]
public static class EllipseAnnotationExamples
{
[Example("EllipseAnnotation")]
public static PlotModel EllipseAnnotation()
{
var model = new PlotModel { Title = "EllipseAnnotation" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
model.Annotations.Add(new EllipseAnnotation { X = 20, Y = 60, Width = 20, Height = 15, Text = "EllipseAnnotation", TextRotation = 10, Fill = OxyColor.FromAColor(99, OxyColors.Green), Stroke = OxyColors.Black, StrokeThickness = 2 });
model.Annotations.Add(new EllipseAnnotation { X = 20, Y = 20, Width = 20, Height = 20, Fill = OxyColor.FromAColor(99, OxyColors.Green), Stroke = OxyColors.Black, StrokeThickness = 2 });
model.Annotations.Add(new EllipseAnnotation { X = 30, Y = 20, Width = 20, Height = 20, Fill = OxyColor.FromAColor(99, OxyColors.Red), Stroke = OxyColors.Black, StrokeThickness = 2 });
model.Annotations.Add(new EllipseAnnotation { X = 25, Y = 30, Width = 20, Height = 20, Fill = OxyColor.FromAColor(99, OxyColors.Blue), Stroke = OxyColors.Black, StrokeThickness = 2 });
return model;
}
}
}

View File

@@ -0,0 +1,29 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FunctionAnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using System;
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
[Examples("FunctionAnnotation"), Tags("Annotations")]
public static class FunctionAnnotationExamples
{
[Example("FunctionAnnotation")]
public static PlotModel FunctionAnnotation()
{
var model = new PlotModel { Title = "FunctionAnnotation" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 });
model.Annotations.Add(new FunctionAnnotation { Equation = Math.Sin, StrokeThickness = 2, Color = OxyColor.FromAColor(120, OxyColors.Blue), Text = "f(x)=sin(x)" });
model.Annotations.Add(new FunctionAnnotation { Equation = y => y * y, StrokeThickness = 2, Color = OxyColor.FromAColor(120, OxyColors.Red), Type = FunctionAnnotationType.EquationY, Text = "f(y)=y^2" });
return model;
}
}
}

View File

@@ -0,0 +1,275 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ImageAnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using System;
using System.Reflection;
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
using OxyPlot.Series;
[Examples("ImageAnnotation"), Tags("Annotations")]
public static class ImageAnnotationExamples
{
[Example("ImageAnnotation")]
public static PlotModel ImageAnnotation()
{
var model = new PlotModel { Title = "ImageAnnotation", PlotMargins = new OxyThickness(60, 4, 4, 60) };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
OxyImage image;
var assembly = typeof(ImageAnnotationExamples).GetTypeInfo().Assembly;
using (var stream = assembly.GetManifestResourceStream("ExampleLibrary.Resources.OxyPlot.png"))
{
image = new OxyImage(stream);
}
// Centered in plot area, filling width
model.Annotations.Add(new ImageAnnotation
{
ImageSource = image,
Opacity = 0.2,
Interpolate = false,
X = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea),
Y = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea),
Width = new PlotLength(1, PlotLengthUnit.RelativeToPlotArea),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Middle
});
// Relative to plot area, inside top/right corner, 120pt wide
model.Annotations.Add(new ImageAnnotation
{
ImageSource = image,
X = new PlotLength(1, PlotLengthUnit.RelativeToPlotArea),
Y = new PlotLength(0, PlotLengthUnit.RelativeToPlotArea),
Width = new PlotLength(120, PlotLengthUnit.ScreenUnits),
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top
});
// Relative to plot area, above top/left corner, 20pt high
model.Annotations.Add(new ImageAnnotation
{
ImageSource = image,
X = new PlotLength(0, PlotLengthUnit.RelativeToPlotArea),
Y = new PlotLength(0, PlotLengthUnit.RelativeToPlotArea),
OffsetY = new PlotLength(-5, PlotLengthUnit.ScreenUnits),
Height = new PlotLength(20, PlotLengthUnit.ScreenUnits),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Bottom
});
// At the point (50,50), 200pt wide
model.Annotations.Add(new ImageAnnotation
{
ImageSource = image,
X = new PlotLength(50, PlotLengthUnit.Data),
Y = new PlotLength(50, PlotLengthUnit.Data),
Width = new PlotLength(200, PlotLengthUnit.ScreenUnits),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top
});
// At the point (50,20), 50 x units wide
model.Annotations.Add(new ImageAnnotation
{
ImageSource = image,
X = new PlotLength(50, PlotLengthUnit.Data),
Y = new PlotLength(20, PlotLengthUnit.Data),
Width = new PlotLength(50, PlotLengthUnit.Data),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top
});
// Relative to the viewport, centered at the bottom, with offset (could also use bottom vertical alignment)
model.Annotations.Add(new ImageAnnotation
{
ImageSource = image,
X = new PlotLength(0.5, PlotLengthUnit.RelativeToViewport),
Y = new PlotLength(1, PlotLengthUnit.RelativeToViewport),
OffsetY = new PlotLength(-35, PlotLengthUnit.ScreenUnits),
Height = new PlotLength(30, PlotLengthUnit.ScreenUnits),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top
});
// Changing opacity
for (int y = 0; y < 10; y++)
{
model.Annotations.Add(
new ImageAnnotation
{
ImageSource = image,
Opacity = (y + 1) / 10.0,
X = new PlotLength(10, PlotLengthUnit.Data),
Y = new PlotLength(y * 2, PlotLengthUnit.Data),
Width = new PlotLength(100, PlotLengthUnit.ScreenUnits),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Bottom
});
}
return model;
}
[Example("ImageAnnotation - gradient backgrounds")]
public static PlotModel ImageAnnotationAsBackgroundGradient()
{
// http://en.wikipedia.org/wiki/Chartjunk
var model = new PlotModel { Title = "Using ImageAnnotations to draw a gradient backgrounds", Subtitle = "But do you really want this? This is called 'chartjunk'!", PlotMargins = new OxyThickness(60, 4, 4, 60) };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
// create a gradient image of height n
int n = 256;
var imageData1 = new OxyColor[1, n];
for (int i = 0; i < n; i++)
{
imageData1[0, i] = OxyColor.Interpolate(OxyColors.Blue, OxyColors.Red, i / (n - 1.0));
}
var image1 = OxyImage.Create(imageData1, ImageFormat.Png); // png is required for silverlight
// or create a gradient image of height 2 (requires bitmap interpolation to be supported)
var imageData2 = new OxyColor[1, 2];
imageData2[0, 0] = OxyColors.Yellow; // top color
imageData2[0, 1] = OxyColors.Gray; // bottom color
var image2 = OxyImage.Create(imageData2, ImageFormat.Png); // png is required for silverlight
// gradient filling the viewport
model.Annotations.Add(new ImageAnnotation
{
ImageSource = image2,
Interpolate = true,
Layer = AnnotationLayer.BelowAxes,
X = new PlotLength(0, PlotLengthUnit.RelativeToViewport),
Y = new PlotLength(0, PlotLengthUnit.RelativeToViewport),
Width = new PlotLength(1, PlotLengthUnit.RelativeToViewport),
Height = new PlotLength(1, PlotLengthUnit.RelativeToViewport),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top
});
// gradient filling the plot area
model.Annotations.Add(new ImageAnnotation
{
ImageSource = image1,
Interpolate = true,
Layer = AnnotationLayer.BelowAxes,
X = new PlotLength(0, PlotLengthUnit.RelativeToPlotArea),
Y = new PlotLength(0, PlotLengthUnit.RelativeToPlotArea),
Width = new PlotLength(1, PlotLengthUnit.RelativeToPlotArea),
Height = new PlotLength(1, PlotLengthUnit.RelativeToPlotArea),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top
});
// verify that a series is rendered above the gradients
model.Series.Add(new FunctionSeries(Math.Sin, 0, 7, 0.01));
return model;
}
[Example("ImageAnnotation - normal axes")]
public static PlotModel ImageAnnotation_NormalAxes()
{
var model = new PlotModel { Title = "ImageAnnotation - normal axes" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
// create an image
var pixels = new OxyColor[2, 2];
pixels[0, 0] = OxyColors.Blue;
pixels[1, 0] = OxyColors.Yellow;
pixels[0, 1] = OxyColors.Green;
pixels[1, 1] = OxyColors.Red;
var image = OxyImage.Create(pixels, ImageFormat.Png);
model.Annotations.Add(
new ImageAnnotation
{
ImageSource = image,
Interpolate = false,
X = new PlotLength(0, PlotLengthUnit.Data),
Y = new PlotLength(0, PlotLengthUnit.Data),
Width = new PlotLength(80, PlotLengthUnit.Data),
Height = new PlotLength(50, PlotLengthUnit.Data),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Bottom
});
return model;
}
[Example("ImageAnnotation - reverse horizontal axis")]
public static PlotModel ImageAnnotation_ReverseHorizontalAxis()
{
var model = new PlotModel { Title = "ImageAnnotation - reverse horizontal axis" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, StartPosition = 1, EndPosition = 0 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
// create an image
var pixels = new OxyColor[2, 2];
pixels[0, 0] = OxyColors.Blue;
pixels[1, 0] = OxyColors.Yellow;
pixels[0, 1] = OxyColors.Green;
pixels[1, 1] = OxyColors.Red;
var image = OxyImage.Create(pixels, ImageFormat.Png);
model.Annotations.Add(
new ImageAnnotation
{
ImageSource = image,
Interpolate = false,
X = new PlotLength(100, PlotLengthUnit.Data),
Y = new PlotLength(0, PlotLengthUnit.Data),
Width = new PlotLength(80, PlotLengthUnit.Data),
Height = new PlotLength(50, PlotLengthUnit.Data),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Bottom
});
return model;
}
[Example("ImageAnnotation - reverse vertical axis")]
public static PlotModel ImageAnnotation_ReverseVerticalAxis()
{
var model = new PlotModel { Title = "ImageAnnotation - reverse vertical axis" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, StartPosition = 1, EndPosition = 0 });
// create an image
var pixels = new OxyColor[2, 2];
pixels[0, 0] = OxyColors.Blue;
pixels[1, 0] = OxyColors.Yellow;
pixels[0, 1] = OxyColors.Green;
pixels[1, 1] = OxyColors.Red;
var image = OxyImage.Create(pixels, ImageFormat.Png);
model.Annotations.Add(
new ImageAnnotation
{
ImageSource = image,
Interpolate = false,
X = new PlotLength(0, PlotLengthUnit.Data),
Y = new PlotLength(100, PlotLengthUnit.Data),
Width = new PlotLength(80, PlotLengthUnit.Data),
Height = new PlotLength(50, PlotLengthUnit.Data),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Bottom
});
return model;
}
}
}

View File

@@ -0,0 +1,188 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LineAnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
[Examples("LineAnnotation"), Tags("Annotations")]
public static class LineAnnotationExamples
{
[Example("LineAnnotation on linear axes")]
public static PlotModel LineAnnotationOnLinearAxes()
{
var model = new PlotModel { Title = "LineAnnotation on linear axes" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 });
model.Annotations.Add(
new LineAnnotation
{
Slope = 0.1,
Intercept = 1,
Text = "First",
BorderBackground = OxyColors.White.ChangeOpacity(0.75),
BorderPadding = new OxyThickness(5)
});
model.Annotations.Add(
new LineAnnotation
{
Slope = 0.3,
Intercept = 2,
MaximumX = 40,
Color = OxyColors.Red,
Text = "Second",
BorderBackground = OxyColors.White.ChangeOpacity(0.75),
BorderPadding = new OxyThickness(5)
});
model.Annotations.Add(
new LineAnnotation
{
Type = LineAnnotationType.Vertical,
X = 4,
MaximumY = 10,
Color = OxyColors.Green,
Text = "Vertical",
BorderBackground = OxyColors.White.ChangeOpacity(0.75),
BorderPadding = new OxyThickness(5)
});
model.Annotations.Add(
new LineAnnotation
{
Type = LineAnnotationType.Horizontal,
Y = 2,
MaximumX = 4,
Color = OxyColors.Gold,
Text = "Horizontal",
BorderBackground = OxyColors.White.ChangeOpacity(0.75),
BorderPadding = new OxyThickness(5)
});
return model;
}
[Example("LineAnnotation on logarithmic axes")]
public static PlotModel LineAnnotationOnLogarithmicAxes()
{
var model = new PlotModel { Title = "LineAnnotation on logarithmic axes" };
model.Axes.Add(new LogarithmicAxis { Position = AxisPosition.Bottom, Minimum = 1, Maximum = 80 });
model.Axes.Add(new LogarithmicAxis { Position = AxisPosition.Left, Minimum = 1, Maximum = 10 });
model.Annotations.Add(new LineAnnotation { Slope = 0.1, Intercept = 1, Text = "First", TextMargin = 40 });
model.Annotations.Add(
new LineAnnotation { Slope = 0.3, Intercept = 2, MaximumX = 40, Color = OxyColors.Red, Text = "Second" });
model.Annotations.Add(
new LineAnnotation
{
Type = LineAnnotationType.Vertical,
X = 4,
MaximumY = 10,
Color = OxyColors.Green,
Text = "Vertical"
});
model.Annotations.Add(
new LineAnnotation
{
Type = LineAnnotationType.Horizontal,
Y = 2,
MaximumX = 4,
Color = OxyColors.Gold,
Text = "Horizontal"
});
return model;
}
[Example("LineAnnotation with text orientation specified")]
public static PlotModel LineAnnotationOnLinearAxesWithTextOrientation()
{
var model = new PlotModel { Title = "LineAnnotations", Subtitle = "with TextOrientation specified" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 });
model.Annotations.Add(
new LineAnnotation
{
Slope = 0.1,
Intercept = 1,
Text = "Horizontal",
TextOrientation = AnnotationTextOrientation.Horizontal,
TextVerticalAlignment = VerticalAlignment.Bottom
});
model.Annotations.Add(
new LineAnnotation
{
Slope = 0.3,
Intercept = 2,
MaximumX = 40,
Color = OxyColors.Red,
Text = "Vertical",
TextOrientation = AnnotationTextOrientation.Vertical
});
model.Annotations.Add(
new LineAnnotation
{
Type = LineAnnotationType.Vertical,
X = 4,
MaximumY = 10,
Color = OxyColors.Green,
Text = "Horizontal (x=4)",
TextPadding = 8,
TextOrientation = AnnotationTextOrientation.Horizontal
});
model.Annotations.Add(
new LineAnnotation
{
Type = LineAnnotationType.Vertical,
X = 45,
MaximumY = 10,
Color = OxyColors.Green,
Text = "Horizontal (x=45)",
TextHorizontalAlignment = HorizontalAlignment.Left,
TextPadding = 8,
TextOrientation = AnnotationTextOrientation.Horizontal
});
model.Annotations.Add(
new LineAnnotation
{
Type = LineAnnotationType.Horizontal,
Y = 2,
MaximumX = 4,
Color = OxyColors.Gold,
Text = "Horizontal",
TextLinePosition = 0.5,
TextOrientation = AnnotationTextOrientation.Horizontal
});
return model;
}
[Example("LineAnnotation - ClipByAxis property")]
public static PlotModel LinearAxesMultipleAxes()
{
var model = new PlotModel { Title = "ClipByAxis property", Subtitle = "This property specifies if the annotation should be clipped by the current axes or by the full plot area." };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80, StartPosition = 0, EndPosition = 0.45, TextColor = OxyColors.Red });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10, StartPosition = 0, EndPosition = 0.45, TextColor = OxyColors.Green });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80, StartPosition = 0.55, EndPosition = 1, TextColor = OxyColors.Blue });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10, StartPosition = 0.55, EndPosition = 1, TextColor = OxyColors.Orange });
model.Annotations.Add(new LineAnnotation { ClipByYAxis = true, Type = LineAnnotationType.Vertical, X = 0, Color = OxyColors.Green, Text = "Vertical, ClipByAxis = true" });
model.Annotations.Add(new LineAnnotation { ClipByYAxis = false, Type = LineAnnotationType.Vertical, X = 20, Color = OxyColors.Green, Text = "Vertical, ClipByAxis = false" });
model.Annotations.Add(new LineAnnotation { ClipByXAxis = true, Type = LineAnnotationType.Horizontal, Y = 2, Color = OxyColors.Gold, Text = "Horizontal, ClipByAxis = true" });
model.Annotations.Add(new LineAnnotation { ClipByXAxis = false, Type = LineAnnotationType.Horizontal, Y = 8, Color = OxyColors.Gold, Text = "Horizontal, ClipByAxis = false" });
return model;
}
[Example("LineAnnotation on reversed axes")]
public static PlotModel ReversedAxes()
{
var model = new PlotModel { Title = "LineAnnotation on reversed axes" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 80, StartPosition = 1, EndPosition = 0 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10, StartPosition = 1, EndPosition = 0 });
model.Annotations.Add(new LineAnnotation { Slope = 0.1, Intercept = 1, Text = "First", TextHorizontalAlignment = HorizontalAlignment.Left });
model.Annotations.Add(new LineAnnotation { Slope = 0.3, Intercept = 2, MaximumX = 40, Color = OxyColors.Red, Text = "Second", TextHorizontalAlignment = HorizontalAlignment.Left, TextVerticalAlignment = VerticalAlignment.Bottom });
model.Annotations.Add(new LineAnnotation { Type = LineAnnotationType.Vertical, X = 4, MaximumY = 10, Color = OxyColors.Green, Text = "Vertical", TextHorizontalAlignment = HorizontalAlignment.Right });
model.Annotations.Add(new LineAnnotation { Type = LineAnnotationType.Horizontal, Y = 2, MaximumX = 4, Color = OxyColors.Gold, Text = "Horizontal", TextHorizontalAlignment = HorizontalAlignment.Left });
return model;
}
}
}

View File

@@ -0,0 +1,161 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PointAnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
[Examples("PointAnnotation"), Tags("Annotations")]
public static class PointAnnotationExamples
{
[Example("PointAnnotation")]
public static PlotModel PointAnnotation()
{
var model = new PlotModel { Title = "PointAnnotation" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
model.Annotations.Add(new PointAnnotation { X = 50, Y = 50, Text = "P1" });
return model;
}
[Example("PointAnnotation - shapes")]
public static PlotModel PointAnnotationShapes()
{
var model = new PlotModel { Title = "PointAnnotation - shapes" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Maximum = 120 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
// filled
model.Annotations.Add(
new PointAnnotation
{
X = 20,
Y = 60,
Text = "Circle",
Shape = MarkerType.Circle,
Fill = OxyColors.LightGray,
Stroke = OxyColors.DarkGray,
StrokeThickness = 1
});
model.Annotations.Add(
new PointAnnotation
{
X = 40,
Y = 60,
Text = "Square",
Shape = MarkerType.Square,
Fill = OxyColors.LightBlue,
Stroke = OxyColors.DarkBlue,
StrokeThickness = 1
});
model.Annotations.Add(
new PointAnnotation
{
X = 60,
Y = 60,
Text = "Triangle",
Shape = MarkerType.Triangle,
Fill = OxyColors.IndianRed,
Stroke = OxyColors.Black,
StrokeThickness = 1
});
model.Annotations.Add(
new PointAnnotation
{
X = 80,
Y = 60,
Text = "Diamond",
Shape = MarkerType.Diamond,
Fill = OxyColors.ForestGreen,
Stroke = OxyColors.Black,
StrokeThickness = 1
});
model.Annotations.Add(
new PointAnnotation
{
X = 100,
Y = 60,
Text = "Custom",
Shape = MarkerType.Custom,
CustomOutline =
new[]
{
new ScreenPoint(-1, -1), new ScreenPoint(1, 1), new ScreenPoint(-1, 1),
new ScreenPoint(1, -1)
},
Stroke = OxyColors.Black,
Fill = OxyColors.CadetBlue,
StrokeThickness = 1
});
// not filled
model.Annotations.Add(
new PointAnnotation
{
X = 20,
Y = 40,
Text = "Cross",
Shape = MarkerType.Cross,
Stroke = OxyColors.IndianRed,
StrokeThickness = 1
});
model.Annotations.Add(
new PointAnnotation
{
X = 40,
Y = 40,
Text = "Plus",
Shape = MarkerType.Plus,
Stroke = OxyColors.Navy,
StrokeThickness = 1
});
model.Annotations.Add(
new PointAnnotation
{
X = 60,
Y = 40,
Text = "Star",
Shape = MarkerType.Star,
Stroke = OxyColors.DarkOliveGreen,
StrokeThickness = 1
});
return model;
}
[Example("PointAnnotation - text alignments")]
public static PlotModel PointAnnotationTextAlignment()
{
var model = new PlotModel { Title = "PointAnnotation - text alignments" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -50, Maximum = 50 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -50, Maximum = 50 });
for (var ha = -1; ha <= 1; ha++)
{
var h = (HorizontalAlignment)ha;
for (var va = -1; va <= 1; va++)
{
var v = (VerticalAlignment)va;
model.Annotations.Add(
new PointAnnotation
{
X = ha * 20,
Y = va * 20,
Size = 10,
Text = h + "," + v,
TextHorizontalAlignment = h,
TextVerticalAlignment = v
});
}
}
return model;
}
}
}

View File

@@ -0,0 +1,158 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PolygonAnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using System;
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
using OxyPlot.Series;
[Examples("PolygonAnnotation"), Tags("Annotations")]
public static class PolygonAnnotationExamples
{
[Example("PolygonAnnotation")]
public static PlotModel PolygonAnnotation()
{
var model = new PlotModel { Title = "PolygonAnnotation" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 20 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 });
var a1 = new PolygonAnnotation { Text = "Polygon 1" };
a1.Points.AddRange(new[] { new DataPoint(4, -2), new DataPoint(8, -4), new DataPoint(17, 7), new DataPoint(5, 8), new DataPoint(2, 5) });
model.Annotations.Add(a1);
return model;
}
[Example("PolygonAnnotation with custom text position and alignment")]
public static PlotModel PolygonAnnotationTextPosition()
{
var model = new PlotModel { Title = "PolygonAnnotation with fixed text position and alignment" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 20 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 });
var a1 = new PolygonAnnotation { Text = "Polygon 1", TextHorizontalAlignment = HorizontalAlignment.Left, TextVerticalAlignment = VerticalAlignment.Bottom, TextPosition = new DataPoint(4.1, -1.9) };
a1.Points.AddRange(new[] { new DataPoint(4, -2), new DataPoint(8, -2), new DataPoint(17, 7), new DataPoint(5, 8), new DataPoint(4, 5) });
model.Annotations.Add(a1);
return model;
}
[Example("AnnotationLayer property")]
public static PlotModel AnnotationLayerProperty()
{
var model = new PlotModel { Title = "Annotation Layers" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 30, MajorGridlineStyle = LineStyle.Solid, MajorGridlineThickness = 1 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10, MajorGridlineStyle = LineStyle.Solid, MajorGridlineThickness = 1 });
var a1 = new PolygonAnnotation
{
Layer = AnnotationLayer.BelowAxes,
Text = "Layer = BelowAxes"
};
a1.Points.AddRange(new[]
{
new DataPoint(-11, -2), new DataPoint(-7, -4), new DataPoint(-3, 7), new DataPoint(-10, 8),
new DataPoint(-13, 5)
});
model.Annotations.Add(a1);
var a2 = new PolygonAnnotation
{
Layer = AnnotationLayer.BelowSeries,
Text = "Layer = BelowSeries"
};
a2.Points.AddRange(new DataPoint[]
{
new DataPoint(4, -2), new DataPoint(8, -4), new DataPoint(12, 7), new DataPoint(5, 8),
new DataPoint(2, 5)
});
model.Annotations.Add(a2);
var a3 = new PolygonAnnotation { Layer = AnnotationLayer.AboveSeries, Text = "Layer = AboveSeries" };
a3.Points.AddRange(new[] { new DataPoint(19, -2), new DataPoint(23, -4), new DataPoint(27, 7), new DataPoint(20, 8), new DataPoint(17, 5) });
model.Annotations.Add(a3);
model.Series.Add(new FunctionSeries(Math.Sin, -20, 30, 400));
return model;
}
[Example("Koch Snowflakes")]
public static PlotModel KockSnowflakes()
{
DataPoint[] triangle(DataPoint centre)
{
return new[]
{
new DataPoint(centre.X, centre.Y + 1),
new DataPoint(centre.X + Math.Sin(Math.PI * 2 / 3), centre.Y + Math.Cos(Math.PI * 2 / 3)),
new DataPoint(centre.X + Math.Sin(Math.PI * 4 / 3), centre.Y + Math.Cos(Math.PI * 4 / 3)),
};
}
var model = new PlotModel { Title = "PolygonAnnotation", PlotType = PlotType.Cartesian };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -4, Maximum = 4 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -2, Maximum = 2 });
var a1 = new PolygonAnnotation { Text = "MSL = 4", MinimumSegmentLength = 4 };
a1.Points.AddRange(KochFractal(triangle(new DataPoint(-2, 0)), 8, true, true));
model.Annotations.Add(a1);
var a2 = new PolygonAnnotation { Text = "MSL = 2", MinimumSegmentLength = 2 };
a2.Points.AddRange(KochFractal(triangle(new DataPoint(0, 0)), 8, true, true));
model.Annotations.Add(a2);
var a3 = new PolygonAnnotation { Text = "MSL = 1", MinimumSegmentLength = 1 };
a3.Points.AddRange(KochFractal(triangle(new DataPoint(2, 0)), 8, true, true));
model.Annotations.Add(a3);
return model;
}
public static DataPoint[] KochFractal(DataPoint[] seed, int n, bool clockwise, bool closed)
{
var cos60 = Math.Cos(Math.PI / 3);
var sin60 = Math.Sin(Math.PI / 3);
var cur = seed;
for (int i = 0; i < n; i++)
{
var next = new DataPoint[closed ? cur.Length * 4 : cur.Length * 4 - 3];
for (int j = 0; j < (closed ? cur.Length : cur.Length - 1); j++)
{
var p0 = cur[j];
var p1 = cur[(j + 1) % cur.Length];
var dx = (p1.X - p0.X) / 3;
var dy = (p1.Y - p0.Y) / 3;
double dx2, dy2;
if (clockwise)
{
dx2 = cos60 * dx - sin60 * dy;
dy2 = cos60 * dy + sin60 * dx;
}
else
{
dx2 = cos60 * dx - sin60 * dy;
dy2 = cos60 * dy + sin60 * dx;
}
next[j * 4] = p0;
next[j * 4 + 1] = new DataPoint(p0.X + dx, p0.Y + dy);
next[j * 4 + 2] = new DataPoint(p0.X + dx + dx2, p0.Y + dy + dy2);
next[j * 4 + 3] = new DataPoint(p0.X + dx * 2, p0.Y + dy * 2);
}
if (!closed)
{
next[next.Length - 1] = cur[cur.Length - 1];
}
cur = next;
}
return cur;
}
}
}

View File

@@ -0,0 +1,66 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PolylineAnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
[Examples("PolylineAnnotation"), Tags("Annotations")]
public static class PolylineAnnotationExamples
{
[Example("PolylineAnnotation")]
public static PlotModel PolylineAnnotations()
{
var model = new PlotModel { Title = "PolylineAnnotation" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = 0, Maximum = 30 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 0, Maximum = 30 });
var a1 = new PolylineAnnotation { Text = "Polyline" };
a1.Points.AddRange(new[] { new DataPoint(0, 10), new DataPoint(5, 5), new DataPoint(20, 1), new DataPoint(30, 20) });
var a2 = new PolylineAnnotation
{
InterpolationAlgorithm = InterpolationAlgorithms.CanonicalSpline,
Text = "Smooth Polyline"
};
a2.Points.AddRange(new[] { new DataPoint(0, 15), new DataPoint(3, 23), new DataPoint(9, 30), new DataPoint(20, 12), new DataPoint(30, 10) });
model.Annotations.Add(a1);
model.Annotations.Add(a2);
return model;
}
[Example("Koch Surfaces")]
public static PlotModel KochSurface()
{
DataPoint[] plane(DataPoint centre)
{
return new[]
{
new DataPoint(centre.X - 1, centre.Y),
new DataPoint(centre.X + 1, centre.Y),
};
}
var model = new PlotModel { Title = "PolygonAnnotation", PlotType = PlotType.Cartesian };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -2, Maximum = 2 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -2, Maximum = 2 });
var a1 = new PolylineAnnotation { Text = "MSL = 4", MinimumSegmentLength = 4, LineStyle = LineStyle.Solid, TextPosition = new DataPoint(0, 1) };
a1.Points.AddRange(PolygonAnnotationExamples.KochFractal(plane(new DataPoint(0, 1)), 8, true, false));
model.Annotations.Add(a1);
var a2 = new PolylineAnnotation { Text = "MSL = 2", MinimumSegmentLength = 2, LineStyle = LineStyle.Solid, TextPosition = new DataPoint(0, 0) };
a2.Points.AddRange(PolygonAnnotationExamples.KochFractal(plane(new DataPoint(0, 0)), 8, true, false));
model.Annotations.Add(a2);
var a3 = new PolylineAnnotation { Text = "MSL = 1", MinimumSegmentLength = 1, LineStyle = LineStyle.Solid, TextPosition = new DataPoint(0, -1) };
a3.Points.AddRange(PolygonAnnotationExamples.KochFractal(plane(new DataPoint(0, -1)), 8, true, false));
model.Annotations.Add(a3);
return model;
}
}
}

View File

@@ -0,0 +1,87 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RectangleAnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
using OxyPlot.Series;
[Examples("RectangleAnnotation"), Tags("Annotations")]
public static class RectangleAnnotationExamples
{
[Example("RectangleAnnotation")]
public static PlotModel RectangleAnnotation()
{
var model = new PlotModel { Title = "RectangleAnnotation" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
model.Annotations.Add(new RectangleAnnotation { MinimumX = 20, MaximumX = 70, MinimumY = 10, MaximumY = 40, TextRotation = 10, Text = "RectangleAnnotation", Fill = OxyColor.FromAColor(99, OxyColors.Blue), Stroke = OxyColors.Black, StrokeThickness = 2 });
return model;
}
[Example("RectangleAnnotations - vertical limit")]
public static PlotModel RectangleAnnotationVerticalLimit()
{
var model = new PlotModel { Title = "RectangleAnnotations - vertical limit" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
model.Annotations.Add(new RectangleAnnotation { MaximumY = 89.5, Text = "Valid area", Fill = OxyColor.FromAColor(99, OxyColors.Black) });
return model;
}
[Example("RectangleAnnotation - horizontal bands")]
public static PlotModel RectangleAnnotationHorizontals()
{
var model = new PlotModel { Title = "RectangleAnnotation - horizontal bands" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = 0, Maximum = 10 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 87, Maximum = 97, MajorStep = 1, MinorStep = 1 });
model.Annotations.Add(new RectangleAnnotation { MinimumY = 89.5, MaximumY = 90.8, Text = "Invalid", Fill = OxyColor.FromAColor(99, OxyColors.Red) });
model.Annotations.Add(new RectangleAnnotation { MinimumY = 90.8, MaximumY = 92.1, Fill = OxyColor.FromAColor(99, OxyColors.Orange) });
model.Annotations.Add(new RectangleAnnotation { MinimumY = 92.1, MaximumY = 94.6, Fill = OxyColor.FromAColor(99, OxyColors.Yellow) });
model.Annotations.Add(new RectangleAnnotation { MinimumY = 94.6, MaximumY = 96, Text = "Ok", Fill = OxyColor.FromAColor(99, OxyColors.Green) });
LineSeries series1;
model.Series.Add(series1 = new LineSeries { Color = OxyColors.Black, StrokeThickness = 6.0, LineJoin = LineJoin.Round });
series1.Points.Add(new DataPoint(0.5, 90.7));
series1.Points.Add(new DataPoint(1.5, 91.2));
series1.Points.Add(new DataPoint(2.5, 91));
series1.Points.Add(new DataPoint(3.5, 89.5));
series1.Points.Add(new DataPoint(4.5, 92.5));
series1.Points.Add(new DataPoint(5.5, 93.1));
series1.Points.Add(new DataPoint(6.5, 94.5));
series1.Points.Add(new DataPoint(7.5, 95.5));
series1.Points.Add(new DataPoint(8.5, 95.7));
series1.Points.Add(new DataPoint(9.5, 96.0));
return model;
}
[Example("RectangleAnnotation - vertical bands")]
public static PlotModel RectangleAnnotationVerticals()
{
var model = new PlotModel { Title = "RectangleAnnotation - vertical bands" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = 0, Maximum = 10 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 87, Maximum = 97, MajorStep = 1, MinorStep = 1 });
model.Annotations.Add(new RectangleAnnotation { MinimumX = 2.5, MaximumX = 2.8, TextRotation = 90, Text = "Red", Fill = OxyColor.FromAColor(99, OxyColors.Red) });
model.Annotations.Add(new RectangleAnnotation { MinimumX = 2.8, MaximumX = 6.1, TextRotation = 90, Text = "Orange", Fill = OxyColor.FromAColor(99, OxyColors.Orange) });
model.Annotations.Add(new RectangleAnnotation { MinimumX = 6.1, MaximumX = 7.6, TextRotation = 90, Text = "Yellow", Fill = OxyColor.FromAColor(99, OxyColors.Yellow) });
model.Annotations.Add(new RectangleAnnotation { MinimumX = 7.6, MaximumX = 9.7, TextRotation = 270, Text = "Green", Fill = OxyColor.FromAColor(99, OxyColors.Green) });
LineSeries series1;
model.Series.Add(series1 = new LineSeries { Color = OxyColors.Black, StrokeThickness = 6.0, LineJoin = LineJoin.Round });
series1.Points.Add(new DataPoint(0.5, 90.7));
series1.Points.Add(new DataPoint(1.5, 91.2));
series1.Points.Add(new DataPoint(2.5, 91));
series1.Points.Add(new DataPoint(3.5, 89.5));
series1.Points.Add(new DataPoint(4.5, 92.5));
series1.Points.Add(new DataPoint(5.5, 93.1));
series1.Points.Add(new DataPoint(6.5, 94.5));
series1.Points.Add(new DataPoint(7.5, 95.5));
series1.Points.Add(new DataPoint(8.5, 95.7));
series1.Points.Add(new DataPoint(9.5, 96.0));
return model;
}
}
}

View File

@@ -0,0 +1,86 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TextAnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using System;
using System.Linq;
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
[Examples("TextAnnotation"), Tags("Annotations")]
public static class TextAnnotationExamples
{
[Example("TextAnnotation")]
public static PlotModel TextAnnotations()
{
var model = new PlotModel { Title = "TextAnnotation" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -15, Maximum = 25 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -5, Maximum = 18 });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(-6, 0), Text = "Text annotation 1" });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(-7, 10), TextRotation = 80, Text = "Text annotation 2" });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(2, 2), TextRotation = 20, TextHorizontalAlignment = HorizontalAlignment.Right, TextVerticalAlignment = VerticalAlignment.Top, Text = "Right/Top" });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(2, 4), TextRotation = 20, TextHorizontalAlignment = HorizontalAlignment.Right, TextVerticalAlignment = VerticalAlignment.Middle, Text = "Right/Middle" });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(2, 6), TextRotation = 20, TextHorizontalAlignment = HorizontalAlignment.Right, TextVerticalAlignment = VerticalAlignment.Bottom, Text = "Right/Bottom" });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(10, 2), TextRotation = 20, TextHorizontalAlignment = HorizontalAlignment.Center, TextVerticalAlignment = VerticalAlignment.Top, Text = "Center/Top" });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(10, 4), TextRotation = 20, TextHorizontalAlignment = HorizontalAlignment.Center, TextVerticalAlignment = VerticalAlignment.Middle, Text = "Center/Middle" });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(10, 6), TextRotation = 20, TextHorizontalAlignment = HorizontalAlignment.Center, TextVerticalAlignment = VerticalAlignment.Bottom, Text = "Center/Bottom" });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(18, 2), TextRotation = 20, TextHorizontalAlignment = HorizontalAlignment.Left, TextVerticalAlignment = VerticalAlignment.Top, Text = "Left/Top" });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(18, 4), TextRotation = 20, TextHorizontalAlignment = HorizontalAlignment.Left, TextVerticalAlignment = VerticalAlignment.Middle, Text = "Left/Middle" });
model.Annotations.Add(new TextAnnotation { TextPosition = new DataPoint(18, 6), TextRotation = 20, TextHorizontalAlignment = HorizontalAlignment.Left, TextVerticalAlignment = VerticalAlignment.Bottom, Text = "Left/Bottom" });
double d = 0.05;
Action<double, double> addPoint = (x, y) =>
{
var annotation = new PolygonAnnotation
{
Layer = AnnotationLayer.BelowAxes,
};
annotation.Points.AddRange(new[]
{
new DataPoint(x - d, y - d), new DataPoint(x + d, y - d), new DataPoint(x + d, y + d),
new DataPoint(x - d, y + d), new DataPoint(x - d, y - d)
});
model.Annotations.Add(annotation);
};
foreach (var a in model.Annotations.ToArray())
{
var ta = a as TextAnnotation;
if (ta != null)
{
addPoint(ta.TextPosition.X, ta.TextPosition.Y);
}
}
return model;
}
[Example("Rotations")]
public static PlotModel Rotations()
{
var model = new PlotModel { Title = "TextAnnotation Rotations" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -5, Maximum = 45 });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, StartPosition = 1, EndPosition = 0, Minimum = -1, Maximum = 8 });
for (var i = 0; i < 360; i += 5)
{
model.Annotations.Add(new TextAnnotation
{
TextRotation = i,
TextPosition = new DataPoint(i % 45, i / 45),
Text = $"{i}°",
TextVerticalAlignment = VerticalAlignment.Middle,
TextHorizontalAlignment = HorizontalAlignment.Center
});
}
return model;
}
}
}

View File

@@ -0,0 +1,407 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TileMapAnnotation.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// <summary>
// Provides an annotation that shows a tile based map.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using OxyPlot;
using OxyPlot.Annotations;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Threading;
/// <summary>
/// Provides an annotation that shows a tile based map.
/// </summary>
/// <remarks>The longitude and latitude range of the map is defined by the range of the x and y axis, respectively.</remarks>
public class TileMapAnnotation : Annotation
{
/// <summary>
/// The image cache.
/// </summary>
private readonly Dictionary<string, OxyImage> images = new Dictionary<string, OxyImage>();
/// <summary>
/// The download queue.
/// </summary>
private readonly Queue<string> queue = new Queue<string>();
/// <summary>
/// The current number of downloads
/// </summary>
private int numberOfDownloads;
/// <summary>
/// Initializes a new instance of the <see cref="TileMapAnnotation" /> class.
/// </summary>
public TileMapAnnotation()
{
this.TileSize = 256;
this.MinZoomLevel = 0;
this.MaxZoomLevel = 20;
this.Opacity = 1.0;
this.MaxNumberOfDownloads = 8;
this.UserAgent = "OxyPlotExampleLibrary";
}
/// <summary>
/// Gets or sets the max number of simultaneous downloads.
/// </summary>
/// <value>The max number of downloads.</value>
public int MaxNumberOfDownloads { get; set; }
/// <summary>
/// Gets or sets the URL.
/// </summary>
/// <value>The URL.</value>
public string Url { get; set; }
/// <summary>
/// Gets or sets the copyright notice.
/// </summary>
/// <value>The copyright notice.</value>
public string CopyrightNotice { get; set; }
/// <summary>
/// Gets or sets the size of the tiles.
/// </summary>
/// <value>The size of the tiles.</value>
public int TileSize { get; set; }
/// <summary>
/// Gets or sets the min zoom level.
/// </summary>
/// <value>The min zoom level.</value>
public int MinZoomLevel { get; set; }
/// <summary>
/// Gets or sets the max zoom level.
/// </summary>
/// <value>The max zoom level.</value>
public int MaxZoomLevel { get; set; }
/// <summary>
/// Gets or sets the opacity.
/// </summary>
/// <value>The opacity.</value>
public double Opacity { get; set; }
/// <summary>
/// Gets or sets the user agent used for requests.
/// </summary>
public string UserAgent { get; set; }
/// <summary>
/// Renders the annotation on the specified context.
/// </summary>
/// <param name="rc">The render context.</param>
public override void Render(IRenderContext rc)
{
var lon0 = this.XAxis.ActualMinimum;
var lon1 = this.XAxis.ActualMaximum;
var lat0 = this.YAxis.ActualMinimum;
var lat1 = this.YAxis.ActualMaximum;
// the desired number of tiles horizontally
double tilesx = this.PlotModel.Width / this.TileSize;
// calculate the desired zoom level
var n = tilesx / (((lon1 + 180) / 360) - ((lon0 + 180) / 360));
var zoom = (int)Math.Round(Math.Log(n) / Math.Log(2));
if (zoom < this.MinZoomLevel)
{
zoom = this.MinZoomLevel;
}
if (zoom > this.MaxZoomLevel)
{
zoom = this.MaxZoomLevel;
}
// find tile coordinates for the corners
double x0, y0;
LatLonToTile(lat0, lon0, zoom, out x0, out y0);
double x1, y1;
LatLonToTile(lat1, lon1, zoom, out x1, out y1);
double xmax = Math.Max(x0, x1);
double xmin = Math.Min(x0, x1);
double ymax = Math.Max(y0, y1);
double ymin = Math.Min(y0, y1);
var clippingRectangle = this.GetClippingRect();
// Add the tiles
for (var x = (int)xmin; x < xmax; x++)
{
for (var y = (int)ymin; y < ymax; y++)
{
string uri = this.GetTileUri(x, y, zoom);
var img = this.GetImage(uri, rc.RendersToScreen);
if (img == null)
{
continue;
}
// transform from tile coordinates to lat/lon
double latitude0, latitude1, longitude0, longitude1;
TileToLatLon(x, y, zoom, out latitude0, out longitude0);
TileToLatLon(x + 1, y + 1, zoom, out latitude1, out longitude1);
// transform from lat/lon to screen coordinates
var s00 = this.Transform(longitude0, latitude0);
var s11 = this.Transform(longitude1, latitude1);
var r = OxyRect.Create(s00.X, s00.Y, s11.X, s11.Y);
// draw the image
rc.DrawImage(img, r.Left, r.Top, r.Width, r.Height, this.Opacity, true);
}
}
// draw the copyright notice
var p = new ScreenPoint(clippingRectangle.Right - 5, clippingRectangle.Bottom - 5);
var textSize = rc.MeasureText(this.CopyrightNotice, this.ActualFont, this.ActualFontSize, this.ActualFontWeight);
rc.DrawRectangle(
new OxyRect(p.X - textSize.Width - 2, p.Y - textSize.Height - 2, textSize.Width + 4, textSize.Height + 4),
OxyColor.FromAColor(200, OxyColors.White),
OxyColors.Undefined,
0,
this.EdgeRenderingMode);
rc.DrawText(
p,
this.CopyrightNotice,
OxyColors.Black,
this.ActualFont,
this.ActualFontSize,
this.ActualFontWeight,
0,
HorizontalAlignment.Right,
VerticalAlignment.Bottom);
}
/// <summary>
/// Transforms a position to a tile coordinate.
/// </summary>
/// <param name="latitude">The latitude.</param>
/// <param name="longitude">The longitude.</param>
/// <param name="zoom">The zoom.</param>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
private static void LatLonToTile(double latitude, double longitude, int zoom, out double x, out double y)
{
// http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
int n = 1 << zoom;
double lat = latitude / 180 * Math.PI;
x = (longitude + 180.0) / 360.0 * n;
y = (1.0 - (Math.Log(Math.Tan(lat) + (1.0 / Math.Cos(lat))) / Math.PI)) / 2.0 * n;
}
/// <summary>
/// Transforms a tile coordinate (x,y) to a position.
/// </summary>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
/// <param name="zoom">The zoom.</param>
/// <param name="latitude">The latitude.</param>
/// <param name="longitude">The longitude.</param>
private static void TileToLatLon(double x, double y, int zoom, out double latitude, out double longitude)
{
int n = 1 << zoom;
longitude = (x / n * 360.0) - 180.0;
double lat = Math.Atan(Math.Sinh(Math.PI * (1 - (2 * y / n))));
latitude = lat * 180.0 / Math.PI;
}
/// <summary>
/// Gets the image from the specified uri.
/// </summary>
/// <param name="uri">The URI.</param>
/// <param name="asyncLoading">Get the image asynchronously if set to <c>true</c>. The plot model will be invalidated when the image has been downloaded.</param>
/// <returns>The image.</returns>
/// <remarks>This method gets the image from cache, or starts an async download.</remarks>
private OxyImage GetImage(string uri, bool asyncLoading)
{
OxyImage img;
if (this.images.TryGetValue(uri, out img))
{
return img;
}
if (!asyncLoading)
{
return this.Download(uri);
}
lock (this.queue)
{
// 'reserve' an image (otherwise multiple downloads of the same uri may happen)
this.images[uri] = null;
this.queue.Enqueue(uri);
}
this.BeginDownload();
return null;
}
/// <summary>
/// Downloads the image from the specified URI.
/// </summary>
/// <param name="uri">The URI.</param>
/// <returns>The image</returns>
private OxyImage Download(string uri)
{
OxyImage img = null;
var mre = new ManualResetEvent(false);
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
request.BeginGetResponse(
r =>
{
try
{
if (request.HaveResponse)
{
var response = request.EndGetResponse(r);
var stream = response.GetResponseStream();
var ms = new MemoryStream();
stream.CopyTo(ms);
var buffer = ms.ToArray();
img = new OxyImage(buffer);
this.images[uri] = img;
}
}
catch (Exception e)
{
var ie = e;
while (ie != null)
{
System.Diagnostics.Debug.WriteLine(ie.Message);
ie = ie.InnerException;
}
}
finally
{
mre.Set();
}
},
request);
mre.WaitOne();
return img;
}
/// <summary>
/// Starts the next download in the queue.
/// </summary>
private void BeginDownload()
{
if (this.numberOfDownloads >= this.MaxNumberOfDownloads)
{
return;
}
string uri = this.queue.Dequeue();
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
#if NETFRAMEWORK
// unavailable in NET Standard 1.0
request.UserAgent = this.UserAgent;
#else
// compiles but does not run under NET Framework
request.Headers["User-Agent"] = this.UserAgent;
#endif
Interlocked.Increment(ref this.numberOfDownloads);
request.BeginGetResponse(
r =>
{
Interlocked.Decrement(ref this.numberOfDownloads);
try
{
if (request.HaveResponse)
{
var response = request.EndGetResponse(r);
var stream = response.GetResponseStream();
this.DownloadCompleted(uri, stream);
}
}
catch (Exception e)
{
var ie = e;
while (ie != null)
{
System.Diagnostics.Debug.WriteLine(ie.Message);
ie = ie.InnerException;
}
}
},
request);
}
/// <summary>
/// The download completed, set the image.
/// </summary>
/// <param name="uri">The URI.</param>
/// <param name="result">The result.</param>
private void DownloadCompleted(string uri, Stream result)
{
if (result == null)
{
return;
}
var ms = new MemoryStream();
result.CopyTo(ms);
var buffer = ms.ToArray();
var img = new OxyImage(buffer);
this.images[uri] = img;
lock (this.queue)
{
// Clear old items in the queue, new ones will be added when the plot is refreshed
foreach (var queuedUri in this.queue)
{
// Remove the 'reserved' image
this.images.Remove(queuedUri);
}
this.queue.Clear();
}
this.PlotModel.InvalidatePlot(false);
if (this.queue.Count > 0)
{
this.BeginDownload();
}
}
/// <summary>
/// Gets the tile URI.
/// </summary>
/// <param name="x">The tile x.</param>
/// <param name="y">The tile y.</param>
/// <param name="zoom">The zoom.</param>
/// <returns>The uri.</returns>
private string GetTileUri(int x, int y, int zoom)
{
string url = this.Url.Replace("{X}", x.ToString(CultureInfo.InvariantCulture));
url = url.Replace("{Y}", y.ToString(CultureInfo.InvariantCulture));
return url.Replace("{Z}", zoom.ToString(CultureInfo.InvariantCulture));
}
}
}

View File

@@ -0,0 +1,70 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TileMapAnnotationExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
[Examples("TileMapAnnotation"), Tags("Annotations")]
public static class TileMapAnnotationExamples
{
[Example("TileMapAnnotation (openstreetmap.org)", true)]
public static PlotModel TileMapAnnotation2()
{
// See policy document: https://operations.osmfoundation.org/policies/tiles/
var model = new PlotModel { Title = "TileMapAnnotation" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = 10.4, Maximum = 10.6, Title = "Longitude" });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 59.88, Maximum = 59.96, Title = "Latitude" });
// Add the tile map annotation
model.Annotations.Add(
new TileMapAnnotation
{
Url = "http://tile.openstreetmap.org/{Z}/{X}/{Y}.png",
CopyrightNotice = "OpenStreetMap",
MaxNumberOfDownloads = 2,
});
return model;
}
[Example("TileMapAnnotation (statkart.no)", true)]
public static PlotModel TileMapAnnotation()
{
var model = new PlotModel { Title = "TileMapAnnotation" };
// TODO: scale ratio between the two axes should be fixed (or depending on latitude...)
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = 10.4, Maximum = 10.6, Title = "Longitude" });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 59.88, Maximum = 59.96, Title = "Latitude" });
// Add the tile map annotation
model.Annotations.Add(
new TileMapAnnotation
{
Url = "http://opencache.statkart.no/gatekeeper/gk/gk.open_gmaps?layers=toporaster3&zoom={Z}&x={X}&y={Y}",
CopyrightNotice = "Kartgrunnlag: Statens kartverk, Geovekst og kommuner.",
MinZoomLevel = 5,
MaxZoomLevel = 19
});
model.Annotations.Add(new ArrowAnnotation
{
EndPoint = new DataPoint(10.563, 59.888),
ArrowDirection = new ScreenVector(-40, -60),
StrokeThickness = 3,
FontSize = 20,
FontWeight = FontWeights.Bold,
TextColor = OxyColor.FromAColor(160, OxyColors.Magenta),
Color = OxyColor.FromAColor(100, OxyColors.Magenta)
});
return model;
}
}
}