forked from oxyplot/oxyplot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPolygonSeriesExamples.cs
More file actions
105 lines (83 loc) · 3.34 KB
/
PolygonSeriesExamples.cs
File metadata and controls
105 lines (83 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.Text;
namespace ExampleLibrary.Series
{
using OxyPlot;
using OxyPlot.Series;
using OxyPlot.Legends;
using OxyPlot.Axes;
[Examples("PolygonSeries"), Tags("Series")]
public static class PolygonSeriesExamples
{
[Example("PolygonSeries")]
[DocumentationExample("Series/PolygonSeries")]
public static PlotModel PolygonSeries()
{
var model = new PlotModel { Title = "Polygon Series", PlotType = PlotType.Cartesian };
model.Axes.Add(new LinearColorAxis());
var ps = new PolygonSeries();
var outlines = new List<DataPoint[]>();
for (int i = 0; i < 5; i++)
{
ps.Items.Add(new PolygonItem(RegularPolygon(new DataPoint(i * 5, 0), 2, 3 + i), i));
outlines.Add(RegularPolygon(new DataPoint(i * 5, 5), 2, 3 + i));
}
ps.Items.Add(new PolygonItem(outlines, 10));
model.Series.Add(ps);
return model;
}
[Example("Hexagonal Grid")]
[DocumentationExample("Series/PolygonSeries")]
public static PlotModel HexGrid()
{
var model = new PlotModel { Title = "Hexagonal Grid" };
model.Axes.Add(new LinearColorAxis() { Position = AxisPosition.Right });
double eval(DataPoint p) => Math.Sin(p.X / 5) + Math.Sqrt(p.Y);
var dim = 1.0;
var w = dim * 2 - Math.Cos(Math.PI / 3) * dim;
var h = Math.Sin(Math.PI / 3) * dim * 2;
var ps = new PolygonSeries() { Stroke = OxyColors.Black, StrokeThickness = 1 };
for (int x = 0; x < 40; x++)
{
for (int y = 0; y < 40; y++)
{
var oy = (x % 2 == 0) ? 0 : h / 2;
var p = new DataPoint(x * w, y * h + oy);
ps.Items.Add(new PolygonItem(RegularPolygon(p, dim, 6), eval(p)));
}
}
model.Series.Add(ps);
return model;
}
private static DataPoint[] RegularPolygon(DataPoint center, double dimension, int polyCount)
{
var res = new DataPoint[polyCount];
for (int i = 0; i < res.Length; i++)
{
var angle = Math.PI * 2 * i / res.Length;
var x = Math.Cos(angle) * dimension;
var y = Math.Sin(angle) * dimension;
res[i] = new DataPoint(center.X + x, center.Y + y);
}
return res;
}
[Example("WithoutColorAxis")]
[DocumentationExample("Series/PolygonSeries")]
public static PlotModel WithoutColorAxis()
{
var model = new PlotModel { Title = "Without ColorAxis", PlotType = PlotType.Cartesian };
model.Axes.Add(new LinearAxis());
var ps = new PolygonSeries();
var outlines = new List<DataPoint[]>();
for (int i = 0; i < 5; i++)
{
ps.Items.Add(new PolygonItem(RegularPolygon(new DataPoint(i * 5, 0), 2, 3 + i), i));
outlines.Add(RegularPolygon(new DataPoint(i * 5, 5), 2, 3 + i));
}
ps.Items.Add(new PolygonItem(outlines, 10));
model.Series.Add(ps);
return model;
}
}
}