-
Notifications
You must be signed in to change notification settings - Fork 979
Expand file tree
/
Copy pathXkcdExamples.cs
More file actions
145 lines (127 loc) · 5.11 KB
/
XkcdExamples.cs
File metadata and controls
145 lines (127 loc) · 5.11 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="XkcdExamples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// <summary>
// Plot examples in XKCD style.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using System;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using OxyPlot.Legends;
/// <summary>
/// Plot examples in XKCD style.
/// </summary>
[Examples("XKCD")]
public static class XkcdExamples
{
/// <summary>
/// Xkcd style example #1.
/// </summary>
/// <returns>A <see cref="PlotModel" />.</returns>
[Example("Test #1")]
public static PlotModel Test1()
{
var model = new PlotModel
{
Title = "XKCD style plot",
Subtitle = "Install the 'Humor Sans' font for the best experience",
RenderingDecorator = rc => new XkcdRenderingDecorator(rc)
};
model.Series.Add(new FunctionSeries(Math.Sin, 0, 10, 50, "sin(x)"));
return model;
}
/// <summary>
/// Xkcd style example #2.
/// </summary>
/// <returns>A <see cref="PlotModel" />.</returns>
[Example("Test #2")]
public static PlotModel Test2()
{
var model = new PlotModel
{
Title = "Test #2",
RenderingDecorator = rc => new XkcdRenderingDecorator(rc)
};
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = 0, Maximum = 8, Title = "INTENSITY" });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "TIME" });
var s1 = new LineSeries
{
Color = OxyColors.Cyan,
StrokeThickness = 4,
};
var s2 = new LineSeries
{
Color = OxyColors.White,
StrokeThickness = 14,
};
var s3 = new LineSeries
{
Color = OxyColors.Red,
StrokeThickness = 4,
};
int n = 257;
double x0 = 1;
double x1 = 9;
for (int i = 0; i < n; i++)
{
var x = x0 + ((x1 - x0) * i / (n - 1));
var y1 = 1.5 + (10.0 * (Math.Sin(x) * Math.Sin(x) / Math.Sqrt(x)) * Math.Exp(-0.5 * (x - 5.0) * (x - 5.0)));
var y2 = 3.0 + (10.0 * (Math.Sin(x) * Math.Sin(x) / Math.Sqrt(x)) * Math.Exp(-0.5 * (x - 7.0) * (x - 7.0)));
s1.Points.Add(new DataPoint(x, y1));
s2.Points.Add(new DataPoint(x, y2));
s3.Points.Add(new DataPoint(x, y2));
}
model.Series.Add(s1);
model.Series.Add(s2);
model.Series.Add(s3);
return model;
}
/// <summary>
/// Xkcd style example #3.
/// </summary>
/// <returns>A <see cref="PlotModel" />.</returns>
[Example("Test #3")]
public static PlotModel Test3()
{
var model = new PlotModel
{
Title = "Test #3",
RenderingDecorator = rc => new XkcdRenderingDecorator(rc)
};
var l = new Legend
{
LegendPlacement = LegendPlacement.Outside,
LegendPosition = LegendPosition.BottomCenter,
LegendOrientation = LegendOrientation.Horizontal,
LegendBorderThickness = 0
};
model.Legends.Add(l);
var s1 = new BarSeries { Title = "Series 1", IsStacked = false, StrokeColor = OxyColors.Black, StrokeThickness = 1, XAxisKey = "x", YAxisKey = "y" };
s1.Items.Add(new BarItem { Value = 25 });
s1.Items.Add(new BarItem { Value = 137 });
s1.Items.Add(new BarItem { Value = 18 });
s1.Items.Add(new BarItem { Value = 40 });
var s2 = new BarSeries { Title = "Series 2", IsStacked = false, StrokeColor = OxyColors.Black, StrokeThickness = 1, XAxisKey = "x", YAxisKey = "y" };
s2.Items.Add(new BarItem { Value = 12 });
s2.Items.Add(new BarItem { Value = 14 });
s2.Items.Add(new BarItem { Value = 120 });
s2.Items.Add(new BarItem { Value = 26 });
var categoryAxis = new CategoryAxis { Position = AxisPosition.Bottom, Key = "y" };
categoryAxis.Labels.Add("Category A");
categoryAxis.Labels.Add("Category B");
categoryAxis.Labels.Add("Category C");
categoryAxis.Labels.Add("Category D");
var valueAxis = new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0, Key = "x" };
model.Series.Add(s1);
model.Series.Add(s2);
model.Axes.Add(categoryAxis);
model.Axes.Add(valueAxis);
return model;
}
}
}