Class: GDChartPie

Inherits:
Object
  • Object
show all
Defined in:
ext/gdchart.c

Constant Summary collapse

PIE3D =

constant

INT2FIX(GDC_3DPIE)
PIE2D =
INT2FIX(GDC_2DPIE)
PCT_NONE =
INT2FIX(GDCPIE_PCT_NONE)
PCT_ABOVE =
INT2FIX(GDCPIE_PCT_ABOVE)
PCT_BELOW =
INT2FIX(GDCPIE_PCT_BELOW)
PCT_RIGHT =
INT2FIX(GDCPIE_PCT_RIGHT)
PCT_LEFT =
INT2FIX(GDCPIE_PCT_LEFT)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject

///////////////////////////////////////////////////////////////////////



463
464
465
466
# File 'ext/gdchart.c', line 463

VALUE gdc_initialize(VALUE obj)
{
  return obj;
}

Instance Attribute Details

#angle_3dObject

#depth_3dObject

#explodeObject

#image_typeObject

#label_distObject

#label_fontObject

#label_lineObject

#label_ptsizeObject

#label_sizeObject

#missingObject

#other_thresholdObject

#percent_fmtObject

#percent_labelsObject

#perspectiveObject

#titleObject

#title_fontObject

#title_ptsizeObject

#title_sizeObject

Class Method Details

.newObject

GDChart class definition



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'ext/gdchart.c', line 444

VALUE gdc_new(VALUE klass)
{
  gdc_t *gdc;
  VALUE obj;

  obj = Data_Make_Struct(klass, struct _gdc_t, 0, gdc_free, gdc);
  gdc->annotation  = NULL;
  gdc->scatter     = NULL;
  gdc->ExtVolColor = NULL;
  gdc->SetColor    = NULL;
  gdc->ExtColor    = NULL;

  rb_obj_call_init(obj, 0, NULL);

  return obj;
}

Instance Method Details

#out_graph(*args) ⇒ Object

///////////////////////////////////////////////////////////////////////



797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
# File 'ext/gdchart.c', line 797

static VALUE gdc_pie_out_graph(int argc, VALUE *argv, VALUE self)
{
  VALUE imgwidth, imgheight;  /* output image size */
  VALUE out;      /* output file descriptor */
  VALUE type;     /* chart type */
  VALUE num_points;   /* x axis points */
  VALUE labels;
  VALUE data;
    
  OpenFile *fptr;
  FILE *f;

  int i;
  int label_num;
  char **c_labels;
  float *fdata;

  rb_scan_args(argc, argv, "7", &imgwidth, &imgheight,
               &out, &type, &num_points, &labels, &data);

  /* Do some sanity check */
  Check_Type(imgwidth, T_FIXNUM);
  Check_Type(imgheight, T_FIXNUM);
  Check_Type(out, T_FILE);
  Check_Type(type, T_FIXNUM); /* XXX: 'type' is constant? */
  Check_Type(num_points, T_FIXNUM);
  Check_Type(labels, T_ARRAY);
  Check_Type(data, T_ARRAY);

  /* Set GDChart options */
  gdc_pie_set_params(self);

  /* prepare output */
  rb_io_binmode(out);
  GetOpenFile(out, fptr);
  rb_io_check_writable(fptr);
  f = GetWriteFile(fptr);

  label_num = RARRAY(labels)->len;
  if(label_num < NUM2INT(num_points))
    label_num = NUM2INT(num_points);

  c_labels = ALLOC_N(char *, label_num);
  for(i = 0; i < label_num; i++) {
    switch(TYPE(rb_ary_entry(labels, i))) {
    case T_NIL:
      c_labels[i] = "";
      break;

    case T_STRING:
      c_labels[i] = STR2CSTR(rb_ary_entry(labels, i));
      break;

    default:
      rb_raise(rb_eTypeError, "type error");
      break;
    }
  }

  fdata = ALLOC_N(float, FIX2INT(num_points));
  for(i = 0; i < FIX2INT(num_points); i++)
    fdata[i] = NUM2DBL(rb_ary_entry(data, i));

  GDC_out_pie(FIX2INT(imgwidth),
              FIX2INT(imgheight),
              f,
              FIX2INT(type),
              FIX2INT(num_points),
              c_labels,
              fdata
              );

  if(c_labels != NULL)   free(c_labels);
  if(fdata != NULL)      free(fdata);

  return Qnil;
}

#set_paramObject

Set GDChart option variable



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'ext/gdchart.c', line 473

static VALUE gdc_set_params(VALUE obj)
{
  gdc_t *gdc;

  set_param(obj, "@ytitle", &GDC_ytitle, STRING);
  set_param(obj, "@xtitle", &GDC_xtitle, STRING);
  set_param(obj, "@ytitle2", &GDC_ytitle2, STRING);
  set_param(obj, "@title", &GDC_title, STRING);
  set_param(obj, "@title_size", &GDC_title_size, FONT_SIZE);
  set_param(obj, "@ytitle_size", &GDC_ytitle_size, FONT_SIZE);
  set_param(obj, "@xtitle_size", &GDC_xtitle_size, FONT_SIZE);
  set_param(obj, "@yaxisfont_size", &GDC_yaxisfont_size, FONT_SIZE);
  set_param(obj, "@xaxisfont_size", &GDC_xaxisfont_size, FONT_SIZE);
  set_param(obj, "@xaxis_angle", &GDC_xaxis_angle, DOUBLE);
#ifdef HAVE_LIBFREETYPE
  set_param(obj, "@title_font", &GDC_title_font, STRING);
  set_param(obj, "@ytitle_font", &GDC_ytitle_font, STRING);
  set_param(obj, "@xtitle_font", &GDC_xtitle_font, STRING);
  set_param(obj, "@xaxis_font", &GDC_xaxis_font, STRING);
  set_param(obj, "@yaxis_font", &GDC_yaxis_font, STRING);
  set_param(obj, "@title_ptsize", &GDC_title_ptsize, DOUBLE);
  set_param(obj, "@ytitle_ptsize", &GDC_ytitle_ptsize, DOUBLE);
  set_param(obj, "@xtitle_ptsize", &GDC_xtitle_ptsize, DOUBLE);
  set_param(obj, "@xaxis_ptsize", &GDC_xaxis_ptsize, DOUBLE);
  set_param(obj, "@yaxis_ptsize", &GDC_yaxis_ptsize, DOUBLE);
#endif
  set_param(obj, "@ylabel_fmt", &GDC_ylabel_fmt, STRING);
  set_param(obj, "@ylabel2_fmt", &GDC_ylabel2_fmt, STRING);
  set_param(obj, "@xlabel_ctl", &GDC_xlabel_ctl, BOOL_ARRAY);
  set_param(obj, "@xlabel_spacing", &GDC_xlabel_spacing, SHORT);
  set_param(obj, "@ylabel_density", &GDC_ylabel_density, CHAR);
  set_param(obj, "@interpolations", &GDC_interpolations, BOOL);
  set_param(obj, "@requested_ymin", &GDC_requested_ymin, FLOAT);
  set_param(obj, "@requested_ymax", &GDC_requested_ymax, FLOAT);
  set_param(obj, "@requested_yinterval", &GDC_requested_yinterval, FLOAT);
  set_param(obj, "@shelf0", &GDC_0Shelf, BOOL);
  set_param(obj, "@grid", &GDC_grid, BOOL);
  set_param(obj, "@ticks", &GDC_ticks, INT);
  set_param(obj, "@xaxis", &GDC_xaxis, BOOL);
  set_param(obj, "@yaxis", &GDC_yaxis, BOOL);
  set_param(obj, "@yaxis2", &GDC_yaxis2, BOOL);
  set_param(obj, "@yval_style", &GDC_yval_style, BOOL);
  set_param(obj, "@stack_type", &GDC_stack_type, STACK_T);
  set_param(obj, "@depth_3d", &GDC_3d_depth, FLOAT);
  set_param(obj, "@angle_3d", &GDC_3d_angle, UCHAR);
  set_param(obj, "@bar_width", &GDC_bar_width, UCHAR);
  set_param(obj, "@hlc_style", &GDC_HLC_style, HLC_STYLE);
  set_param(obj, "@hlc_cap_width", &GDC_HLC_cap_width, UCHAR);
  set_param(obj, "@annotation", &GDC_annotation, ANNOTATION_T);
  set_param(obj, "@annotation_font_size", &GDC_annotation_font_size, FONT_SIZE);
#ifdef HAVE_LIBFREETYPE
  set_param(obj, "@annotation_font", &GDC_annotation_font, FONT_SIZE);
  set_param(obj, "@annotation_ptsize", &GDC_annotation_ptsize, DOUBLE);
#endif
  set_param(obj, "@num_scatter_pts", &GDC_num_scatter_pts, INT);
  set_param(obj, "@scatter", &GDC_scatter, SCATTER_T_ARRAY);
  set_param(obj, "@thumbnail", &GDC_thumbnail, BOOL);
  set_param(obj, "@thumblabel", &GDC_thumblabel, STRING);
  set_param(obj, "@thumbval", &GDC_thumbval, FLOAT);
  set_param(obj, "@border", &GDC_border, BOOL);
  set_param(obj, "@bg_color", &GDC_BGColor, ULONG);
  set_param(obj, "@grid_color", &GDC_GridColor, ULONG);
  set_param(obj, "@line_color", &GDC_LineColor, ULONG);
  set_param(obj, "@plot_color", &GDC_PlotColor, ULONG);
  set_param(obj, "@vol_color", &GDC_VolColor, ULONG);
  set_param(obj, "@title_color", &GDC_TitleColor, ULONG);
  set_param(obj, "@xtitle_color", &GDC_XTitleColor, ULONG);
  set_param(obj, "@ytitle_color", &GDC_YTitleColor, ULONG);
  set_param(obj, "@ytitle2_color", &GDC_YTitle2Color, ULONG);
  set_param(obj, "@xlabel_color", &GDC_XLabelColor, ULONG);
  set_param(obj, "@ylabel_color", &GDC_YLabelColor, ULONG);
  set_param(obj, "@ylabel2_color", &GDC_YLabel2Color, ULONG);
  set_param(obj, "@ext_vol_color", &GDC_ExtVolColor, ULONG_ARRAY);
  set_param(obj, "@set_color", &GDC_SetColor, ULONG_ARRAY);
  set_param(obj, "@ext_color", &GDC_ExtColor, ULONG_ARRAY);
  set_param(obj, "@transparent_bg", &GDC_transparent_bg, CHAR);
  set_param(obj, "@bg_image", &GDC_BGImage, STRING);

  set_param(obj, "@hard_size", &GDC_hard_size, BOOL);
  set_param(obj, "@hard_xorig", &GDC_hard_xorig, INT);
  set_param(obj, "@hard_graphwidth", &GDC_hard_graphwidth, INT);
  set_param(obj, "@hard_yorig", &GDC_hard_yorig, INT);
  set_param(obj, "@hard_grapheight", &GDC_hard_grapheight, INT);

  set_param(obj, "@image_type", &GDC_image_type, INT);


  Data_Get_Struct(obj, struct _gdc_t, gdc);

  /*
   * Before set new data, free allocated old data if it exist.
   */
  SAFE_FREE(gdc, annotation);
  SAFE_FREE(gdc, scatter);
  SAFE_FREE(gdc, ExtVolColor);
  SAFE_FREE(gdc, SetColor);
  SAFE_FREE(gdc, ExtColor);

  /*
   * Copy pointers which indicate dynamically allocated structure.
   * It is used to do GC by Ruby.
   *
   * ANNOTATION_T, SCATTER_T, ULONG_ARRAY parameters allocate memory
   * dynamically.
   */
  gdc->annotation  = GDC_annotation;
  gdc->scatter     = GDC_scatter;
  gdc->ExtVolColor = GDC_ExtVolColor;
  gdc->SetColor    = GDC_SetColor;
  gdc->ExtColor    = GDC_ExtColor;

  return obj;
}