-
Notifications
You must be signed in to change notification settings - Fork 17
/
Graph.pm
1804 lines (1309 loc) · 51.8 KB
/
Graph.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
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
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
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
794
795
796
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
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#==========================================================================
# Copyright (c) 1995-2000 Martien Verbruggen
#--------------------------------------------------------------------------
#
# Name:
# GD::Graph.pm
#
# Description:
# Module to create graphs from a data set drawing on a GD::Image
# object
#
# Package of a number of graph types:
# GD::Graph::bars
# GD::Graph::hbars
# GD::Graph::lines
# GD::Graph::points
# GD::Graph::linespoints
# GD::Graph::area
# GD::Graph::pie
# GD::Graph::mixed
#
# $Id: Graph.pm,v 1.55 2007/04/26 04:12:47 ben Exp $
#
#==========================================================================
#
# GD::Graph
#
# Parent class containing data all graphs have in common.
#
package GD::Graph;
($GD::Graph::prog_version) = '$Revision: 1.55 $' =~ /\s([\d.]+)/;
$GD::Graph::VERSION = '1.48';
use strict;
use GD;
use GD::Text::Align;
use GD::Graph::Data;
use GD::Graph::Error;
use Carp;
@GD::Graph::ISA = qw(GD::Graph::Error);
# Some tools and utils
use GD::Graph::colour qw(:colours);
my %GDsize = (
'x' => 400,
'y' => 300
);
my %Defaults = (
# Set the top, bottom, left and right margin for the chart. These
# margins will be left empty.
t_margin => 0,
b_margin => 0,
l_margin => 0,
r_margin => 0,
# Set the factor with which to resize the logo in the chart (need to
# automatically compute something nice for this, really), set the
# default logo file name, and set the logo position (UR, BR, UL, BL)
logo => undef,
logo_resize => 1.0,
logo_position => 'LR',
# Do we want a transparent background?
transparent => 1,
# Do we want interlacing?
interlaced => 1,
# Set the background colour, the default foreground colour (used
# for axes etc), the textcolour, the colour for labels, the colour
# for numbers on the axes, the colour for accents (extra lines, tick
# marks, etc..)
bgclr => 'white', # background colour
fgclr => 'dblue', # Axes and grid
boxclr => undef, # Fill colour for box axes, default: not used
accentclr => 'gray', # bar, area and pie outlines.
labelclr => 'dblue', # labels on axes
axislabelclr => 'dblue', # values on axes
legendclr => 'dblue', # Text for the legend
textclr => 'dblue', # All text, apart from the following 2
valuesclr => 'dblue', # values printed above the points
# data set colours
dclrs => [qw(lred lgreen lblue lyellow lpurple cyan lorange)],
# number of pixels to use as text spacing
text_space => 4,
# These have undefined values, but are here so that the set method
# knows about them:
title => undef,
);
sub _has_default {
my $self = shift;
my $attr = shift || return;
exists $Defaults{$attr}
}
#
# PUBLIC methods, documented in pod.
#
sub new # ( width, height ) optional;
{
my $type = shift;
my $self = {};
bless $self, $type;
if (@_)
{
# If there are any parameters, they should be the size
return GD::Graph->_set_error(
"Usage: GD::Graph::<type>::new(width, height)") unless @_ >= 2;
$self->{width} = shift;
$self->{height} = shift;
}
else
{
# There were obviously no parameters, so use defaults
$self->{width} = $GDsize{'x'};
$self->{height} = $GDsize{'y'};
}
# Initialise all relevant parameters to defaults
# These are defined in the subclasses. See there.
$self->initialise() or return;
return $self;
}
sub get
{
my $self = shift;
my @wanted = map $self->{$_}, @_;
wantarray ? @wanted : $wanted[0];
}
sub set
{
my $self = shift;
my %args = @_;
my $w = 0;
foreach (keys %args)
{
# Enforce read-only attributes.
/^width$/ || /^height$/ and do
{
$self->_set_warning("Read-only attribute '$_' not set");
$w++;
next;
};
$self->{$_} = $args{$_}, next if $self->_has_default($_);
$w++;
$self->_set_warning("No attribute '$_'");
}
return $w ? undef : "No problems";
}
# Generic routine to instantiate GD::Text::Align objects for text
# attributes
sub _set_font
{
my $self = shift;
my $name = shift;
if (! exists $self->{$name})
{
$self->{$name} = GD::Text::Align->new($self->{graph},
valign => 'top',
halign => 'center',
) or return $self->_set_error("Couldn't set font");
}
$self->{$name}->set_font(@_);
}
sub set_title_font # (fontname, size)
{
my $self = shift;
$self->_set_font('gdta_title', @_);
}
sub set_text_clr # (colour name)
{
my $self = shift;
my $clr = shift;
$self->set(
textclr => $clr,
labelclr => $clr,
axislabelclr => $clr,
valuesclr => $clr,
);
}
sub plot
{
# ABSTRACT
my $self = shift;
$self->die_abstract("sub plot missing,");
}
# Set defaults that apply to all graph/chart types.
# This is called by the default initialise methods
# from the objects further down the tree.
sub initialise
{
my $self = shift;
foreach (keys %Defaults)
{
$self->set($_ => $Defaults{$_});
}
$self->open_graph() or return;
$self->set_title_font(GD::Font->Large) or return;
}
# Check the integrity of the submitted data
#
# Checks are done to assure that every input array
# has the same number of data points, it sets the variables
# that store the number of sets and the number of points
# per set, and kills the process if there are no datapoints
# in the sets, or if there are no data sets.
sub check_data # \@data
{
my $self = shift;
my $data = shift;
$self->{_data} = GD::Graph::Data->new($data)
or return $self->_set_error(GD::Graph::Data->error);
$self->{_data}->make_strict;
$self->{_data}->num_sets > 0 && $self->{_data}->num_points > 0
or return $self->_set_error('No data sets or points');
if ($self->{show_values})
{
# If this isn't a GD::Graph::Data compatible structure, then
# we'll just use the data structure.
#
# XXX We should probably check a few more things here, e.g.
# similarity between _data and show_values.
#
my $ref = ref($self->{show_values});
if (! $ref || ($ref ne 'GD::Graph::Data' && $ref ne 'ARRAY'))
{
$self->{show_values} = $self->{_data}
}
elsif ($ref eq 'ARRAY')
{
$self->{show_values} =
GD::Graph::Data->new($self->{show_values})
or return $self->_set_error(GD::Graph::Data->error);
}
}
return $self;
}
# Open the graph output canvas by creating a new GD object.
sub open_graph
{
my $self = shift;
return $self->{graph} if exists $self->{graph};
$self->{graph} = 2.0 <= $GD::VERSION
? GD::Image->newPalette($self->{width}, $self->{height})
: GD::Image->new($self->{width}, $self->{height});
}
# Initialise the graph output canvas, setting colours (and getting back
# index numbers for them) setting the graph to transparent, and
# interlaced, putting a logo (if defined) on there.
sub init_graph
{
my $self = shift;
$self->{bgci} = $self->set_clr(_rgb($self->{bgclr}));
$self->{fgci} = $self->set_clr(_rgb($self->{fgclr}));
$self->{tci} = $self->set_clr(_rgb($self->{textclr}));
$self->{lci} = $self->set_clr(_rgb($self->{labelclr}));
$self->{alci} = $self->set_clr(_rgb($self->{axislabelclr}));
$self->{acci} = $self->set_clr(_rgb($self->{accentclr}));
$self->{valuesci} = $self->set_clr(_rgb($self->{valuesclr}));
$self->{legendci} = $self->set_clr(_rgb($self->{legendclr}));
$self->{boxci} = $self->set_clr(_rgb($self->{boxclr}))
if $self->{boxclr};
$self->{graph}->transparent($self->{bgci}) if $self->{transparent};
$self->{graph}->interlaced( $self->{interlaced} || undef ); # required by GD.pm
# XXX yuck. This doesn't belong here.. or does it?
$self->put_logo();
return $self;
}
sub _read_logo_file
{
my $self = shift;
my $glogo;
local (*LOGO);
my $logo_path = $self->{logo};
open(LOGO, $logo_path)
or do { carp "Unable to open logo file '$logo_path': $!";return};
binmode(LOGO);
# if the file has an extension, use that importer
my $gdimport;
my @tried;
# possibly forward-compatible: just try whatever file extension
if ( $logo_path =~ /\.(\w+)$/i) {
my $fmt = lc $1;
$fmt = "jpeg" if 'jpg' eq $fmt;
push @tried, uc $fmt;
if ($gdimport = GD::Image->can("newFrom\u$fmt")) {
if ('xpm' ne $fmt) { $glogo = GD::Image->$gdimport(\*LOGO) }
else { $glogo = GD::Image->$gdimport($logo_path) } # quirky special case
}
}
# if that didn't work, try using magic numbers
if (!$glogo) {
my $logodata;
read LOGO,$logodata, -s LOGO;
my %magic = (
pack("H8",'ffd8ffe0') => "jpeg",
'GIF8' => "gif",
'.PNG' => "png",
'/* X'=> "xpm", # technically '/* XPM */', but I'm hashing, here
);
if (my $match = $magic{ substr $logodata, 0, 4 }) {
push @tried, $match;
my $matchmethod = "newFrom\u$match";
if ($gdimport = GD::Image->can($matchmethod . "Data")) {
$glogo = GD::Image->$gdimport($logodata);
} elsif ($gdimport = GD::Image->can($matchmethod)) {
if ('xpm' eq $match) {
$glogo = GD::Image->$gdimport($logo_path);
} else {
seek LOGO,0,0;
$glogo = GD::Image->$gdimport(\*LOGO);
}
}
# should this actually be "if (!$glogo), rather than an else?
} else { # Hail Mary, full of Grace! Blessed art thou among women...
push @tried, 'libgd best-guess';
$glogo = GD::Image->new($logodata);
}
}
close LOGO or croak "Unable to close logo file '$logo_path': $!";
# XXX change to use warnings::enabled when we break 5.005 compatibility
carp "Problems reading $logo_path (tried: @tried)" unless $glogo;
return $glogo;
}
# read in the logo, and paste it on the graph canvas
sub put_logo
{
my $self = shift;
return unless defined $self->{logo};
my $glogo = $self->_read_logo_file() or return;
my ($x, $y);
my $r = $self->{logo_resize};
my $r_margin = (defined $self->{r_margin_abs}) ?
$self->{r_margin_abs} : $self->{r_margin};
my $b_margin = (defined $self->{b_margin_abs}) ?
$self->{b_margin_abs} : $self->{b_margin};
my ($w, $h) = $glogo->getBounds;
LOGO: for ($self->{logo_position}) {
/UL/i and do {
$x = $self->{l_margin};
$y = $self->{t_margin};
last LOGO;
};
/UR/i and do {
$x = $self->{width} - $r_margin - $w * $r;
$y = $self->{t_margin};
last LOGO;
};
/LL/i and do {
$x = $self->{l_margin};
$y = $self->{height} - $b_margin - $h * $r;
last LOGO;
};
# default "LR"
$x = $self->{width} - $r_margin - $r * $w;
$y = $self->{height} - $b_margin - $r * $h;
last LOGO;
}
$self->{graph}->copyResized($glogo,
$x, $y, 0, 0, $r * $w, $r * $h, $w, $h);
}
# Set a colour to work with on the canvas, by rgb value.
# Return the colour index in the palette
sub set_clr # GD::Image, r, g, b
{
my $self = shift;
return unless @_;
my $gd = $self->{graph};
# All of this could potentially be done by using colorResolve
# The problem is that colorResolve doesn't return an error
# condition (-1) if it can't allocate a color. Instead it always
# returns 0.
# Check if this colour already exists on the canvas
my $i = $gd->colorExact(@_);
# if not, allocate a new one, and return its index
$i = $gd->colorAllocate(@_) if $i < 0;
# if this fails, we should use colorClosest.
$i = $gd->colorClosest(@_) if $i < 0;
# TODO Deal with antialiasing here?
if (0 && $self->can("setAntiAliased"))
{
$self->setAntiAliased($i);
eval "$i = gdAntiAliased";
}
return $i;
}
# Set a temporary colour that can be used with fillToBorder
sub _set_tmp_clr
{
my $self = shift;
# XXX Error checks!
$self->{graph}->colorAllocate(0,0,0);
}
# Remove the temporary colour
sub _rm_tmp_clr
{
my $self = shift;
return unless @_;
# XXX Error checks?
$self->{graph}->colorDeallocate(shift);
}
# Set a colour, disregarding wether or not it already exists. This may
# be necessary where one wants the same colour to have a different
# index, as in pie slices of the same color as the edge.
# Note that this could be cleaned up after needed, but we won't do that.
sub set_clr_uniq # GD::Image, r, g, b
{
my $self = shift;
return unless @_;
$self->{graph}->colorAllocate(@_);
}
# Return an array of rgb values for a colour number
sub pick_data_clr # number
{
my $self = shift;
_rgb($self->{dclrs}[$_[0] % @{$self->{dclrs}} - 1]);
}
# contrib "Bremford, Mike" <mike.bremford@gs.com>
sub pick_border_clr # number
{
my $self = shift;
ref $self->{borderclrs} ?
_rgb($self->{borderclrs}[$_[0] % @{$self->{borderclrs}} - 1]) :
_rgb($self->{accentclr});
}
sub gd
{
my $self = shift;
return $self->{graph};
}
sub export_format
{
my $proto = shift;
my @f = grep { GD::Image->can($_) &&
do {
my $g = GD::Image->new(5,5);
$g->colorAllocate(0,0,0);
$g->$_()
};
} qw(gif png jpeg xbm xpm gd gd2);
wantarray ? @f : $f[0];
}
# The following method is undocumented, and will not be supported as
# part of the interface. There isn't really much reason to do so.
sub import_format
{
my $proto = shift;
# xpm now included despite bugginess--should document the problem, though
my @f = grep { GD::Image->can("newFrom\u$_") }
qw(gif png jpeg xbm xpm gd gd2);
wantarray ? @f : $f[0];
}
sub can_do_ttf
{
my $proto = shift;
return GD::Text->can_do_ttf;
}
# DEBUGGING
# data_dump obsolete now, use Data::Dumper
sub die_abstract
{
my $self = shift;
my $msg = shift;
# ABSTRACT
confess
"Subclass (" .
ref($self) .
") not implemented correctly: " .
(defined($msg) ? $msg : "unknown error");
}
"Just another true value";
__END__
=head1 NAME
GD::Graph - Graph Plotting Module for Perl 5
=head1 SYNOPSIS
use GD::Graph::moduleName;
=head1 DESCRIPTION
B<GD::Graph> is a I<perl5> module to create charts using the GD module.
The following classes for graphs with axes are defined:
=over 4
=item C<GD::Graph::lines>
Create a line chart.
=item C<GD::Graph::bars> and C<GD::Graph::hbars>
Create a bar chart with vertical or horizontal bars.
=item C<GD::Graph::points>
Create an chart, displaying the data as points.
=item C<GD::Graph::linespoints>
Combination of lines and points.
=item C<GD::Graph::area>
Create a graph, representing the data as areas under a line.
=item C<GD::Graph::mixed>
Create a mixed type graph, any combination of the above. At the moment
this is fairly limited. Some of the options that can be used with some
of the individual graph types won't work very well. Bar graphs drawn
after lines or points graphs may obscure the earlier data, and
specifying bar_width will not produce the results you probably expected.
=back
Additional types:
=over 4
=item C<GD::Graph::pie>
Create a pie chart.
=back
=head1 DISTRIBUTION STATUS
Distribution has no releases since 2007. It has new maintainer starting
of 1.45 and my plan is to keep modules backwards compatible as much as
possible, fix bugs with test cases, apply patches and release new versions
to the CPAN.
I got repository from Martien without Benjamin's work, Benjamin couldn't
find his repository, so everything else is imported from CPAN and BackPAN.
Now it's all on github L<https://github.com/ruz/GDGraph>. May be at some
point Benjamin will find his VCS backup and we can restore full history.
Release 1.44_01 (development release) was released in 2007 by Benjamin,
but never made into production version. This dev version contains very
nice changes (truecolor, anti-aliasing and alpha support), but due to
nature of how GD and GD::Graph works authors had to add third optional
argument (truecolor) to all constructors in GD::Graph modules. I think
that this should be and can be adjusted to receive named arguments in
constructor and still be backwards compatible. If you were using that
dev release and want to fast forward inclusion of this work into production
release then contact ruz@cpan.org
Martien also has changes in his repository that were never published
to CPAN. These are smaller and well isolated, so I can merge them faster.
My goal at this moment is to merge existing versions together, get rid
of CVS reminders, do some repo cleanup, review existing tickets on
rt.cpan.org. Join if you want to help.
=head1 EXAMPLES
See the samples directory in the distribution, and read the Makefile
there.
=head1 USAGE
Fill an array of arrays with the x values and the values of the data
sets. Make sure that every array is the same size, otherwise
I<GD::Graph> will complain and refuse to compile the graph.
@data = (
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
[ sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ]
);
If you don't have a value for a point in a certain dataset, you can
use B<undef>, and the point will be skipped.
Create a new I<GD::Graph> object by calling the I<new> method on the
graph type you want to create (I<chart> is I<bars>, I<hbars>,
I<lines>, I<points>, I<linespoints>, I<mixed> or I<pie>).
my $graph = GD::Graph::chart->new(400, 300);
Set the graph options.
$graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'Some simple graph',
y_max_value => 8,
y_tick_number => 8,
y_label_skip => 2
) or die $graph->error;
and plot the graph.
my $gd = $graph->plot(\@data) or die $graph->error;
Then do whatever your current version of GD allows you to do to save the
file. For versions of GD older than 1.19 (or more recent than 2.15),
you'd do something like:
open(IMG, '>file.gif') or die $!;
binmode IMG;
print IMG $gd->gif;
close IMG;
and for newer versions (1.20 and up) you'd write
open(IMG, '>file.png') or die $!;
binmode IMG;
print IMG $gd->png;
or
open(IMG, '>file.gd2') or die $!;
binmode IMG;
print IMG $gd->gd2;
Then there's also of course the possibility of using a shorter
version (for each of the export functions that GD supports):
print IMG $graph->plot(\@data)->gif;
print IMG $graph->plot(\@data)->png;
print IMG $graph->plot(\@data)->gd;
print IMG $graph->plot(\@data)->gd2;
If you want to write something that doesn't require your code to 'know'
whether to use gif or png, you could do something like:
if ($gd->can('png')) { # blabla }
or you can use the convenience method C<export_format>:
my $format = $graph->export_format;
open(IMG, ">file.$format") or die $!;
binmode IMG;
print IMG $graph->plot(\@data)->$format();
close IMG;
or for CGI programs:
use CGI qw(:standard);
#...
my $format = $graph->export_format;
print header("image/$format");
binmode STDOUT;
print $graph->plot(\@data)->$format();
(the parentheses after $format are necessary, to help the compiler
decide that you mean a method name there)
See under L<"SEE ALSO"> for references to other documentation,
especially the FAQ.
=head1 METHODS
=head2 Methods for all graphs
=over 4
=item GD::Graph::chart-E<gt>new([width,height])
Create a new object $graph with optional width and height.
Default width = 400, default height = 300. I<chart> is either
I<bars>, I<lines>, I<points>, I<linespoints>, I<area>, I<mixed> or
I<pie>.
=item $graph-E<gt>set_text_clr(I<colour name>)
Set the colour of the text. This will set the colour of the titles,
labels, and axis labels to I<colour name>. Also see the options
I<textclr>, I<labelclr> and I<axislabelclr>.
=item $graph-E<gt>set_title_font(font specification)
Set the font that will be used for the title of the chart.
See L<"FONTS">.
=item $graph-E<gt>plot(I<\@data>)
Plot the chart, and return the GD::Image object.
=item $graph-E<gt>set(attrib1 =E<gt> value1, attrib2 =E<gt> value2 ...)
Set chart options. See OPTIONS section.
=item $graph-E<gt>get(attrib1, attrib2)
Returns a list of the values of the attributes. In scalar context
returns the value of the first attribute only.
=item $graph-E<gt>gd()
Get the GD::Image object that is going to be used to draw on. You can do
this either before or after calling the plot method, to do your own
drawing.
B<Note:> as of the current version, this GD::Image object will always
be palette-based, even if the installed version of GD supports
true-color images.
Note also that if you draw on the GD::Image object before calling the plot
method, you are responsible for making sure that the background
colour is correct and for setting transparency.
=item $graph-E<gt>export_format()
Query the export format of the GD library in use. In scalar context, it
returns 'gif', 'png' or undefined, which is sufficient for most people's
use. In a list context, it returns a list of all the formats that are
supported by the current version of GD. It can be called as a class or
object method
=item $graph-E<gt>can_do_ttf()
Returns true if the current GD library supports TrueType fonts, False
otherwise. Can also be called as a class method or static method.
=back
=head2 Methods for Pie charts
=over 4
=item $graph-E<gt>set_label_font(font specification)
=item $graph-E<gt>set_value_font(font specification)
Set the font that will be used for the label of the pie or the
values on the pie.
See L<"FONTS">.
=back
=head2 Methods for charts with axes.
=over 4
=item $graph-E<gt>set_x_label_font(font specification)
=item $graph-E<gt>set_y_label_font(font specification)
=item $graph-E<gt>set_x_axis_font(font specification)
=item $graph-E<gt>set_y_axis_font(font specification)
=item $graph-E<gt>set_values_font(font specification)
Set the font for the x and y axis label, the x and y axis
value labels, and for the values printed above the data points.
See L<"FONTS">.
=item $graph-E<gt>get_hotspot($dataset, $point)
B<Experimental>:
Return a coordinate specification for a point in a dataset. Returns a
list. If the point is not specified, returns a list of array references
for all points in the dataset. If the dataset is also not specified,
returns a list of array references for each data set.
See L<"HOTSPOTS">.
=item $graph-E<gt>get_feature_coordinates($feature_name)
B<Experimental>:
Return a coordinate specification for a certain feature in the chart.
Currently, features that are defined are I<axes>, the coordinates of
the rectangle within the axes; I<x_label>, I<y1_label> and
I<y2_label>, the labels printed along the axes, with I<y_label>
provided as an alias for I<y1_label>; and I<title> which is the title
text box.
See L<"HOTSPOTS">.
=back
=head1 OPTIONS
=head2 Options for all graphs
=over 4
=item width, height
The width and height of the canvas in pixels
Default: 400 x 300.
B<NB> At the moment, these are read-only options. If you want to set
the size of a graph, you will have to do that with the I<new> method.
=item t_margin, b_margin, l_margin, r_margin
Top, bottom, left and right margin of the canvas. These margins will be
left blank.
Default: 0 for all.
=item logo
Name of a logo file. Generally, this should be the same format as your
version of GD exports images in. Currently, this file may be in any
format that GD can import, but please see L<GD> if you use an
XPM file and get unexpected results.
Default: no logo.
=item logo_resize, logo_position
Factor to resize the logo by, and the position on the canvas of the
logo. Possible values for logo_position are 'LL', 'LR', 'UL', and
'UR'. (lower and upper left and right).
Default: 'LR'.
=item transparent
If set to a true value, the produced image will have the background
colour marked as transparent (see also option I<bgclr>). Default: 1.
=item interlaced
If set to a true value, the produced image will be interlaced.
Default: 1.
B<Note>: versions of GD higher than 2.0 (that is, since GIF support
was restored after being removed owing to patent issues) do not support
interlacing of GIF images. Support for interlaced PNG and progressive
JPEG images remains available using this option.
=back
=head2 Colours
=over 4
=item bgclr, fgclr, boxclr, accentclr, shadowclr
Drawing colours used for the chart: background, foreground (axes and
grid), axis box fill colour, accents (bar, area and pie outlines), and
shadow (currently only for bars).
All colours should have a valid value as described in L<"COLOURS">,
except boxclr, which can be undefined, in which case the box will not be
filled.
=item shadow_depth
Depth of a shadow, positive for right/down shadow, negative for left/up
shadow, 0 for no shadow (default).
Also see the C<shadowclr> and C<bar_spacing> options.
=item labelclr, axislabelclr, legendclr, valuesclr, textclr
Text Colours used for the chart: label (labels for the axes or pie),
axis label (misnomer: values printed along the axes, or on a pie slice),
legend text, shown values text, and all other text.
All colours should have a valid value as described in L<"COLOURS">.
=item dclrs (short for datacolours)
This controls the colours for the bars, lines, markers, or pie slices.
This should be a reference to an array of colour names as defined in
L<GD::Graph::colour> (S<C<perldoc GD::Graph::colour>> for the names available).
$graph->set( dclrs => [ qw(green pink blue cyan) ] );
The first (fifth, ninth) data set will be green, the next pink, etc.
A colour can be C<undef>, in which case the data set will not be drawn.
This can be useful for cumulative bar sets where you want certain data
series (often the first one) not to show up, which can be used to
emulate error bars (see examples 1-7 and 6-3 in the distribution).
Default: [ qw(lred lgreen lblue lyellow lpurple cyan lorange) ]
=item borderclrs
This controls the colours of the borders of the bars data sets. Like
dclrs, it is a reference to an array of colour names as defined in
L<GD::Graph::colour>.
Setting a border colour to C<undef> means the border will not be drawn.
=item cycle_clrs
If set to a true value, bars will not have a colour from C<dclrs> per
dataset, but per point. The colour sequence will be identical for each
dataset. Note that this may have a weird effect if you are drawing more
than one data set. If this is set to a value larger than 1 the border
colour of the bars will cycle through the colours in C<borderclrs>.
=item accent_treshold
Not really a colour, but it does control a visual aspect: Accents on
bars are only drawn when the width of a bar is larger than this number
of pixels. Accents inside areas are only drawn when the horizontal
distance between points is larger than this number.
Default 4
=back
=head2 Options for graphs with axes.
options for I<bars>, I<lines>, I<points>, I<linespoints>, I<mixed> and
I<area> charts.
=over 4
=item x_label, y_label
The labels to be printed next to, or just below, the axes. Note that if
you use the two_axes option that you need to use y1_label and y2_label.
=item long_ticks, tick_length
If I<long_ticks> is a true value, ticks will be drawn the same length
as the axes. Otherwise ticks will be drawn with length
I<tick_length>. if I<tick_length> is negative, the ticks will be drawn
outside the axes. Default: long_ticks = 0, tick_length = 4.
These attributes can also be set for x and y axes separately with