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
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3db7eaae732fa2dc3c6a965be27ada3e5ffcc2580f127d773488fef9ca44c1d8
|
|
4
|
+
data.tar.gz: b985fe5e2ad2c12a50e1281df00f46131d55b6055c3be0221f50389f0d74efee
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 230141e79847d2ce21183ac4a6e144ae2cd5c08c737b35e7e469a6cbbfd0ef85809daeaa5bce1bb3f4769804132f6907de3aefc028c2c7e9a15401b8d30d1717
|
|
7
|
+
data.tar.gz: 7f20fb46e23fafe25a167f5034a1b4644d095af89b6b493715a107318548653a50d6f93e3c479e12e94d82d141f00f2879fe96f18c865226c6a587d2c84035f1
|
data/README.md
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>Nimble Terminal Charts for Ruby</h1>
|
|
3
|
+
<h4>Terminal Charts for Beautiful Data Visualization</h4>
|
|
4
|
+
|
|
5
|
+
<p>
|
|
6
|
+
<a href="https://rubygems.org/gems/ntcharts"><img alt="Gem Version" src="https://img.shields.io/gem/v/ntcharts"></a>
|
|
7
|
+
<a href="https://github.com/marcoroth/ntcharts-ruby/blob/main/LICENSE.txt"><img alt="License" src="https://img.shields.io/github/license/marcoroth/ntcharts-ruby"></a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p>Ruby bindings for <a href="https://github.com/NimbleMarkets/ntcharts">NimbleMarkets/ntcharts</a>.<br/>Render beautiful charts directly in your terminal. Built with TUIs in mind.</p>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
**Add to your Gemfile:**
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem "ntcharts"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Or install directly:**
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
gem install ntcharts
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Sparkline
|
|
30
|
+
|
|
31
|
+
**Compact time-series visualization:**
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
require "ntcharts"
|
|
35
|
+
|
|
36
|
+
chart = Ntcharts::Sparkline.new(40, 6)
|
|
37
|
+
[1, 4, 2, 7, 3, 9, 5, 8, 2, 6].each { |v| chart.push(v) }
|
|
38
|
+
chart.draw
|
|
39
|
+
puts chart.view
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Styled sparkline with lipgloss:**
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
require "lipgloss"
|
|
46
|
+
|
|
47
|
+
style = Lipgloss::Style.new.foreground("#FF6B6B")
|
|
48
|
+
chart = Ntcharts::Sparkline.new(40, 6)
|
|
49
|
+
chart.style = style # Accepts Lipgloss::Style or Ntcharts::Style
|
|
50
|
+
|
|
51
|
+
[5, 3, 7, 2, 9, 4, 6, 1, 8, 3].each { |v| chart.push(v) }
|
|
52
|
+
chart.draw_braille
|
|
53
|
+
puts chart.view
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Barchart
|
|
57
|
+
|
|
58
|
+
**Horizontal and vertical bar charts:**
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
chart = Ntcharts::Barchart.new(50, 12)
|
|
62
|
+
|
|
63
|
+
chart.push(label: "Go", values: [{ value: 85, style: style }])
|
|
64
|
+
chart.push(label: "Ruby", values: [{ value: 92, style: style }])
|
|
65
|
+
chart.push(label: "Python", values: [{ value: 78, style: style }])
|
|
66
|
+
|
|
67
|
+
puts chart.render
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Stacked bar segments:**
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
chart.push(
|
|
74
|
+
label: "Sales",
|
|
75
|
+
values: [
|
|
76
|
+
{ value: 30, style: red_style },
|
|
77
|
+
{ value: 45, style: green_style },
|
|
78
|
+
{ value: 25, style: blue_style }
|
|
79
|
+
]
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### LineChart
|
|
84
|
+
|
|
85
|
+
**X/Y coordinate plotting:**
|
|
86
|
+
|
|
87
|
+
```ruby
|
|
88
|
+
chart = Ntcharts::Linechart.new(50, 12, 0.0, 10.0, 0.0, 10.0)
|
|
89
|
+
|
|
90
|
+
(0..10).each do |i|
|
|
91
|
+
x = i.to_f
|
|
92
|
+
y = Math.sin(i * 0.5) * 4 + 5
|
|
93
|
+
chart.draw_rune(x, y, "*")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
chart.draw_axes
|
|
97
|
+
puts chart.view
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Braille lines for smooth curves:**
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
chart = Ntcharts::Linechart.new(60, 15, 0.0, 30.0, -5.0, 10.0)
|
|
104
|
+
|
|
105
|
+
points = (0..30).map { |i| [i.to_f, Math.sin(i * 0.2) * 4 + 3] }
|
|
106
|
+
|
|
107
|
+
points.each_cons(2) do |(x1, y1), (x2, y2)|
|
|
108
|
+
chart.draw_braille_line(x1, y1, x2, y2)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
chart.draw_axes
|
|
112
|
+
puts chart.view
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Line styles
|
|
116
|
+
|
|
117
|
+
**Thin lines (box-drawing characters)**
|
|
118
|
+
|
|
119
|
+
```ruby
|
|
120
|
+
chart.draw_line(0, 0, 10, 10, Ntcharts::Linechart::LINE_STYLE_THIN)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Arc lines (curved connections)**
|
|
124
|
+
```ruby
|
|
125
|
+
chart.draw_line(0, 0, 10, 10, Ntcharts::Linechart::LINE_STYLE_ARC)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### WaveLineChart
|
|
129
|
+
|
|
130
|
+
**Multiple named datasets:**
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
chart = Ntcharts::Wavelinechart.new(60, 15)
|
|
134
|
+
|
|
135
|
+
(0..40).each { |i| chart.plot(i.to_f, Math.sin(i * 0.15) * 5 + 5) }
|
|
136
|
+
|
|
137
|
+
(0..40).each do |i|
|
|
138
|
+
chart.plot_data_set("series_a", i.to_f, Math.cos(i * 0.15) * 4 + 5)
|
|
139
|
+
chart.plot_data_set("series_b", i.to_f, Math.sin(i * 0.1) * 3 + 5)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
chart.draw_all
|
|
143
|
+
puts chart.view
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### StreamLineChart
|
|
147
|
+
|
|
148
|
+
**Real-time scrolling data:**
|
|
149
|
+
|
|
150
|
+
```ruby
|
|
151
|
+
chart = Ntcharts::Streamlinechart.new(60, 12)
|
|
152
|
+
chart.style = Lipgloss::Style.new.foreground("#00D4FF")
|
|
153
|
+
|
|
154
|
+
loop do
|
|
155
|
+
value = Math.sin(Time.now.to_f) * 4 + 5
|
|
156
|
+
chart.push(value)
|
|
157
|
+
|
|
158
|
+
system("clear")
|
|
159
|
+
puts chart.render
|
|
160
|
+
sleep 0.1
|
|
161
|
+
end
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### TimeSeriesLineChart
|
|
165
|
+
|
|
166
|
+
**Time-based X-axis with date labels:**
|
|
167
|
+
|
|
168
|
+
```ruby
|
|
169
|
+
chart = Ntcharts::Timeserieslinechart.new(70, 15)
|
|
170
|
+
|
|
171
|
+
now = Time.now
|
|
172
|
+
(0..60).each do |i|
|
|
173
|
+
time = now - (60 - i) * 60
|
|
174
|
+
value = Math.sin(i * 0.1) * 10 + 50
|
|
175
|
+
chart.push(time, value)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
chart.draw_braille
|
|
179
|
+
puts chart.view
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Styling
|
|
183
|
+
|
|
184
|
+
**All charts support lipgloss styling:**
|
|
185
|
+
|
|
186
|
+
```ruby
|
|
187
|
+
require "lipgloss"
|
|
188
|
+
|
|
189
|
+
chart_style = Lipgloss::Style.new.foreground("#FF6B6B")
|
|
190
|
+
axis_style = Lipgloss::Style.new.foreground("#666666")
|
|
191
|
+
label_style = Lipgloss::Style.new.foreground("#888888")
|
|
192
|
+
|
|
193
|
+
chart.style = chart_style
|
|
194
|
+
chart.axis_style = axis_style
|
|
195
|
+
chart.label_style = label_style
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Or use Ntcharts::Style directly:**
|
|
199
|
+
|
|
200
|
+
```ruby
|
|
201
|
+
style = Ntcharts::Style.new
|
|
202
|
+
.foreground("#00FF00")
|
|
203
|
+
.background("#000033")
|
|
204
|
+
.bold(true)
|
|
205
|
+
|
|
206
|
+
chart.style = style
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Chart Types
|
|
210
|
+
|
|
211
|
+
| Chart | Description | Key Features |
|
|
212
|
+
|-------|-------------|--------------|
|
|
213
|
+
| `Sparkline` | Compact time-series | Column and braille rendering modes |
|
|
214
|
+
| `Barchart` | Bar charts | Horizontal/vertical, stacked segments |
|
|
215
|
+
| `Linechart` | Base X/Y plotting | Points, lines, braille, custom runes |
|
|
216
|
+
| `Wavelinechart` | Multi-dataset lines | Named datasets, arc/thin line styles |
|
|
217
|
+
| `Streamlinechart` | Scrolling streams | Push data, auto-scroll right-to-left |
|
|
218
|
+
| `Timeserieslinechart` | Time-based charts | Ruby Time objects, date labels |
|
|
219
|
+
|
|
220
|
+
## Sparkline Methods
|
|
221
|
+
|
|
222
|
+
| Method | Description |
|
|
223
|
+
|--------|-------------|
|
|
224
|
+
| `push(value)` | Add a data point |
|
|
225
|
+
| `draw` | Render with column characters |
|
|
226
|
+
| `draw_braille` | Render with braille dots |
|
|
227
|
+
| `view` | Get rendered string |
|
|
228
|
+
| `style=` | Set chart style |
|
|
229
|
+
| `max=` | Set maximum value |
|
|
230
|
+
| `auto_max_value=` | Enable/disable auto-scaling |
|
|
231
|
+
| `resize(width, height)` | Resize the chart |
|
|
232
|
+
| `clear` | Clear all data |
|
|
233
|
+
|
|
234
|
+
## Barchart Methods
|
|
235
|
+
|
|
236
|
+
| Method | Description |
|
|
237
|
+
|--------|-------------|
|
|
238
|
+
| `push(bar_data)` | Add a bar (Hash or BarData) |
|
|
239
|
+
| `push_all(array)` | Add multiple bars |
|
|
240
|
+
| `render` | Draw and return view |
|
|
241
|
+
| `horizontal=` | Set horizontal orientation |
|
|
242
|
+
| `bar_width=` | Set bar width |
|
|
243
|
+
| `bar_gap=` | Set gap between bars |
|
|
244
|
+
| `show_axis=` | Show/hide axis |
|
|
245
|
+
| `axis_style=` | Set axis style |
|
|
246
|
+
| `label_style=` | Set label style |
|
|
247
|
+
|
|
248
|
+
## LineChart Methods
|
|
249
|
+
|
|
250
|
+
| Method | Description |
|
|
251
|
+
|--------|-------------|
|
|
252
|
+
| `draw_rune(x, y, char, [style])` | Draw character at point |
|
|
253
|
+
| `draw_line(x1, y1, x2, y2, line_style, [style])` | Draw line segment |
|
|
254
|
+
| `draw_braille_line(x1, y1, x2, y2, [style])` | Draw braille line |
|
|
255
|
+
| `draw_axes` | Draw X and Y axes |
|
|
256
|
+
| `view` | Get rendered string |
|
|
257
|
+
| `set_x_range(min, max)` | Set X data range |
|
|
258
|
+
| `set_y_range(min, max)` | Set Y data range |
|
|
259
|
+
| `x_step=` / `y_step=` | Set axis step (0 to hide) |
|
|
260
|
+
|
|
261
|
+
## StreamLineChart Methods
|
|
262
|
+
|
|
263
|
+
| Method | Description |
|
|
264
|
+
|--------|-------------|
|
|
265
|
+
| `push(value)` | Add value (scrolls left) |
|
|
266
|
+
| `render` | Draw and return view |
|
|
267
|
+
| `set_y_range(min, max)` | Set Y range |
|
|
268
|
+
| `style=` | Set line style |
|
|
269
|
+
| `clear_data` | Clear data points |
|
|
270
|
+
|
|
271
|
+
## TimeSeriesLineChart Methods
|
|
272
|
+
|
|
273
|
+
| Method | Description |
|
|
274
|
+
|--------|-------------|
|
|
275
|
+
| `push(time, value)` | Add time point |
|
|
276
|
+
| `push_data_set(name, time, value)` | Add to named dataset |
|
|
277
|
+
| `draw` / `draw_all` | Render default/all datasets |
|
|
278
|
+
| `draw_braille` / `draw_braille_all` | Braille rendering |
|
|
279
|
+
| `set_time_range(min, max)` | Set time range |
|
|
280
|
+
| `line_style=` | Set line style (THIN/ARC) |
|
|
281
|
+
|
|
282
|
+
## Line Style Constants
|
|
283
|
+
|
|
284
|
+
Available on `Linechart`, `Wavelinechart`, `Streamlinechart`, `Timeserieslinechart`:
|
|
285
|
+
|
|
286
|
+
| Constant | Description |
|
|
287
|
+
|----------|-------------|
|
|
288
|
+
| `LINE_STYLE_THIN` | Box-drawing characters |
|
|
289
|
+
| `LINE_STYLE_ARC` | Curved arc connections |
|
|
290
|
+
|
|
291
|
+
## Development
|
|
292
|
+
|
|
293
|
+
**Requirements:**
|
|
294
|
+
- Go 1.23+
|
|
295
|
+
- Ruby 3.2+
|
|
296
|
+
|
|
297
|
+
**Install dependencies:**
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
bundle install
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
**Build the Go library and compile the extension:**
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
bundle exec rake go:build
|
|
307
|
+
bundle exec rake compile
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Run demos:**
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
./demo/sparkline
|
|
314
|
+
./demo/barchart
|
|
315
|
+
./demo/linechart
|
|
316
|
+
./demo/wavelinechart
|
|
317
|
+
./demo/streamlinechart
|
|
318
|
+
./demo/timeserieslinechart
|
|
319
|
+
./demo/streaming
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Contributing
|
|
323
|
+
|
|
324
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/ntcharts-ruby.
|
|
325
|
+
|
|
326
|
+
## License
|
|
327
|
+
|
|
328
|
+
The gem is available as open source under the terms of the MIT License.
|
|
329
|
+
|
|
330
|
+
## Acknowledgments
|
|
331
|
+
|
|
332
|
+
This gem wraps [NimbleMarkets/ntcharts](https://github.com/NimbleMarkets/ntcharts), which builds on the excellent [Charm](https://charm.sh) ecosystem including [lipgloss](https://github.com/charmbracelet/lipgloss).
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
#include "extension.h"
|
|
2
|
+
|
|
3
|
+
static void barchart_free(void *pointer) {
|
|
4
|
+
ntcharts_barchart_t *barchart = (ntcharts_barchart_t *)pointer;
|
|
5
|
+
if (barchart->handle != 0) {
|
|
6
|
+
ntcharts_barchart_free(barchart->handle);
|
|
7
|
+
}
|
|
8
|
+
xfree(barchart);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static size_t barchart_memsize(const void *pointer) {
|
|
12
|
+
return sizeof(ntcharts_barchart_t);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const rb_data_type_t barchart_type = {
|
|
16
|
+
.wrap_struct_name = "Ntcharts::Barchart",
|
|
17
|
+
.function = {
|
|
18
|
+
.dmark = NULL,
|
|
19
|
+
.dfree = barchart_free,
|
|
20
|
+
.dsize = barchart_memsize,
|
|
21
|
+
},
|
|
22
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
static VALUE barchart_alloc(VALUE klass) {
|
|
26
|
+
ntcharts_barchart_t *barchart = ALLOC(ntcharts_barchart_t);
|
|
27
|
+
barchart->handle = 0;
|
|
28
|
+
return TypedData_Wrap_Struct(klass, &barchart_type, barchart);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
VALUE barchart_wrap(VALUE klass, unsigned long long handle) {
|
|
32
|
+
ntcharts_barchart_t *barchart = ALLOC(ntcharts_barchart_t);
|
|
33
|
+
barchart->handle = handle;
|
|
34
|
+
return TypedData_Wrap_Struct(klass, &barchart_type, barchart);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static VALUE barchart_initialize(VALUE self, VALUE width, VALUE height) {
|
|
38
|
+
GET_BARCHART(self, barchart);
|
|
39
|
+
barchart->handle = ntcharts_barchart_new(NUM2INT(width), NUM2INT(height));
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static VALUE barchart_width(VALUE self) {
|
|
44
|
+
GET_BARCHART(self, barchart);
|
|
45
|
+
return INT2NUM(ntcharts_barchart_width(barchart->handle));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static VALUE barchart_height(VALUE self) {
|
|
49
|
+
GET_BARCHART(self, barchart);
|
|
50
|
+
return INT2NUM(ntcharts_barchart_height(barchart->handle));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static VALUE barchart_max_value(VALUE self) {
|
|
54
|
+
GET_BARCHART(self, barchart);
|
|
55
|
+
return DBL2NUM(ntcharts_barchart_max_value(barchart->handle));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static VALUE barchart_scale(VALUE self) {
|
|
59
|
+
GET_BARCHART(self, barchart);
|
|
60
|
+
return DBL2NUM(ntcharts_barchart_scale(barchart->handle));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static VALUE barchart_bar_width(VALUE self) {
|
|
64
|
+
GET_BARCHART(self, barchart);
|
|
65
|
+
return INT2NUM(ntcharts_barchart_bar_width(barchart->handle));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static VALUE barchart_bar_gap(VALUE self) {
|
|
69
|
+
GET_BARCHART(self, barchart);
|
|
70
|
+
return INT2NUM(ntcharts_barchart_bar_gap(barchart->handle));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static VALUE barchart_show_axis_p(VALUE self) {
|
|
74
|
+
GET_BARCHART(self, barchart);
|
|
75
|
+
return ntcharts_barchart_show_axis(barchart->handle) ? Qtrue : Qfalse;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static VALUE barchart_horizontal_p(VALUE self) {
|
|
79
|
+
GET_BARCHART(self, barchart);
|
|
80
|
+
return ntcharts_barchart_horizontal(barchart->handle) ? Qtrue : Qfalse;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static VALUE barchart_set_max(VALUE self, VALUE max_val) {
|
|
84
|
+
GET_BARCHART(self, barchart);
|
|
85
|
+
ntcharts_barchart_set_max(barchart->handle, NUM2DBL(max_val));
|
|
86
|
+
return self;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static VALUE barchart_set_bar_width(VALUE self, VALUE width) {
|
|
90
|
+
GET_BARCHART(self, barchart);
|
|
91
|
+
ntcharts_barchart_set_bar_width(barchart->handle, NUM2INT(width));
|
|
92
|
+
return self;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static VALUE barchart_set_bar_gap(VALUE self, VALUE gap) {
|
|
96
|
+
GET_BARCHART(self, barchart);
|
|
97
|
+
ntcharts_barchart_set_bar_gap(barchart->handle, NUM2INT(gap));
|
|
98
|
+
return self;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static VALUE barchart_set_horizontal(VALUE self, VALUE horizontal) {
|
|
102
|
+
GET_BARCHART(self, barchart);
|
|
103
|
+
ntcharts_barchart_set_horizontal(barchart->handle, RTEST(horizontal) ? 1 : 0);
|
|
104
|
+
return self;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static VALUE barchart_set_show_axis(VALUE self, VALUE show_axis) {
|
|
108
|
+
GET_BARCHART(self, barchart);
|
|
109
|
+
ntcharts_barchart_set_show_axis(barchart->handle, RTEST(show_axis) ? 1 : 0);
|
|
110
|
+
return self;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static VALUE barchart_set_auto_max_value(VALUE self, VALUE auto_max) {
|
|
114
|
+
GET_BARCHART(self, barchart);
|
|
115
|
+
ntcharts_barchart_set_auto_max_value(barchart->handle, RTEST(auto_max) ? 1 : 0);
|
|
116
|
+
return self;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static VALUE barchart_set_auto_bar_width(VALUE self, VALUE auto_width) {
|
|
120
|
+
GET_BARCHART(self, barchart);
|
|
121
|
+
ntcharts_barchart_set_auto_bar_width(barchart->handle, RTEST(auto_width) ? 1 : 0);
|
|
122
|
+
return self;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static VALUE barchart_set_axis_style(VALUE self, VALUE style) {
|
|
126
|
+
GET_BARCHART(self, barchart);
|
|
127
|
+
ntcharts_style_t *style_ptr;
|
|
128
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
129
|
+
ntcharts_barchart_set_axis_style(barchart->handle, style_ptr->handle);
|
|
130
|
+
return self;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static VALUE barchart_set_label_style(VALUE self, VALUE style) {
|
|
134
|
+
GET_BARCHART(self, barchart);
|
|
135
|
+
ntcharts_style_t *style_ptr;
|
|
136
|
+
TypedData_Get_Struct(style, ntcharts_style_t, &style_type, style_ptr);
|
|
137
|
+
ntcharts_barchart_set_label_style(barchart->handle, style_ptr->handle);
|
|
138
|
+
return self;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static VALUE barchart_resize(VALUE self, VALUE width, VALUE height) {
|
|
142
|
+
GET_BARCHART(self, barchart);
|
|
143
|
+
ntcharts_barchart_resize(barchart->handle, NUM2INT(width), NUM2INT(height));
|
|
144
|
+
return self;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static VALUE barchart_clear(VALUE self) {
|
|
148
|
+
GET_BARCHART(self, barchart);
|
|
149
|
+
ntcharts_barchart_clear(barchart->handle);
|
|
150
|
+
return self;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
static VALUE barchart_push(VALUE self, VALUE bar_data) {
|
|
154
|
+
GET_BARCHART(self, barchart);
|
|
155
|
+
VALUE json_str = rb_funcall(bar_data, rb_intern("to_json"), 0);
|
|
156
|
+
ntcharts_barchart_push(barchart->handle, StringValueCStr(json_str));
|
|
157
|
+
return self;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static VALUE barchart_push_all(VALUE self, VALUE bar_data_array) {
|
|
161
|
+
GET_BARCHART(self, barchart);
|
|
162
|
+
Check_Type(bar_data_array, T_ARRAY);
|
|
163
|
+
VALUE json_str = rb_funcall(bar_data_array, rb_intern("to_json"), 0);
|
|
164
|
+
ntcharts_barchart_push_all(barchart->handle, StringValueCStr(json_str));
|
|
165
|
+
return self;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static VALUE barchart_draw(VALUE self) {
|
|
169
|
+
GET_BARCHART(self, barchart);
|
|
170
|
+
ntcharts_barchart_draw(barchart->handle);
|
|
171
|
+
return self;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static VALUE barchart_view(VALUE self) {
|
|
175
|
+
GET_BARCHART(self, barchart);
|
|
176
|
+
char *result = ntcharts_barchart_view(barchart->handle);
|
|
177
|
+
VALUE rb_result = rb_utf8_str_new_cstr(result);
|
|
178
|
+
ntcharts_free(result);
|
|
179
|
+
return rb_result;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
static VALUE barchart_to_s(VALUE self) {
|
|
183
|
+
return barchart_view(self);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
void Init_ntcharts_barchart(void) {
|
|
187
|
+
cBarchart = rb_define_class_under(mNtcharts, "Barchart", rb_cObject);
|
|
188
|
+
|
|
189
|
+
rb_define_alloc_func(cBarchart, barchart_alloc);
|
|
190
|
+
rb_define_method(cBarchart, "initialize", barchart_initialize, 2);
|
|
191
|
+
rb_define_method(cBarchart, "width", barchart_width, 0);
|
|
192
|
+
rb_define_method(cBarchart, "height", barchart_height, 0);
|
|
193
|
+
rb_define_method(cBarchart, "max_value", barchart_max_value, 0);
|
|
194
|
+
rb_define_method(cBarchart, "scale", barchart_scale, 0);
|
|
195
|
+
rb_define_method(cBarchart, "bar_width", barchart_bar_width, 0);
|
|
196
|
+
rb_define_method(cBarchart, "bar_gap", barchart_bar_gap, 0);
|
|
197
|
+
rb_define_method(cBarchart, "show_axis?", barchart_show_axis_p, 0);
|
|
198
|
+
rb_define_method(cBarchart, "horizontal?", barchart_horizontal_p, 0);
|
|
199
|
+
rb_define_method(cBarchart, "max=", barchart_set_max, 1);
|
|
200
|
+
rb_define_method(cBarchart, "bar_width=", barchart_set_bar_width, 1);
|
|
201
|
+
rb_define_method(cBarchart, "bar_gap=", barchart_set_bar_gap, 1);
|
|
202
|
+
rb_define_method(cBarchart, "horizontal=", barchart_set_horizontal, 1);
|
|
203
|
+
rb_define_method(cBarchart, "show_axis=", barchart_set_show_axis, 1);
|
|
204
|
+
rb_define_method(cBarchart, "auto_max_value=", barchart_set_auto_max_value, 1);
|
|
205
|
+
rb_define_method(cBarchart, "auto_bar_width=", barchart_set_auto_bar_width, 1);
|
|
206
|
+
rb_define_method(cBarchart, "_set_axis_style", barchart_set_axis_style, 1);
|
|
207
|
+
rb_define_method(cBarchart, "_set_label_style", barchart_set_label_style, 1);
|
|
208
|
+
rb_define_method(cBarchart, "resize", barchart_resize, 2);
|
|
209
|
+
rb_define_method(cBarchart, "clear", barchart_clear, 0);
|
|
210
|
+
rb_define_method(cBarchart, "_push", barchart_push, 1);
|
|
211
|
+
rb_define_method(cBarchart, "_push_all", barchart_push_all, 1);
|
|
212
|
+
rb_define_method(cBarchart, "draw", barchart_draw, 0);
|
|
213
|
+
rb_define_method(cBarchart, "view", barchart_view, 0);
|
|
214
|
+
rb_define_method(cBarchart, "to_s", barchart_to_s, 0);
|
|
215
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "mkmf"
|
|
4
|
+
|
|
5
|
+
extension_name = "ntcharts"
|
|
6
|
+
|
|
7
|
+
def detect_platform
|
|
8
|
+
cpu = RbConfig::CONFIG["host_cpu"]
|
|
9
|
+
os = RbConfig::CONFIG["host_os"]
|
|
10
|
+
|
|
11
|
+
arch = case cpu
|
|
12
|
+
when /aarch64|arm64/ then "arm64"
|
|
13
|
+
when /x86_64|amd64/ then "amd64"
|
|
14
|
+
when /arm/ then "arm"
|
|
15
|
+
when /i[3-6]86/ then "386"
|
|
16
|
+
else cpu
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
goos = case os
|
|
20
|
+
when /darwin/ then "darwin"
|
|
21
|
+
when /mswin|mingw/ then "windows"
|
|
22
|
+
else "linux"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
"#{goos}_#{arch}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
platform = detect_platform
|
|
29
|
+
go_lib_dir = File.expand_path("../../go/build/#{platform}", __dir__)
|
|
30
|
+
|
|
31
|
+
puts "Looking for Go library in: #{go_lib_dir}"
|
|
32
|
+
|
|
33
|
+
unless File.exist?(File.join(go_lib_dir, "libntcharts.a"))
|
|
34
|
+
abort <<~ERROR
|
|
35
|
+
Could not find libntcharts.a for platform #{platform}
|
|
36
|
+
|
|
37
|
+
Please build the Go archive first:
|
|
38
|
+
cd go && go build -buildmode=c-archive -o build/#{platform}/libntcharts.a .
|
|
39
|
+
|
|
40
|
+
Or run:
|
|
41
|
+
bundle exec rake go:build
|
|
42
|
+
ERROR
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
$LDFLAGS << " -L#{go_lib_dir}"
|
|
46
|
+
$INCFLAGS << " -I#{go_lib_dir}"
|
|
47
|
+
|
|
48
|
+
$LOCAL_LIBS << " #{go_lib_dir}/libntcharts.a"
|
|
49
|
+
|
|
50
|
+
case RbConfig::CONFIG["host_os"]
|
|
51
|
+
when /darwin/
|
|
52
|
+
$LDFLAGS << " -framework CoreFoundation -framework Security -framework SystemConfiguration"
|
|
53
|
+
$LDFLAGS << " -lresolv"
|
|
54
|
+
when /linux/
|
|
55
|
+
$LDFLAGS << " -lpthread -lm -ldl"
|
|
56
|
+
$LDFLAGS << " -lresolv" if find_library("resolv", "res_query")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
$srcs = [
|
|
60
|
+
"extension.c",
|
|
61
|
+
"sparkline.c",
|
|
62
|
+
"barchart.c",
|
|
63
|
+
"linechart.c",
|
|
64
|
+
"wavelinechart.c",
|
|
65
|
+
"streamlinechart.c",
|
|
66
|
+
"timeserieslinechart.c",
|
|
67
|
+
"style.c",
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
create_makefile("#{extension_name}/#{extension_name}")
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#include "extension.h"
|
|
2
|
+
|
|
3
|
+
VALUE mNtcharts;
|
|
4
|
+
VALUE cSparkline;
|
|
5
|
+
VALUE cBarchart;
|
|
6
|
+
VALUE cLinechart;
|
|
7
|
+
VALUE cWavelinechart;
|
|
8
|
+
VALUE cStreamlinechart;
|
|
9
|
+
VALUE cTimeserieslinechart;
|
|
10
|
+
VALUE cStyle;
|
|
11
|
+
|
|
12
|
+
static VALUE ntcharts_upstream_version_rb(VALUE self) {
|
|
13
|
+
char *version = ntcharts_upstream_version();
|
|
14
|
+
VALUE rb_version = rb_utf8_str_new_cstr(version);
|
|
15
|
+
|
|
16
|
+
ntcharts_free(version);
|
|
17
|
+
|
|
18
|
+
return rb_version;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static VALUE ntcharts_version_rb(VALUE self) {
|
|
22
|
+
VALUE gem_version = rb_const_get(self, rb_intern("VERSION"));
|
|
23
|
+
VALUE upstream_version = ntcharts_upstream_version_rb(self);
|
|
24
|
+
VALUE format_string = rb_utf8_str_new_cstr("ntcharts v%s (upstream %s) [Go native extension]");
|
|
25
|
+
|
|
26
|
+
return rb_funcall(rb_mKernel, rb_intern("sprintf"), 3, format_string, gem_version, upstream_version);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
__attribute__((__visibility__("default"))) void Init_ntcharts(void) {
|
|
30
|
+
rb_require("json");
|
|
31
|
+
|
|
32
|
+
mNtcharts = rb_define_module("Ntcharts");
|
|
33
|
+
|
|
34
|
+
Init_ntcharts_sparkline();
|
|
35
|
+
Init_ntcharts_barchart();
|
|
36
|
+
Init_ntcharts_linechart();
|
|
37
|
+
Init_ntcharts_wavelinechart();
|
|
38
|
+
Init_ntcharts_streamlinechart();
|
|
39
|
+
Init_ntcharts_timeserieslinechart();
|
|
40
|
+
Init_ntcharts_style();
|
|
41
|
+
|
|
42
|
+
rb_define_singleton_method(mNtcharts, "upstream_version", ntcharts_upstream_version_rb, 0);
|
|
43
|
+
rb_define_singleton_method(mNtcharts, "version", ntcharts_version_rb, 0);
|
|
44
|
+
}
|