本文整理汇总了PHP中Image_Canvas::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Image_Canvas::factory方法的具体用法?PHP Image_Canvas::factory怎么用?PHP Image_Canvas::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image_Canvas
的用法示例。
在下文中一共展示了Image_Canvas::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Image_Canvas_WithMap
/**
* Create the canvas.
*
* Parameters available:
*
* 'width' The width of the graph on the canvas
*
* 'height' The height of the graph on the canvas
*
* 'left' The left offset of the graph on the canvas
*
* 'top' The top offset of the graph on the canvas
*
* 'usemap' Initialize an image map
*
* @param array $params Parameter array
* @abstract
*/
function Image_Canvas_WithMap($params)
{
parent::Image_Canvas($params);
if (isset($params['usemap']) && $params['usemap'] === true) {
$this->_imageMap =& Image_Canvas::factory('ImageMap', array('left' => $this->_left, 'top' => $this->_top, 'width' => $this->_width, 'height' => $this->_height));
}
}
示例2: handleDirFiles
function handleDirFiles($dir_name, $save_dir)
{
list($directories, $files) = File_Find::maptree($dir_name);
$new_dir = $save_dir . basename($dir_name);
if (!file_exists($new_dir)) {
mkdir($new_dir, 0777);
}
foreach ($files as $image_file) {
if (ereg("(.*)jpg\$", $image_file)) {
$new_filename = $new_dir . "/" . basename($image_file, ".jpg") . "_resize.jpg";
echo $new_filename . "\n";
$tn_image = new Thumbnail($image_file, 340);
$tn_image->save($new_filename);
$Canvas =& Image_Canvas::factory(isset($_GET['canvas']) ? $_GET['canvas'] : 'jpg', array('width' => 340, 'height' => 340));
$Canvas->image(array('x' => 340, 'y' => 340, 'filename' => $new_filename, 'alignment' => array('horizontal' => 'right', 'vertical' => 'bottom')));
$Canvas->setFont(array('name' => 'Courier New', 'size' => 16, 'color' => '#FF66FF'));
//#FF0033
$Canvas->addText(array('x' => 165, 'y' => 200, 'text' => 'arzen1013', 'alignment' => array('horizontal' => 'center', 'vertical' => 'bottom')));
$Canvas->setFont(array('name' => 'Courier New', 'size' => 10, 'color' => '#000000'));
//#FF0033
$Canvas->addText(array('x' => 165, 'y' => 320, 'text' => 'http://shop33691629.taobao.com/', 'alignment' => array('horizontal' => 'center', 'vertical' => 'bottom')));
$Canvas->save(array('filename' => $new_filename));
}
}
}
示例3: create_graph_usemap01
function create_graph_usemap01($width = 700, $height = 160, $fontsize = 7)
{
$Canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true));
// This is how you get the ImageMap object,
// fx. to save map to file (using toHtml())
$Imagemap = $Canvas->getImageMap();
// Create the graph
//$Graph =& Image_Graph::factory('graph', array(600, 140));
$Graph =& Image_Graph::factory('graph', $Canvas);
// add a TrueType font
//$myfont = '/usr/share/fonts/truetype/freefont/FreeSans.ttf';
$myfont = '/usr/share/fonts/truetype/freefont/FreeSerif.ttf';
$Font =& $Graph->addNew('font', $myfont);
//$Font =& $Graph->addNew('font', 'Verdana');
//$Font =& $Graph->addNew('font', 'Helvetica');
// set the font size
$Font->setSize($fontsize);
$Graph->setFont($Font);
#return array(&$Graph, &$Font);
return $Graph;
}
示例4: testCompensatedPrioritiesSharpChangingZoneInvetory
/**
* A method to visually test the compensatedPriorities() method.
*
* Tests a series of operation intervals for a zone where some ads are limited
* to appear only in certain "channels" of the zone, and display the results
* graphically. Uses a changing number of impressions in the zone each operation
* interval.
*/
function testCompensatedPrioritiesSharpChangingZoneInvetory()
{
$conf = $GLOBALS['_MAX']['CONF'];
// Mock the OA_Dal_Maintenance_Priority class
$oDal = new MockOA_Dal_Maintenance_Priority($this);
$oServiceLocator =& OA_ServiceLocator::instance();
$oServiceLocator->register('OA_Dal_Maintenance_Priority', $oDal);
// Partially mock the OA_Maintenance_Priority_AdServer_Task_PriorityCompensation class
$oPriorityCompensation = new PartialMock_OA_Maintenance_Priority_AdServer_Task_PriorityCompensation($this);
$oPriorityCompensation->setReturnReference('_getDal', $oDal);
$oPriorityCompensation->OA_Maintenance_Priority_AdServer_Task_PriorityCompensation();
// Define the number of iterations to test over
$iterations = 48;
// Define the maximum number of impressions in the zone
$maxZoneImpressions = 10000;
// Define the maximum number of impressions in the zone
$minZoneImpressions = 1000;
// Define the zone impression period
$zoneImpressionPeriod = 24;
// Define the channels, including the % of zone impressions in each
$aChannels[1] = 0.1;
// Channel 1: 10% of zone traffic
$aChannels[2] = 0.02;
// Channel 2: 2% of zone traffic
// Define the ads, including the required impressions each iteration,
// the channel the ad is limited to (if any) and the colour to use in
// the graph of results
$aAds[1] = array('impressions' => 5000, 'channel' => null, 'colour' => 'red');
$aAds[2] = array('impressions' => 1500, 'channel' => 1, 'colour' => 'blue');
$aAds[3] = array('impressions' => 750, 'channel' => 2, 'colour' => 'green');
// Preapare the graph data sets, ready to accept test data
foreach ($aAds as $adKey => $aAdData) {
// Add the new data to the graph of the results
$dataSetName = 'oDataSet_Ad' . $adKey . '_RequiredImpressions';
${$dataSetName} =& Image_Graph::factory('dataset');
${$dataSetName}->setName('Ad ' . $adKey . ': Required Impressions');
$dataSetName = 'oDataSet_Ad' . $adKey . '_AvailableImpressions';
${$dataSetName} =& Image_Graph::factory('dataset');
${$dataSetName}->setName('Ad ' . $adKey . ': Available Impressions');
$dataSetName = 'oDataSet_Ad' . $adKey . '_ActualImpressions';
${$dataSetName} =& Image_Graph::factory('dataset');
${$dataSetName}->setName('Ad ' . $adKey . ': Delivered Impressions');
}
$oDataSetBestError =& Image_Graph::factory('dataset');
$oDataSetBestError->setName('Least Possible Error In Delivery');
$oDataSetTotalError =& Image_Graph::factory('dataset');
$oDataSetTotalError->setName('Total Error In Delivery');
// Prepare the ads/zone for the initial iteration
$thisZoneImpressions = $minZoneImpressions;
$oZone = new OX_Maintenance_Priority_Zone(array('zoneid' => 1));
$oZone->availableImpressions = $thisZoneImpressions;
foreach ($aAds as $adKey => $aAdData) {
$oAd = new OA_Maintenance_Priority_Ad(array('ad_id' => $adKey));
$oAd->requiredImpressions = $aAdData['impressions'];
$oAd->requestedImpressions = $aAdData['impressions'];
$oZone->addAdvert($oAd);
}
$result = $oPriorityCompensation->compensatedPriorities($oZone);
// Perform the iterations
for ($iteration = 1; $iteration <= $iterations; $iteration++) {
// Calculate how many impressions will be delivered for each ad
foreach ($aAds as $adKey => $aAdData) {
$aDelivered[$adKey] = 0;
}
$this->_predictDelivery($aDelivered, $thisZoneImpressions, $aAds, $aChannels, $result, $oPriorityCompensation);
// Add the new data to the graph of the results
$bestError = 0;
$totalError = 0;
foreach ($aAds as $adKey => $aAdData) {
$dataSetName = 'oDataSet_Ad' . $adKey . '_RequiredImpressions';
${$dataSetName}->addPoint($iteration, $aAds[$adKey]['impressions']);
$dataSetName = 'oDataSet_Ad' . $adKey . '_AvailableImpressions';
if (is_null($aAdData['channel'])) {
${$dataSetName}->addPoint($iteration, $thisZoneImpressions);
} else {
${$dataSetName}->addPoint($iteration, $thisZoneImpressions * $aChannels[$aAdData['channel']]);
}
$dataSetName = 'oDataSet_Ad' . $adKey . '_ActualImpressions';
${$dataSetName}->addPoint($iteration, $aDelivered[$adKey]);
if (!is_null($aAdData['channel']) && $thisZoneImpressions * $aChannels[$aAdData['channel']] < $aAds[$adKey]['impressions']) {
$bestError += abs($thisZoneImpressions * $aChannels[$aAdData['channel']] - $aAds[$adKey]['impressions']);
}
$totalError += abs($oZone->aAdverts[$adKey]->requiredImpressions - $aDelivered[$adKey]);
}
$oDataSetBestError->addPoint($iteration, $bestError);
$oDataSetTotalError->addPoint($iteration, $totalError);
// Prepare the ads/zone for the next iteration
$previousZoneImpressions = $thisZoneImpressions;
if ($iteration == 1) {
$thisZoneImpressions = $this->_predictSharpZoneInventory($minZoneImpressions, $maxZoneImpressions, $zoneImpressionPeriod, $iteration);
} else {
$thisZoneImpressions = $this->_predictSharpZoneInventory($minZoneImpressions, $maxZoneImpressions, $zoneImpressionPeriod, $iteration);
//.........这里部分代码省略.........
示例5: array
if (empty($graphinfo['imageX'])) {
$graphinfo['imageX'] = 700;
}
if (empty($graphinfo['imageY'])) {
$graphinfo['imageY'] = 600;
}
if (!isset($graphinfo['charttype'])) {
$graphinfo['charttype'] = 'bar';
}
if (!isset($graphinfo['markers'])) {
$graphinfo['markers'] = true;
}
if (!isset($graphinfo['legendsplit'])) {
$graphinfo['legendsplit'] = 90;
}
$canvas =& Image_Canvas::factory('png', array('width' => $graphinfo['imageX'], 'height' => $graphinfo['imageY'], 'antialias' => true));
$graph =& Image_Graph::factory('graph', $canvas);
if (isset($graphinfo['orientation']) && $graphinfo['orientation'] == 'horizontal') {
$graph->horizontal = true;
} else {
$graph->horizontal = false;
}
if (!empty($conf['graph']['ttf_font'])) {
// add a TrueType font
$Font =& $graph->addNew('ttf_font', $conf['graph']['ttf_font']);
// Set the font size to 11 pixels. Yes, 8 really does mean 11
$Font->setSize(8);
$graph->setFont($Font);
}
// create the plotarea layout
if ($graph->horizontal) {
示例6: file
* Main purpose:
* Color chart of named colors
*
* Other:
* Using canvass "outside" Image_Graph
*
* $Id: color_chart.php,v 1.2 2005/08/03 21:21:52 nosey Exp $
*
* @package Image_Graph
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
*/
$file = file('./data/colors.txt');
require_once 'Image/Canvas.php';
require_once 'Image/Graph/Color.php';
require_once 'Image/Graph/Constants.php';
$Canvas =& Image_Canvas::factory('gd', array('width' => 600, 'height' => 1200));
$i = 0;
$cols = 10;
$Width = $Canvas->getWidth() / $cols;
$rows = count($file) / $cols;
$rows = floor($rows) + ($rows > floor($rows) ? 1 : 0);
$Height = $Canvas->getHeight() / $rows;
while (list($id, $color) = each($file)) {
$color = trim($color);
$x = $i % $cols * $Width + $Width / 2;
$y = floor($i / $cols) * $Height;
$Canvas->setLineColor('black');
$Canvas->setFillColor($color);
$Canvas->rectangle($x - $Width / 4, $y, $x + $Width / 4, $y + $Height / 3);
$Canvas->write($x, $y + $Height / 3 + 3, $color, IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_TOP);
$rgbColor = Image_Graph_Color::color2RGB($color);
示例7: Image_Graph
/**
* 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. &$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
* describing a new canvas or a valid {@link Image_Canvas} object
* @param int $height The height of the graph in pixels
* @param bool $createTransparent Specifies whether the graph should be
* created with a transparent background (fx for PNG's - note: transparent
* PNG's is not supported by Internet Explorer!)
*/
function Image_Graph($params, $height = false, $createTransparent = false)
{
parent::__construct();
$this->setFont(Image_Graph::factory('Image_Graph_Font'));
if (defined('IMAGE_GRAPH_DEFAULT_CANVAS_TYPE')) {
$canvasType = IMAGE_GRAPH_DEFAULT_CANVAS_TYPE;
} else {
$canvasType = 'png';
// use GD as default, if nothing else is specified
}
if (is_array($params)) {
if (isset($params['canvas'])) {
$canvasType = $params['canvas'];
}
$width = 0;
$height = 0;
if (isset($params['width'])) {
$width = $params['width'];
}
if (isset($params['height'])) {
$height = $params['height'];
}
} elseif (is_a($params, 'Image_Canvas')) {
$this->_canvas =& $params;
$width = $this->_canvas->getWidth();
$height = $this->_canvas->getHeight();
} elseif (is_numeric($params)) {
$width = $params;
}
if ($this->_canvas == null) {
include_once 'Image/Canvas.php';
$this->_canvas =& Image_Canvas::factory($canvasType, array('width' => $width, 'height' => $height));
}
$this->_setCoords(0, 0, $width - 1, $height - 1);
}
示例8: array
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this library; if not, write
* to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*
* @category Images
* @package Image_Canvas
* @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: imagemap.php,v 1.4 2005/08/10 20:01:05 nosey Exp $
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=212
*/
require_once 'Image/Canvas.php';
$canvas =& Image_Canvas::factory('png', array('width' => 800, 'height' => 500, 'usemap' => true, 'antialias' => 'native'));
$canvas->setLineColor('black');
$canvas->rectangle(array('x0' => 0, 'y0' => 0, 'x1' => $canvas->getWidth() - 1, 'y1' => $canvas->getHeight() - 1));
$canvas->setLineColor('gray');
$canvas->line(array('x0' => 450, 'y0' => 50, 'x1' => 550, 'y1' => 100, 'url' => 'http://pear.veggerby.dk/', 'target' => '_blank', 'alt' => 'Line', 'mapsize' => 5));
$canvas->setLineColor('gray');
$canvas->line(array('x0' => 600, 'y0' => 125, 'x1' => 700, 'y1' => 50, 'url' => 'http://pear.veggerby.dk/', 'target' => '_blank', 'alt' => 'Line', 'mapsize' => 5));
$canvas->setLineColor('blue');
$canvas->rectangle(array('x0' => 50, 'y0' => 50, 'x1' => 350, 'y1' => 100, 'url' => 'http://pear.veggerby.dk/', 'target' => '_blank', 'alt' => 'Rectangle'));
$canvas->setLineColor('red');
$canvas->ellipse(array('x' => 200, 'y' => 200, 'rx' => 75, 'ry' => 75, 'url' => 'http://pear.php.net/Image_Graph/', 'alt' => 'Circle'));
$canvas->setLineColor('brown');
$canvas->ellipse(array('x' => 500, 'y' => 200, 'rx' => 100, 'ry' => 75, 'url' => 'http://pear.php.net/Image_Graph/', 'alt' => 'Ellipse'));
$canvas->setLineColor('green');
for ($i = 0; $i < 8; $i++) {
$canvas->addVertex(array('x' => 115 + $i * 50, 'y' => 330, 'alt' => 'Vertex #' . $i * 3, 'url' => 'test?id=' . $i * 3));
示例9: array
* Usage example for Image_Graph.
*
* Main purpose:
* Demonstrate SWF canvas
*
* Other:
* None specific
*
* $Id$
*
* @package Image_Graph
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
*/
require_once 'Image/Graph.php';
require_once 'Image/Canvas.php';
$Canvas =& Image_Canvas::factory('swf', array('width' => 600, 'height' => 400));
// create the graph
$Graph =& Image_Graph::factory('graph', $Canvas);
// add a TrueType font
$Font =& $Graph->addNew('font', 'Verdana');
// set the font size to 11 pixels
$Font->setSize(11);
$Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Simple Line Chart Sample', &$Font)), Image_Graph::vertical($Plotarea = Image_Graph::factory('plotarea'), $Legend = Image_Graph::factory('legend'), 90), 5));
$Legend->setPlotarea($Plotarea);
// create the dataset
$Dataset =& Image_Graph::factory('random', array(10, 2, 15, true));
// create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea->addNew('line', $Dataset);
// set a line color
$Plot->setLineColor('red');
// output the Graph
示例10: var_dump
# $displayTiming = TRUE;
#echo "<br> TEST:"; var_dump($CONFIG);
//$_REQUEST = cleanup_input_request();
$probeid = $_REQUEST['probeid'];
if (!is_numeric($probeid)) {
die("Cannot proceed -- Missing probeid input");
}
$tstampF = $_REQUEST['tstampF'];
$tstampT = $_REQUEST['tstampT'];
$bucketsz = $_REQUEST['bucketsz'];
# Select all channel within the period
$data =& multicast_probe_data_query_ts($probeid, $tstampF, $tstampT);
//$data = multicast_probe_data_query($probeid, $fromT, $toT);
//db_disconnect();
#print_r($data);
$Canvas =& Image_Canvas::factory('png', array('width' => 400, 'height' => 350, 'usemap' => true));
// This is how you get the ImageMap object,
// fx. to save map to file (using toHtml())
$Imagemap = $Canvas->getImageMap();
// create the graph
//$Graph =& Image_Graph::factory('graph', array(400, 350));
$Graph =& Image_Graph::factory('graph', $Canvas);
// add a TrueType font
$myfont = '/usr/share/fonts/truetype/freefont/FreeSerif.ttf';
$Font =& $Graph->addNew('font', $myfont);
//$Font =& $Graph->addNew('font', 'Verdana');
// set the font size to 11 pixels
$Font->setSize(8);
$Graph->setFont($Font);
// setup the plotarea, legend and their layout
$Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Channel Drop Proportion', 12)), Image_Graph::vertical($Plotarea = Image_Graph::factory('plotarea'), $Legend = Image_Graph::factory('legend'), 70), 5));
示例11: array
* Usage example for Image_Graph.
*
* Main purpose:
* Demonstrate logarithmic axis
*
* Other:
* Matrix layout, Axis titles
*
* $Id: log_axis_forcemin.php,v 1.1 2006/02/28 22:48:07 nosey Exp $
*
* @package Image_Graph
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
*/
require_once 'Image/Graph.php';
require_once 'Image/Canvas.php';
$Canvas =& Image_Canvas::factory('png', array('width' => 600, 'height' => 400, 'antialias' => true));
// create the graph
$Graph =& Image_Graph::factory('graph', $Canvas);
// add a TrueType font
$Font =& $Graph->addNew('font', 'Verdana');
// set the font size to 15 pixels
$Font->setSize(8);
// add a title using the created font
for ($i = 0; $i < 2; $i++) {
for ($j = 0; $j < 2; $j++) {
$Axis['X'][$i * 2 + $j] = 'axis' . ($i % 2 == 0 ? '' : '_log');
$Axis['Y'][$i * 2 + $j] = 'axis' . ($j % 2 == 0 ? '' : '_log');
}
}
for ($i = 0; $i < 4; $i++) {
$Plotarea[$i] =& Image_Graph::factory('plotarea', array($Axis['X'][$i], $Axis['Y'][$i]));
示例12: array
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this library; if not, write
* to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*
* @category Images
* @package Image_Canvas
* @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: canvas.php,v 1.1 2005/08/03 21:11:22 nosey Exp $
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=212
*/
include_once 'Image/Canvas.php';
$Canvas =& Image_Canvas::factory(isset($_GET['canvas']) ? $_GET['canvas'] : 'png', array('width' => 400, 'height' => 300));
$Canvas->setLineColor('black');
$Canvas->rectangle(array('x0' => 0, 'y0' => 0, 'x1' => 399, 'y1' => 299));
$Canvas->setGradientFill(array('direction' => 'horizontal', 'start' => 'red', 'end' => 'blue'));
$Canvas->setLineColor('black');
$Canvas->ellipse(array('x' => 199, 'y' => 149, 'rx' => 50, 'ry' => 50));
$Canvas->setFont(array('name' => 'Arial', 'size' => 12));
$Canvas->addText(array('x' => 0, 'y' => 0, 'text' => 'Demonstration of what Image_Canvas do!'));
$Canvas->setFont(array('name' => 'Times New Roman', 'size' => 12));
$Canvas->addText(array('x' => 399, 'y' => 20, 'text' => 'This does not demonstrate what is does!', 'alignment' => array('horizontal' => 'right')));
$Canvas->setFont(array('name' => 'Courier New', 'size' => 7, 'angle' => 270));
$Canvas->addText(array('x' => 350, 'y' => 50, 'text' => 'True, but it\'s all independent of the format!', 'alignment' => array('horizontal' => 'right')));
$Canvas->setFont(array('name' => 'Garamond', 'size' => 10));
$Canvas->addText(array('x' => 199, 'y' => 295, 'text' => '[Changing format is done by changing 3 letters in the source]', 'alignment' => array('horizontal' => 'center', 'vertical' => 'bottom')));
$Canvas->addVertex(array('x' => 50, 'y' => 200));
$Canvas->addVertex(array('x' => 100, 'y' => 200));
示例13: testScaleBackComplex2
/**
* A method to visually test the scaling back of the compensation factor.
*
* Performs a more relalistic version of the test above, with multiple ads,
* and disabling of an ad during the operation of the zone.
*/
function testScaleBackComplex2()
{
$conf = $GLOBALS['_MAX']['CONF'];
// Mock the OA_Dal_Maintenance_Priority class
$oDal = new MockOA_Dal_Maintenance_Priority($this);
$oServiceLocator =& OA_ServiceLocator::instance();
$oServiceLocator->register('OA_Dal_Maintenance_Priority', $oDal);
// Partially mock the OA_Maintenance_Priority_AdServer_Task_PriorityCompensation class
$oPriorityCompensation = new PartialMock_OA_Maintenance_Priority_AdServer_Task_PriorityCompensationScaleBack($this);
$oPriorityCompensation->setReturnReference('_getDal', $oDal);
$oPriorityCompensation->OA_Maintenance_Priority_AdServer_Task_PriorityCompensation();
// Define the number of initial iterations to test over
$initialIterations = 12;
// Define how many impressions are in the zone in each initial iteration
$initialZoneImpressions = 10;
// Define the number of final iterations to test over
$finalIterations = 24;
// Define how many impressions are in the zone in each final iteration
$finalZoneImpressions = 20000;
// Define the channels, including the % of zone impressions in each
$aChannels[1] = 0.1;
// Channel 1: 10% of zone traffic
$aChannels[2] = 0.05;
// Channel 2: 5% of zone traffic
// Define the test ads, giving the number of required impressions
// each hour (fixed), the channel the ad is in (if any), and the
// colour to graph the ad
// The number of ads must not exceed ($initialZoneImpressions - 1)
// or ($finalZoneImpressions - 1), to ensure that the values for
// the requestedImpressions >= 1 for all ads
$aAds[1] = array('requiredImpressions' => 5000, 'channel' => null, 'requiredColour' => '#AA00FF', 'requestedColour' => 'blue', 'availableColour' => 'black', 'deliveredColour' => 'green', 'priorityFactorColour' => 'red');
$aAds[2] = array('requiredImpressions' => 5000, 'channel' => 1, 'requiredColour' => '#AA00FF', 'requestedColour' => 'blue', 'availableColour' => 'black', 'deliveredColour' => 'green', 'priorityFactorColour' => 'red');
$aAds[3] = array('requiredImpressions' => 5000, 'channel' => 2, 'requiredColour' => '#AA00FF', 'requestedColour' => 'blue', 'availableColour' => 'black', 'deliveredColour' => 'green', 'priorityFactorColour' => 'red');
// Preapare the graph data sets, ready to accept test data
foreach ($aAds as $adKey => $aAdData) {
$dataSetName = 'oDataSet_Ad_' . $adKey . '_RequiredImpressions';
${$dataSetName} =& Image_Graph::factory('dataset');
${$dataSetName}->setName('Ad ' . $adKey . ': Required Impressions');
$dataSetName = 'oDataSet_Ad_' . $adKey . '_RequestedImpressions';
${$dataSetName} =& Image_Graph::factory('dataset');
${$dataSetName}->setName('Ad ' . $adKey . ': Requested Impressions');
$dataSetName = 'oDataSet_Ad_' . $adKey . '_AvailableImpressions';
${$dataSetName} =& Image_Graph::factory('dataset');
${$dataSetName}->setName('Ad ' . $adKey . ': Available Impressions');
$dataSetName = 'oDataSet_Ad_' . $adKey . '_DeliveredImpressions';
${$dataSetName} =& Image_Graph::factory('dataset');
${$dataSetName}->setName('Ad ' . $adKey . ': Delivered Impressions');
$dataSetName = 'oDataSet_Ad_' . $adKey . '_PriorityFactor';
${$dataSetName} =& Image_Graph::factory('dataset');
${$dataSetName}->setName('Ad ' . $adKey . ': Priority Factor');
$dataSetName = 'oDataSet_Ad_' . $adKey . '_Priority';
${$dataSetName} =& Image_Graph::factory('dataset');
${$dataSetName}->setName('Ad ' . $adKey . ': Priority');
}
// Prepare the zone/ads for the initial iterations
$oZone = new OX_Maintenance_Priority_Zone(array('zoneid' => 1));
$oZone->availableImpressions = $initialZoneImpressions;
$zoneTotalRequired = 0;
foreach ($aAds as $adKey => $aAdData) {
$zoneTotalRequired += $aAdData['requiredImpressions'];
}
foreach ($aAds as $adKey => $aAdData) {
$oAd = new OA_Maintenance_Priority_Ad(array('ad_id' => $adKey));
$oAd->requiredImpressions = $aAdData['requiredImpressions'];
if ($zoneTotalRequired > $oZone->availableImpressions) {
$oAd->requestedImpressions = floor(($oZone->availableImpressions - 1) / count($aAds));
} else {
$oAd->requestedImpressions = $aAdData['requiredImpressions'];
}
$oZone->addAdvert($oAd);
}
$result = $oPriorityCompensation->compensatedPriorities($oZone);
// Perform the initial iterations
$oSavedZone;
$zoneImpressions = $initialZoneImpressions;
for ($iteration = 0; $iteration <= $initialIterations; $iteration++) {
// As these are the initial iterations, no delivery of any ads (zone not active)
foreach ($aAds as $adKey => $aAdData) {
$aDelivered[$adKey] = 0;
}
// Add the new data to the graph of the results
foreach ($aAds as $adKey => $aAdData) {
$dataSetName = 'oDataSet_Ad_' . $adKey . '_RequiredImpressions';
${$dataSetName}->addPoint($iteration, $aAds[$adKey]['requiredImpressions']);
$dataSetName = 'oDataSet_Ad_' . $adKey . '_RequestedImpressions';
${$dataSetName}->addPoint($iteration, $result['ads'][$adKey]['requested_impressions']);
$dataSetName = 'oDataSet_Ad_' . $adKey . '_AvailableImpressions';
if (is_null($aAdData['channel'])) {
${$dataSetName}->addPoint($iteration, $zoneImpressions);
} else {
${$dataSetName}->addPoint($iteration, $zoneImpressions * $aChannels[$aAdData['channel']]);
}
$dataSetName = 'oDataSet_Ad_' . $adKey . '_DeliveredImpressions';
${$dataSetName}->addPoint($iteration, $aDelivered[$adKey]);
//.........这里部分代码省略.........
示例14: error_reporting
* Usage example for Image_Graph.
*
* Main purpose:
* PDF canvas
*
* Other:
* Datapreprocessor, Axis markers
*
* $Id$
*
* @package Image_Graph
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
*/
error_reporting(E_ALL);
require_once 'Image/Graph.php';
require_once 'Image/Canvas.php';
$Canvas =& Image_Canvas::factory('File_PDF', array('page' => 'A4'));
// create the graph
$Graph =& Image_Graph::factory('graph', $Canvas);
// // setup the plotarea, legend and their layout
$Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Simple Line Chart Sample', 12)), Image_Graph::vertical($Plotarea = Image_Graph::factory('plotarea'), $Legend = Image_Graph::factory('legend'), 88), 5));
// link the legend with the plotares
$Legend->setPlotarea($Plotarea);
// create a random dataset for sake of simplicity
$Dataset =& Image_Graph::factory('random', array(10, 2, 15, true));
// create the plot as line chart using the dataset
$Plot =& $Plotarea->addNew('line', array(&$Dataset));
// set a line color
$Plot->setLineColor('red');
// output the Graph
$Graph->done();
示例15: error_reporting
*
* Main purpose:
* PDF canvas
*
* Other:
* Datapreprocessor, Axis markers
*
* $Id$
*
* @package Image_Graph
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
*/
error_reporting(E_ALL);
require_once 'Image/Graph.php';
require_once 'Image/Canvas.php';
$Canvas =& Image_Canvas::factory('cpdf', array('page' => 'A3', 'align' => 'center', 'width' => 600, 'height' => 400));
// create the graph
$Graph =& Image_Graph::factory('graph', $Canvas);
$Font =& $Graph->addNew('font', 'Verdana');
$Font->setSize(7);
$Graph->setFont($Font);
$Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Image_Graph Demonstration', 12)), Image_Graph::vertical(Image_Graph::vertical($Plotarea_Weather = Image_Graph::factory('plotarea'), $Legend_Weather = Image_Graph::factory('legend'), 85), Image_Graph::horizontal(Image_Graph::vertical(Image_Graph::vertical(Image_Graph::factory('title', array('Demonstration of Mathematical Functions', 10)), $Plotarea_SinCos = Image_Graph::factory('plotarea', 'axis'), 5), $Legend_SinCos = Image_Graph::factory('legend'), 90), $Plotarea_Car = Image_Graph::factory('plotarea'), 50), 60), 5));
$Legend_Weather->setPlotarea($Plotarea_Weather);
$Legend_Weather->setFontSize(7);
$Legend_SinCos->setPlotarea($Plotarea_SinCos);
$Legend_SinCos->setFontSize(8);
$GridY_Weather =& $Plotarea_Weather->addNew('line_grid', null, IMAGE_GRAPH_AXIS_Y);
$GridY_Weather->setLineColor('gray@0.1');
$Marker_AverageSpan =& $Plotarea_Weather->addNew('Image_Graph_Axis_Marker_Area', IMAGE_GRAPH_AXIS_Y);
$Marker_AverageSpan->setFillColor('green@0.2');
$Marker_AverageSpan->setLowerBound(3.8);