ntcharts 0.1.0-arm-linux-musl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +332 -0
- data/ext/ntcharts/barchart.c +215 -0
- data/ext/ntcharts/extconf.rb +70 -0
- data/ext/ntcharts/extension.c +44 -0
- data/ext/ntcharts/extension.h +92 -0
- data/ext/ntcharts/linechart.c +341 -0
- data/ext/ntcharts/sparkline.c +161 -0
- data/ext/ntcharts/streamlinechart.c +183 -0
- data/ext/ntcharts/style.c +77 -0
- data/ext/ntcharts/timeserieslinechart.c +296 -0
- data/ext/ntcharts/wavelinechart.c +248 -0
- data/go/barchart.go +356 -0
- data/go/build/linux_arm/libntcharts.a +0 -0
- data/go/build/linux_arm/libntcharts.h +276 -0
- data/go/go.mod +32 -0
- data/go/go.sum +51 -0
- data/go/linechart.go +441 -0
- data/go/ntcharts.go +279 -0
- data/go/sparkline.go +194 -0
- data/go/streamlinechart.go +234 -0
- data/go/timeserieslinechart.go +354 -0
- data/go/wavelinechart.go +309 -0
- data/lib/ntcharts/3.2/ntcharts.so +0 -0
- data/lib/ntcharts/3.3/ntcharts.so +0 -0
- data/lib/ntcharts/3.4/ntcharts.so +0 -0
- data/lib/ntcharts/4.0/ntcharts.so +0 -0
- data/lib/ntcharts/bar_data.rb +51 -0
- data/lib/ntcharts/version.rb +5 -0
- data/lib/ntcharts.rb +102 -0
- data/ntcharts.gemspec +36 -0
- metadata +91 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#ifndef NTCHARTS_EXTENSION_H
|
|
2
|
+
#define NTCHARTS_EXTENSION_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
#include "libntcharts.h"
|
|
6
|
+
|
|
7
|
+
extern VALUE mNtcharts;
|
|
8
|
+
extern VALUE cSparkline;
|
|
9
|
+
extern VALUE cBarchart;
|
|
10
|
+
extern VALUE cLinechart;
|
|
11
|
+
extern VALUE cWavelinechart;
|
|
12
|
+
extern VALUE cStreamlinechart;
|
|
13
|
+
extern VALUE cTimeserieslinechart;
|
|
14
|
+
extern VALUE cStyle;
|
|
15
|
+
|
|
16
|
+
extern const rb_data_type_t sparkline_type;
|
|
17
|
+
extern const rb_data_type_t barchart_type;
|
|
18
|
+
extern const rb_data_type_t linechart_type;
|
|
19
|
+
extern const rb_data_type_t wavelinechart_type;
|
|
20
|
+
extern const rb_data_type_t streamlinechart_type;
|
|
21
|
+
extern const rb_data_type_t timeserieslinechart_type;
|
|
22
|
+
extern const rb_data_type_t style_type;
|
|
23
|
+
|
|
24
|
+
typedef struct {
|
|
25
|
+
unsigned long long handle;
|
|
26
|
+
} ntcharts_sparkline_t;
|
|
27
|
+
|
|
28
|
+
typedef struct {
|
|
29
|
+
unsigned long long handle;
|
|
30
|
+
} ntcharts_barchart_t;
|
|
31
|
+
|
|
32
|
+
typedef struct {
|
|
33
|
+
unsigned long long handle;
|
|
34
|
+
} ntcharts_linechart_t;
|
|
35
|
+
|
|
36
|
+
typedef struct {
|
|
37
|
+
unsigned long long handle;
|
|
38
|
+
} ntcharts_wavelinechart_t;
|
|
39
|
+
|
|
40
|
+
typedef struct {
|
|
41
|
+
unsigned long long handle;
|
|
42
|
+
} ntcharts_streamlinechart_t;
|
|
43
|
+
|
|
44
|
+
typedef struct {
|
|
45
|
+
unsigned long long handle;
|
|
46
|
+
} ntcharts_timeserieslinechart_t;
|
|
47
|
+
|
|
48
|
+
typedef struct {
|
|
49
|
+
unsigned long long handle;
|
|
50
|
+
} ntcharts_style_t;
|
|
51
|
+
|
|
52
|
+
#define GET_SPARKLINE(self, sparkline) \
|
|
53
|
+
ntcharts_sparkline_t *sparkline; \
|
|
54
|
+
TypedData_Get_Struct(self, ntcharts_sparkline_t, &sparkline_type, sparkline)
|
|
55
|
+
|
|
56
|
+
#define GET_BARCHART(self, barchart) \
|
|
57
|
+
ntcharts_barchart_t *barchart; \
|
|
58
|
+
TypedData_Get_Struct(self, ntcharts_barchart_t, &barchart_type, barchart)
|
|
59
|
+
|
|
60
|
+
#define GET_LINECHART(self, linechart) \
|
|
61
|
+
ntcharts_linechart_t *linechart; \
|
|
62
|
+
TypedData_Get_Struct(self, ntcharts_linechart_t, &linechart_type, linechart)
|
|
63
|
+
|
|
64
|
+
#define GET_WAVELINECHART(self, wavelinechart) \
|
|
65
|
+
ntcharts_wavelinechart_t *wavelinechart; \
|
|
66
|
+
TypedData_Get_Struct(self, ntcharts_wavelinechart_t, &wavelinechart_type, wavelinechart)
|
|
67
|
+
|
|
68
|
+
#define GET_STREAMLINECHART(self, streamlinechart) \
|
|
69
|
+
ntcharts_streamlinechart_t *streamlinechart; \
|
|
70
|
+
TypedData_Get_Struct(self, ntcharts_streamlinechart_t, &streamlinechart_type, streamlinechart)
|
|
71
|
+
|
|
72
|
+
#define GET_TIMESERIESLINECHART(self, timeserieslinechart) \
|
|
73
|
+
ntcharts_timeserieslinechart_t *timeserieslinechart; \
|
|
74
|
+
TypedData_Get_Struct(self, ntcharts_timeserieslinechart_t, ×erieslinechart_type, timeserieslinechart)
|
|
75
|
+
|
|
76
|
+
#define GET_STYLE(self, style) \
|
|
77
|
+
ntcharts_style_t *style; \
|
|
78
|
+
TypedData_Get_Struct(self, ntcharts_style_t, &style_type, style)
|
|
79
|
+
|
|
80
|
+
VALUE sparkline_wrap(VALUE klass, unsigned long long handle);
|
|
81
|
+
VALUE barchart_wrap(VALUE klass, unsigned long long handle);
|
|
82
|
+
VALUE style_wrap(VALUE klass, unsigned long long handle);
|
|
83
|
+
|
|
84
|
+
void Init_ntcharts_sparkline(void);
|
|
85
|
+
void Init_ntcharts_barchart(void);
|
|
86
|
+
void Init_ntcharts_linechart(void);
|
|
87
|
+
void Init_ntcharts_wavelinechart(void);
|
|
88
|
+
void Init_ntcharts_streamlinechart(void);
|
|
89
|
+
void Init_ntcharts_timeserieslinechart(void);
|
|
90
|
+
void Init_ntcharts_style(void);
|
|
91
|
+
|
|
92
|
+
#endif
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
#include "extension.h"
|
|
2
|
+
|
|
3
|
+
static void linechart_free(void *pointer) {
|
|
4
|
+
ntcharts_linechart_t *linechart = (ntcharts_linechart_t *)pointer;
|
|
5
|
+
if (linechart->handle != 0) {
|
|
6
|
+
ntcharts_linechart_free(linechart->handle);
|
|
7
|
+
}
|
|
8
|
+
xfree(linechart);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static size_t linechart_memsize(const void *pointer) {
|
|
12
|
+
return sizeof(ntcharts_linechart_t);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const rb_data_type_t linechart_type = {
|
|
16
|
+
.wrap_struct_name = "Ntcharts::Linechart",
|
|
17
|
+
.function = {
|
|
18
|
+
.dmark = NULL,
|
|
19
|
+
.dfree = linechart_free,
|
|
20
|
+
.dsize = linechart_memsize,
|
|
21
|
+
},
|
|
22
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
static VALUE linechart_alloc(VALUE klass) {
|
|
26
|
+
ntcharts_linechart_t *linechart = ALLOC(ntcharts_linechart_t);
|
|
27
|
+
linechart->handle = 0;
|
|
28
|
+
return TypedData_Wrap_Struct(klass, &linechart_type, linechart);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
VALUE linechart_wrap(VALUE klass, unsigned long long handle) {
|
|
32
|
+
ntcharts_linechart_t *linechart = ALLOC(ntcharts_linechart_t);
|
|
33
|
+
linechart->handle = handle;
|
|
34
|
+
return TypedData_Wrap_Struct(klass, &linechart_type, linechart);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static VALUE linechart_initialize(int argc, VALUE *argv, VALUE self) {
|
|
38
|
+
GET_LINECHART(self, linechart);
|
|
39
|
+
|
|
40
|
+
if (argc == 2) {
|
|
41
|
+
// Auto-range mode: width, height only
|
|
42
|
+
linechart->handle = ntcharts_linechart_new_with_auto_range(NUM2INT(argv[0]), NUM2INT(argv[1]));
|
|
43
|
+
} else if (argc == 6) {
|
|
44
|
+
// Full mode: width, height, min_x, max_x, min_y, max_y
|
|
45
|
+
linechart->handle = ntcharts_linechart_new(
|
|
46
|
+
NUM2INT(argv[0]), NUM2INT(argv[1]),
|
|
47
|
+
NUM2DBL(argv[2]), NUM2DBL(argv[3]),
|
|
48
|
+
NUM2DBL(argv[4]), NUM2DBL(argv[5])
|
|
49
|
+
);
|
|
50
|
+
} else {
|
|
51
|
+
rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 2 or 6)", argc);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return self;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static VALUE linechart_width(VALUE self) {
|
|
58
|
+
GET_LINECHART(self, linechart);
|
|
59
|
+
return INT2NUM(ntcharts_linechart_width(linechart->handle));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static VALUE linechart_height(VALUE self) {
|
|
63
|
+
GET_LINECHART(self, linechart);
|
|
64
|
+
return INT2NUM(ntcharts_linechart_height(linechart->handle));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static VALUE linechart_graph_width(VALUE self) {
|
|
68
|
+
GET_LINECHART(self, linechart);
|
|
69
|
+
return INT2NUM(ntcharts_linechart_graph_width(linechart->handle));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static VALUE linechart_graph_height(VALUE self) {
|
|
73
|
+
GET_LINECHART(self, linechart);
|
|
74
|
+
return INT2NUM(ntcharts_linechart_graph_height(linechart->handle));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static VALUE linechart_min_x(VALUE self) {
|
|
78
|
+
GET_LINECHART(self, linechart);
|
|
79
|
+
return DBL2NUM(ntcharts_linechart_min_x(linechart->handle));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static VALUE linechart_max_x(VALUE self) {
|
|
83
|
+
GET_LINECHART(self, linechart);
|
|
84
|
+
return DBL2NUM(ntcharts_linechart_max_x(linechart->handle));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static VALUE linechart_min_y(VALUE self) {
|
|
88
|
+
GET_LINECHART(self, linechart);
|
|
89
|
+
return DBL2NUM(ntcharts_linechart_min_y(linechart->handle));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static VALUE linechart_max_y(VALUE self) {
|
|
93
|
+
GET_LINECHART(self, linechart);
|
|
94
|
+
return DBL2NUM(ntcharts_linechart_max_y(linechart->handle));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static VALUE linechart_view_min_x(VALUE self) {
|
|
98
|
+
GET_LINECHART(self, linechart);
|
|
99
|
+
return DBL2NUM(ntcharts_linechart_view_min_x(linechart->handle));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static VALUE linechart_view_max_x(VALUE self) {
|
|
103
|
+
GET_LINECHART(self, linechart);
|
|
104
|
+
return DBL2NUM(ntcharts_linechart_view_max_x(linechart->handle));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static VALUE linechart_view_min_y(VALUE self) {
|
|
108
|
+
GET_LINECHART(self, linechart);
|
|
109
|
+
return DBL2NUM(ntcharts_linechart_view_min_y(linechart->handle));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static VALUE linechart_view_max_y(VALUE self) {
|
|
113
|
+
GET_LINECHART(self, linechart);
|
|
114
|
+
return DBL2NUM(ntcharts_linechart_view_max_y(linechart->handle));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static VALUE linechart_x_step(VALUE self) {
|
|
118
|
+
GET_LINECHART(self, linechart);
|
|
119
|
+
return INT2NUM(ntcharts_linechart_x_step(linechart->handle));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static VALUE linechart_y_step(VALUE self) {
|
|
123
|
+
GET_LINECHART(self, linechart);
|
|
124
|
+
return INT2NUM(ntcharts_linechart_y_step(linechart->handle));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static VALUE linechart_set_x_step(VALUE self, VALUE step) {
|
|
128
|
+
GET_LINECHART(self, linechart);
|
|
129
|
+
ntcharts_linechart_set_x_step(linechart->handle, NUM2INT(step));
|
|
130
|
+
return self;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static VALUE linechart_set_y_step(VALUE self, VALUE step) {
|
|
134
|
+
GET_LINECHART(self, linechart);
|
|
135
|
+
ntcharts_linechart_set_y_step(linechart->handle, NUM2INT(step));
|
|
136
|
+
return self;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static VALUE linechart_set_x_range(VALUE self, VALUE min_val, VALUE max_val) {
|
|
140
|
+
GET_LINECHART(self, linechart);
|
|
141
|
+
ntcharts_linechart_set_x_range(linechart->handle, NUM2DBL(min_val), NUM2DBL(max_val));
|
|
142
|
+
return self;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static VALUE linechart_set_y_range(VALUE self, VALUE min_val, VALUE max_val) {
|
|
146
|
+
GET_LINECHART(self, linechart);
|
|
147
|
+
ntcharts_linechart_set_y_range(linechart->handle, NUM2DBL(min_val), NUM2DBL(max_val));
|
|
148
|
+
return self;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static VALUE linechart_set_view_x_range(VALUE self, VALUE min_val, VALUE max_val) {
|
|
152
|
+
GET_LINECHART(self, linechart);
|
|
153
|
+
int result = ntcharts_linechart_set_view_x_range(linechart->handle, NUM2DBL(min_val), NUM2DBL(max_val));
|
|
154
|
+
return result ? Qtrue : Qfalse;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static VALUE linechart_set_view_y_range(VALUE self, VALUE min_val, VALUE max_val) {
|
|
158
|
+
GET_LINECHART(self, linechart);
|
|
159
|
+
int result = ntcharts_linechart_set_view_y_range(linechart->handle, NUM2DBL(min_val), NUM2DBL(max_val));
|
|
160
|
+
return result ? Qtrue : Qfalse;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static VALUE linechart_set_auto_x_range(VALUE self, VALUE auto_min, VALUE auto_max) {
|
|
164
|
+
GET_LINECHART(self, linechart);
|
|
165
|
+
ntcharts_linechart_set_auto_x_range(linechart->handle, RTEST(auto_min) ? 1 : 0, RTEST(auto_max) ? 1 : 0);
|
|
166
|
+
return self;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static VALUE linechart_set_auto_y_range(VALUE self, VALUE auto_min, VALUE auto_max) {
|
|
170
|
+
GET_LINECHART(self, linechart);
|
|
171
|
+
ntcharts_linechart_set_auto_y_range(linechart->handle, RTEST(auto_min) ? 1 : 0, RTEST(auto_max) ? 1 : 0);
|
|
172
|
+
return self;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static VALUE linechart_resize(VALUE self, VALUE width, VALUE height) {
|
|
176
|
+
GET_LINECHART(self, linechart);
|
|
177
|
+
ntcharts_linechart_resize(linechart->handle, NUM2INT(width), NUM2INT(height));
|
|
178
|
+
return self;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
static VALUE linechart_clear(VALUE self) {
|
|
182
|
+
GET_LINECHART(self, linechart);
|
|
183
|
+
ntcharts_linechart_clear(linechart->handle);
|
|
184
|
+
return self;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
static VALUE linechart_draw_axes(VALUE self) {
|
|
188
|
+
GET_LINECHART(self, linechart);
|
|
189
|
+
ntcharts_linechart_draw_axes(linechart->handle);
|
|
190
|
+
return self;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
static VALUE linechart_draw_rune(int argc, VALUE *argv, VALUE self) {
|
|
194
|
+
GET_LINECHART(self, linechart);
|
|
195
|
+
VALUE x, y, r, style;
|
|
196
|
+
rb_scan_args(argc, argv, "31", &x, &y, &r, &style);
|
|
197
|
+
|
|
198
|
+
int rune_val;
|
|
199
|
+
|
|
200
|
+
if (RB_TYPE_P(r, T_STRING)) {
|
|
201
|
+
const char *str = StringValueCStr(r);
|
|
202
|
+
rune_val = (unsigned char)str[0];
|
|
203
|
+
} else {
|
|
204
|
+
rune_val = NUM2INT(r);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (NIL_P(style)) {
|
|
208
|
+
ntcharts_linechart_draw_rune(linechart->handle, NUM2DBL(x), NUM2DBL(y), rune_val);
|
|
209
|
+
} else {
|
|
210
|
+
ntcharts_style_t *style_ptr;
|
|
211
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
212
|
+
ntcharts_linechart_draw_rune_with_style(linechart->handle, NUM2DBL(x), NUM2DBL(y), rune_val, style_ptr->handle);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return self;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
static VALUE linechart_draw_line(int argc, VALUE *argv, VALUE self) {
|
|
219
|
+
GET_LINECHART(self, linechart);
|
|
220
|
+
VALUE x1, y1, x2, y2, line_style, style;
|
|
221
|
+
rb_scan_args(argc, argv, "42", &x1, &y1, &x2, &y2, &line_style, &style);
|
|
222
|
+
|
|
223
|
+
int ls = NIL_P(line_style) ? 0 : NUM2INT(line_style);
|
|
224
|
+
|
|
225
|
+
if (NIL_P(style)) {
|
|
226
|
+
ntcharts_linechart_draw_line(linechart->handle,
|
|
227
|
+
NUM2DBL(x1), NUM2DBL(y1), NUM2DBL(x2), NUM2DBL(y2), ls);
|
|
228
|
+
} else {
|
|
229
|
+
ntcharts_style_t *style_ptr;
|
|
230
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
231
|
+
ntcharts_linechart_draw_line_with_style(linechart->handle,
|
|
232
|
+
NUM2DBL(x1), NUM2DBL(y1), NUM2DBL(x2), NUM2DBL(y2), ls, style_ptr->handle);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return self;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static VALUE linechart_draw_braille_line(int argc, VALUE *argv, VALUE self) {
|
|
239
|
+
GET_LINECHART(self, linechart);
|
|
240
|
+
VALUE x1, y1, x2, y2, style;
|
|
241
|
+
rb_scan_args(argc, argv, "41", &x1, &y1, &x2, &y2, &style);
|
|
242
|
+
|
|
243
|
+
if (NIL_P(style)) {
|
|
244
|
+
ntcharts_linechart_draw_braille_line(linechart->handle,
|
|
245
|
+
NUM2DBL(x1), NUM2DBL(y1), NUM2DBL(x2), NUM2DBL(y2));
|
|
246
|
+
} else {
|
|
247
|
+
ntcharts_style_t *style_ptr;
|
|
248
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
249
|
+
ntcharts_linechart_draw_braille_line_with_style(linechart->handle,
|
|
250
|
+
NUM2DBL(x1), NUM2DBL(y1), NUM2DBL(x2), NUM2DBL(y2), style_ptr->handle);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return self;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
static VALUE linechart_set_style(VALUE self, VALUE style) {
|
|
257
|
+
GET_LINECHART(self, linechart);
|
|
258
|
+
ntcharts_style_t *style_ptr;
|
|
259
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
260
|
+
ntcharts_linechart_set_style(linechart->handle, style_ptr->handle);
|
|
261
|
+
return self;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
static VALUE linechart_set_axis_style(VALUE self, VALUE style) {
|
|
265
|
+
GET_LINECHART(self, linechart);
|
|
266
|
+
ntcharts_style_t *style_ptr;
|
|
267
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
268
|
+
ntcharts_linechart_set_axis_style(linechart->handle, style_ptr->handle);
|
|
269
|
+
return self;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
static VALUE linechart_set_label_style(VALUE self, VALUE style) {
|
|
273
|
+
GET_LINECHART(self, linechart);
|
|
274
|
+
ntcharts_style_t *style_ptr;
|
|
275
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
276
|
+
ntcharts_linechart_set_label_style(linechart->handle, style_ptr->handle);
|
|
277
|
+
return self;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
static VALUE linechart_view(VALUE self) {
|
|
281
|
+
GET_LINECHART(self, linechart);
|
|
282
|
+
char *result = ntcharts_linechart_view(linechart->handle);
|
|
283
|
+
VALUE rb_result = rb_utf8_str_new_cstr(result);
|
|
284
|
+
ntcharts_free(result);
|
|
285
|
+
return rb_result;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
static VALUE linechart_to_s(VALUE self) {
|
|
289
|
+
return linechart_view(self);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
void Init_ntcharts_linechart(void) {
|
|
293
|
+
cLinechart = rb_define_class_under(mNtcharts, "Linechart", rb_cObject);
|
|
294
|
+
|
|
295
|
+
rb_define_alloc_func(cLinechart, linechart_alloc);
|
|
296
|
+
rb_define_method(cLinechart, "initialize", linechart_initialize, -1);
|
|
297
|
+
|
|
298
|
+
rb_define_method(cLinechart, "width", linechart_width, 0);
|
|
299
|
+
rb_define_method(cLinechart, "height", linechart_height, 0);
|
|
300
|
+
rb_define_method(cLinechart, "graph_width", linechart_graph_width, 0);
|
|
301
|
+
rb_define_method(cLinechart, "graph_height", linechart_graph_height, 0);
|
|
302
|
+
|
|
303
|
+
rb_define_method(cLinechart, "min_x", linechart_min_x, 0);
|
|
304
|
+
rb_define_method(cLinechart, "max_x", linechart_max_x, 0);
|
|
305
|
+
rb_define_method(cLinechart, "min_y", linechart_min_y, 0);
|
|
306
|
+
rb_define_method(cLinechart, "max_y", linechart_max_y, 0);
|
|
307
|
+
rb_define_method(cLinechart, "view_min_x", linechart_view_min_x, 0);
|
|
308
|
+
rb_define_method(cLinechart, "view_max_x", linechart_view_max_x, 0);
|
|
309
|
+
rb_define_method(cLinechart, "view_min_y", linechart_view_min_y, 0);
|
|
310
|
+
rb_define_method(cLinechart, "view_max_y", linechart_view_max_y, 0);
|
|
311
|
+
|
|
312
|
+
rb_define_method(cLinechart, "x_step", linechart_x_step, 0);
|
|
313
|
+
rb_define_method(cLinechart, "y_step", linechart_y_step, 0);
|
|
314
|
+
rb_define_method(cLinechart, "x_step=", linechart_set_x_step, 1);
|
|
315
|
+
rb_define_method(cLinechart, "y_step=", linechart_set_y_step, 1);
|
|
316
|
+
|
|
317
|
+
rb_define_method(cLinechart, "set_x_range", linechart_set_x_range, 2);
|
|
318
|
+
rb_define_method(cLinechart, "set_y_range", linechart_set_y_range, 2);
|
|
319
|
+
rb_define_method(cLinechart, "set_view_x_range", linechart_set_view_x_range, 2);
|
|
320
|
+
rb_define_method(cLinechart, "set_view_y_range", linechart_set_view_y_range, 2);
|
|
321
|
+
rb_define_method(cLinechart, "set_auto_x_range", linechart_set_auto_x_range, 2);
|
|
322
|
+
rb_define_method(cLinechart, "set_auto_y_range", linechart_set_auto_y_range, 2);
|
|
323
|
+
|
|
324
|
+
rb_define_method(cLinechart, "resize", linechart_resize, 2);
|
|
325
|
+
rb_define_method(cLinechart, "clear", linechart_clear, 0);
|
|
326
|
+
rb_define_method(cLinechart, "draw_axes", linechart_draw_axes, 0);
|
|
327
|
+
|
|
328
|
+
rb_define_method(cLinechart, "draw_rune", linechart_draw_rune, -1);
|
|
329
|
+
rb_define_method(cLinechart, "draw_line", linechart_draw_line, -1);
|
|
330
|
+
rb_define_method(cLinechart, "draw_braille_line", linechart_draw_braille_line, -1);
|
|
331
|
+
|
|
332
|
+
rb_define_method(cLinechart, "_set_style", linechart_set_style, 1);
|
|
333
|
+
rb_define_method(cLinechart, "_set_axis_style", linechart_set_axis_style, 1);
|
|
334
|
+
rb_define_method(cLinechart, "_set_label_style", linechart_set_label_style, 1);
|
|
335
|
+
|
|
336
|
+
rb_define_method(cLinechart, "view", linechart_view, 0);
|
|
337
|
+
rb_define_method(cLinechart, "to_s", linechart_to_s, 0);
|
|
338
|
+
|
|
339
|
+
rb_define_const(cLinechart, "LINE_STYLE_THIN", INT2NUM(0));
|
|
340
|
+
rb_define_const(cLinechart, "LINE_STYLE_ARC", INT2NUM(1));
|
|
341
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#include "extension.h"
|
|
2
|
+
|
|
3
|
+
static void sparkline_free(void *pointer) {
|
|
4
|
+
ntcharts_sparkline_t *sparkline = (ntcharts_sparkline_t *)pointer;
|
|
5
|
+
if (sparkline->handle != 0) {
|
|
6
|
+
ntcharts_sparkline_free(sparkline->handle);
|
|
7
|
+
}
|
|
8
|
+
xfree(sparkline);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static size_t sparkline_memsize(const void *pointer) {
|
|
12
|
+
return sizeof(ntcharts_sparkline_t);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const rb_data_type_t sparkline_type = {
|
|
16
|
+
.wrap_struct_name = "Ntcharts::Sparkline",
|
|
17
|
+
.function = {
|
|
18
|
+
.dmark = NULL,
|
|
19
|
+
.dfree = sparkline_free,
|
|
20
|
+
.dsize = sparkline_memsize,
|
|
21
|
+
},
|
|
22
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
static VALUE sparkline_alloc(VALUE klass) {
|
|
26
|
+
ntcharts_sparkline_t *sparkline = ALLOC(ntcharts_sparkline_t);
|
|
27
|
+
sparkline->handle = 0;
|
|
28
|
+
return TypedData_Wrap_Struct(klass, &sparkline_type, sparkline);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
VALUE sparkline_wrap(VALUE klass, unsigned long long handle) {
|
|
32
|
+
ntcharts_sparkline_t *sparkline = ALLOC(ntcharts_sparkline_t);
|
|
33
|
+
sparkline->handle = handle;
|
|
34
|
+
return TypedData_Wrap_Struct(klass, &sparkline_type, sparkline);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static VALUE sparkline_initialize(VALUE self, VALUE width, VALUE height) {
|
|
38
|
+
GET_SPARKLINE(self, sparkline);
|
|
39
|
+
sparkline->handle = ntcharts_sparkline_new(NUM2INT(width), NUM2INT(height));
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static VALUE sparkline_width(VALUE self) {
|
|
44
|
+
GET_SPARKLINE(self, sparkline);
|
|
45
|
+
return INT2NUM(ntcharts_sparkline_width(sparkline->handle));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static VALUE sparkline_height(VALUE self) {
|
|
49
|
+
GET_SPARKLINE(self, sparkline);
|
|
50
|
+
return INT2NUM(ntcharts_sparkline_height(sparkline->handle));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static VALUE sparkline_max_value(VALUE self) {
|
|
54
|
+
GET_SPARKLINE(self, sparkline);
|
|
55
|
+
return DBL2NUM(ntcharts_sparkline_max_value(sparkline->handle));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static VALUE sparkline_scale(VALUE self) {
|
|
59
|
+
GET_SPARKLINE(self, sparkline);
|
|
60
|
+
return DBL2NUM(ntcharts_sparkline_scale(sparkline->handle));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static VALUE sparkline_set_max(VALUE self, VALUE max_val) {
|
|
64
|
+
GET_SPARKLINE(self, sparkline);
|
|
65
|
+
ntcharts_sparkline_set_max(sparkline->handle, NUM2DBL(max_val));
|
|
66
|
+
return self;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static VALUE sparkline_set_style(VALUE self, VALUE style) {
|
|
70
|
+
GET_SPARKLINE(self, sparkline);
|
|
71
|
+
ntcharts_style_t *style_ptr;
|
|
72
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
73
|
+
ntcharts_sparkline_set_style(sparkline->handle, style_ptr->handle);
|
|
74
|
+
return self;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static VALUE sparkline_set_auto_max_value(VALUE self, VALUE auto_val) {
|
|
78
|
+
GET_SPARKLINE(self, sparkline);
|
|
79
|
+
ntcharts_sparkline_set_auto_max_value(sparkline->handle, RTEST(auto_val) ? 1 : 0);
|
|
80
|
+
return self;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static VALUE sparkline_resize(VALUE self, VALUE width, VALUE height) {
|
|
84
|
+
GET_SPARKLINE(self, sparkline);
|
|
85
|
+
ntcharts_sparkline_resize(sparkline->handle, NUM2INT(width), NUM2INT(height));
|
|
86
|
+
return self;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static VALUE sparkline_clear(VALUE self) {
|
|
90
|
+
GET_SPARKLINE(self, sparkline);
|
|
91
|
+
ntcharts_sparkline_clear(sparkline->handle);
|
|
92
|
+
return self;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static VALUE sparkline_push(VALUE self, VALUE value) {
|
|
96
|
+
GET_SPARKLINE(self, sparkline);
|
|
97
|
+
ntcharts_sparkline_push(sparkline->handle, NUM2DBL(value));
|
|
98
|
+
return self;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static VALUE sparkline_push_all(VALUE self, VALUE values) {
|
|
102
|
+
GET_SPARKLINE(self, sparkline);
|
|
103
|
+
Check_Type(values, T_ARRAY);
|
|
104
|
+
VALUE json_str = rb_funcall(values, rb_intern("to_json"), 0);
|
|
105
|
+
ntcharts_sparkline_push_all(sparkline->handle, StringValueCStr(json_str));
|
|
106
|
+
return self;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static VALUE sparkline_draw(VALUE self) {
|
|
110
|
+
GET_SPARKLINE(self, sparkline);
|
|
111
|
+
ntcharts_sparkline_draw(sparkline->handle);
|
|
112
|
+
return self;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static VALUE sparkline_draw_columns_only(VALUE self) {
|
|
116
|
+
GET_SPARKLINE(self, sparkline);
|
|
117
|
+
ntcharts_sparkline_draw_columns_only(sparkline->handle);
|
|
118
|
+
return self;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static VALUE sparkline_draw_braille(VALUE self) {
|
|
122
|
+
GET_SPARKLINE(self, sparkline);
|
|
123
|
+
ntcharts_sparkline_draw_braille(sparkline->handle);
|
|
124
|
+
return self;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static VALUE sparkline_view(VALUE self) {
|
|
128
|
+
GET_SPARKLINE(self, sparkline);
|
|
129
|
+
char *result = ntcharts_sparkline_view(sparkline->handle);
|
|
130
|
+
VALUE rb_result = rb_utf8_str_new_cstr(result);
|
|
131
|
+
ntcharts_free(result);
|
|
132
|
+
return rb_result;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static VALUE sparkline_to_s(VALUE self) {
|
|
136
|
+
return sparkline_view(self);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
void Init_ntcharts_sparkline(void) {
|
|
140
|
+
cSparkline = rb_define_class_under(mNtcharts, "Sparkline", rb_cObject);
|
|
141
|
+
|
|
142
|
+
rb_define_alloc_func(cSparkline, sparkline_alloc);
|
|
143
|
+
|
|
144
|
+
rb_define_method(cSparkline, "initialize", sparkline_initialize, 2);
|
|
145
|
+
rb_define_method(cSparkline, "width", sparkline_width, 0);
|
|
146
|
+
rb_define_method(cSparkline, "height", sparkline_height, 0);
|
|
147
|
+
rb_define_method(cSparkline, "max_value", sparkline_max_value, 0);
|
|
148
|
+
rb_define_method(cSparkline, "scale", sparkline_scale, 0);
|
|
149
|
+
rb_define_method(cSparkline, "max=", sparkline_set_max, 1);
|
|
150
|
+
rb_define_method(cSparkline, "_set_style", sparkline_set_style, 1);
|
|
151
|
+
rb_define_method(cSparkline, "auto_max_value=", sparkline_set_auto_max_value, 1);
|
|
152
|
+
rb_define_method(cSparkline, "resize", sparkline_resize, 2);
|
|
153
|
+
rb_define_method(cSparkline, "clear", sparkline_clear, 0);
|
|
154
|
+
rb_define_method(cSparkline, "push", sparkline_push, 1);
|
|
155
|
+
rb_define_method(cSparkline, "push_all", sparkline_push_all, 1);
|
|
156
|
+
rb_define_method(cSparkline, "draw", sparkline_draw, 0);
|
|
157
|
+
rb_define_method(cSparkline, "draw_columns_only", sparkline_draw_columns_only, 0);
|
|
158
|
+
rb_define_method(cSparkline, "draw_braille", sparkline_draw_braille, 0);
|
|
159
|
+
rb_define_method(cSparkline, "view", sparkline_view, 0);
|
|
160
|
+
rb_define_method(cSparkline, "to_s", sparkline_to_s, 0);
|
|
161
|
+
}
|