ntcharts 0.1.0-arm64-darwin
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/darwin_arm64/libntcharts.a +0 -0
- data/go/build/darwin_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.bundle +0 -0
- data/lib/ntcharts/3.3/ntcharts.bundle +0 -0
- data/lib/ntcharts/3.4/ntcharts.bundle +0 -0
- data/lib/ntcharts/4.0/ntcharts.bundle +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
data/go/linechart.go
ADDED
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
*/
|
|
6
|
+
import "C"
|
|
7
|
+
|
|
8
|
+
import (
|
|
9
|
+
"github.com/NimbleMarkets/ntcharts/canvas"
|
|
10
|
+
"github.com/NimbleMarkets/ntcharts/canvas/runes"
|
|
11
|
+
"github.com/NimbleMarkets/ntcharts/linechart"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
//export ntcharts_linechart_new
|
|
15
|
+
func ntcharts_linechart_new(width C.int, height C.int, minX C.double, maxX C.double, minY C.double, maxY C.double) C.ulonglong {
|
|
16
|
+
m := linechart.New(int(width), int(height), float64(minX), float64(maxX), float64(minY), float64(maxY))
|
|
17
|
+
return C.ulonglong(allocLinechart(&m))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//export ntcharts_linechart_new_with_auto_range
|
|
21
|
+
func ntcharts_linechart_new_with_auto_range(width C.int, height C.int) C.ulonglong {
|
|
22
|
+
m := linechart.New(int(width), int(height), 0, 1, 0, 1, linechart.WithAutoXYRange())
|
|
23
|
+
return C.ulonglong(allocLinechart(&m))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//export ntcharts_linechart_free
|
|
27
|
+
func ntcharts_linechart_free(id C.ulonglong) {
|
|
28
|
+
freeLinechart(uint64(id))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//export ntcharts_linechart_width
|
|
32
|
+
func ntcharts_linechart_width(id C.ulonglong) C.int {
|
|
33
|
+
l := getLinechart(uint64(id))
|
|
34
|
+
if l == nil {
|
|
35
|
+
return 0
|
|
36
|
+
}
|
|
37
|
+
return C.int(l.Width())
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//export ntcharts_linechart_height
|
|
41
|
+
func ntcharts_linechart_height(id C.ulonglong) C.int {
|
|
42
|
+
l := getLinechart(uint64(id))
|
|
43
|
+
|
|
44
|
+
if l == nil {
|
|
45
|
+
return 0
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return C.int(l.Height())
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//export ntcharts_linechart_graph_width
|
|
52
|
+
func ntcharts_linechart_graph_width(id C.ulonglong) C.int {
|
|
53
|
+
l := getLinechart(uint64(id))
|
|
54
|
+
|
|
55
|
+
if l == nil {
|
|
56
|
+
return 0
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return C.int(l.GraphWidth())
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//export ntcharts_linechart_graph_height
|
|
63
|
+
func ntcharts_linechart_graph_height(id C.ulonglong) C.int {
|
|
64
|
+
l := getLinechart(uint64(id))
|
|
65
|
+
|
|
66
|
+
if l == nil {
|
|
67
|
+
return 0
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return C.int(l.GraphHeight())
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//export ntcharts_linechart_min_x
|
|
74
|
+
func ntcharts_linechart_min_x(id C.ulonglong) C.double {
|
|
75
|
+
l := getLinechart(uint64(id))
|
|
76
|
+
|
|
77
|
+
if l == nil {
|
|
78
|
+
return 0
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return C.double(l.MinX())
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//export ntcharts_linechart_max_x
|
|
85
|
+
func ntcharts_linechart_max_x(id C.ulonglong) C.double {
|
|
86
|
+
l := getLinechart(uint64(id))
|
|
87
|
+
|
|
88
|
+
if l == nil {
|
|
89
|
+
return 0
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return C.double(l.MaxX())
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//export ntcharts_linechart_min_y
|
|
96
|
+
func ntcharts_linechart_min_y(id C.ulonglong) C.double {
|
|
97
|
+
l := getLinechart(uint64(id))
|
|
98
|
+
|
|
99
|
+
if l == nil {
|
|
100
|
+
return 0
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return C.double(l.MinY())
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//export ntcharts_linechart_max_y
|
|
107
|
+
func ntcharts_linechart_max_y(id C.ulonglong) C.double {
|
|
108
|
+
l := getLinechart(uint64(id))
|
|
109
|
+
|
|
110
|
+
if l == nil {
|
|
111
|
+
return 0
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return C.double(l.MaxY())
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
//export ntcharts_linechart_view_min_x
|
|
118
|
+
func ntcharts_linechart_view_min_x(id C.ulonglong) C.double {
|
|
119
|
+
l := getLinechart(uint64(id))
|
|
120
|
+
|
|
121
|
+
if l == nil {
|
|
122
|
+
return 0
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return C.double(l.ViewMinX())
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
//export ntcharts_linechart_view_max_x
|
|
129
|
+
func ntcharts_linechart_view_max_x(id C.ulonglong) C.double {
|
|
130
|
+
l := getLinechart(uint64(id))
|
|
131
|
+
|
|
132
|
+
if l == nil {
|
|
133
|
+
return 0
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return C.double(l.ViewMaxX())
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//export ntcharts_linechart_view_min_y
|
|
140
|
+
func ntcharts_linechart_view_min_y(id C.ulonglong) C.double {
|
|
141
|
+
l := getLinechart(uint64(id))
|
|
142
|
+
|
|
143
|
+
if l == nil {
|
|
144
|
+
return 0
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return C.double(l.ViewMinY())
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//export ntcharts_linechart_view_max_y
|
|
151
|
+
func ntcharts_linechart_view_max_y(id C.ulonglong) C.double {
|
|
152
|
+
l := getLinechart(uint64(id))
|
|
153
|
+
|
|
154
|
+
if l == nil {
|
|
155
|
+
return 0
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return C.double(l.ViewMaxY())
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//export ntcharts_linechart_x_step
|
|
162
|
+
func ntcharts_linechart_x_step(id C.ulonglong) C.int {
|
|
163
|
+
l := getLinechart(uint64(id))
|
|
164
|
+
|
|
165
|
+
if l == nil {
|
|
166
|
+
return 0
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return C.int(l.XStep())
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//export ntcharts_linechart_y_step
|
|
173
|
+
func ntcharts_linechart_y_step(id C.ulonglong) C.int {
|
|
174
|
+
l := getLinechart(uint64(id))
|
|
175
|
+
|
|
176
|
+
if l == nil {
|
|
177
|
+
return 0
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return C.int(l.YStep())
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
//export ntcharts_linechart_set_x_step
|
|
184
|
+
func ntcharts_linechart_set_x_step(id C.ulonglong, step C.int) {
|
|
185
|
+
l := getLinechart(uint64(id))
|
|
186
|
+
|
|
187
|
+
if l != nil {
|
|
188
|
+
l.SetXStep(int(step))
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//export ntcharts_linechart_set_y_step
|
|
193
|
+
func ntcharts_linechart_set_y_step(id C.ulonglong, step C.int) {
|
|
194
|
+
l := getLinechart(uint64(id))
|
|
195
|
+
|
|
196
|
+
if l != nil {
|
|
197
|
+
l.SetYStep(int(step))
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
//export ntcharts_linechart_set_x_range
|
|
202
|
+
func ntcharts_linechart_set_x_range(id C.ulonglong, minVal C.double, maxVal C.double) {
|
|
203
|
+
l := getLinechart(uint64(id))
|
|
204
|
+
|
|
205
|
+
if l != nil {
|
|
206
|
+
l.SetXRange(float64(minVal), float64(maxVal))
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
//export ntcharts_linechart_set_y_range
|
|
211
|
+
func ntcharts_linechart_set_y_range(id C.ulonglong, minVal C.double, maxVal C.double) {
|
|
212
|
+
l := getLinechart(uint64(id))
|
|
213
|
+
|
|
214
|
+
if l != nil {
|
|
215
|
+
l.SetYRange(float64(minVal), float64(maxVal))
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
//export ntcharts_linechart_set_view_x_range
|
|
220
|
+
func ntcharts_linechart_set_view_x_range(id C.ulonglong, minVal C.double, maxVal C.double) C.int {
|
|
221
|
+
l := getLinechart(uint64(id))
|
|
222
|
+
|
|
223
|
+
if l != nil && l.SetViewXRange(float64(minVal), float64(maxVal)) {
|
|
224
|
+
return 1
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return 0
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
//export ntcharts_linechart_set_view_y_range
|
|
231
|
+
func ntcharts_linechart_set_view_y_range(id C.ulonglong, minVal C.double, maxVal C.double) C.int {
|
|
232
|
+
l := getLinechart(uint64(id))
|
|
233
|
+
|
|
234
|
+
if l != nil && l.SetViewYRange(float64(minVal), float64(maxVal)) {
|
|
235
|
+
return 1
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return 0
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
//export ntcharts_linechart_set_auto_x_range
|
|
242
|
+
func ntcharts_linechart_set_auto_x_range(id C.ulonglong, autoMin C.int, autoMax C.int) {
|
|
243
|
+
l := getLinechart(uint64(id))
|
|
244
|
+
|
|
245
|
+
if l != nil {
|
|
246
|
+
l.AutoMinX = autoMin != 0
|
|
247
|
+
l.AutoMaxX = autoMax != 0
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
//export ntcharts_linechart_set_auto_y_range
|
|
252
|
+
func ntcharts_linechart_set_auto_y_range(id C.ulonglong, autoMin C.int, autoMax C.int) {
|
|
253
|
+
l := getLinechart(uint64(id))
|
|
254
|
+
if l != nil {
|
|
255
|
+
l.AutoMinY = autoMin != 0
|
|
256
|
+
l.AutoMaxY = autoMax != 0
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
//export ntcharts_linechart_resize
|
|
261
|
+
func ntcharts_linechart_resize(id C.ulonglong, width C.int, height C.int) {
|
|
262
|
+
l := getLinechart(uint64(id))
|
|
263
|
+
|
|
264
|
+
if l != nil {
|
|
265
|
+
l.Resize(int(width), int(height))
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
//export ntcharts_linechart_clear
|
|
270
|
+
func ntcharts_linechart_clear(id C.ulonglong) {
|
|
271
|
+
l := getLinechart(uint64(id))
|
|
272
|
+
|
|
273
|
+
if l != nil {
|
|
274
|
+
l.Clear()
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
//export ntcharts_linechart_draw_axes
|
|
279
|
+
func ntcharts_linechart_draw_axes(id C.ulonglong) {
|
|
280
|
+
l := getLinechart(uint64(id))
|
|
281
|
+
|
|
282
|
+
if l != nil {
|
|
283
|
+
l.DrawXYAxisAndLabel()
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
//export ntcharts_linechart_draw_rune
|
|
288
|
+
func ntcharts_linechart_draw_rune(id C.ulonglong, x C.double, y C.double, r C.int) {
|
|
289
|
+
l := getLinechart(uint64(id))
|
|
290
|
+
|
|
291
|
+
if l != nil {
|
|
292
|
+
l.DrawRune(canvas.Float64Point{X: float64(x), Y: float64(y)}, rune(r))
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
//export ntcharts_linechart_draw_rune_with_style
|
|
297
|
+
func ntcharts_linechart_draw_rune_with_style(id C.ulonglong, x C.double, y C.double, r C.int, styleID C.ulonglong) {
|
|
298
|
+
l := getLinechart(uint64(id))
|
|
299
|
+
|
|
300
|
+
if l == nil {
|
|
301
|
+
return
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
s, ok := getStyle(uint64(styleID))
|
|
305
|
+
|
|
306
|
+
if !ok {
|
|
307
|
+
l.DrawRune(canvas.Float64Point{X: float64(x), Y: float64(y)}, rune(r))
|
|
308
|
+
return
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
l.DrawRuneWithStyle(canvas.Float64Point{X: float64(x), Y: float64(y)}, rune(r), s)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
//export ntcharts_linechart_draw_line
|
|
315
|
+
func ntcharts_linechart_draw_line(id C.ulonglong, x1 C.double, y1 C.double, x2 C.double, y2 C.double, lineStyle C.int) {
|
|
316
|
+
l := getLinechart(uint64(id))
|
|
317
|
+
|
|
318
|
+
if l != nil {
|
|
319
|
+
ls := getLineStyle(int(lineStyle))
|
|
320
|
+
l.DrawLine(canvas.Float64Point{X: float64(x1), Y: float64(y1)}, canvas.Float64Point{X: float64(x2), Y: float64(y2)}, ls)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
//export ntcharts_linechart_draw_line_with_style
|
|
325
|
+
func ntcharts_linechart_draw_line_with_style(id C.ulonglong, x1 C.double, y1 C.double, x2 C.double, y2 C.double, lineStyle C.int, styleID C.ulonglong) {
|
|
326
|
+
l := getLinechart(uint64(id))
|
|
327
|
+
|
|
328
|
+
if l == nil {
|
|
329
|
+
return
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
ls := getLineStyle(int(lineStyle))
|
|
333
|
+
|
|
334
|
+
s, ok := getStyle(uint64(styleID))
|
|
335
|
+
|
|
336
|
+
if !ok {
|
|
337
|
+
l.DrawLine(canvas.Float64Point{X: float64(x1), Y: float64(y1)}, canvas.Float64Point{X: float64(x2), Y: float64(y2)}, ls)
|
|
338
|
+
return
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
l.DrawLineWithStyle(canvas.Float64Point{X: float64(x1), Y: float64(y1)}, canvas.Float64Point{X: float64(x2), Y: float64(y2)}, ls, s)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
//export ntcharts_linechart_draw_braille_line
|
|
345
|
+
func ntcharts_linechart_draw_braille_line(id C.ulonglong, x1 C.double, y1 C.double, x2 C.double, y2 C.double) {
|
|
346
|
+
l := getLinechart(uint64(id))
|
|
347
|
+
|
|
348
|
+
if l != nil {
|
|
349
|
+
l.DrawBrailleLine(canvas.Float64Point{X: float64(x1), Y: float64(y1)}, canvas.Float64Point{X: float64(x2), Y: float64(y2)})
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
//export ntcharts_linechart_draw_braille_line_with_style
|
|
354
|
+
func ntcharts_linechart_draw_braille_line_with_style(id C.ulonglong, x1 C.double, y1 C.double, x2 C.double, y2 C.double, styleID C.ulonglong) {
|
|
355
|
+
l := getLinechart(uint64(id))
|
|
356
|
+
|
|
357
|
+
if l == nil {
|
|
358
|
+
return
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
s, ok := getStyle(uint64(styleID))
|
|
362
|
+
|
|
363
|
+
if !ok {
|
|
364
|
+
l.DrawBrailleLine(canvas.Float64Point{X: float64(x1), Y: float64(y1)}, canvas.Float64Point{X: float64(x2), Y: float64(y2)})
|
|
365
|
+
return
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
l.DrawBrailleLineWithStyle(canvas.Float64Point{X: float64(x1), Y: float64(y1)}, canvas.Float64Point{X: float64(x2), Y: float64(y2)}, s)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
//export ntcharts_linechart_set_style
|
|
372
|
+
func ntcharts_linechart_set_style(id C.ulonglong, styleID C.ulonglong) {
|
|
373
|
+
l := getLinechart(uint64(id))
|
|
374
|
+
|
|
375
|
+
if l == nil {
|
|
376
|
+
return
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
s, ok := getStyle(uint64(styleID))
|
|
380
|
+
|
|
381
|
+
if ok {
|
|
382
|
+
l.Style = s
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
//export ntcharts_linechart_set_axis_style
|
|
387
|
+
func ntcharts_linechart_set_axis_style(id C.ulonglong, styleID C.ulonglong) {
|
|
388
|
+
l := getLinechart(uint64(id))
|
|
389
|
+
|
|
390
|
+
if l == nil {
|
|
391
|
+
return
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
s, ok := getStyle(uint64(styleID))
|
|
395
|
+
|
|
396
|
+
if ok {
|
|
397
|
+
l.AxisStyle = s
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
//export ntcharts_linechart_set_label_style
|
|
402
|
+
func ntcharts_linechart_set_label_style(id C.ulonglong, styleID C.ulonglong) {
|
|
403
|
+
l := getLinechart(uint64(id))
|
|
404
|
+
|
|
405
|
+
if l == nil {
|
|
406
|
+
return
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
s, ok := getStyle(uint64(styleID))
|
|
410
|
+
|
|
411
|
+
if ok {
|
|
412
|
+
l.LabelStyle = s
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
//export ntcharts_linechart_view
|
|
417
|
+
func ntcharts_linechart_view(id C.ulonglong) *C.char {
|
|
418
|
+
l := getLinechart(uint64(id))
|
|
419
|
+
|
|
420
|
+
if l == nil {
|
|
421
|
+
return C.CString("")
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return C.CString(l.View())
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const (
|
|
428
|
+
LineStyleThin = 0
|
|
429
|
+
LineStyleArc = 1
|
|
430
|
+
)
|
|
431
|
+
|
|
432
|
+
func getLineStyle(style int) runes.LineStyle {
|
|
433
|
+
switch style {
|
|
434
|
+
case LineStyleThin:
|
|
435
|
+
return runes.ThinLineStyle
|
|
436
|
+
case LineStyleArc:
|
|
437
|
+
return runes.ArcLineStyle
|
|
438
|
+
default:
|
|
439
|
+
return runes.ThinLineStyle
|
|
440
|
+
}
|
|
441
|
+
}
|
data/go/ntcharts.go
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
*/
|
|
6
|
+
import "C"
|
|
7
|
+
|
|
8
|
+
import (
|
|
9
|
+
"runtime/debug"
|
|
10
|
+
"sync"
|
|
11
|
+
"unsafe"
|
|
12
|
+
"github.com/NimbleMarkets/ntcharts/barchart"
|
|
13
|
+
"github.com/NimbleMarkets/ntcharts/linechart"
|
|
14
|
+
"github.com/NimbleMarkets/ntcharts/linechart/streamlinechart"
|
|
15
|
+
"github.com/NimbleMarkets/ntcharts/linechart/timeserieslinechart"
|
|
16
|
+
"github.com/NimbleMarkets/ntcharts/linechart/wavelinechart"
|
|
17
|
+
"github.com/NimbleMarkets/ntcharts/sparkline"
|
|
18
|
+
"github.com/charmbracelet/lipgloss"
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
var (
|
|
22
|
+
nextID uint64 = 1
|
|
23
|
+
nextIDMu sync.Mutex
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
func getNextID() uint64 {
|
|
27
|
+
nextIDMu.Lock()
|
|
28
|
+
defer nextIDMu.Unlock()
|
|
29
|
+
id := nextID
|
|
30
|
+
nextID++
|
|
31
|
+
return id
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var (
|
|
35
|
+
sparklines = make(map[uint64]*sparkline.Model)
|
|
36
|
+
sparklinesMu sync.RWMutex
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
func allocSparkline(s *sparkline.Model) uint64 {
|
|
40
|
+
id := getNextID()
|
|
41
|
+
sparklinesMu.Lock()
|
|
42
|
+
sparklines[id] = s
|
|
43
|
+
sparklinesMu.Unlock()
|
|
44
|
+
return id
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
func getSparkline(id uint64) *sparkline.Model {
|
|
48
|
+
sparklinesMu.RLock()
|
|
49
|
+
defer sparklinesMu.RUnlock()
|
|
50
|
+
return sparklines[id]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
func freeSparkline(id uint64) {
|
|
54
|
+
sparklinesMu.Lock()
|
|
55
|
+
delete(sparklines, id)
|
|
56
|
+
sparklinesMu.Unlock()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var (
|
|
60
|
+
barcharts = make(map[uint64]*barchart.Model)
|
|
61
|
+
barchartsMu sync.RWMutex
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
func allocBarchart(b *barchart.Model) uint64 {
|
|
65
|
+
id := getNextID()
|
|
66
|
+
barchartsMu.Lock()
|
|
67
|
+
barcharts[id] = b
|
|
68
|
+
barchartsMu.Unlock()
|
|
69
|
+
return id
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
func getBarchart(id uint64) *barchart.Model {
|
|
73
|
+
barchartsMu.RLock()
|
|
74
|
+
defer barchartsMu.RUnlock()
|
|
75
|
+
return barcharts[id]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func freeBarchart(id uint64) {
|
|
79
|
+
barchartsMu.Lock()
|
|
80
|
+
delete(barcharts, id)
|
|
81
|
+
barchartsMu.Unlock()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
var (
|
|
85
|
+
linecharts = make(map[uint64]*linechart.Model)
|
|
86
|
+
linechartsMu sync.RWMutex
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
func allocLinechart(l *linechart.Model) uint64 {
|
|
90
|
+
id := getNextID()
|
|
91
|
+
linechartsMu.Lock()
|
|
92
|
+
linecharts[id] = l
|
|
93
|
+
linechartsMu.Unlock()
|
|
94
|
+
return id
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
func getLinechart(id uint64) *linechart.Model {
|
|
98
|
+
linechartsMu.RLock()
|
|
99
|
+
defer linechartsMu.RUnlock()
|
|
100
|
+
return linecharts[id]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
func freeLinechart(id uint64) {
|
|
104
|
+
linechartsMu.Lock()
|
|
105
|
+
delete(linecharts, id)
|
|
106
|
+
linechartsMu.Unlock()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var (
|
|
110
|
+
wavelinecharts = make(map[uint64]*wavelinechart.Model)
|
|
111
|
+
wavelinechartsMu sync.RWMutex
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
func allocWavelinechart(w *wavelinechart.Model) uint64 {
|
|
115
|
+
id := getNextID()
|
|
116
|
+
wavelinechartsMu.Lock()
|
|
117
|
+
wavelinecharts[id] = w
|
|
118
|
+
wavelinechartsMu.Unlock()
|
|
119
|
+
return id
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
func getWavelinechart(id uint64) *wavelinechart.Model {
|
|
123
|
+
wavelinechartsMu.RLock()
|
|
124
|
+
defer wavelinechartsMu.RUnlock()
|
|
125
|
+
return wavelinecharts[id]
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
func freeWavelinechart(id uint64) {
|
|
129
|
+
wavelinechartsMu.Lock()
|
|
130
|
+
delete(wavelinecharts, id)
|
|
131
|
+
wavelinechartsMu.Unlock()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
var (
|
|
135
|
+
streamlinecharts = make(map[uint64]*streamlinechart.Model)
|
|
136
|
+
streamlinechartsMu sync.RWMutex
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
func allocStreamlinechart(s *streamlinechart.Model) uint64 {
|
|
140
|
+
id := getNextID()
|
|
141
|
+
streamlinechartsMu.Lock()
|
|
142
|
+
streamlinecharts[id] = s
|
|
143
|
+
streamlinechartsMu.Unlock()
|
|
144
|
+
return id
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
func getStreamlinechart(id uint64) *streamlinechart.Model {
|
|
148
|
+
streamlinechartsMu.RLock()
|
|
149
|
+
defer streamlinechartsMu.RUnlock()
|
|
150
|
+
return streamlinecharts[id]
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
func freeStreamlinechart(id uint64) {
|
|
154
|
+
streamlinechartsMu.Lock()
|
|
155
|
+
delete(streamlinecharts, id)
|
|
156
|
+
streamlinechartsMu.Unlock()
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
var (
|
|
160
|
+
timeserieslinecharts = make(map[uint64]*timeserieslinechart.Model)
|
|
161
|
+
timeserieslinechartsMu sync.RWMutex
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
func allocTimeserieslinechart(t *timeserieslinechart.Model) uint64 {
|
|
165
|
+
id := getNextID()
|
|
166
|
+
timeserieslinechartsMu.Lock()
|
|
167
|
+
timeserieslinecharts[id] = t
|
|
168
|
+
timeserieslinechartsMu.Unlock()
|
|
169
|
+
return id
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
func getTimeserieslinechart(id uint64) *timeserieslinechart.Model {
|
|
173
|
+
timeserieslinechartsMu.RLock()
|
|
174
|
+
defer timeserieslinechartsMu.RUnlock()
|
|
175
|
+
return timeserieslinecharts[id]
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
func freeTimeserieslinechart(id uint64) {
|
|
179
|
+
timeserieslinechartsMu.Lock()
|
|
180
|
+
delete(timeserieslinecharts, id)
|
|
181
|
+
timeserieslinechartsMu.Unlock()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
var (
|
|
185
|
+
styles = make(map[uint64]lipgloss.Style)
|
|
186
|
+
stylesMu sync.RWMutex
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
func allocStyle(s lipgloss.Style) uint64 {
|
|
190
|
+
id := getNextID()
|
|
191
|
+
stylesMu.Lock()
|
|
192
|
+
styles[id] = s
|
|
193
|
+
stylesMu.Unlock()
|
|
194
|
+
return id
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
func getStyle(id uint64) (lipgloss.Style, bool) {
|
|
198
|
+
stylesMu.RLock()
|
|
199
|
+
defer stylesMu.RUnlock()
|
|
200
|
+
s, ok := styles[id]
|
|
201
|
+
return s, ok
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
func freeStyle(id uint64) {
|
|
205
|
+
stylesMu.Lock()
|
|
206
|
+
delete(styles, id)
|
|
207
|
+
stylesMu.Unlock()
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
//export ntcharts_free
|
|
211
|
+
func ntcharts_free(pointer *C.char) {
|
|
212
|
+
C.free(unsafe.Pointer(pointer))
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
//export ntcharts_upstream_version
|
|
216
|
+
func ntcharts_upstream_version() *C.char {
|
|
217
|
+
info, ok := debug.ReadBuildInfo()
|
|
218
|
+
|
|
219
|
+
if !ok {
|
|
220
|
+
return C.CString("unknown")
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
for _, dep := range info.Deps {
|
|
224
|
+
if dep.Path == "github.com/NimbleMarkets/ntcharts" {
|
|
225
|
+
return C.CString(dep.Version)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return C.CString("unknown")
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
//export ntcharts_style_new
|
|
233
|
+
func ntcharts_style_new() C.ulonglong {
|
|
234
|
+
s := lipgloss.NewStyle()
|
|
235
|
+
return C.ulonglong(allocStyle(s))
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
//export ntcharts_style_free
|
|
239
|
+
func ntcharts_style_free(id C.ulonglong) {
|
|
240
|
+
freeStyle(uint64(id))
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
//export ntcharts_style_foreground
|
|
244
|
+
func ntcharts_style_foreground(id C.ulonglong, color *C.char) C.ulonglong {
|
|
245
|
+
s, ok := getStyle(uint64(id))
|
|
246
|
+
|
|
247
|
+
if !ok {
|
|
248
|
+
s = lipgloss.NewStyle()
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
newStyle := s.Foreground(lipgloss.Color(C.GoString(color)))
|
|
252
|
+
return C.ulonglong(allocStyle(newStyle))
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
//export ntcharts_style_background
|
|
256
|
+
func ntcharts_style_background(id C.ulonglong, color *C.char) C.ulonglong {
|
|
257
|
+
s, ok := getStyle(uint64(id))
|
|
258
|
+
|
|
259
|
+
if !ok {
|
|
260
|
+
s = lipgloss.NewStyle()
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
newStyle := s.Background(lipgloss.Color(C.GoString(color)))
|
|
264
|
+
return C.ulonglong(allocStyle(newStyle))
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
//export ntcharts_style_bold
|
|
268
|
+
func ntcharts_style_bold(id C.ulonglong, bold C.int) C.ulonglong {
|
|
269
|
+
s, ok := getStyle(uint64(id))
|
|
270
|
+
|
|
271
|
+
if !ok {
|
|
272
|
+
s = lipgloss.NewStyle()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
newStyle := s.Bold(bold != 0)
|
|
276
|
+
return C.ulonglong(allocStyle(newStyle))
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
func main() {}
|