This chapter documents the callback feature in PHPlot.
Callbacks allow a programmer using PHPlot to insert their own functions into the graph drawing process. Callbacks are currently also used for development and testing of PHPlot.
All PHPlot class variables, and all methods/functions which are not documented in the "Reference" section of the PHPlot Reference Manual, are considered to be for internal use and are subject to be changed or removed at any time. If you call internal functions, or access internal class variables, you greatly increase the risk of breaking your application with future PHPlot releases.
Refer to these entries in the Function Reference:
SetCallback - Register a callback function
GetCallback - Return a currently registered callback function
RemoveCallback - Unregister a callback function
Either a function name or an object and method can be registered as a callback with SetCallback. For more information about using callbacks with objects and methods, see the PHP manual under Types, Pseudo Types, Callback and the documentation for the PHP call_user_func function. Also refer to Section 6.4, “Object Methods as Callbacks” later in this manual. Whether calling a function or an object method as a callback, the same calling sequence is used.
function_name($img, $passthrough_arg, [other_args...])
The GD image resource for the plot image.
The third argument supplied to SetCallback ($arg) when the callback is established. This allows the programmer to pass information to the callback without using global variables. This can be any PHP type including array. To pass a reference, you should put it into an array and pass the array.
Zero or more additional arguments supplied by PHPlot to callbacks of this type. Refer to Section 6.3, “Available Callbacks” to see what callback reasons supply extra arguments.
For example, given this callback setup:
$plot->SetCallback('draw_graph', 'my_drawing_callback', $myvar);
Then PHPlot will call:
my_drawing_callback($img, $myvar_value, $plot_area);
Where $myvar_value is the value of $myvar at the time SetCallback was called. (The plot_area parameter is only supplied for the draw_graph callback in PHPlot-5.1.0 and later.)
Some callbacks are expected to return a value. This is documented in Section 6.3, “Available Callbacks”. In all other cases, the return value from a callback function is ignored. (Callbacks which return a value were implemented in PHPlot-5.1.3.)