xlsxwriter 0.2.1.pre → 0.2.1.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/xlsxwriter/chart.c +68 -78
- data/ext/xlsxwriter/chart.h +2 -2
- data/ext/xlsxwriter/chartsheet.c +307 -0
- data/ext/xlsxwriter/chartsheet.h +15 -0
- data/ext/xlsxwriter/common.h +104 -0
- data/ext/xlsxwriter/workbook.c +42 -21
- data/ext/xlsxwriter/worksheet.c +94 -233
- data/ext/xlsxwriter/worksheet.h +1 -1
- data/ext/xlsxwriter/xlsxwriter.c +2 -0
- data/lib/xlsxwriter/version.rb +1 -1
- data/test/test-chartsheet.rb +201 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 785d6f62717613d9737bd4879dedc8077ac690de96bf3f4fafd7b2c7917956c9
|
4
|
+
data.tar.gz: 73d5337504d25eb891c34eeaa37fcebfa5961dd9e5d49276d27243198287af8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0b99c9b0b3bf2ce4499f33acceda7596910beede83721018a38c04ae4b754b56b793b861bb5af59dc0bcdbeb55f473eaa7b9b16c34cef021575c14ec001c382
|
7
|
+
data.tar.gz: 00e8d80d92f11aec6366f3ead33d64251787d54cffb77bfd0769299079d904595ed22d5eaaa8dcc40d4a098eedfeecdf4d553a0a0a30f1a8710c4be8f33577e0
|
data/ext/xlsxwriter/chart.c
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
#include
|
1
|
+
#include <ruby.h>
|
2
2
|
#include <ruby/encoding.h>
|
3
|
+
|
4
|
+
#include "chart.h"
|
5
|
+
#include "common.h"
|
3
6
|
#include "workbook.h"
|
4
7
|
#include "worksheet.h"
|
5
8
|
|
@@ -7,10 +10,10 @@ VALUE cChart;
|
|
7
10
|
VALUE cChartSeries;
|
8
11
|
VALUE cChartAxis;
|
9
12
|
|
10
|
-
#define DEF_PROP_SETTER(type, field, value
|
13
|
+
#define DEF_PROP_SETTER(type, field, value) VALUE type ## _set_ ## field ## _ (VALUE self, VALUE val) { \
|
11
14
|
struct type *ptr; \
|
12
15
|
Data_Get_Struct(self, struct type, ptr); \
|
13
|
-
type ## _set_ ## field (ptr->
|
16
|
+
type ## _set_ ## field (ptr->type, value); \
|
14
17
|
return val; \
|
15
18
|
}
|
16
19
|
|
@@ -66,13 +69,13 @@ chart_axis_init(VALUE self, VALUE chart, VALUE type) {
|
|
66
69
|
if (c_ptr && c_ptr->chart) {
|
67
70
|
ID axis = rb_check_id_cstr("x", 1, NULL);
|
68
71
|
if (axis && axis == rb_check_id(&type)) {
|
69
|
-
ptr->
|
72
|
+
ptr->chart_axis = c_ptr->chart->x_axis;
|
70
73
|
return self;
|
71
74
|
}
|
72
75
|
|
73
76
|
axis = rb_check_id_cstr("y", 1, NULL);
|
74
77
|
if (axis && axis == rb_check_id(&type)) {
|
75
|
-
ptr->
|
78
|
+
ptr->chart_axis = c_ptr->chart->y_axis;
|
76
79
|
return self;
|
77
80
|
}
|
78
81
|
|
@@ -91,7 +94,7 @@ chart_series_alloc(VALUE klass) {
|
|
91
94
|
|
92
95
|
obj = Data_Make_Struct(klass, struct chart_series, NULL, NULL, ptr);
|
93
96
|
|
94
|
-
ptr->
|
97
|
+
ptr->chart_series = NULL;
|
95
98
|
|
96
99
|
return obj;
|
97
100
|
}
|
@@ -114,7 +117,7 @@ chart_series_init(int argc, VALUE *argv, VALUE self) {
|
|
114
117
|
vals = StringValueCStr(argv[1]);
|
115
118
|
}
|
116
119
|
if (c_ptr && c_ptr->chart) {
|
117
|
-
ptr->
|
120
|
+
ptr->chart_series = chart_add_series(c_ptr->chart, cats, vals);
|
118
121
|
}
|
119
122
|
|
120
123
|
return self;
|
@@ -181,9 +184,8 @@ chart_title_set_name_range_(int argc, VALUE *argv, VALUE self) {
|
|
181
184
|
lxw_row_t row;
|
182
185
|
lxw_col_t col;
|
183
186
|
extract_cell(argc - 1, argv + 1, &row, &col);
|
184
|
-
|
185
|
-
|
186
|
-
chart_title_set_name_range(ptr->chart, str, row, col);
|
187
|
+
|
188
|
+
LXW_NO_RESULT_CALL(chart, title_set_name_range, str, row, col);
|
187
189
|
return self;
|
188
190
|
}
|
189
191
|
|
@@ -195,10 +197,7 @@ chart_title_set_name_range_(int argc, VALUE *argv, VALUE self) {
|
|
195
197
|
*/
|
196
198
|
VALUE
|
197
199
|
chart_legend_set_position_(VALUE self, VALUE pos) {
|
198
|
-
|
199
|
-
Data_Get_Struct(self, struct chart, ptr);
|
200
|
-
|
201
|
-
chart_legend_set_position(ptr->chart, NUM2UINT(rb_check_to_int(pos)));
|
200
|
+
LXW_NO_RESULT_CALL(chart, legend_set_position, NUM2UINT(rb_check_to_int(pos)));
|
202
201
|
return pos;
|
203
202
|
}
|
204
203
|
|
@@ -209,11 +208,8 @@ chart_legend_set_position_(VALUE self, VALUE pos) {
|
|
209
208
|
*/
|
210
209
|
VALUE
|
211
210
|
chart_legend_set_font_(VALUE self, VALUE opts) {
|
212
|
-
struct chart *ptr;
|
213
211
|
lxw_chart_font font = val_to_lxw_chart_font(opts);
|
214
|
-
|
215
|
-
|
216
|
-
chart_legend_set_font(ptr->chart, &font);
|
212
|
+
LXW_NO_RESULT_CALL(chart, legend_set_font, &font);
|
217
213
|
return self;
|
218
214
|
}
|
219
215
|
|
@@ -234,9 +230,7 @@ chart_legend_delete_series_(VALUE self, VALUE series) {
|
|
234
230
|
}
|
235
231
|
series_arr[len] = -1;
|
236
232
|
|
237
|
-
|
238
|
-
Data_Get_Struct(self, struct chart, ptr);
|
239
|
-
chart_legend_delete_series(ptr->chart, series_arr);
|
233
|
+
LXW_ERR_RESULT_CALL(chart, legend_delete_series, series_arr);
|
240
234
|
return self;
|
241
235
|
}
|
242
236
|
|
@@ -246,18 +240,18 @@ chart_legend_delete_series_(VALUE self, VALUE series) {
|
|
246
240
|
*
|
247
241
|
* Sets the chart +style+ (integer from 1 to 48, default is 2).
|
248
242
|
*/
|
249
|
-
DEF_PROP_SETTER(chart, style, NUM2INT(rb_check_to_int(val))
|
243
|
+
DEF_PROP_SETTER(chart, style, NUM2INT(rb_check_to_int(val)))
|
250
244
|
|
251
245
|
|
252
246
|
/* Document-method: XlsxWriter::Workbook::Chart#rotation=
|
253
247
|
*
|
254
248
|
*/
|
255
|
-
DEF_PROP_SETTER(chart, rotation, NUM2UINT(rb_check_to_int(val))
|
249
|
+
DEF_PROP_SETTER(chart, rotation, NUM2UINT(rb_check_to_int(val)))
|
256
250
|
|
257
251
|
/* Document-method: XlsxWriter::Workbook::Chart#hole_size=
|
258
252
|
*
|
259
253
|
*/
|
260
|
-
DEF_PROP_SETTER(chart, hole_size, NUM2UINT(rb_check_to_int(val))
|
254
|
+
DEF_PROP_SETTER(chart, hole_size, NUM2UINT(rb_check_to_int(val)))
|
261
255
|
|
262
256
|
|
263
257
|
/* :nodoc: */
|
@@ -301,17 +295,17 @@ chart_set_axis_id_2_(VALUE self, VALUE val) {
|
|
301
295
|
*
|
302
296
|
* Sets the chart axis +name+.
|
303
297
|
*/
|
304
|
-
DEF_PROP_SETTER(chart_axis, name, StringValueCStr(val)
|
298
|
+
DEF_PROP_SETTER(chart_axis, name, StringValueCStr(val))
|
305
299
|
|
306
300
|
/* Document-method XlsxWriter::Workbook::Chart::Axis#interval_unit=
|
307
301
|
*
|
308
302
|
*/
|
309
|
-
DEF_PROP_SETTER(chart_axis, interval_unit, NUM2UINT(rb_check_to_int(val))
|
303
|
+
DEF_PROP_SETTER(chart_axis, interval_unit, NUM2UINT(rb_check_to_int(val)))
|
310
304
|
|
311
305
|
/* Document-method XlsxWriter::Workbook::Chart::Axis#interval_tick=
|
312
306
|
*
|
313
307
|
*/
|
314
|
-
DEF_PROP_SETTER(chart_axis, interval_tick, NUM2UINT(rb_check_to_int(val))
|
308
|
+
DEF_PROP_SETTER(chart_axis, interval_tick, NUM2UINT(rb_check_to_int(val)))
|
315
309
|
|
316
310
|
/* Document-method: XlsxWriter::Workbook::Chart::Axis#max=
|
317
311
|
*
|
@@ -319,7 +313,7 @@ DEF_PROP_SETTER(chart_axis, interval_tick, NUM2UINT(rb_check_to_int(val)), axis)
|
|
319
313
|
*
|
320
314
|
* Sets the chart axis +max+ value.
|
321
315
|
*/
|
322
|
-
DEF_PROP_SETTER(chart_axis, max, NUM2DBL(rb_check_to_float(val))
|
316
|
+
DEF_PROP_SETTER(chart_axis, max, NUM2DBL(rb_check_to_float(val)))
|
323
317
|
|
324
318
|
/* Document-method: XlsxWriter::Workbook::Chart::Axis#min=
|
325
319
|
*
|
@@ -327,47 +321,47 @@ DEF_PROP_SETTER(chart_axis, max, NUM2DBL(rb_check_to_float(val)), axis)
|
|
327
321
|
*
|
328
322
|
* Sets the chart axis +min+ value.
|
329
323
|
*/
|
330
|
-
DEF_PROP_SETTER(chart_axis, min, NUM2DBL(rb_check_to_float(val))
|
324
|
+
DEF_PROP_SETTER(chart_axis, min, NUM2DBL(rb_check_to_float(val)))
|
331
325
|
|
332
326
|
/* Document-method: XlsxWriter::Workbook::Chart::Axis#major_tick_mark=
|
333
327
|
*
|
334
328
|
*/
|
335
|
-
DEF_PROP_SETTER(chart_axis, major_tick_mark, NUM2UINT(rb_check_to_int(val))
|
329
|
+
DEF_PROP_SETTER(chart_axis, major_tick_mark, NUM2UINT(rb_check_to_int(val)))
|
336
330
|
|
337
331
|
/* Document-method: XlsxWriter::Workbook::Chart::Axis#minor_tick_mark=
|
338
332
|
*
|
339
333
|
*/
|
340
|
-
DEF_PROP_SETTER(chart_axis, minor_tick_mark, NUM2UINT(rb_check_to_int(val))
|
334
|
+
DEF_PROP_SETTER(chart_axis, minor_tick_mark, NUM2UINT(rb_check_to_int(val)))
|
341
335
|
|
342
336
|
/* Document-method: XlsxWriter::Workbook::Chart::Axis#major_unit=
|
343
337
|
*
|
344
338
|
*/
|
345
|
-
DEF_PROP_SETTER(chart_axis, major_unit, NUM2DBL(rb_check_to_float(val))
|
339
|
+
DEF_PROP_SETTER(chart_axis, major_unit, NUM2DBL(rb_check_to_float(val)))
|
346
340
|
|
347
341
|
/* Document-method: XlsxWriter::Workbook::Chart::Axis#minor_unit=
|
348
342
|
*
|
349
343
|
*/
|
350
|
-
DEF_PROP_SETTER(chart_axis, minor_unit, NUM2DBL(rb_check_to_float(val))
|
344
|
+
DEF_PROP_SETTER(chart_axis, minor_unit, NUM2DBL(rb_check_to_float(val)))
|
351
345
|
|
352
346
|
/* Document-method: XlsxWriter::Workbook::Chart::Axis#label_align=
|
353
347
|
*
|
354
348
|
*/
|
355
|
-
DEF_PROP_SETTER(chart_axis, label_align, NUM2UINT(rb_check_to_int(val))
|
349
|
+
DEF_PROP_SETTER(chart_axis, label_align, NUM2UINT(rb_check_to_int(val)))
|
356
350
|
|
357
351
|
/* Document-method: XlsxWriter::Workbook::Chart::Axis#label_position=
|
358
352
|
*
|
359
353
|
*/
|
360
|
-
DEF_PROP_SETTER(chart_axis, label_position, NUM2DBL(rb_check_to_float(val))
|
354
|
+
DEF_PROP_SETTER(chart_axis, label_position, NUM2DBL(rb_check_to_float(val)))
|
361
355
|
|
362
356
|
/* Document-method: XlsxWriter::Workbook::Chart::Axis#log_base=
|
363
357
|
*
|
364
358
|
*/
|
365
|
-
DEF_PROP_SETTER(chart_axis, log_base, NUM2DBL(rb_check_to_float(val))
|
359
|
+
DEF_PROP_SETTER(chart_axis, log_base, NUM2DBL(rb_check_to_float(val)))
|
366
360
|
|
367
361
|
/* Document-method: XlsxWriter::Workbook::Chart::Axis#num_format=
|
368
362
|
*
|
369
363
|
*/
|
370
|
-
DEF_PROP_SETTER(chart_axis, num_format, StringValueCStr(val)
|
364
|
+
DEF_PROP_SETTER(chart_axis, num_format, StringValueCStr(val))
|
371
365
|
|
372
366
|
/* call-seq:
|
373
367
|
* axis.set_name_range(name, cell) -> self
|
@@ -382,9 +376,7 @@ chart_axis_set_name_range_(int argc, VALUE *argv, VALUE self) {
|
|
382
376
|
lxw_row_t row;
|
383
377
|
lxw_col_t col;
|
384
378
|
extract_cell(argc - 1, argv + 1, &row, &col);
|
385
|
-
|
386
|
-
Data_Get_Struct(self, struct chart_axis, ptr);
|
387
|
-
chart_axis_set_name_range(ptr->axis, str, row, col);
|
379
|
+
LXW_NO_RESULT_CALL(chart_axis, set_name_range, str, row, col);
|
388
380
|
return self;
|
389
381
|
}
|
390
382
|
|
@@ -394,11 +386,8 @@ chart_axis_set_name_range_(int argc, VALUE *argv, VALUE self) {
|
|
394
386
|
*/
|
395
387
|
VALUE
|
396
388
|
chart_axis_set_name_font_(VALUE self, VALUE value) {
|
397
|
-
struct chart_axis *ptr;
|
398
389
|
lxw_chart_font font = val_to_lxw_chart_font(value);
|
399
|
-
|
400
|
-
|
401
|
-
chart_axis_set_name_font(ptr->axis, &font);
|
390
|
+
LXW_NO_RESULT_CALL(chart_axis, set_name_font, &font);
|
402
391
|
return self;
|
403
392
|
}
|
404
393
|
|
@@ -408,11 +397,8 @@ chart_axis_set_name_font_(VALUE self, VALUE value) {
|
|
408
397
|
*/
|
409
398
|
VALUE
|
410
399
|
chart_axis_set_num_font_(VALUE self, VALUE value) {
|
411
|
-
struct chart_axis *ptr;
|
412
400
|
lxw_chart_font font = val_to_lxw_chart_font(value);
|
413
|
-
|
414
|
-
|
415
|
-
chart_axis_set_num_font(ptr->axis, &font);
|
401
|
+
LXW_NO_RESULT_CALL(chart_axis, set_num_font, &font);
|
416
402
|
return self;
|
417
403
|
}
|
418
404
|
|
@@ -422,12 +408,8 @@ chart_axis_set_num_font_(VALUE self, VALUE value) {
|
|
422
408
|
*/
|
423
409
|
VALUE
|
424
410
|
chart_axis_set_line_(VALUE self, VALUE opts) {
|
425
|
-
struct chart_axis *ptr;
|
426
411
|
lxw_chart_line line = val_to_lxw_chart_line(opts);
|
427
|
-
|
428
|
-
Data_Get_Struct(self, struct chart_axis, ptr);
|
429
|
-
|
430
|
-
chart_axis_set_line(ptr->axis, &line);
|
412
|
+
LXW_NO_RESULT_CALL(chart_axis, set_line, &line);
|
431
413
|
return self;
|
432
414
|
}
|
433
415
|
|
@@ -437,19 +419,15 @@ chart_axis_set_line_(VALUE self, VALUE opts) {
|
|
437
419
|
*/
|
438
420
|
VALUE
|
439
421
|
chart_axis_set_fill_(VALUE self, VALUE opts) {
|
440
|
-
struct chart_axis *ptr;
|
441
422
|
lxw_chart_fill fill = val_to_lxw_chart_fill(opts);
|
442
|
-
|
443
|
-
Data_Get_Struct(self, struct chart_axis, ptr);
|
444
|
-
|
445
|
-
chart_axis_set_fill(ptr->axis, &fill);
|
423
|
+
LXW_NO_RESULT_CALL(chart_axis, set_fill, &fill);
|
446
424
|
return self;
|
447
425
|
}
|
448
426
|
|
449
427
|
/* Document-method XlsxWriter::Workbook::Chart::Axis#position=
|
450
428
|
*
|
451
429
|
*/
|
452
|
-
DEF_PROP_SETTER(chart_axis, position, NUM2UINT(rb_check_to_int(val))
|
430
|
+
DEF_PROP_SETTER(chart_axis, position, NUM2UINT(rb_check_to_int(val)))
|
453
431
|
|
454
432
|
/* call-seq: axis.reverse = true
|
455
433
|
*
|
@@ -457,11 +435,8 @@ DEF_PROP_SETTER(chart_axis, position, NUM2UINT(rb_check_to_int(val)), axis)
|
|
457
435
|
*/
|
458
436
|
VALUE
|
459
437
|
chart_axis_set_reverse_(VALUE self, VALUE p) {
|
460
|
-
struct chart_axis *ptr;
|
461
438
|
if (RTEST(p)) {
|
462
|
-
|
463
|
-
|
464
|
-
chart_axis_set_reverse(ptr->axis);
|
439
|
+
LXW_NO_RESULT_CALL(chart_axis, set_reverse);
|
465
440
|
}
|
466
441
|
return p;
|
467
442
|
}
|
@@ -472,7 +447,7 @@ chart_axis_set_source_linked_(VALUE self, VALUE val) {
|
|
472
447
|
|
473
448
|
Data_Get_Struct(self, struct chart_axis, ptr);
|
474
449
|
|
475
|
-
ptr->
|
450
|
+
ptr->chart_axis->source_linked = NUM2UINT(rb_check_to_int(val));
|
476
451
|
|
477
452
|
return val;
|
478
453
|
}
|
@@ -493,9 +468,29 @@ chart_series_set_categories_(int argc, VALUE *argv, VALUE self) {
|
|
493
468
|
lxw_row_t row_from, row_to;
|
494
469
|
lxw_col_t col_from, col_to;
|
495
470
|
extract_range(argc - 1, argv + 1, &row_from, &col_from, &row_to, &col_to);
|
496
|
-
|
497
|
-
|
498
|
-
|
471
|
+
LXW_NO_RESULT_CALL(chart_series, set_categories, str, row_from, col_from, row_to, col_to);
|
472
|
+
return self;
|
473
|
+
}
|
474
|
+
|
475
|
+
/* call-seq: series.set_fill(options)
|
476
|
+
*
|
477
|
+
* Sets chart series fill options. See {libxlsxwriter doc}[https://libxlsxwriter.github.io/structlxw__chart__fill.html] for details.
|
478
|
+
*/
|
479
|
+
VALUE
|
480
|
+
chart_series_set_fill_(VALUE self, VALUE opts) {
|
481
|
+
lxw_chart_fill fill = val_to_lxw_chart_fill(opts);
|
482
|
+
LXW_NO_RESULT_CALL(chart_series, set_fill, &fill);
|
483
|
+
return self;
|
484
|
+
}
|
485
|
+
|
486
|
+
/* call-seq: series.set_line(options)
|
487
|
+
*
|
488
|
+
* Sets chart series line options. See {libxlsxwriter doc}[https://libxlsxwriter.github.io/structlxw__chart__line.html] for details.
|
489
|
+
*/
|
490
|
+
VALUE
|
491
|
+
chart_series_set_line_(VALUE self, VALUE opts) {
|
492
|
+
lxw_chart_line line = val_to_lxw_chart_line(opts);
|
493
|
+
LXW_NO_RESULT_CALL(chart_series, set_line, &line);
|
499
494
|
return self;
|
500
495
|
}
|
501
496
|
|
@@ -513,9 +508,7 @@ chart_series_set_values_(int argc, VALUE *argv, VALUE self) {
|
|
513
508
|
lxw_row_t row_from, row_to;
|
514
509
|
lxw_col_t col_from, col_to;
|
515
510
|
extract_range(argc - 1, argv + 1, &row_from, &col_from, &row_to, &col_to);
|
516
|
-
|
517
|
-
Data_Get_Struct(self, struct chart_series, ptr);
|
518
|
-
chart_series_set_values(ptr->series, str, row_from, col_from, row_to, col_to);
|
511
|
+
LXW_NO_RESULT_CALL(chart_series, set_values, str, row_from, col_from, row_to, col_to);
|
519
512
|
return self;
|
520
513
|
}
|
521
514
|
|
@@ -525,7 +518,7 @@ chart_series_set_values_(int argc, VALUE *argv, VALUE self) {
|
|
525
518
|
*
|
526
519
|
* Set chart series name.
|
527
520
|
*/
|
528
|
-
DEF_PROP_SETTER(chart_series, name, StringValueCStr(val)
|
521
|
+
DEF_PROP_SETTER(chart_series, name, StringValueCStr(val))
|
529
522
|
|
530
523
|
/* call-seq:
|
531
524
|
* series.set_name_range(name, cell) -> self
|
@@ -540,19 +533,14 @@ chart_series_set_name_range_(int argc, VALUE *argv, VALUE self) {
|
|
540
533
|
lxw_row_t row;
|
541
534
|
lxw_col_t col;
|
542
535
|
extract_cell(argc - 1, argv + 1, &row, &col);
|
543
|
-
|
544
|
-
Data_Get_Struct(self, struct chart_series, ptr);
|
545
|
-
chart_series_set_name_range(ptr->series, str, row, col);
|
536
|
+
LXW_NO_RESULT_CALL(chart_series, set_name_range, str, row, col);
|
546
537
|
return self;
|
547
538
|
}
|
548
539
|
|
549
540
|
VALUE
|
550
541
|
chart_series_set_invert_if_negative_(VALUE self, VALUE p) {
|
551
|
-
struct chart_series *ptr;
|
552
542
|
if (RTEST(p)) {
|
553
|
-
|
554
|
-
|
555
|
-
chart_series_set_invert_if_negative(ptr->series);
|
543
|
+
LXW_NO_RESULT_CALL(chart_series, set_invert_if_negative);
|
556
544
|
}
|
557
545
|
return p;
|
558
546
|
}
|
@@ -669,6 +657,8 @@ void init_xlsxwriter_chart() {
|
|
669
657
|
rb_define_method(cChartSeries, "initialize", chart_series_init, -1);
|
670
658
|
|
671
659
|
rb_define_method(cChartSeries, "set_categories", chart_series_set_categories_, -1);
|
660
|
+
rb_define_method(cChartSeries, "set_fill", chart_series_set_fill_, 1);
|
661
|
+
rb_define_method(cChartSeries, "set_line", chart_series_set_line_, 1);
|
672
662
|
rb_define_method(cChartSeries, "set_values", chart_series_set_values_, -1);
|
673
663
|
rb_define_method(cChartSeries, "name=", chart_series_set_name_, 1);
|
674
664
|
rb_define_method(cChartSeries, "set_name_range", chart_series_set_name_range_, -1);
|
data/ext/xlsxwriter/chart.h
CHANGED
@@ -9,11 +9,11 @@ struct chart {
|
|
9
9
|
};
|
10
10
|
|
11
11
|
struct chart_axis {
|
12
|
-
lxw_chart_axis *
|
12
|
+
lxw_chart_axis *chart_axis;
|
13
13
|
};
|
14
14
|
|
15
15
|
struct chart_series {
|
16
|
-
lxw_chart_series *
|
16
|
+
lxw_chart_series *chart_series;
|
17
17
|
};
|
18
18
|
|
19
19
|
lxw_chart_fill val_to_lxw_chart_fill(VALUE opts);
|
@@ -0,0 +1,307 @@
|
|
1
|
+
#include "chart.h"
|
2
|
+
#include "chartsheet.h"
|
3
|
+
#include "common.h"
|
4
|
+
#include "workbook.h"
|
5
|
+
#include "xlsxwriter_ext.h"
|
6
|
+
|
7
|
+
VALUE cChartsheet;
|
8
|
+
|
9
|
+
void chartsheet_free(void *p);
|
10
|
+
|
11
|
+
|
12
|
+
VALUE
|
13
|
+
chartsheet_alloc(VALUE klass) {
|
14
|
+
VALUE obj;
|
15
|
+
struct chartsheet *ptr;
|
16
|
+
|
17
|
+
obj = Data_Make_Struct(klass, struct chartsheet, NULL, chartsheet_free, ptr);
|
18
|
+
|
19
|
+
ptr->chartsheet = NULL;
|
20
|
+
|
21
|
+
return obj;
|
22
|
+
}
|
23
|
+
|
24
|
+
/* :nodoc: */
|
25
|
+
VALUE
|
26
|
+
chartsheet_init(int argc, VALUE *argv, VALUE self) {
|
27
|
+
char *name = NULL;
|
28
|
+
struct workbook *wb_ptr;
|
29
|
+
struct chartsheet *ptr;
|
30
|
+
|
31
|
+
Data_Get_Struct(self, struct chartsheet, ptr);
|
32
|
+
|
33
|
+
if (argc == 2) {
|
34
|
+
name = StringValueCStr(argv[1]);
|
35
|
+
}
|
36
|
+
|
37
|
+
rb_iv_set(self, "@workbook", argv[0]);
|
38
|
+
|
39
|
+
Data_Get_Struct(argv[0], struct workbook, wb_ptr);
|
40
|
+
ptr->chartsheet = workbook_add_chartsheet(wb_ptr->workbook, name);
|
41
|
+
if (!ptr->chartsheet)
|
42
|
+
rb_raise(eXlsxWriterError, "chartsheet was not created");
|
43
|
+
return self;
|
44
|
+
}
|
45
|
+
|
46
|
+
/* :nodoc: */
|
47
|
+
VALUE
|
48
|
+
chartsheet_release(VALUE self) {
|
49
|
+
struct chartsheet *ptr;
|
50
|
+
Data_Get_Struct(self, struct chartsheet, ptr);
|
51
|
+
|
52
|
+
chartsheet_free(ptr);
|
53
|
+
return self;
|
54
|
+
}
|
55
|
+
|
56
|
+
void
|
57
|
+
chartsheet_free(void *p) {
|
58
|
+
struct chartsheet *ptr = p;
|
59
|
+
|
60
|
+
if (ptr->chartsheet)
|
61
|
+
ptr->chartsheet = NULL;
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
/* call-seq: cs.activate -> self
|
66
|
+
*
|
67
|
+
* Set the chartsheet to be active on opening the workbook.
|
68
|
+
*/
|
69
|
+
VALUE
|
70
|
+
chartsheet_activate_(VALUE self) {
|
71
|
+
LXW_NO_RESULT_CALL(chartsheet, activate);
|
72
|
+
return self;
|
73
|
+
}
|
74
|
+
|
75
|
+
/* call-seq: cs.chart = chart
|
76
|
+
*
|
77
|
+
* Set the chart chartsheet contains.
|
78
|
+
*/
|
79
|
+
VALUE
|
80
|
+
chartsheet_set_chart_(VALUE self, VALUE chart) {
|
81
|
+
struct chart *chart_ptr;
|
82
|
+
Data_Get_Struct(chart, struct chart, chart_ptr);
|
83
|
+
|
84
|
+
LXW_ERR_RESULT_CALL(chartsheet, set_chart, chart_ptr->chart);
|
85
|
+
return self;
|
86
|
+
}
|
87
|
+
|
88
|
+
/* call-seq: cs.hide -> self
|
89
|
+
*
|
90
|
+
* Hide the chartsheet.
|
91
|
+
*/
|
92
|
+
VALUE
|
93
|
+
chartsheet_hide_(VALUE self) {
|
94
|
+
LXW_NO_RESULT_CALL(chartsheet, hide);
|
95
|
+
return self;
|
96
|
+
}
|
97
|
+
|
98
|
+
/* call-seq: cs.paper=(type) -> type
|
99
|
+
*
|
100
|
+
* Sets the paper +type+ for printing. See {libxlsxwriter doc}[https://libxlsxwriter.github.io/worksheet_8h.html#a9f8af12017797b10c5ee68e04149032f] for options.
|
101
|
+
*/
|
102
|
+
VALUE
|
103
|
+
chartsheet_set_paper_(VALUE self, VALUE paper_type) {
|
104
|
+
LXW_NO_RESULT_CALL(chartsheet, set_paper, NUM2INT(paper_type));
|
105
|
+
return self;
|
106
|
+
}
|
107
|
+
|
108
|
+
/* call-seq: cs.protect(password[, opts]) -> self
|
109
|
+
*
|
110
|
+
* Protects the worksheet elements from modification.
|
111
|
+
* See {libxlsxwriter doc}[https://libxlsxwriter.github.io/worksheet_8h.html#a1b49e135d4debcdb25941f2f40f04cb0]
|
112
|
+
* for options.
|
113
|
+
*/
|
114
|
+
VALUE
|
115
|
+
chartsheet_protect_(int argc, VALUE *argv, VALUE self) {
|
116
|
+
rb_check_arity(argc, 0, 2);
|
117
|
+
struct _protect_options po = _extract_protect_options(argc, argv);
|
118
|
+
LXW_NO_RESULT_CALL(chartsheet, protect, po.password, (po.with_options ? &po.options : NULL));
|
119
|
+
return self;
|
120
|
+
}
|
121
|
+
|
122
|
+
/* call-seq: cs.set_fitst_sheet -> self
|
123
|
+
*
|
124
|
+
* Set the sheet to be the first visible in the sheets list (which is placed
|
125
|
+
* under the work area in Excel).
|
126
|
+
*/
|
127
|
+
VALUE
|
128
|
+
chartsheet_set_first_sheet_(VALUE self) {
|
129
|
+
LXW_NO_RESULT_CALL(chartsheet, set_first_sheet);
|
130
|
+
return self;
|
131
|
+
}
|
132
|
+
|
133
|
+
/* call-seq: cs.set_footer(text[, opts])
|
134
|
+
*
|
135
|
+
* See Worksheet#set_header for params description.
|
136
|
+
*/
|
137
|
+
VALUE
|
138
|
+
chartsheet_set_footer_(int argc, VALUE *argv, VALUE self) {
|
139
|
+
rb_check_arity(argc, 1, 2);
|
140
|
+
struct _header_options ho = _extract_header_options(argc, argv);
|
141
|
+
struct chartsheet *ptr;
|
142
|
+
Data_Get_Struct(self, struct chartsheet, ptr);
|
143
|
+
lxw_error err;
|
144
|
+
if (!ho.with_options) {
|
145
|
+
err = chartsheet_set_footer(ptr->chartsheet, ho.str);
|
146
|
+
} else {
|
147
|
+
err = chartsheet_set_footer_opt(ptr->chartsheet, ho.str, &ho.options);
|
148
|
+
}
|
149
|
+
handle_lxw_error(err);
|
150
|
+
return self;
|
151
|
+
}
|
152
|
+
|
153
|
+
/* call-seq: cs.select -> self
|
154
|
+
*
|
155
|
+
* Set the chartsheet to be selected on opening the workbook.
|
156
|
+
*/
|
157
|
+
VALUE
|
158
|
+
chartsheet_select_(VALUE self) {
|
159
|
+
LXW_NO_RESULT_CALL(chartsheet, select);
|
160
|
+
return self;
|
161
|
+
}
|
162
|
+
|
163
|
+
/* call-seq: cs.set_header(text[, opts])
|
164
|
+
*
|
165
|
+
* See Worksheet#set_header for params description.
|
166
|
+
*/
|
167
|
+
VALUE
|
168
|
+
chartsheet_set_header_(int argc, VALUE *argv, VALUE self) {
|
169
|
+
rb_check_arity(argc, 1, 2);
|
170
|
+
struct _header_options ho = _extract_header_options(argc, argv);
|
171
|
+
struct chartsheet *ptr;
|
172
|
+
Data_Get_Struct(self, struct chartsheet, ptr);
|
173
|
+
lxw_error err;
|
174
|
+
if (!ho.with_options) {
|
175
|
+
err = chartsheet_set_header(ptr->chartsheet, ho.str);
|
176
|
+
} else {
|
177
|
+
err = chartsheet_set_header_opt(ptr->chartsheet, ho.str, &ho.options);
|
178
|
+
}
|
179
|
+
handle_lxw_error(err);
|
180
|
+
return self;
|
181
|
+
}
|
182
|
+
|
183
|
+
/* call-seq: cs.set_landscape -> self
|
184
|
+
*
|
185
|
+
* Sets print orientation of the chartsheet to landscape.
|
186
|
+
*/
|
187
|
+
VALUE
|
188
|
+
chartsheet_set_landscape_(VALUE self) {
|
189
|
+
LXW_NO_RESULT_CALL(chartsheet, set_landscape);
|
190
|
+
return self;
|
191
|
+
}
|
192
|
+
|
193
|
+
/* Sets the chartsheet margins (Numeric) for the printed page. */
|
194
|
+
VALUE
|
195
|
+
chartsheet_set_margins_(VALUE self, VALUE left, VALUE right, VALUE top, VALUE bottom) {
|
196
|
+
LXW_NO_RESULT_CALL(chartsheet, set_margins, NUM2DBL(left), NUM2DBL(right), NUM2DBL(top), NUM2DBL(bottom));
|
197
|
+
return self;
|
198
|
+
}
|
199
|
+
|
200
|
+
/* call-seq: cs.set_portrait -> self
|
201
|
+
*
|
202
|
+
* Sets print orientation of the chartsheet to portrait.
|
203
|
+
*/
|
204
|
+
VALUE
|
205
|
+
chartsheet_set_portrait_(VALUE self) {
|
206
|
+
LXW_NO_RESULT_CALL(chartsheet, set_portrait);
|
207
|
+
return self;
|
208
|
+
}
|
209
|
+
|
210
|
+
/* call-seq: cs.tab_color=(color) -> color
|
211
|
+
*
|
212
|
+
* Set the tab color (from RGB integer).
|
213
|
+
*
|
214
|
+
* ws.tab_color = 0xF0F0F0
|
215
|
+
*/
|
216
|
+
VALUE
|
217
|
+
chartsheet_set_tab_color_(VALUE self, VALUE color) {
|
218
|
+
LXW_NO_RESULT_CALL(chartsheet, set_tab_color, NUM2INT(color));
|
219
|
+
return color;
|
220
|
+
}
|
221
|
+
|
222
|
+
/* call-seq: cs.zoom=(zoom) -> zoom
|
223
|
+
*
|
224
|
+
* Sets the worksheet zoom factor in the range 10 <= +zoom+ <= 400.
|
225
|
+
*/
|
226
|
+
VALUE
|
227
|
+
chartsheet_set_zoom_(VALUE self, VALUE val) {
|
228
|
+
LXW_NO_RESULT_CALL(chartsheet, set_zoom, NUM2INT(val));
|
229
|
+
return self;
|
230
|
+
}
|
231
|
+
|
232
|
+
/* call-seq: cs.horizontal_dpi -> int
|
233
|
+
*
|
234
|
+
* Returns the horizontal dpi.
|
235
|
+
*/
|
236
|
+
VALUE
|
237
|
+
chartsheet_get_horizontal_dpi_(VALUE self) {
|
238
|
+
struct chartsheet *ptr;
|
239
|
+
Data_Get_Struct(self, struct chartsheet, ptr);
|
240
|
+
return INT2NUM(ptr->chartsheet->worksheet->horizontal_dpi);
|
241
|
+
}
|
242
|
+
|
243
|
+
/* call-seq: cs.horizontal_dpi=(dpi) -> dpi
|
244
|
+
*
|
245
|
+
* Sets the horizontal dpi.
|
246
|
+
*/
|
247
|
+
VALUE
|
248
|
+
chartsheet_set_horizontal_dpi_(VALUE self, VALUE val) {
|
249
|
+
struct chartsheet *ptr;
|
250
|
+
Data_Get_Struct(self, struct chartsheet, ptr);
|
251
|
+
ptr->chartsheet->worksheet->horizontal_dpi = NUM2INT(val);
|
252
|
+
return val;
|
253
|
+
}
|
254
|
+
|
255
|
+
/* call-seq: cs.vertical_dpi -> int
|
256
|
+
*
|
257
|
+
* Returns the vertical dpi.
|
258
|
+
*/
|
259
|
+
VALUE
|
260
|
+
chartsheet_get_vertical_dpi_(VALUE self) {
|
261
|
+
struct chartsheet *ptr;
|
262
|
+
Data_Get_Struct(self, struct chartsheet, ptr);
|
263
|
+
return INT2NUM(ptr->chartsheet->worksheet->vertical_dpi);
|
264
|
+
}
|
265
|
+
|
266
|
+
/* call-seq: cs.vertical_dpi=(dpi) -> dpi
|
267
|
+
*
|
268
|
+
* Sets the vertical dpi.
|
269
|
+
*/
|
270
|
+
VALUE
|
271
|
+
chartsheet_set_vertical_dpi_(VALUE self, VALUE val) {
|
272
|
+
struct chartsheet *ptr;
|
273
|
+
Data_Get_Struct(self, struct chartsheet, ptr);
|
274
|
+
ptr->chartsheet->worksheet->vertical_dpi = NUM2INT(val);
|
275
|
+
return val;
|
276
|
+
}
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
void
|
281
|
+
init_xlsxwriter_chartsheet() {
|
282
|
+
/* Xlsx chartsheet */
|
283
|
+
cChartsheet = rb_define_class_under(mXlsxWriter, "Chartsheet", rb_cObject);
|
284
|
+
|
285
|
+
rb_define_alloc_func(cChartsheet, chartsheet_alloc);
|
286
|
+
rb_define_method(cChartsheet, "initialize", chartsheet_init, -1);
|
287
|
+
rb_define_method(cChartsheet, "free", chartsheet_release, 0);
|
288
|
+
rb_define_method(cChartsheet, "activate", chartsheet_activate_, 0);
|
289
|
+
rb_define_method(cChartsheet, "chart=", chartsheet_set_chart_, 1);
|
290
|
+
rb_define_method(cChartsheet, "hide", chartsheet_hide_, 0);
|
291
|
+
rb_define_method(cChartsheet, "paper=", chartsheet_set_paper_, 1);
|
292
|
+
rb_define_method(cChartsheet, "protect", chartsheet_protect_, -1);
|
293
|
+
rb_define_method(cChartsheet, "select", chartsheet_select_, 0);
|
294
|
+
rb_define_method(cChartsheet, "set_first_sheet", chartsheet_set_first_sheet_, 0);
|
295
|
+
rb_define_method(cChartsheet, "set_footer", chartsheet_set_footer_, -1);
|
296
|
+
rb_define_method(cChartsheet, "set_header", chartsheet_set_header_, -1);
|
297
|
+
rb_define_method(cChartsheet, "set_landscape", chartsheet_set_landscape_, 0);
|
298
|
+
rb_define_method(cChartsheet, "set_margins", chartsheet_set_margins_, 4);
|
299
|
+
rb_define_method(cChartsheet, "set_portrait", chartsheet_set_portrait_, 0);
|
300
|
+
rb_define_method(cChartsheet, "tab_color=", chartsheet_set_tab_color_, 1);
|
301
|
+
rb_define_method(cChartsheet, "zoom=", chartsheet_set_zoom_, 1);
|
302
|
+
|
303
|
+
rb_define_method(cChartsheet, "horizontal_dpi", chartsheet_get_horizontal_dpi_, 0);
|
304
|
+
rb_define_method(cChartsheet, "horizontal_dpi=", chartsheet_set_horizontal_dpi_, 1);
|
305
|
+
rb_define_method(cChartsheet, "vertical_dpi", chartsheet_get_vertical_dpi_, 0);
|
306
|
+
rb_define_method(cChartsheet, "vertical_dpi=", chartsheet_set_vertical_dpi_, 1);
|
307
|
+
}
|