Class: GDChart

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

Overview

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

Defined Under Namespace

Classes: Annotation, Scatter

Constant Summary collapse

LINE =

Chart types

INT2FIX(GDC_LINE)
AREA =
INT2FIX(GDC_AREA)
BAR =
INT2FIX(GDC_BAR)
FLOATINGBAR =
INT2FIX(GDC_FLOATINGBAR)
HILOCLOSE =
INT2FIX(GDC_HILOCLOSE)
COMBO_LINE_BAR =
INT2FIX(GDC_COMBO_LINE_BAR)
COMBO_HLC_BAR =
INT2FIX(GDC_COMBO_HLC_BAR)
COMBO_LINE_AREA =
INT2FIX(GDC_COMBO_LINE_AREA)
COMBO_LINE_LINE =
INT2FIX(GDC_COMBO_LINE_LINE)
COMBO_HLC_AREA =
INT2FIX(GDC_COMBO_HLC_AREA)
HILOCLOSE3D =
INT2FIX(GDC_3DHILOCLOSE)
COMBO_LINE_BAR3D =
INT2FIX(GDC_3DCOMBO_LINE_BAR)
COMBO_LINE_AREA3D =
INT2FIX(GDC_3DCOMBO_LINE_AREA)
COMBO_LINE_LINE3D =
INT2FIX(GDC_3DCOMBO_LINE_LINE)
COMBO_HLC_BAR3D =
INT2FIX(GDC_3DCOMBO_HLC_BAR)
COMBO_HLC_AREA3D =
INT2FIX(GDC_3DCOMBO_HLC_AREA)
BAR3D =
INT2FIX(GDC_3DBAR)
FLOATINGBAR3D =
INT2FIX(GDC_3DFLOATINGBAR)
AREA3D =
INT2FIX(GDC_3DAREA)
LINE3D =
INT2FIX(GDC_3DLINE)
STACK_DEPTH =

Stack types

INT2FIX(GDC_STACK_DEPTH)
STACK_SUM =
INT2FIX(GDC_STACK_SUM)
STACK_BESIDE =
INT2FIX(GDC_STACK_BESIDE)
STACK_LAYER =
INT2FIX(GDC_STACK_LAYER)
HLC_DIAMOND =

HiLoClose chart styles

INT2FIX(GDC_HLC_DIAMOND)
HLC_CLOSE_CONNECTED =
INT2FIX(GDC_HLC_CLOSE_CONNECTED)
HLC_CONNECTING =
INT2FIX(GDC_HLC_CONNECTING)
HLC_I_CAP =
INT2FIX(GDC_HLC_I_CAP)
TICK_LABELS =

Axis tick types

INT2FIX(GDC_TICK_LABELS)
TICK_POINTS =
INT2FIX(GDC_TICK_POINTS)
TICK_NONE =
INT2FIX(GDC_TICK_NONE)
BORDER_NONE =

Border types

INT2FIX(GDC_BORDER_NONE)
BORDER_ALL =
INT2FIX(GDC_BORDER_ALL)
BORDER_X =
INT2FIX(GDC_BORDER_X)
BORDER_Y =
INT2FIX(GDC_BORDER_Y)
BORDER_Y2 =
INT2FIX(GDC_BORDER_Y2)
BORDER_TOP =
INT2FIX(GDC_BORDER_TOP)
GIF =

Output types

INT2FIX(GDC_GIF)
JPEG =
INT2FIX(GDC_JPEG)
PNG =
INT2FIX(GDC_PNG)
WBMP =
INT2FIX(GDC_WBMP)
TINY =

Font sizes

INT2FIX(GDC_TINY)
SMALL =
INT2FIX(GDC_SMALL)
MEDBOLD =
INT2FIX(GDC_MEDBOLD)
LARGE =
INT2FIX(GDC_LARGE)
GIANT =
INT2FIX(GDC_GIANT)
JUSTIFY_RIGHT =

Text justifications

INT2FIX(GDC_JUSTIFY_RIGHT)
JUSTIFY_CENTER =
INT2FIX(GDC_JUSTIFY_CENTER)
JUSTIFY_LEFT =
INT2FIX(GDC_JUSTIFY_LEFT)
INTERP_VALUE =
rb_float_new(GDC_INTERP_VALUE)
NOVALUE =
rb_float_new(GDC_NOVALUE)
NOCOLOR =
INT2FIX(GDC_NOCOLOR)
DFLTCOLOR =
INT2FIX(GDC_DFLTCOLOR)

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

#annotationObject

#annotation_fontObject

#annotation_font_sizeObject

#annotation_ptsizeObject

#bar_widthObject

#borderObject

#depth_3dObject

#gridObject

#hard_grapheightObject

#hard_graphwidthObject

#hard_sizeObject

#hard_xorigObject

#hard_yorigObject

#image_typeObject

#interpolationsObject

#num_scatter_ptsObject

#requested_yintervalObject

#requested_ymaxObject

#requested_yminObject

#scatterObject

#stack_typeObject

#thumblabelObject

#thumbnailObject

#thumbvalObject

#ticksObject

#titleObject

#title_fontObject

#title_ptsizeObject

#title_sizeObject

#transparent_bgObject

#xaxisObject

#xaxis_angleObject

#xaxis_fontObject

#xaxis_ptsizeObject

#xaxisfont_sizeObject

#xlabel_ctlObject

#xlabel_spacingObject

#xtitleObject

#xtitle_fontObject

#xtitle_ptsizeObject

#xtitle_sizeObject

#yaxisObject

#yaxis2Object

#yaxis_fontObject

#yaxis_ptsizeObject

#yaxisfont_sizeObject

#ylabel2_fmtObject

#ylabel_densityObject

#ylabel_fmtObject

#ytitleObject

#ytitle2Object

#ytitle_fontObject

#ytitle_ptsizeObject

#ytitle_sizeObject

#yval_styleObject

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

output graph image



678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# File 'ext/gdchart.c', line 678

static VALUE gdc_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 num_sets;		/* number of data sets */
  VALUE data;
  VALUE combodata;
    
  OpenFile *fptr;
  FILE *f;

  int i;
  int label_num;
  int all_points;
  char **c_labels;
  float *fdata, *fcombodata;

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

  /* Do type 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(num_sets, T_FIXNUM);
  Check_Type(data, T_ARRAY);
  if(combodata != Qnil)
    Check_Type(combodata, T_ARRAY);

  /* Set GDChart options */
  gdc_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;
    }
  }

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


  if(combodata == Qnil)
    fcombodata = NULL;  
  else {
    fcombodata = ALLOC_N(float, FIX2INT(num_points));
    for(i = 0; i < FIX2INT(num_points); i++)
      fcombodata[i] = NUM2DBL(rb_ary_entry(combodata, i));
    
  }
    
#ifdef DEBUG
  for(i = 0; i < FIX2INT(num_points) * FIX2INT(num_sets); i++)
    rb_warn("fdata[%d] = %f", i, fdata[i]);

  rb_warn("Going to call GDC_out_graph...");
  rb_warn("Arguments to GDC_outgraph:");
  rb_warn("%d, %d, %x, %d, %d, %p, %d, %p, %p",FIX2INT(imgwidth),
          FIX2INT(imgheight),
          f,
          FIX2INT(type),
          FIX2INT(num_points),
          clabels,
          FIX2INT(num_sets),
          fdata,
          0
          );
#endif

  GDC_out_graph(FIX2INT(imgwidth),
                FIX2INT(imgheight),
                f,
                FIX2INT(type),
                FIX2INT(num_points),
                c_labels,
                FIX2INT(num_sets),
                fdata,
                fcombodata
                );

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

  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;
}