[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Image/ -> Graph.php (sommaire)

Image_Graph - Main class for the graph creation. PHP versions 4 and 5

Author: Jesper Veggerby <pear.nosey@veggerby.dk>
Copyright: Copyright (C) 2003, 2004 Jesper Veggerby Hansen
License: http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
Version: CVS: $Id: Graph.php,v 1.58 2005/11/27 18:48:05 nosey Exp $
Poids: 851 lignes (28 kb)
Inclus ou requis: 11 fois
Référencé: 0 fois
Nécessite: 4 fichiers
 Image/Canvas.php
 Image/Graph/Constants.php
 Image/Graph/Element.php
 PEAR.php

Définit 1 class

Image_Graph:: (17 méthodes):
  Image_Graph()
  _getCanvas()
  setCanvas()
  _getMicroTime()
  width()
  height()
  displayErrors()
  setLog()
  factory()
  layoutFactory()
  horizontal()
  vertical()
  _default_error_handler()
  _displayErrors()
  _displayError()
  done()
  _done()


Classe: Image_Graph  - X-Ref

Main class for the graph creation.

This is the main class, it manages the canvas and performs the final output
by sequentialy making the elements output their results. The final output is
handled using the {@link Image_Canvas} classes which makes it possible
to use different engines (fx GD, PDFlib, libswf, etc) for output to several
formats with a non-intersecting API.

This class also handles coordinates and the correct managment of setting the
correct coordinates on child elements.

Image_Graph($params, $height = false, $createTransparent = false)   X-Ref
Image_Graph [Constructor].

If passing the 3 parameters they are defined as follows:'

Fx.:

$Graph =& new Image_Graph(400, 300);

or using the factory method:

$Graph =& Image_Graph::factory('graph', array(400, 300));

This causes a 'png' canvas to be created by default.

Otherwise use a single parameter either as an associated array or passing
the canvas along to the constructor:

1) Create a new canvas with the following parameters:

'canvas' - The canvas type, can be any of 'gd', 'jpg', 'png' or 'svg'
(more to come) - if omitted the default is 'gd'

'width' - The width of the graph

'height' - The height of the graph

An example of this usage:

$Graph =& Image_Graph::factory('graph', array(array('width' => 400,
'height' => 300, 'canvas' => 'jpg')));

NB! In thïs case remember the "double" array (see {@link Image_Graph::
factory()})

2) Use the canvas specified, pass a valid Image_Canvas as
parameter. Remember to pass by reference, i. e. &amp;$canvas, fx.:

$Graph =& new Image_Graph($Canvas);

or using the factory method:

$Graph =& Image_Graph::factory('graph', $Canvas));

param: mixed $params The width of the graph, an indexed array
param: int $height The height of the graph in pixels
param: bool $createTransparent Specifies whether the graph should be

_getCanvas()   X-Ref
Gets the canvas for this graph.

The canvas is set by either passing it to the constructor {@link
Image_Graph::ImageGraph()} or using the {@link Image_Graph::setCanvas()}
method.

return: Image_Canvas The canvas used by this graph

setCanvas(&$canvas)   X-Ref
Sets the canvas for this graph.

Calling this method makes this graph use the newly specified canvas for
handling output. This method should be called whenever multiple
'outputs' are required. Invoke this method after calls to {@link
Image_Graph:: done()} has been performed, to switch canvass.

param: Image_Canvas $canvas The new canvas
return: Image_Canvas The new canvas

_getMicroTime()   X-Ref
Gets a very precise timestamp

return: The number of seconds to a lot of decimals

width()   X-Ref
Gets the width of this graph.

The width is returned as 'defined' by the canvas.

return: int the width of this graph

height()   X-Ref
Gets the height of this graph.

The height is returned as 'defined' by the canvas.

return: int the height of this graph

displayErrors()   X-Ref
Enables displaying of errors on the output.

Use this method to enforce errors to be displayed on the output. Calling
this method makes PHP uses this graphs error handler as default {@link
Image_Graph::_default_error_handler()}.

setLog($log)   X-Ref
Sets the log method for this graph.

Use this method to enable logging. This causes any errors caught
by either the error handler {@see Image_Graph::displayErrors()}
or explicitly by calling {@link Image_Graph_Common::_error()} be
logged using the specified logging method.

If a filename is specified as log method, a Log object is created (using
the 'file' handler), with a handle of 'Image_Graph Error Log'.

Logging requires {@link Log}.

param: mixed $log The log method, either a Log object or filename to log

factory($class, $params = null)   X-Ref
Factory method to create Image_Graph objects.

Used for 'lazy including', i.e. loading only what is necessary, when it
is necessary. If only one parameter is required for the constructor of
the class simply pass this parameter as the $params parameter, unless the
parameter is an array or a reference to a value, in that case you must
'enclose' the parameter in an array. Similar if the constructor takes
more than one parameter specify the parameters in an array, i.e

Image_Graph::factory('MyClass', array($param1, $param2, &$param3));

Variables that need to be passed by reference *must* have the &amp;
before the variable, i.e:

Image_Graph::factory('line', &$Dataset);

or

Image_graph::factory('bar', array(array(&$Dataset1, &$Dataset2),
'stacked'));

Class name can be either of the following:

1 The 'real' Image_Graph class name, i.e. Image_Graph_Plotarea or
Image_Graph_Plot_Line

2 Short class name (leave out Image_Graph) and retain case, i.e.
Plotarea, Plot_Line *not* plot_line

3 Class name 'alias', the following are supported:

'graph' = Image_Graph

'plotarea' = Image_Graph_Plotarea

'line' = Image_Graph_Plot_Line

'area' = Image_Graph_Plot_Area

'bar' = Image_Graph_Plot_Bar

'pie' = Image_Graph_Plot_Pie

'radar' = Image_Graph_Plot_Radar

'step' = Image_Graph_Plot_Step

'impulse' = Image_Graph_Plot_Impulse

'dot' or 'scatter' = Image_Graph_Plot_Dot

'smooth_line' = Image_Graph_Plot_Smoothed_Line

'smooth_area' = Image_Graph_Plot_Smoothed_Area
'dataset' = Image_Graph_Dataset_Trivial

'random' = Image_Graph_Dataset_Random

'function' = Image_Graph_Dataset_Function

'vector' = Image_Graph_Dataset_VectorFunction

'category' = Image_Graph_Axis_Category

'axis' = Image_Graph_Axis

'axis_log' = Image_Graph_Axis_Logarithmic

'title' = Image_Graph_Title

'line_grid' = Image_Graph_Grid_Lines

'bar_grid' = Image_Graph_Grid_Bars

'polar_grid' = Image_Graph_Grid_Polar

'legend' = Image_Graph_Legend

'font' = Image_Graph_Font

'ttf_font' = Image_Graph_Font

'Image_Graph_Font_TTF' = Image_Graph_Font (to maintain BC with Image_Graph_Font_TTF)

'gradient' = Image_Graph_Fill_Gradient

'icon_marker' = Image_Graph_Marker_Icon

'value_marker' = Image_Graph_Marker_Value

param: string $class The class for the new object
param: mixed $params The paramaters to pass to the constructor
return: object A new object for the class

layoutFactory($layout, &$part1, &$part2, $percentage = 50)   X-Ref
Factory method to create layouts.

This method is used for easy creation, since using {@link Image_Graph::
factory()} does not work with passing newly created objects from
Image_Graph::factory() as reference, this is something that is
fortunately fixed in PHP5. Also used for 'lazy including', i.e. loading
only what is necessary, when it is necessary.

Use {@link Image_Graph::horizontal()} or {@link Image_Graph::vertical()}
instead for easier access.

param: mixed $layout The type of layout, can be either 'Vertical'
param: Image_Graph_Element $part1 The 1st part of the layout
param: Image_Graph_Element $part2 The 2nd part of the layout
param: int $percentage The percentage of the layout to split at
return: Image_Graph_Layout The newly created layout object

horizontal(&$part1, &$part2, $percentage = 50)   X-Ref
Factory method to create horizontal layout.

See {@link Image_Graph::layoutFactory()}

param: Image_Graph_Element $part1 The 1st (left) part of the layout
param: Image_Graph_Element $part2 The 2nd (right) part of the layout
param: int $percentage The percentage of the layout to split at
return: Image_Graph_Layout The newly created layout object

vertical(&$part1, &$part2, $percentage = 50)   X-Ref
Factory method to create vertical layout.

See {@link Image_Graph::layoutFactory()}

param: Image_Graph_Element $part1 The 1st (top) part of the layout
param: Image_Graph_Element $part2 The 2nd (bottom) part of the layout
param: int $percentage The percentage of the layout to split at
return: Image_Graph_Layout The newly created layout object

_default_error_handler($error_type, $error_msg, $error_file, $error_line, $error_context)   X-Ref
The error handling routine set by set_error_handler().

This method is used internaly by Image_Graph and PHP as a proxy for {@link
Image_Graph::_error()}.

param: string $error_type The type of error being handled.
param: string $error_msg The error message being handled.
param: string $error_file The file in which the error occurred.
param: integer $error_line The line in which the error occurred.
param: string $error_context The context in which the error occurred.

_displayErrors()   X-Ref
Displays the errors on the error stack.

Invoking this method cause all errors on the error stack to be displayed
on the graph-output, by calling the {@link Image_Graph::_displayError()}
method.


_displayError($x, $y, $error)   X-Ref
Display an error from the error stack.

This method writes error messages caught from the {@link Image_Graph::
_default_error_handler()} if {@Image_Graph::displayErrors()} was invoked,
and the error explicitly set by the system using {@link
Image_Graph_Common::_error()}.

param: int $x The horizontal position of the error message
param: int $y The vertical position of the error message
param: array $error The error context

done($param = false)   X-Ref
Outputs this graph using the canvas.

This causes the graph to make all elements perform their output. Their
result is 'written' to the output using the canvas, which also performs
the actual output, fx. it being to a file or directly to the browser
(in the latter case, the canvas will also make sure the correct HTTP
headers are sent, making the browser handle the output correctly, if
supported by it).

Parameters are the ones supported by the canvas, common ones are:

'filename' To output to a file instead of browser

'tohtml' Return a HTML string that encompasses the current graph/canvas - this
implies an implicit save using the following parameters: 'filename' The "temporary"
filename of the graph, 'filepath' A path in the file system where Image_Graph can
store the output (this file must be in DOCUMENT_ROOT scope), 'urlpath' The URL that the
'filepath' corresponds to (i.e. filepath + filename must be reachable from a browser using
urlpath + filename)

param: mixed $param The output parameters to pass to the canvas
return: bool Was the output 'good' (true) or 'bad' (false).

_done($param = false)   X-Ref
Outputs this graph using the canvas.

This causes the graph to make all elements perform their output. Their
result is 'written' to the output using the canvas, which also performs
the actual output, fx. it being to a file or directly to the browser
(in the latter case, the canvas will also make sure the correct HTTP
headers are sent, making the browser handle the output correctly, if
supported by it).

param: mixed $param The output parameters to pass to the canvas
return: bool Was the output 'good' (true) or 'bad' (false).



Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7