-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcpp-simple.cpp
More file actions
91 lines (60 loc) · 1.92 KB
/
cpp-simple.cpp
File metadata and controls
91 lines (60 loc) · 1.92 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
/* vim: set noet sw=8 ts=8 tw=120: */
#include <glib.h>
#include <stdio.h>
#include <locale.h>
#include "blot.hpp"
#define DATA_X_MIN -1
#define DATA_X_MAX 1
#define DATA_X_RANGE (DATA_X_MAX - DATA_X_MIN)
#define DATA_Y_MIN -1
#define DATA_Y_MAX 1
#define DATA_Y_RANGE (DATA_Y_MAX - DATA_Y_MIN)
#define SCAT_COUNT 9
int main(void)
{
setlocale(LC_CTYPE, "");
/* build a dummy dataset */
std::vector<double> scat_x(SCAT_COUNT);
std::vector<double> scat_y(SCAT_COUNT);
for (int i=0; i<SCAT_COUNT; i++) {
double f = (double)i / (SCAT_COUNT-1);
scat_x[i] = DATA_X_MIN + (f * DATA_X_RANGE);
scat_y[i] = DATA_Y_MIN + (f * DATA_Y_RANGE);
}
std::vector<double> line_x = { DATA_X_MIN, DATA_Y_MAX };
std::vector<double> line_y = { DATA_Y_MAX, DATA_Y_MIN };
/* configure the figure */
Blot::Figure fig;
fig.set_axis_color(8);
fig.set_screen_size(80, 40);
fig.set_x_limits(DATA_X_MIN*2, DATA_X_MAX*2);
fig.set_y_limits(DATA_Y_MIN*2, DATA_Y_MAX*2);
#if 1
/* hack for now to add origin lines */
/* plot X-axis origin */
std::vector<gint32> xax = { DATA_X_MIN*2, DATA_X_MAX*2 };
std::vector<gint32> xay = { 0, 0 };
fig.line(xax, xay, 8, NULL);
/* plot Y-axis origin */
std::vector<gint32> yax = { 0, 0 };
std::vector<gint32> yay = {DATA_Y_MIN*2, DATA_Y_MAX*2 };
fig.line(yax, yay, 8, NULL);
#endif
/* add a scatter plot */
fig.scatter(scat_x, scat_y, 9, "scatter");
/* add a line plot */
fig.line(line_x, line_y, 10, "line");
/* render the plots */
blot_render_flags flags
= BLOT_RENDER_BRAILLE
| BLOT_RENDER_LEGEND_BELOW
| BLOT_RENDER_DONT_INVERT_Y_AXIS;
Blot::Screen scr = fig.render(flags);
/* print it to screen */
gsize txt_size = 0;
const wchar_t *txt = scr.get_text(txt_size);
printf("--------------------------------------------------------------------------------\n");
printf("%ls", txt);
printf("--------------------------------------------------------------------------------\n");
return 0;
}