File: base.tex

package info (click to toggle)
libchart-perl 2.4.1-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,804 kB
  • ctags: 370
  • sloc: perl: 9,120; makefile: 532
file content (369 lines) | stat: -rwxr-xr-x 19,138 bytes parent folder | download | duplicates (2)
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
%
% Base.tex
%
\section{Chart::Base}

\name{Chart::Base} \index{Chart::Base}
\file{Base.pm}
\requires{GD, Carp, FileHandle}
\begin{Description}
   \class{Base} is the \textbf{abstract superclass} of the modules: \module{Bars}, 
   \module{Composite}, \module{Direction}, \module{ErrorBars}, 
   \module{HorizontalBars}, 
   \module{Lines}, \module{LinesPoints}, \module{Mountain}, 
   \module{Pareto}, \module{Pie}, \module{Points}, \module{Split}, \module{StackedBars}.
   \index{Base} \index{Bars} \index{Composite} \index{Direction} \index{ErrorBars} 
   \index{HorizontalBars} \index{Lines} \index{LinesPoints} \index{Mountain} \index{Pareto} 
   \index{Pie} \index{Points} \index{Split} \index{StackedBars}

   The class \class{Base} provides all public methods and most of the attributs of a chart object.
\end{Description}


\begin{Constructor}
An instance of a chart object can be created with the constructor new(): \index{new()}
\begin{quote}
\parindent 0pt
\fett{\$obj = Chart::\textit{Type}->new();}

\fett{\$obj = Chart::\textit{Type}->new(\parameter{width}, \parameter{height});}
\end{quote}
\textit{Type} means the type of chart it returns, i.e. \module{Chart::Bars} 
returns a chart with bars.

If \textit{new()} has no arguments, 
the constructor returns an object with the size 300x400 pixels. 
If \textit{new()} has two arguments \parameter{width} and \parameter{height}, 
it returns a chart object of the desired size. 
\end{Constructor}

\Methods\parindent 0pt
\label{methods}
\method{\$obj->add\_dataset(@array);}\\
\method{\$obj->add\_dataset($\backslash$@array\_ref);}\\
\index{\$obj->add\_datasetadd\_dataset}
\methodexplanation{Adds a dataset to the object. 
The parameter is an array or a reference to an array. 
Generally, the first added array is interpreted as being the x-tick labels. 
The following arrays include the data points. 
For example if the first call is 
\example{\$obj->add\_dataset('Harry', 'Sally');}  
and the second call is
\example{\$obj->add\_dataset(5, 8);}
then chart will draw a picture with two bars and label them with Harry and Sally.\\[\itemabstand]
Some modules will handle that a little bit different. 
Have a look at the respective descriptions of the specific modules to get more information.
There are also differences if you want to use the \fett{xy\_plot} option, to create a xy-graph.}

\method{\$obj->add\_pt(@array);}\\
\method{\$obj->add\_pt($\backslash$@array\_ref);}\\
\index{\$obj->add\_pt(@array)}
\methodexplanation{This is another method to add data to a chart object. 
An argument can be an array or a reference to an array. 
If you use this method, chart wants the complete data of one data point.\\
For example\\
\example{\$obj->add\_pt('Harry', 5);}\\
\example{\$obj->add\_pt('Sally', 8);}\\
would create the same graph as the example for \method{add\_dataset} above.}

\method{\$obj->add\_datafile( "file", \kursiv{type} );}\\
\method{\$obj->add\_datafile( \$filehandle, \kursiv{type} );}\\
\index{\$obj->add\_datafile}
\methodexplanation{This method adds the contents of a complete data file to the chart object.\\
\kursiv{Type} can be '\kursiv{set}' or '\kursiv{pt}'. 
If the parameter is '\kursiv{set}' then one line in the data file has to be a complete data set. 
The values of the set has to be separated by whitespaces. 
For Example, the file contents has to looks like
\begin{quote}
\texttt{Harry  Sally}\\
\texttt{3      8}\\
\texttt{2      1}\\
\end{quote}

If the parameter is '\parameter{pt}' the lines of the file 
        have to look like the parameter arrays of the \method{add\_pt} method. 
 Which means, the line includes all values of one data point, also separated by whitespaces. 
For Example:
\begin{quote}
\small
\texttt{Harry 3 2}\\
\texttt{Sally 8 1}\\
\end{quote}
}


\method{\$obj->get\_data();}\\
\index{\$obj->get\_data}
\methodexplanation{If you want a copy of the data that has been added so far, 
      make a call to the \method{get\_data} method like \\
      \example{\$dataref = \$obj->get\_data();}\\[\itemabstand]
      It returns a reference to an array of references to datasets. 
       For Example, you can get the x-tick labels by:\\ 
      \example{@x\_labels = @\{\$dataref->[0]\};}
}

 
\method{\$obj->clear\_data();} \\ 
\index{\$obj->clear\_data}
\methodexplanation{This is the method to remove all data that may have been entered till now.}

\method{\$obj->set( \kursiv{attribut 1} => \kursiv{value 1}, \ldots ,\mbox{\kursiv{attribute n} => \kursiv{value n}} );}\\
\method{\$obj->set( \%hash );}\\
\method{\$obj->set( \kursiv{attribut 1}, \kursiv{value 1}, \ldots ,\mbox{\kursiv{attribute n}, \kursiv{value n}} );}\\
\method{\$obj->set( @array );}\\
\index{\$obj->set}
\methodexplanation{Use this method to change the attributes of the chart object. 
   Set looks for a hash of keys and values or an array of keys and values.\\
     For Example 
        \example{\$obj->set( 'title' => 'The title of the image');}
      would set the title. The same job would do:\\
      \example{\%hash = ('title' => 'The title of the image');}\\ 
       \example{\$obj->set( \%hash);}}

\method{\$obj->png( "file" );} \\
\method{\$obj->png( \$filehandle );} \\
\method{\$obj->png( FILEHANDLE );} \\
\method{\$obj->png( "file", $\backslash$@data );}\\
\index{\$obj->png}
\methodexplanation{
This method creates the png file. 
The file parameter can be the file name, a reference to a filehandle or a filehandle itself. 
If the file doesn't exist, chart will create a file for you. 
If there is already a file, chart will overwrite this file. In case of an error, 
the file is not created.\\
You can also add the data to the chart object in the png method. 
The \parameter{@data} array should contain references to arrays of data, 
with the first array reference pointing to an array with x-tick labels. 
\parameter{@data} could look like
\example{@data = (['Harry', 'Sally'], [5, 8], [50, 80]);}\\
This would set up an graph with two datasets, and three data points in these sets.
}

\method{\$obj->jpeg( "file" );} \\
\method{\$obj->jpeg( \$filehandle );} \\
\method{\$obj->jpeg( FILEHANDLE );} \\
\method{\$obj->jpeg( "file", $\backslash$@data );}\\
\index{\$obj->jpeg}
\methodexplanation{
    These are the methods to create jpeg files. They work similar like the png() method.}
    
\method{\$obj->cgi\_png();} \\
\method{\$obj->cgi\_jpeg();} \\
\index{\$obj->cgi\_png}\index{\$obj->cgi\_jpeg}
\methodexplanation{
With the cgi methods you can create dynamic images for your web site. 
The cgi methods will print the chart, along with the appropriate http header to stdout, 
allowing you to call chart-generating scripts directly from your html pages 
(ie. with a <img scr=image.pl>HTML tag).}

\method{\$obj->imagemap\_dump();} \\ 
\index{\$obj->imagemap\_dump}
\methodexplanation{
           Chart can also return the pixel position information 
           so that you can create image maps from the files Chart generates. 
           Simply set the 'imagemap' option to 'true' before you generate the file, 
           then call the \method{imagemap\_dump} method to retrieve the information. 
           A structure will be returned almost identical to the \parameter{@data} array 
           described above to pass the data into Chart.

           \example{\$imagemap\_data = \$obj->imagemap\_dump();}

           Instead of single data values, references to arrays of pixel information is passed. 
           For the classes \class{Bars}, \class{HorizontalBars}, 
           \class{Pareto} and \class{StackedBars} charts, 
           the arrays will contain two x-y pairs (specifying the upper left and the lower right corner of the bar).
           Compare to: \\
            \example{( \$x1, \$y1, \$x2, \$y2 ) = @\{ \$imagemap\_data->[\$dataset][\$datapoint] \};}\\[\itemabstand]
 
           For the classes \class{Lines}, \class{Points}, 
            \class{LinesPoints} and \class{Split}, the arrays will contain a single xy-pair 
          (specifying the center of the point). 
         Compare to:\\
            \example{( \$x, \$y) = @\{ \$imagemap\_data->[\$dataset][\$datapoint] \};}\\[\itemabstand]

           A few caveats apply here. First of all, Chart uses the GD-module by Lincoln Stein 
         to draw lines, circles, strings, and so on. 
GD treats the upper-left corner of the png/jpeg as the reference point, 
therefore, positive y values are measured from the top of the png/jpeg, not from the bottom. 
Second, these values will mostly contain long decimal values. 
GD, of course, has to truncate these to single pixel values. 
In a worst-case scenario, this will result in an error of one pixel on your imagemap. 
If this is really an issue, your only option is to experiment with it, 
or to contact Lincoln Stein and ask him. Third, 
please remember that the 0th dataset will be empty, since that's the place for the data point labels.}

   
\label{options}
\Attributes
These are the options which have effects on all types of chart:
\begin{description}
\item ['transparent']Makes the background of the image transparent if set to 'true'. 
                    Useful for making web page images. 
                    It doesn't work for all browsers. 
                    Defaults to false.

\item ['png\_border']Sets the number of pixels 
                     used as a border between the graph and the edges of the png/jpeg. 
                     Defaults to 10.
                     
\item ['graph\_border']
        Sets the number of pixels used as a border between the title/labels 
        and the actual graph within the png/jpeg. Defaults to 10.

\item['text\_space']
       Sets the amount of space left on the sides of text, to make it more readable.  Defaults to 2.

\item['title']Tells Chart what to use for the title of the graph.  
      If empty, no title is drawn.  
      '$\backslash$es' are treated as newline. 
      Remember, if you want to use normal quotation marks instead of single quotation marks 
      you have to quote "`$\backslash\backslash$n"'. Default is empty.

\item['sub\_title']Writes a sub-title under the title in smaller letters.

\item['x\_label']Tells Chart what to use for the x-axis label.  
                 If empty, no label is drawn.  Default is empty.
                 
\item['y\_label', 'y\_label2']Tells Chart what kind of label should be used for the description
          of the y axis on the lft or the right side accordingly.  
          If empty, no label is drawn.  Default is empty.

\item['legend']Specifies the placement of the legend.  
             Valid values are 'left', 'right', 'top', 'bottom'.  
             Setting this to 'none' tells chart not to draw a legend.  Default is 'right'.

\item['legend\_labels']
            Sets the values for the labels for the different datasets. 
            Should be assigned a reference to an array of labels.  For example,\\
            \example{@labels = ('foo', 'bar')};\\
            \example{\$obj->set ('legend\_labels' => $\backslash$@labels);}\\
            Default is empty, in which case 'Dataset 1', 'Dataset 2', etc.
             are used as the labels.
             
\item['tick\_len']Sets the length of the x- and y-ticks in pixels.  Default is 4.

\item['x\_ticks']Specifies how to draw the x-tick labels.  
        Valid values are 'normal', 'staggered' (staggers the labels vertically), 
        and 'vertical' (the labels are draw upwards).  Default is 'normal'.

\item['y\_ticks']The number of ticks to plot on the y scale, 
      including the end points. e.g. If the scale runs from 0 to 50,
			with ticks every 10, y\_ticks will have the value of 6.

\item['min\_y\_ticks']Sets the minimum number of y\_ticks to draw when generating a scale. 
        Default is 6, the minimum is 2.
        
\item['max\_y\_ticks']Sets the maximum number of y\_ticks to draw when generating a scale. 
       Default is 100. This limit is used to avoid plotting an unreasonably 
       large number of ticks if non-round values are used for the min\_val and
       max\_val.\\[\itemabstand]
       The value for 'max\_y\_ticks' should be at least 5 times larger than 'min\_y\_ticks'.
       
\item['max\_x\_ticks', 'min\_x\_ticks'] Works similar as 'max\_y\_ticks' and 'min\_y\_ticks'. 
      Of course, it works only for xy-plots! 

\item['integer\_ticks\_only']Specifies how to draw the x- and y-ticks: 
      as floating point ('false', '0') 
      or as integer numbers ('true', 1). 
      If you want integer ticks, it is maybe better to set the option 'precision' at zero. 
      Default: 'false'

\item['skip\_int\_ticks']If 'integer\_ticks\_only' was set to 'true' the labels and 
          ticks at the y-axis will be drawn every nth tick. 
          Of course in HorizontalBars it affects the x-axis. Default to 1, no skipping.

\item['precision'] Sets the number of numerals after the decimal point. 
             Affects in most cases the y-axis. 
             But also the x-axis if 'xy\_plot' is set and the labels in a pie chart. Defaults to 3.

\item['max\_val']Sets the maximum y-value on the graph, overriding the normal autoscaling.  
            Does not work for a Split chart. Default is undef.

\item['min\_val']Sets the minimum y-value on the graph, overriding the normal autoscaling.  
           Does not work for a Split chart. Default is undef.\\
\\
Caution should be used when setting 'max\_val' and 'min\_val' to floating point or non-round numbers. This is because the scale must start \& end on a tick, ticks must have round-number intervals, and include round numbers.\\
\\
Example: Suppose your dataset has a range of 35-114 units, If you specify them as the 'min\_val' \& 'max\_val', The y\_axis will be plot with 80 ticks every 1 unit.. If no 'min\_val' \& 'max\_val', the system will autoscale the range to 30-120 with 10 ticks every 10 units.\\
\\
If the 'min\_val' \& 'max\_val' are specified to exesive precision, they may be overiden by the system, plotting a maximum 'max\_y\_ticks' ticks. 

\item['include\_zero']If 'true', forces the y-axis to include zero if it is not in the 
            dataset range. Default is 'false'.\\
\\
In general, it is better to use this, than to set the 'min\_val' if that is all you want to achieve.
\item['skip\_x\_ticks']Sets the number of x-ticks and x-tick labels to skip.  (ie. if 'skip\_x\_ticks' was set to 4, Chart would draw every 4th x-tick and x-tick label).  Default is undef.

\item['custom\_x\_ticks']This option allows you to specify exactly 
            which x-ticks and x-tick labels should be drawn. 
            It should be assigned a reference to an array of desired ticks.  
            Just remember that I'm counting from the 0th element of the array.  
            (e.g., if 'custom\_x\_ticks' is assigned [0,3,4], 
            then the 0nd, 3rd, and 4th x-ticks will be displayed) 
            It doesn't work for \class{Split}, \class{HorizontalBars} and \class{Pie}.
            
\item['f\_x\_tick'] Needs a reference to a function 
           which uses the x-tick labels generated by the \parameter{@data->[0]} as the argument. 
           The result of this function reformats the labels as a string. 
           For instance\\
           \example{\$obj -> set ('f\_x\_tick' => $\backslash$\&formatter;}\\
           An example for the function formatter: x labels are seconds since an event. 
           The referenced function can transform this seconds to hour, minutes and seconds.

\item['f\_y\_tick']The same situation as for 'f\_x\_tick' but now used for y labels.

\item['colors']This option lets you control the colors the chart will use.  
              It takes a reference to a hash.  
              The hash should contain keys mapped to references to arrays of rgb values.  
              For instance,\\
              \example{\$obj->set('colors' => {'background' => [255,255,255]});}\\
              sets the background color to white (which is the default).  
              Valid keys for this hash are
              \begin{itemize}
              \item 'background' (background color for the png)
              \item 'title' (color of the title)
              \item 'text' (all the text in the chart)
              \item 'x\_label' (color of the x axis label)
              \item 'y\_label' (color of the first y axis label)
              \item 'y\_label2' (color of the second y axis label)
              \item 'grid\_lines' (color of the grid lines)
              \item 'x\_grid\_lines' (color of the x grid lines - for x axis ticks)
              \item 'y\_grid\_lines' (color of the y grid lines - for to left y axis ticks)
              \item 'y2\_grid\_lines' (color of the y2 grid lines - for right y axis ticks)
              \item 'dataset0'..'dataset63' (the different datasets)
              \item 'misc' (everything else, e.g. ticks, box around the legend)
              \end{itemize}
             NB. For composite charts, there is a limit of 8 datasets per component. 
             The colors for 'dataset8' through 'dataset15' 
             become the colors for 'dataset0' through 'dataset7' for the second component chart.

\item['title\_font'] This option changes the font of the title. 
               The key has to be a Gd font. e.g. GD::Font->Large 

\item['label\_font'] This option changes the font of the labels. The key has to be a Gd font. 

\item['legend\_font'] This option changes the font of the text of the legend. The key has to be a Gd font. 

\item['tick\_label\_font'] This option changes the font of the ticks. The key has to be a Gd font. 

\item['grey\_background']Puts a nice soft grey background on the actual data plot when set to 'true'.  Default is 'true'.

\item['x\_grid\_lines']Draws grid lines matching up to x ticks if set to 'true'. Default is 'false'.

\item['y\_grid\_lines']Draws grid lines matching up to y ticks if set to 'true'. Default is 'false'.

\item['grid\_lines']Draws grid lines matching up to x and y ticks if set to 'true'. Default is 'false'. 

\item['imagemap']Lets Chart know you're going to ask for information 
        about the placement of the data for use in 
         creating an image map from the png. This information can be retrieved using the imagemap\_dump() method.         NB. that the imagemap\_dump() method cannot be called until 
         after the Chart has been generated (e.g. using the png() or cgi\_png() methods).

\item['ylabel2']The label for the right y-axis (the second component chart).  Default is undef.

\item['no\_cache']Adds Pragma: no-cache to the http header. 
           Be careful with this one, as Netscape 4.5 is     unfriendly with POST using this method.

\item['legend\_example\_size'] Sets the length of the example line in the legend. Defaults to 20.
\end{description}