ntcharts 0.1.0-aarch64-linux-gnu
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_arm64/libntcharts.a +0 -0
- data/go/build/linux_arm64/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,248 @@
|
|
|
1
|
+
#include "extension.h"
|
|
2
|
+
|
|
3
|
+
static void wavelinechart_free(void *pointer) {
|
|
4
|
+
ntcharts_wavelinechart_t *chart = (ntcharts_wavelinechart_t *)pointer;
|
|
5
|
+
if (chart->handle != 0) {
|
|
6
|
+
ntcharts_wavelinechart_free(chart->handle);
|
|
7
|
+
}
|
|
8
|
+
xfree(chart);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static size_t wavelinechart_memsize(const void *pointer) {
|
|
12
|
+
return sizeof(ntcharts_wavelinechart_t);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const rb_data_type_t wavelinechart_type = {
|
|
16
|
+
.wrap_struct_name = "Ntcharts::Wavelinechart",
|
|
17
|
+
.function = {
|
|
18
|
+
.dmark = NULL,
|
|
19
|
+
.dfree = wavelinechart_free,
|
|
20
|
+
.dsize = wavelinechart_memsize,
|
|
21
|
+
},
|
|
22
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
static VALUE wavelinechart_alloc(VALUE klass) {
|
|
26
|
+
ntcharts_wavelinechart_t *chart = ALLOC(ntcharts_wavelinechart_t);
|
|
27
|
+
chart->handle = 0;
|
|
28
|
+
return TypedData_Wrap_Struct(klass, &wavelinechart_type, chart);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static VALUE wavelinechart_initialize(VALUE self, VALUE width, VALUE height) {
|
|
32
|
+
GET_WAVELINECHART(self, chart);
|
|
33
|
+
chart->handle = ntcharts_wavelinechart_new(NUM2INT(width), NUM2INT(height));
|
|
34
|
+
return self;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static VALUE wavelinechart_width(VALUE self) {
|
|
38
|
+
GET_WAVELINECHART(self, chart);
|
|
39
|
+
return INT2NUM(ntcharts_wavelinechart_width(chart->handle));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static VALUE wavelinechart_height(VALUE self) {
|
|
43
|
+
GET_WAVELINECHART(self, chart);
|
|
44
|
+
return INT2NUM(ntcharts_wavelinechart_height(chart->handle));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static VALUE wavelinechart_graph_width(VALUE self) {
|
|
48
|
+
GET_WAVELINECHART(self, chart);
|
|
49
|
+
return INT2NUM(ntcharts_wavelinechart_graph_width(chart->handle));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static VALUE wavelinechart_graph_height(VALUE self) {
|
|
53
|
+
GET_WAVELINECHART(self, chart);
|
|
54
|
+
return INT2NUM(ntcharts_wavelinechart_graph_height(chart->handle));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static VALUE wavelinechart_min_x(VALUE self) {
|
|
58
|
+
GET_WAVELINECHART(self, chart);
|
|
59
|
+
return DBL2NUM(ntcharts_wavelinechart_min_x(chart->handle));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static VALUE wavelinechart_max_x(VALUE self) {
|
|
63
|
+
GET_WAVELINECHART(self, chart);
|
|
64
|
+
return DBL2NUM(ntcharts_wavelinechart_max_x(chart->handle));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static VALUE wavelinechart_min_y(VALUE self) {
|
|
68
|
+
GET_WAVELINECHART(self, chart);
|
|
69
|
+
return DBL2NUM(ntcharts_wavelinechart_min_y(chart->handle));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static VALUE wavelinechart_max_y(VALUE self) {
|
|
73
|
+
GET_WAVELINECHART(self, chart);
|
|
74
|
+
return DBL2NUM(ntcharts_wavelinechart_max_y(chart->handle));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static VALUE wavelinechart_set_y_range(VALUE self, VALUE min_val, VALUE max_val) {
|
|
78
|
+
GET_WAVELINECHART(self, chart);
|
|
79
|
+
ntcharts_wavelinechart_set_y_range(chart->handle, NUM2DBL(min_val), NUM2DBL(max_val));
|
|
80
|
+
return self;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static VALUE wavelinechart_set_view_x_range(VALUE self, VALUE min_val, VALUE max_val) {
|
|
84
|
+
GET_WAVELINECHART(self, chart);
|
|
85
|
+
ntcharts_wavelinechart_set_view_x_range(chart->handle, NUM2DBL(min_val), NUM2DBL(max_val));
|
|
86
|
+
return self;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static VALUE wavelinechart_set_view_y_range(VALUE self, VALUE min_val, VALUE max_val) {
|
|
90
|
+
GET_WAVELINECHART(self, chart);
|
|
91
|
+
ntcharts_wavelinechart_set_view_y_range(chart->handle, NUM2DBL(min_val), NUM2DBL(max_val));
|
|
92
|
+
return self;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static VALUE wavelinechart_resize(VALUE self, VALUE width, VALUE height) {
|
|
96
|
+
GET_WAVELINECHART(self, chart);
|
|
97
|
+
ntcharts_wavelinechart_resize(chart->handle, NUM2INT(width), NUM2INT(height));
|
|
98
|
+
return self;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static VALUE wavelinechart_clear(VALUE self) {
|
|
102
|
+
GET_WAVELINECHART(self, chart);
|
|
103
|
+
ntcharts_wavelinechart_clear(chart->handle);
|
|
104
|
+
return self;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static VALUE wavelinechart_clear_all_data(VALUE self) {
|
|
108
|
+
GET_WAVELINECHART(self, chart);
|
|
109
|
+
ntcharts_wavelinechart_clear_all_data(chart->handle);
|
|
110
|
+
return self;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static VALUE wavelinechart_clear_data_set(VALUE self, VALUE name) {
|
|
114
|
+
GET_WAVELINECHART(self, chart);
|
|
115
|
+
ntcharts_wavelinechart_clear_data_set(chart->handle, StringValueCStr(name));
|
|
116
|
+
return self;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static VALUE wavelinechart_plot(VALUE self, VALUE x, VALUE y) {
|
|
120
|
+
GET_WAVELINECHART(self, chart);
|
|
121
|
+
ntcharts_wavelinechart_plot(chart->handle, NUM2DBL(x), NUM2DBL(y));
|
|
122
|
+
return self;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static VALUE wavelinechart_plot_data_set(VALUE self, VALUE name, VALUE x, VALUE y) {
|
|
126
|
+
GET_WAVELINECHART(self, chart);
|
|
127
|
+
ntcharts_wavelinechart_plot_data_set(chart->handle, StringValueCStr(name), NUM2DBL(x), NUM2DBL(y));
|
|
128
|
+
return self;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static VALUE wavelinechart_set_styles(VALUE self, VALUE line_style, VALUE style) {
|
|
132
|
+
GET_WAVELINECHART(self, chart);
|
|
133
|
+
ntcharts_style_t *style_ptr;
|
|
134
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
135
|
+
ntcharts_wavelinechart_set_styles(chart->handle, NUM2INT(line_style), style_ptr->handle);
|
|
136
|
+
return self;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static VALUE wavelinechart_set_data_set_styles(VALUE self, VALUE name, VALUE line_style, VALUE style) {
|
|
140
|
+
GET_WAVELINECHART(self, chart);
|
|
141
|
+
ntcharts_style_t *style_ptr;
|
|
142
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
143
|
+
ntcharts_wavelinechart_set_data_set_styles(chart->handle, StringValueCStr(name), NUM2INT(line_style), style_ptr->handle);
|
|
144
|
+
return self;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static VALUE wavelinechart_set_style(VALUE self, VALUE style) {
|
|
148
|
+
GET_WAVELINECHART(self, chart);
|
|
149
|
+
ntcharts_style_t *style_ptr;
|
|
150
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
151
|
+
ntcharts_wavelinechart_set_style(chart->handle, style_ptr->handle);
|
|
152
|
+
return self;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static VALUE wavelinechart_set_axis_style(VALUE self, VALUE style) {
|
|
156
|
+
GET_WAVELINECHART(self, chart);
|
|
157
|
+
ntcharts_style_t *style_ptr;
|
|
158
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
159
|
+
ntcharts_wavelinechart_set_axis_style(chart->handle, style_ptr->handle);
|
|
160
|
+
return self;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static VALUE wavelinechart_set_label_style(VALUE self, VALUE style) {
|
|
164
|
+
GET_WAVELINECHART(self, chart);
|
|
165
|
+
ntcharts_style_t *style_ptr;
|
|
166
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
167
|
+
ntcharts_wavelinechart_set_label_style(chart->handle, style_ptr->handle);
|
|
168
|
+
return self;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
static VALUE wavelinechart_draw(VALUE self) {
|
|
172
|
+
GET_WAVELINECHART(self, chart);
|
|
173
|
+
ntcharts_wavelinechart_draw(chart->handle);
|
|
174
|
+
return self;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static VALUE wavelinechart_draw_all(VALUE self) {
|
|
178
|
+
GET_WAVELINECHART(self, chart);
|
|
179
|
+
ntcharts_wavelinechart_draw_all(chart->handle);
|
|
180
|
+
return self;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
static VALUE wavelinechart_view(VALUE self) {
|
|
184
|
+
GET_WAVELINECHART(self, chart);
|
|
185
|
+
char *result = ntcharts_wavelinechart_view(chart->handle);
|
|
186
|
+
VALUE rb_result = rb_utf8_str_new_cstr(result);
|
|
187
|
+
ntcharts_free(result);
|
|
188
|
+
return rb_result;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
static VALUE wavelinechart_render(VALUE self) {
|
|
192
|
+
wavelinechart_draw(self);
|
|
193
|
+
return wavelinechart_view(self);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
static VALUE wavelinechart_render_all(VALUE self) {
|
|
197
|
+
wavelinechart_draw_all(self);
|
|
198
|
+
return wavelinechart_view(self);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
static VALUE wavelinechart_to_s(VALUE self) {
|
|
202
|
+
return wavelinechart_view(self);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
void Init_ntcharts_wavelinechart(void) {
|
|
206
|
+
cWavelinechart = rb_define_class_under(mNtcharts, "Wavelinechart", rb_cObject);
|
|
207
|
+
|
|
208
|
+
rb_define_alloc_func(cWavelinechart, wavelinechart_alloc);
|
|
209
|
+
rb_define_method(cWavelinechart, "initialize", wavelinechart_initialize, 2);
|
|
210
|
+
|
|
211
|
+
rb_define_method(cWavelinechart, "width", wavelinechart_width, 0);
|
|
212
|
+
rb_define_method(cWavelinechart, "height", wavelinechart_height, 0);
|
|
213
|
+
rb_define_method(cWavelinechart, "graph_width", wavelinechart_graph_width, 0);
|
|
214
|
+
rb_define_method(cWavelinechart, "graph_height", wavelinechart_graph_height, 0);
|
|
215
|
+
|
|
216
|
+
rb_define_method(cWavelinechart, "min_x", wavelinechart_min_x, 0);
|
|
217
|
+
rb_define_method(cWavelinechart, "max_x", wavelinechart_max_x, 0);
|
|
218
|
+
rb_define_method(cWavelinechart, "min_y", wavelinechart_min_y, 0);
|
|
219
|
+
rb_define_method(cWavelinechart, "max_y", wavelinechart_max_y, 0);
|
|
220
|
+
|
|
221
|
+
rb_define_method(cWavelinechart, "set_y_range", wavelinechart_set_y_range, 2);
|
|
222
|
+
rb_define_method(cWavelinechart, "set_view_x_range", wavelinechart_set_view_x_range, 2);
|
|
223
|
+
rb_define_method(cWavelinechart, "set_view_y_range", wavelinechart_set_view_y_range, 2);
|
|
224
|
+
|
|
225
|
+
rb_define_method(cWavelinechart, "resize", wavelinechart_resize, 2);
|
|
226
|
+
rb_define_method(cWavelinechart, "clear", wavelinechart_clear, 0);
|
|
227
|
+
rb_define_method(cWavelinechart, "clear_all_data", wavelinechart_clear_all_data, 0);
|
|
228
|
+
rb_define_method(cWavelinechart, "clear_data_set", wavelinechart_clear_data_set, 1);
|
|
229
|
+
|
|
230
|
+
rb_define_method(cWavelinechart, "plot", wavelinechart_plot, 2);
|
|
231
|
+
rb_define_method(cWavelinechart, "plot_data_set", wavelinechart_plot_data_set, 3);
|
|
232
|
+
|
|
233
|
+
rb_define_method(cWavelinechart, "set_styles", wavelinechart_set_styles, 2);
|
|
234
|
+
rb_define_method(cWavelinechart, "set_data_set_styles", wavelinechart_set_data_set_styles, 3);
|
|
235
|
+
rb_define_method(cWavelinechart, "_set_style", wavelinechart_set_style, 1);
|
|
236
|
+
rb_define_method(cWavelinechart, "_set_axis_style", wavelinechart_set_axis_style, 1);
|
|
237
|
+
rb_define_method(cWavelinechart, "_set_label_style", wavelinechart_set_label_style, 1);
|
|
238
|
+
|
|
239
|
+
rb_define_method(cWavelinechart, "draw", wavelinechart_draw, 0);
|
|
240
|
+
rb_define_method(cWavelinechart, "draw_all", wavelinechart_draw_all, 0);
|
|
241
|
+
rb_define_method(cWavelinechart, "view", wavelinechart_view, 0);
|
|
242
|
+
rb_define_method(cWavelinechart, "render", wavelinechart_render, 0);
|
|
243
|
+
rb_define_method(cWavelinechart, "render_all", wavelinechart_render_all, 0);
|
|
244
|
+
rb_define_method(cWavelinechart, "to_s", wavelinechart_to_s, 0);
|
|
245
|
+
|
|
246
|
+
rb_define_const(cWavelinechart, "LINE_STYLE_THIN", INT2NUM(0));
|
|
247
|
+
rb_define_const(cWavelinechart, "LINE_STYLE_ARC", INT2NUM(1));
|
|
248
|
+
}
|
data/go/barchart.go
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import "C"
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"encoding/json"
|
|
7
|
+
"github.com/NimbleMarkets/ntcharts/barchart"
|
|
8
|
+
"github.com/charmbracelet/lipgloss"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
type BarValueJSON struct {
|
|
12
|
+
Name string `json:"name"`
|
|
13
|
+
Value float64 `json:"value"`
|
|
14
|
+
StyleHandle uint64 `json:"style_handle,omitempty"`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type BarDataJSON struct {
|
|
18
|
+
Label string `json:"label"`
|
|
19
|
+
Values []BarValueJSON `json:"values"`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
func parseBarData(jsonStr string) barchart.BarData {
|
|
23
|
+
var data BarDataJSON
|
|
24
|
+
|
|
25
|
+
if err := json.Unmarshal([]byte(jsonStr), &data); err != nil {
|
|
26
|
+
return barchart.BarData{}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
barData := barchart.BarData{Label: data.Label}
|
|
30
|
+
|
|
31
|
+
for _, v := range data.Values {
|
|
32
|
+
style := lipgloss.NewStyle()
|
|
33
|
+
|
|
34
|
+
if v.StyleHandle != 0 {
|
|
35
|
+
if s, ok := getStyle(v.StyleHandle); ok {
|
|
36
|
+
style = s
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
barValue := barchart.BarValue{
|
|
41
|
+
Name: v.Name,
|
|
42
|
+
Value: v.Value,
|
|
43
|
+
Style: style,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
barData.Values = append(barData.Values, barValue)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return barData
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//export ntcharts_barchart_new
|
|
53
|
+
func ntcharts_barchart_new(width C.int, height C.int) C.ulonglong {
|
|
54
|
+
b := barchart.New(int(width), int(height))
|
|
55
|
+
return C.ulonglong(allocBarchart(&b))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//export ntcharts_barchart_free
|
|
59
|
+
func ntcharts_barchart_free(id C.ulonglong) {
|
|
60
|
+
freeBarchart(uint64(id))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//export ntcharts_barchart_width
|
|
64
|
+
func ntcharts_barchart_width(id C.ulonglong) C.int {
|
|
65
|
+
b := getBarchart(uint64(id))
|
|
66
|
+
|
|
67
|
+
if b == nil {
|
|
68
|
+
return 0
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return C.int(b.Width())
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//export ntcharts_barchart_height
|
|
75
|
+
func ntcharts_barchart_height(id C.ulonglong) C.int {
|
|
76
|
+
b := getBarchart(uint64(id))
|
|
77
|
+
|
|
78
|
+
if b == nil {
|
|
79
|
+
return 0
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return C.int(b.Height())
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
//export ntcharts_barchart_max_value
|
|
86
|
+
func ntcharts_barchart_max_value(id C.ulonglong) C.double {
|
|
87
|
+
b := getBarchart(uint64(id))
|
|
88
|
+
|
|
89
|
+
if b == nil {
|
|
90
|
+
return 0
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return C.double(b.MaxValue())
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//export ntcharts_barchart_scale
|
|
97
|
+
func ntcharts_barchart_scale(id C.ulonglong) C.double {
|
|
98
|
+
b := getBarchart(uint64(id))
|
|
99
|
+
|
|
100
|
+
if b == nil {
|
|
101
|
+
return 0
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return C.double(b.Scale())
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//export ntcharts_barchart_bar_width
|
|
108
|
+
func ntcharts_barchart_bar_width(id C.ulonglong) C.int {
|
|
109
|
+
b := getBarchart(uint64(id))
|
|
110
|
+
|
|
111
|
+
if b == nil {
|
|
112
|
+
return 0
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return C.int(b.BarWidth())
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//export ntcharts_barchart_bar_gap
|
|
119
|
+
func ntcharts_barchart_bar_gap(id C.ulonglong) C.int {
|
|
120
|
+
b := getBarchart(uint64(id))
|
|
121
|
+
|
|
122
|
+
if b == nil {
|
|
123
|
+
return 0
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return C.int(b.BarGap())
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//export ntcharts_barchart_show_axis
|
|
130
|
+
func ntcharts_barchart_show_axis(id C.ulonglong) C.int {
|
|
131
|
+
b := getBarchart(uint64(id))
|
|
132
|
+
|
|
133
|
+
if b == nil {
|
|
134
|
+
return 0
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if b.ShowAxis() {
|
|
138
|
+
return 1
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return 0
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
//export ntcharts_barchart_horizontal
|
|
145
|
+
func ntcharts_barchart_horizontal(id C.ulonglong) C.int {
|
|
146
|
+
b := getBarchart(uint64(id))
|
|
147
|
+
|
|
148
|
+
if b == nil {
|
|
149
|
+
return 0
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if b.Horizontal() {
|
|
153
|
+
return 1
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return 0
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//export ntcharts_barchart_set_max
|
|
160
|
+
func ntcharts_barchart_set_max(id C.ulonglong, maxVal C.double) {
|
|
161
|
+
b := getBarchart(uint64(id))
|
|
162
|
+
|
|
163
|
+
if b == nil {
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
b.SetMax(float64(maxVal))
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
//export ntcharts_barchart_set_bar_width
|
|
171
|
+
func ntcharts_barchart_set_bar_width(id C.ulonglong, width C.int) {
|
|
172
|
+
b := getBarchart(uint64(id))
|
|
173
|
+
|
|
174
|
+
if b == nil {
|
|
175
|
+
return
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
b.AutoBarWidth = false
|
|
179
|
+
b.SetBarWidth(int(width))
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
//export ntcharts_barchart_set_bar_gap
|
|
183
|
+
func ntcharts_barchart_set_bar_gap(id C.ulonglong, gap C.int) {
|
|
184
|
+
b := getBarchart(uint64(id))
|
|
185
|
+
|
|
186
|
+
if b == nil {
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
b.SetBarGap(int(gap))
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
//export ntcharts_barchart_set_horizontal
|
|
194
|
+
func ntcharts_barchart_set_horizontal(id C.ulonglong, horizontal C.int) {
|
|
195
|
+
b := getBarchart(uint64(id))
|
|
196
|
+
|
|
197
|
+
if b == nil {
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
b.SetHorizontal(horizontal != 0)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
//export ntcharts_barchart_set_show_axis
|
|
205
|
+
func ntcharts_barchart_set_show_axis(id C.ulonglong, showAxis C.int) {
|
|
206
|
+
b := getBarchart(uint64(id))
|
|
207
|
+
|
|
208
|
+
if b == nil {
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
b.SetShowAxis(showAxis != 0)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
//export ntcharts_barchart_set_auto_max_value
|
|
216
|
+
func ntcharts_barchart_set_auto_max_value(id C.ulonglong, autoMax C.int) {
|
|
217
|
+
b := getBarchart(uint64(id))
|
|
218
|
+
|
|
219
|
+
if b == nil {
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
b.AutoMaxValue = autoMax != 0
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
//export ntcharts_barchart_set_auto_bar_width
|
|
227
|
+
func ntcharts_barchart_set_auto_bar_width(id C.ulonglong, autoWidth C.int) {
|
|
228
|
+
b := getBarchart(uint64(id))
|
|
229
|
+
|
|
230
|
+
if b == nil {
|
|
231
|
+
return
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
b.AutoBarWidth = autoWidth != 0
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
//export ntcharts_barchart_set_axis_style
|
|
238
|
+
func ntcharts_barchart_set_axis_style(id C.ulonglong, styleID C.ulonglong) {
|
|
239
|
+
b := getBarchart(uint64(id))
|
|
240
|
+
|
|
241
|
+
if b == nil {
|
|
242
|
+
return
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if style, ok := getStyle(uint64(styleID)); ok {
|
|
246
|
+
b.AxisStyle = style
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
//export ntcharts_barchart_set_label_style
|
|
251
|
+
func ntcharts_barchart_set_label_style(id C.ulonglong, styleID C.ulonglong) {
|
|
252
|
+
b := getBarchart(uint64(id))
|
|
253
|
+
|
|
254
|
+
if b == nil {
|
|
255
|
+
return
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if style, ok := getStyle(uint64(styleID)); ok {
|
|
259
|
+
b.LabelStyle = style
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
//export ntcharts_barchart_resize
|
|
264
|
+
func ntcharts_barchart_resize(id C.ulonglong, width C.int, height C.int) {
|
|
265
|
+
b := getBarchart(uint64(id))
|
|
266
|
+
|
|
267
|
+
if b == nil {
|
|
268
|
+
return
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
b.Resize(int(width), int(height))
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
//export ntcharts_barchart_clear
|
|
275
|
+
func ntcharts_barchart_clear(id C.ulonglong) {
|
|
276
|
+
b := getBarchart(uint64(id))
|
|
277
|
+
|
|
278
|
+
if b == nil {
|
|
279
|
+
return
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
b.Clear()
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
//export ntcharts_barchart_push
|
|
286
|
+
func ntcharts_barchart_push(id C.ulonglong, barDataJSON *C.char) {
|
|
287
|
+
b := getBarchart(uint64(id))
|
|
288
|
+
|
|
289
|
+
if b == nil {
|
|
290
|
+
return
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
barData := parseBarData(C.GoString(barDataJSON))
|
|
294
|
+
b.Push(barData)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
//export ntcharts_barchart_push_all
|
|
298
|
+
func ntcharts_barchart_push_all(id C.ulonglong, barDataArrayJSON *C.char) {
|
|
299
|
+
b := getBarchart(uint64(id))
|
|
300
|
+
|
|
301
|
+
if b == nil {
|
|
302
|
+
return
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
var dataArray []BarDataJSON
|
|
306
|
+
|
|
307
|
+
if err := json.Unmarshal([]byte(C.GoString(barDataArrayJSON)), &dataArray); err != nil {
|
|
308
|
+
return
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
for _, data := range dataArray {
|
|
312
|
+
barData := barchart.BarData{Label: data.Label}
|
|
313
|
+
|
|
314
|
+
for _, v := range data.Values {
|
|
315
|
+
style := lipgloss.NewStyle()
|
|
316
|
+
|
|
317
|
+
if v.StyleHandle != 0 {
|
|
318
|
+
if s, ok := getStyle(v.StyleHandle); ok {
|
|
319
|
+
style = s
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
barValue := barchart.BarValue{
|
|
324
|
+
Name: v.Name,
|
|
325
|
+
Value: v.Value,
|
|
326
|
+
Style: style,
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
barData.Values = append(barData.Values, barValue)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
b.Push(barData)
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
//export ntcharts_barchart_draw
|
|
337
|
+
func ntcharts_barchart_draw(id C.ulonglong) {
|
|
338
|
+
b := getBarchart(uint64(id))
|
|
339
|
+
|
|
340
|
+
if b == nil {
|
|
341
|
+
return
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
b.Draw()
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
//export ntcharts_barchart_view
|
|
348
|
+
func ntcharts_barchart_view(id C.ulonglong) *C.char {
|
|
349
|
+
b := getBarchart(uint64(id))
|
|
350
|
+
|
|
351
|
+
if b == nil {
|
|
352
|
+
return C.CString("")
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return C.CString(b.View())
|
|
356
|
+
}
|
|
Binary file
|