-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.d
More file actions
109 lines (90 loc) · 2.73 KB
/
Copy pathapp.d
File metadata and controls
109 lines (90 loc) · 2.73 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
module app;
import rk.tplot;
void main()
{
linePlotExample();
scatterPlotExample();
barChartExample();
combinedExample();
histogramExample();
pieChartExample();
}
void linePlotExample()
{
auto p = Plot(800, 500);
double[] x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
double[] y1 = [2.3, 4.1, 3.5, 6.2, 5.8, 7.1, 8.3, 7.9, 9.2, 10.1];
double[] y2 = [1.1, 2.5, 4.0, 3.8, 5.0, 6.3, 5.5, 7.2, 8.0, 8.8];
p.plot(x, y1, "Temperature");
p.plot(x, y2, "Humidity");
p.setTitle("Line Plot Example");
p.setXLabel("Day");
p.setYLabel("Value");
p.save("examples/line_plot.svg");
}
void scatterPlotExample()
{
auto p = Plot(800, 500);
double[] x = [1.2, 2.4, 3.1, 4.5, 5.3, 6.0, 7.2, 8.1, 9.4, 10.0];
double[] y = [3.1, 2.8, 5.2, 4.1, 7.0, 6.5, 8.2, 7.8, 9.5, 10.2];
p.scatter(x, y, "Data Points");
p.setTitle("Scatter Plot Example");
p.setXLabel("X");
p.setYLabel("Y");
p.save("examples/scatter_plot.svg");
}
void barChartExample()
{
auto p = Plot(800, 500);
double[] categories = [1, 2, 3, 4, 5];
double[] values1 = [23, 45, 31, 52, 38];
double[] values2 = [18, 35, 42, 28, 45];
p.bar(categories, values1, "Product A");
p.bar(categories, values2, "Product B");
p.setTitle("Bar Chart Example");
p.setXLabel("Category");
p.setYLabel("Sales");
p.save("examples/bar_chart.svg");
}
void combinedExample()
{
auto p = Plot(900, 600);
double[] x = [1, 2, 3, 4, 5, 6, 7, 8];
double[] trend = [2.0, 3.5, 3.8, 5.2, 5.0, 6.8, 7.2, 8.0];
double[] actual = [2.2, 3.1, 4.3, 4.8, 5.5, 6.2, 7.5, 7.8];
double[] bars = [1.5, 2.8, 3.2, 4.0, 3.8, 5.1, 5.5, 6.2];
p.bar(x, bars, "Volume");
p.plot(x, trend, "Trend");
p.scatter(x, actual, "Actual");
p.setTitle("Combined Plot");
p.setXLabel("Month");
p.setYLabel("Value");
p.save("examples/combined_plot.svg");
}
void histogramExample()
{
auto p = Plot(800, 500);
// Simulate some data (normal-ish distribution)
double[] data = [
2.1, 3.5, 4.2, 4.8, 5.1, 5.3, 5.5, 5.7, 5.9, 6.0,
6.1, 6.2, 6.3, 6.4, 6.5, 6.5, 6.6, 6.7, 6.8, 6.9,
7.0, 7.1, 7.2, 7.3, 7.5, 7.8, 8.0, 8.2, 8.5, 9.1,
5.0, 5.5, 6.0, 6.3, 6.5, 6.8, 7.0, 7.2, 7.5, 8.0,
4.5, 5.2, 5.8, 6.1, 6.4, 6.6, 6.9, 7.1, 7.4, 7.7
];
p.hist(data, 10, "Scores");
p.setTitle("Score Distribution");
p.setXLabel("Score");
p.setYLabel("Frequency");
p.save("examples/histogram.svg");
}
void pieChartExample()
{
auto p = Plot(600, 450);
p.pie(
[35.0, 22.0, 18.0, 12.0, 8.0, 2.0, 3.0],
["Rent", "Food", "Transport", "Savings", "Entertainment", "Internet", "Other"]
);
p.setTitle("Monthly Budget");
p.save("examples/pie_chart.svg");
}