-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathumplot.um
96 lines (75 loc) · 2.07 KB
/
umplot.um
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
type (
Point* = struct {
x, y: real
}
Kind* = enum {
line = 1
scatter
}
Style* = struct {
kind: Kind
color: uint32
width: real
}
Series* = struct {
points: []Point
name: str
style: Style
}
Grid* = struct {
xNumLines, yNumLines: int
color: uint32
fontSize: int
visible, labelled: bool
}
Titles* = struct {
x, y, graph: str
color: uint32
fontSize: int
visible: bool
}
Legend* = struct {
visible: bool
}
Plot* = struct {
series: []Series
grid: Grid
titles: Titles
legend: Legend
}
)
fn (s: ^Series) clear*() {
s.points = []Point{}
}
fn (s: ^Series) add*(x, y: real) {
s.points = append(s.points, Point{x, y})
}
fn init*(numSeries: int = 1, kind: Kind = .line): Plot {
plt := Plot{series: make([]Series, numSeries)}
const getDefaultColors = fn (numColors: int): []uint32 {
basicColors := []uint32{0xFF0000DD, 0xFFDD0000, 0xFF00DD00}
colors := make([]uint32, numColors)
for i := 0; i < numColors; i++ {
if i < len(basicColors) {
colors[i] = basicColors[i]
} else {
j := i - len(basicColors)
colors[i] = (colors[j] + colors[j + 1]) / 2
}
}
return colors
}
defaultColors := getDefaultColors(numSeries)
for i := 0; i < numSeries; i++ {
plt.series[i].name = ""
plt.series[i].style = {kind: kind, color: defaultColors[i], width: 3.0}
}
plt.grid = {xNumLines: 5, yNumLines: 5, color: 0xFF505050, fontSize: 12, visible: true, labelled: true}
plt.titles = {x: "", y: "", graph: "", color: plt.grid.color, fontSize: plt.grid.fontSize, visible: true}
plt.legend = {visible: true}
return plt
}
fn umplot_plot(p: ^Plot): int
fn (p: ^Plot) plot*() {
umplot_plot(p)
}