示例#1
0
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));
        }
    }
}
示例#2
0
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;
}
示例#3
0
 /**
  * Overlay image
  *
  * Parameter array:
  * 'x': int X-point of overlayed image
  * 'y': int Y-point of overlayed image
  * 'filename': string The filename of the image to overlay
  * 'width': int [optional] The width of the overlayed image (resizing if possible)
  * 'height': int [optional] The height of the overlayed image (resizing if possible)
  * 'alignment': array [optional] Alignment
  */
 function image($params)
 {
     if (isset($this->_imageMap)) {
         $this->_imageMap->image($params);
     }
     parent::image($params);
 }
示例#4
0
 * 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 <*****@*****.**>
 */
$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);
示例#5
0
 /**
  * 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
  * 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);
 }
示例#6
0
 * Usage example for Image_Graph.
 * 
 * Main purpose: 
 * Show radar chart
 * 
 * Other: 
 * None specific
 * 
 * $Id$
 * 
 * @package Image_Graph
 * @author Jesper Veggerby <*****@*****.**>
 */
require_once 'Image/Graph.php';
require_once 'Image/Canvas.php';
$Canvas =& Image_Canvas::factory('png', array('width' => 400, 'height' => 300, 'antialias' => 'native'));
// 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(8);
$Graph->setFont($Font);
$Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Spider/Radar Chart Sample', 12)), Image_Graph::vertical($Plotarea = Image_Graph::factory('Image_Graph_Plotarea_Radar'), $Legend = Image_Graph::factory('legend'), 90), 5));
$Legend->setPlotarea($Plotarea);
$Plotarea->addNew('Image_Graph_Grid_Polar', IMAGE_GRAPH_AXIS_Y);
// create the dataset
$DS1 =& Image_Graph::factory('dataset');
$DS1->addPoint('Life', rand(1, 6));
$DS1->addPoint('Universe', rand(1, 6));
$DS1->addPoint('Everything', rand(1, 6));
/** Function to render the Horizontal Graph
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 */
function horizontal_graph($referdata, $refer_code, $width, $height, $left, $right, $top, $bottom, $title, $target_val, $cache_file_name, $html_image_name)
{
    global $log, $root_directory, $lang_crm, $theme;
    //We'll be getting the values in the form of a string separated by commas
    $datay = explode("::", $referdata);
    // The datay values
    $datax = explode("::", $refer_code);
    // The datax values
    // The links values are given as string in the encoded form, here we are decoding it
    $target_val = urldecode($target_val);
    $target = explode("::", $target_val);
    $alts = array();
    $temp = array();
    for ($i = 0; $i < count($datax); $i++) {
        $name = $datax[$i];
        $pos = substr_count($name, " ");
        // JFV : prevent utf-8 char garbled and display percentage correctly
        global $default_charset;
        $sum = 0;
        for ($j = 0; $j < count($datay); $j++) {
            $sum += $datay[$j];
        }
        $alts[] = htmlentities($name, ENT_QUOTES, $default_charset) . " = " . sprintf('%0.1f%%', 100 * $datay[$i] / $sum);
        //		$alts[]=htmlentities($name)."=%d";
        // JFV END
        //If the daatx value of a string is greater, adding '\n' to it so that it'll cme inh 2nd line
        if (strlen($name) >= 14) {
            $name = substr($name, 0, 44);
        }
        if ($pos >= 2) {
            $val = explode(" ", $name);
            $n = count($val) - 1;
            $x = "";
            for ($j = 0; $j < count($val); $j++) {
                if ($j != $n) {
                    $x .= " " . $val[$j];
                } else {
                    $x .= "@#" . $val[$j];
                }
            }
            $name = $x;
        }
        $name = str_replace("@#", "\n", $name);
        $temp[] = $name;
    }
    $datax = $temp;
    //datay is the values
    //datax is the status
    // Set the basic parameters of the graph
    $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true));
    $imagemap = $canvas->getImageMap();
    $graph =& Image_Graph::factory('graph', $canvas);
    $font =& $graph->addNew('font', calculate_font_name($lang_crm));
    // set the font size to 12
    $font->setSize(8);
    if ($theme == "blue") {
        $font_color = "#212473";
    } else {
        $font_color = "#000000";
    }
    $font->setColor($font_color);
    $graph->setFont($font);
    $titlestr =& Image_Graph::factory('title', array($title, 8));
    $plotarea =& Image_Graph::factory('plotarea', array('axis', 'axis', 'horizontal'));
    $graph->add(Image_Graph::vertical($titlestr, $plotarea, 5));
    // Now create a bar plot
    $max = 0;
    // To create unique lables we need to keep track of lable name and its count
    $uniquex = array();
    $xlabels = array();
    $dataset =& Image_Graph::factory('dataset');
    if ($theme == 'woodspice') {
        $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED, '#804000', 'white'));
    } elseif ($theme == 'bluelagoon') {
        $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED, 'blue', 'white'));
    } elseif ($theme == 'softed') {
        $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED, 'blue', 'white'));
    } else {
        $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED, 'black', 'white'));
    }
    for ($i = 0; $i < count($datay); $i++) {
        $x = 1 + 2 * $i;
        if ($datay[$i] >= $max) {
            $max = $datay[$i];
        }
        $dataset->addPoint($x, $datay[$i], array('url' => $target[$i], 'alt' => $alts[$i]));
        // build the xaxis label array to allow intermediate ticks
        $xlabels[$x] = $datax[$i];
        $xlabels[$x + 1] = '';
        // To have unique names even in case of duplicates let us add the id
        $datax_appearance = $uniquex[$datax[$i]];
        if ($datax_appearance == null) {
            $uniquex[$datax[$i]] = 1;
        } else {
            $xlabels[$x] = $datax[$i] . ' [' . $datax_appearance . ']';
            $uniquex[$datax[$i]] = $datax_appearance + 1;
        }
    }
    $bplot =& $plotarea->addNew('bar', $dataset);
    $bplot->setFillStyle($fill);
    //You can change the width of the bars if you like
    $bplot->setBarWidth(50 / count($datax), "%");
    $bplot->setPadding(array('top' => 10));
    // We want to display the value of each bar at the top
    //$bplot->value->Show();
    //$bplot->value->SetFont(FF_FONT2,FS_BOLD,12);
    //$bplot->value->SetAlign('left','center');
    //$bplot->value->SetColor("black","gray4");
    //$bplot->value->SetFormat('%d');
    //$graph->SetBackgroundGradient('#E5E5E5','white',GRAD_VER,BGRAD_PLOT);
    $bplot->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL, 'white', 'white')));
    //$bplot->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL, 'white', '#E5E5E5')));
    //$bplot->SetFillGradient("navy","lightsteelblue",GRAD_MIDVER);
    //$graph->SetFrame(false);
    //$graph->SetMarginColor('cadetblue2');
    //$graph->ygrid->SetFill(true,'azure1','azure2');
    //$graph->xgrid->Show();
    // Add the bar to the graph
    //$graph->Add($bplot);
    // Setup title
    //$titlestr->setText($title);
    // Setup X-axis
    $xaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    $yaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $yaxis->setFontSize(10);
    // Invert X-axis and put Y-axis at bottom
    $xaxis->setInverted(true);
    $yaxis->setAxisIntersection('max');
    // set grid
    $gridY =& $plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y);
    $gridY->setLineColor('#FFFFFF@0.5');
    $gridY2 =& $plotarea->addNew('bar_grid', null, IMAGE_GRAPH_AXIS_Y);
    $gridY2->setFillColor('#FFFFFF@0.2');
    // Add some grace to y-axis so the bars doesn't go
    // all the way to the end of the plot area
    $yaxis->forceMaximum(round($max * 1.1 + 0.5));
    $ticks = get_tickspacing(round($max * 1.1 + 0.5));
    // First make the labels look right
    $yaxis->setLabelInterval($ticks[0]);
    $yaxis->setTickOptions(-5, 0);
    $yaxis->setLabelInterval($ticks[1], 2);
    $yaxis->setTickOptions(-2, 0, 2);
    // Create the xaxis labels
    $array_data =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array', array($xlabels));
    // The fix the tick marks
    $xaxis->setDataPreprocessor($array_data);
    $xaxis->forceMinimum(0);
    $xaxis->forceMaximum(2 * count($datay));
    $xaxis->setLabelInterval(1);
    $xaxis->setTickOptions(0, 0);
    $xaxis->setLabelInterval(2, 2);
    $xaxis->setTickOptions(5, 0, 2);
    // set markers
    $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y);
    $marker->setFillColor('000000@0.0');
    $marker->setBorderColor('000000@0.0');
    $marker->setFontSize(10);
    // shift markers 10 pix right
    $marker_pointing =& $graph->addNew('Image_Graph_Marker_Pointing', array(40, 0, &$marker));
    $marker_pointing->setLineColor('000000@0.0');
    $bplot->setMarker($marker_pointing);
    //Getting the graph in the form of html page
    $img = $graph->done(array('tohtml' => true, 'border' => 0, 'filename' => $cache_file_name, 'filepath' => '', 'urlpath' => ''));
    save_image_map($cache_file_name . '.map', $img);
    return $img;
}
示例#8
0
 /**
  * Save the result of the canvas to a file
  *
  * Parameter array:
  * 'filename': string The file to output to
  * @param array $params Parameter array, the contents and meaning depends on the actual Canvas
  * @abstract
  */
 function save($params = false)
 {
     parent::save($params);
     $file = fopen($param['filename'], 'w+');
     fwrite($file, $this->toHtml($params));
     fclose($file);
 }
示例#9
0
文件: db.php 项目: demental/m
 function _regenerateThumbUnit($photo, $v, &$obj, $field)
 {
     $firstRedim = true;
     if (!isset($v['x']) && !isset($v['y']) && !isset($v['maxx']) && !isset($v['maxy']) && !isset($v['overlay'])) {
         copy($photo, IMAGES_UPLOAD_FOLDER . $v['path'] . '/' . $obj->{$field});
         $name = $obj->{$field};
     } else {
         $ph = new traitephoto();
         $ph->photo = $photo;
         $ph->path = IMAGES_UPLOAD_FOLDER . $v['path'];
         $ph->nomsouhaite = $obj->{$field};
         $ph->qualite = $v['quality'];
         $ph->width = $v['x'];
         $ph->height = $v['y'];
         $ph->maxx = $v['maxx'];
         $ph->maxy = $v['maxy'];
         if (isset($v['overlay']) && $firstRedim) {
             $type = 'png';
             $ph->path = FileUtils::getFolderPath(TMP_PATH);
             $ph->nomsouhaite = 'overlaytemp.png';
         } else {
             $type = $v['type'] ? $v['type'] : null;
         }
         $ph->resize();
         $name = $ph->save($type);
         if (isset($v['overlay']) && $firstRedim) {
             $source = $v['path'] . '/' . $name;
             $infosSource =& Image_Transform::factory('GD');
             if (PEAR::isError($infosSource)) {
                 throw new Exception($infosSource->getMessage());
             }
             $tmp = FileUtils::getFolderPath(TMP_PATH);
             $infosSource->load($tmp . 'overlaytemp.png');
             $infosOver =& Image_Transform::factory('GD');
             $infosOver->load(APP_ROOT . $v['overlay'][0]);
             $opts = array('width' => $infosSource->getImageWidth(), 'height' => $infosSource->getImageHeight(), 'transparent' => true);
             $img =& Image_Canvas::factory('png', $opts);
             $img->image(array('filename' => TMP_PATH . 'overlaytemp.png', 'x' => 0, 'y' => 0));
             switch ($v['overlay']['position']) {
                 case 'top-left':
                     $x = 0;
                     $y = 0;
                     break;
                 case 'top-right':
                     $x = $infosSource->getImageWidth() - $infosOver->getImageWidth();
                     $y = 0;
                     break;
                 case 'bottom-left':
                     $x = 0;
                     $y = $infosSource->getImageHeight() - $infosOver->getImageHeight();
                     break;
                 case 'bottom-right':
                     $x = $infosSource->getImageWidth() - $infosOver->getImageWidth();
                     $y = $infosSource->getImageHeight() - $infosOver->getImageHeight();
                     break;
                 default:
                     $x = 0;
                     $y = 0;
                     break;
             }
             $img->image(array('filename' => APP_ROOT . $v['overlay'][0], 'x' => $x, 'y' => $y));
             $img->save(array('filename' => $tmp . 'overlaytemp.png'));
             $ph = new traitephoto();
             $ph->photo = $tmp . 'overlaytemp.png';
             $ph->path = IMAGES_UPLOAD_FOLDER . $v['path'];
             $ph->nomsouhaite = $obj->{$field};
             $ph->qualite = $v['quality'];
             $ph->resize();
             $name = $ph->save($v['type'] ? $v['type'] : null);
             unset($ph);
         }
     }
     if ($name != $obj->{$field}) {
         @unlink(IMAGES_UPLOAD_FOLDER . $v['path'] . '/' . $obj->{$field});
     }
     unset($ph);
     return $name;
 }
示例#10
0
 /**
  * A method to launch and display the widget
  */
 function display()
 {
     if ($this->draw) {
         $useAntialias = is_callable('imageantialias');
         $Canvas = Image_Canvas::factory('png', array('width' => 239, 'height' => 132, 'antialias' => $useAntialias ? 'native' : false));
         $Graph = Image_Graph::factory('graph', $Canvas);
         if (is_callable('imagettftext')) {
             $Font = $Graph->addNew('ttf_font', MAX_PATH . '/lib/fonts/Bitstream/Vera.ttf');
             $Font->setSize(7);
             $Graph->setFont($Font);
         } else {
             // TTF library not available, use standard bitmap font
             $Graph->setFontSize(7);
         }
         $Datasets = array(Image_Graph::factory('dataset'), Image_Graph::factory('dataset'));
         $Datasets[0]->setName('Impressions');
         $Datasets[1]->setName('Clicks');
         foreach ($this->aData[0] as $k => $v) {
             $Datasets[0]->addPoint($k, $v);
         }
         $scaleY2 = 1.75;
         $maxImpr = max($this->aData[0]);
         $maxClick = max($this->aData[1]);
         $relation = $maxImpr / ($maxClick > 0 ? $maxClick : 1);
         // impressions/clicks
         $factor = $relation / $scaleY2;
         //scale down to make click ~ 57% of impressions bar height
         foreach ($this->aData[1] as $k => $v) {
             $Datasets[1]->addPoint($k, $v * $factor);
         }
         $Graph->add($Plotarea = Image_Graph::factory('plotarea'));
         $PlotBg = Image_Graph::factory('Fill_Array');
         $PlotBg->addColor('white');
         $PlotFg = Image_Graph::factory('Line_Array');
         $PlotFg->addColor('white');
         $Plotarea->setBackground($PlotBg);
         $Plotarea->setBorderColor('white');
         $Grid = $Plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y);
         $Grid->setLineColor('#cccccc');
         $Plot = $Plotarea->addNew('bar', array($Datasets));
         $Plot->setLineColor('black@0.2');
         $FillArray = Image_Graph::factory('Fill_Array');
         $FillArray->add(Image_Graph::factory('Fill_Gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, '#b5da3c', '#6a9a2a')));
         $FillArray->add(Image_Graph::factory('Fill_Gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, '#bb5c9e', '#8b4a9e')));
         $Plot->setFillStyle($FillArray);
         $AxisY2 = $Plotarea->addNew('axis', array(IMAGE_GRAPH_AXIS_Y_SECONDARY));
         $AxisY2->forceMaximum(max($this->aData[1]) * $scaleY2 + 1);
         $AxisY = $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
         if (!max($this->aData[0])) {
             $AxisY->forceMaximum(1);
         }
         $func = create_function('$value', 'return OA_Dashboard_Widget_Graph::_formatY($value);');
         $AxisY->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', $func));
         $AxisY2->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', $func));
         ob_start();
         $Graph->done();
         $content = ob_get_clean();
         $this->oTpl->assign('content', $content);
     } else {
         $this->oTpl->assign('title', $this->title);
         $this->oTpl->assign('imageSrc', "dashboard.php?widget={$this->widgetName}&draw=1&cb=" . $this->oTpl->cacheId);
     }
     $this->oTpl->display();
 }
示例#11
0
# $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));
示例#12
0
 * 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 <*****@*****.**>
 */
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]));
示例#13
0
 * 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 <*****@*****.**>
 * @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));
 /**
  * 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]);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_PriorityFactor';
             ${$dataSetName}->addPoint($iteration, $result['ads'][$adKey]['priority_factor']);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_Priority';
             ${$dataSetName}->addPoint($iteration, $result['ads'][$adKey]['priority']);
         }
         // Prepare the ads/zone for the next iteration
         $oZone = new OX_Maintenance_Priority_Zone(array('zoneid' => 1));
         $oZone->availableImpressions = $zoneImpressions;
         $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 > $zoneImpressions) {
                 $oAd->requestedImpressions = floor(($zoneImpressions - 1) / count($aAds));
             } else {
                 $oAd->requestedImpressions = $aAdData['requiredImpressions'];
             }
             $oAd->pastRequiredImpressions = $aAdData['requiredImpressions'];
             $oAd->pastRequestedImpressions = $result['ads'][$adKey]['requested_impressions'];
             $oAd->pastActualImpressions = $aDelivered[$adKey];
             $oAd->pastAdZonePriorityFactor = $result['ads'][$adKey]['priority_factor'];
             $oAd->pastZoneTrafficFraction = $result['ads'][$adKey]['past_zone_traffic_fraction'];
             $oZone->addAdvert($oAd);
         }
         // Move to the next iteration
         $result = $oPriorityCompensation->compensatedPriorities($oZone);
     }
     // Prepare the zone/ads for the final iterations
     $zoneTotalRequired = 0;
     foreach ($aAds as $adKey => $aAdData) {
         $zoneTotalRequired += $aAdData['requiredImpressions'];
     }
     foreach ($aAds as $adKey => $aAdData) {
         $oAd =& $oZone->aAdverts[$adKey];
         $oAd->requiredImpressions = $aAdData['requiredImpressions'];
         if ($zoneTotalRequired > $oZone->availableImpressions) {
             $oAd->requestedImpressions = floor(($oZone->availableImpressions - 1) / count($aAds));
         } else {
             $oAd->requestedImpressions = $aAdData['requiredImpressions'];
         }
     }
     $result = $oPriorityCompensation->compensatedPriorities($oZone);
     // Perform the final iterations
     $zoneImpressions = $finalZoneImpressions;
     for ($iteration = $initialIterations + 1; $iteration <= $initialIterations + $finalIterations; $iteration++) {
         // As these are the final iteration, calculate delivery
         foreach ($aAds as $adKey => $aAdData) {
             $aDelivered[$adKey] = 0;
         }
         $this->_predictDelivery($aDelivered, $zoneImpressions, $aAds, $aChannels, $result, $oPriorityCompensation);
         // 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]);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_PriorityFactor';
             ${$dataSetName}->addPoint($iteration, $result['ads'][$adKey]['priority_factor']);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_Priority';
             ${$dataSetName}->addPoint($iteration, $result['ads'][$adKey]['priority']);
         }
         // Prepare the ads/zone for the next iteration
         $oZone = new OX_Maintenance_Priority_Zone(array('zoneid' => 1));
         $oZone->availableImpressions = $zoneImpressions;
         $zoneTotalRequired = 0;
         foreach ($aAds as $adKey => $aAdData) {
             if (!($iteration > ($initialIterations + $finalIterations) / 2 && $adKey == 2)) {
                 $zoneTotalRequired += $aAdData['requiredImpressions'];
             }
         }
         foreach ($aAds as $adKey => $aAdData) {
             if (!($iteration > ($initialIterations + $finalIterations) / 2 && $adKey == 2)) {
                 $oAd = new OA_Maintenance_Priority_Ad(array('ad_id' => $adKey));
                 $oAd->requiredImpressions = $aAdData['requiredImpressions'];
                 if ($zoneTotalRequired > $zoneImpressions) {
                     $oAd->requestedImpressions = floor(($zoneImpressions - 1) / count($aAds));
                 } else {
                     $oAd->requestedImpressions = $aAdData['requiredImpressions'];
                 }
                 $oAd->pastRequiredImpressions = $aAdData['requiredImpressions'];
                 $oAd->pastRequestedImpressions = $result['ads'][$adKey]['requested_impressions'];
                 $oAd->pastActualImpressions = $aDelivered[$adKey];
                 $oAd->pastAdZonePriorityFactor = $result['ads'][$adKey]['priority_factor'];
                 $oAd->pastZoneTrafficFraction = $result['ads'][$adKey]['past_zone_traffic_fraction'];
                 $oZone->addAdvert($oAd);
             }
         }
         $result = $oPriorityCompensation->compensatedPriorities($oZone);
     }
     // Prepare the main graph
     $oCanvas =& Image_Canvas::factory('png', array('width' => 600, 'height' => 600, 'antialias' => false));
     $oGraph =& Image_Graph::factory('graph', $oCanvas);
     if (function_exists('imagettfbbox') && isset($conf['graphs']['ttfName'])) {
         $oFont =& $oGraph->addNew('ttf_font', $conf['graphs']['ttfName']);
         $oFont->setSize(9);
         $oGraph->setFont($oFont);
     }
     $oGraph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Priority Compensation in Fixed Impression Zone: Multi-Ad Complex Scale-Back Test', 12)), Image_Graph::vertical($oPlotarea = Image_Graph::factory('plotarea', array('axis', 'axis')), $oLegend = Image_Graph::factory('legend'), 90), 10));
     $oLegend->setPlotarea($oPlotarea);
     $oPlotareaSecondary =& Image_Graph::factory('plotarea', array('axis', 'axis', IMAGE_GRAPH_AXIS_Y_SECONDARY));
     $oGraph->add($oPlotareaSecondary);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_X);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_Y);
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_X);
     $oAxis->setTitle('Operation Intervals');
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
     $oAxis->setTitle('Impressions', 'vertical');
     $oAxis =& Image_Graph::factory('axis', IMAGE_GRAPH_AXIS_Y_SECONDARY);
     $oPlotarea->add($oAxis);
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY);
     $oAxis->setTitle('Priority Factor', 'vertical2');
     // Ad the data sets to the graph
     foreach ($aAds as $adKey => $aAdData) {
         if ($adKey == 1) {
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_PriorityFactor';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName}, IMAGE_GRAPH_AXIS_Y_SECONDARY);
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', array($aAdData['priorityFactorColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_DeliveredImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', array($aAdData['deliveredColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_AvailableImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dashed', array($aAdData['availableColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_RequiredImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dashed', array($aAdData['requiredColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_RequestedImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dotted', array($aAdData['requestedColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
         }
     }
     $oPlotarea->setFillColor('white');
     $filename = "results/" . __CLASS__ . '_' . __FUNCTION__ . "1.png";
     $oGraph->done(array('filename' => MAX_PATH . '/tests/' . $filename));
     echo '<img src="' . $filename . '" alt=""/>' . "\n";
     // Prepare the priority graph
     $oCanvas =& Image_Canvas::factory('png', array('width' => 600, 'height' => 600, 'antialias' => false));
     $oGraph =& Image_Graph::factory('graph', $oCanvas);
     if (function_exists('imagettfbbox') && isset($conf['graphs']['ttfName'])) {
         $oFont =& $oGraph->addNew('ttf_font', $conf['graphs']['ttfName']);
         $oFont->setSize(9);
         $oGraph->setFont($oFont);
     }
     $oGraph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Priority Compensation in Fixed Impression Zone: Multi-Ad Complex Scale-Back Test', 12)), Image_Graph::vertical($oPlotarea = Image_Graph::factory('plotarea', array('axis', 'axis')), $oLegend = Image_Graph::factory('legend'), 90), 10));
     $oLegend->setPlotarea($oPlotarea);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_X);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_Y);
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_X);
     $oAxis->setTitle('Operation Intervals');
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
     $oAxis->setTitle('Priority', 'vertical');
     // Ad the data sets to the graph
     foreach ($aAds as $adKey => $aAdData) {
         if ($adKey == 1) {
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_Priority';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', array($aAdData['priorityFactorColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
         }
     }
     $oPlotarea->setFillColor('white');
     $filename = "results/" . __CLASS__ . '_' . __FUNCTION__ . "2.png";
     $oGraph->done(array('filename' => MAX_PATH . '/tests/' . $filename));
     echo '<img src="' . $filename . '" alt=""/>' . "\n";
     // Prepare the main graph
     $oCanvas =& Image_Canvas::factory('png', array('width' => 600, 'height' => 600, 'antialias' => false));
     $oGraph =& Image_Graph::factory('graph', $oCanvas);
     if (function_exists('imagettfbbox') && isset($conf['graphs']['ttfName'])) {
         $oFont =& $oGraph->addNew('ttf_font', $conf['graphs']['ttfName']);
         $oFont->setSize(9);
         $oGraph->setFont($oFont);
     }
     $oGraph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Priority Compensation in Fixed Impression Zone: Multi-Ad Complex Scale-Back Test', 12)), Image_Graph::vertical($oPlotarea = Image_Graph::factory('plotarea', array('axis', 'axis')), $oLegend = Image_Graph::factory('legend'), 90), 10));
     $oLegend->setPlotarea($oPlotarea);
     $oPlotareaSecondary =& Image_Graph::factory('plotarea', array('axis', 'axis', IMAGE_GRAPH_AXIS_Y_SECONDARY));
     $oGraph->add($oPlotareaSecondary);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_X);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_Y);
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_X);
     $oAxis->setTitle('Operation Intervals');
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
     $oAxis->setTitle('Impressions', 'vertical');
     $oAxis =& Image_Graph::factory('axis', IMAGE_GRAPH_AXIS_Y_SECONDARY);
     $oPlotarea->add($oAxis);
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY);
     $oAxis->setTitle('Priority Factor', 'vertical2');
     // Ad the data sets to the graph
     foreach ($aAds as $adKey => $aAdData) {
         if ($adKey == 2) {
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_PriorityFactor';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName}, IMAGE_GRAPH_AXIS_Y_SECONDARY);
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', array($aAdData['priorityFactorColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_DeliveredImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', array($aAdData['deliveredColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_AvailableImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dashed', array($aAdData['availableColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_RequiredImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dashed', array($aAdData['requiredColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_RequestedImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dotted', array($aAdData['requestedColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
         }
     }
     $oPlotarea->setFillColor('white');
     $filename = "results/" . __CLASS__ . '_' . __FUNCTION__ . "3.png";
     $oGraph->done(array('filename' => MAX_PATH . '/tests/' . $filename));
     echo '<img src="' . $filename . '" alt=""/>' . "\n";
     // Prepare the priority graph
     $oCanvas =& Image_Canvas::factory('png', array('width' => 600, 'height' => 600, 'antialias' => false));
     $oGraph =& Image_Graph::factory('graph', $oCanvas);
     if (function_exists('imagettfbbox') && isset($conf['graphs']['ttfName'])) {
         $oFont =& $oGraph->addNew('ttf_font', $conf['graphs']['ttfName']);
         $oFont->setSize(9);
         $oGraph->setFont($oFont);
     }
     $oGraph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Priority Compensation in Fixed Impression Zone: Multi-Ad Complex Scale-Back Test', 12)), Image_Graph::vertical($oPlotarea = Image_Graph::factory('plotarea', array('axis', 'axis')), $oLegend = Image_Graph::factory('legend'), 90), 10));
     $oLegend->setPlotarea($oPlotarea);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_X);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_Y);
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_X);
     $oAxis->setTitle('Operation Intervals');
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
     $oAxis->setTitle('Priority', 'vertical');
     // Ad the data sets to the graph
     foreach ($aAds as $adKey => $aAdData) {
         if ($adKey == 2) {
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_Priority';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', array($aAdData['priorityFactorColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
         }
     }
     $oPlotarea->setFillColor('white');
     $filename = "results/" . __CLASS__ . '_' . __FUNCTION__ . "4.png";
     $oGraph->done(array('filename' => MAX_PATH . '/tests/' . $filename));
     echo '<img src="' . $filename . '" alt=""/>' . "\n";
     // Prepare the main graph
     $oCanvas =& Image_Canvas::factory('png', array('width' => 600, 'height' => 600, 'antialias' => false));
     $oGraph =& Image_Graph::factory('graph', $oCanvas);
     if (function_exists('imagettfbbox') && isset($conf['graphs']['ttfName'])) {
         $oFont =& $oGraph->addNew('ttf_font', $conf['graphs']['ttfName']);
         $oFont->setSize(9);
         $oGraph->setFont($oFont);
     }
     $oGraph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Priority Compensation in Fixed Impression Zone: Multi-Ad Complex Scale-Back Test', 12)), Image_Graph::vertical($oPlotarea = Image_Graph::factory('plotarea', array('axis', 'axis')), $oLegend = Image_Graph::factory('legend'), 90), 10));
     $oLegend->setPlotarea($oPlotarea);
     $oPlotareaSecondary =& Image_Graph::factory('plotarea', array('axis', 'axis', IMAGE_GRAPH_AXIS_Y_SECONDARY));
     $oGraph->add($oPlotareaSecondary);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_X);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_Y);
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_X);
     $oAxis->setTitle('Operation Intervals');
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
     $oAxis->setTitle('Impressions', 'vertical');
     $oAxis =& Image_Graph::factory('axis', IMAGE_GRAPH_AXIS_Y_SECONDARY);
     $oPlotarea->add($oAxis);
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY);
     $oAxis->setTitle('Priority Factor', 'vertical2');
     // Ad the data sets to the graph
     foreach ($aAds as $adKey => $aAdData) {
         if ($adKey == 3) {
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_PriorityFactor';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName}, IMAGE_GRAPH_AXIS_Y_SECONDARY);
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', array($aAdData['priorityFactorColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_DeliveredImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', array($aAdData['deliveredColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_AvailableImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dashed', array($aAdData['availableColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_RequiredImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dashed', array($aAdData['requiredColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_RequestedImpressions';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dotted', array($aAdData['requestedColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
         }
     }
     $oPlotarea->setFillColor('white');
     $filename = "results/" . __CLASS__ . '_' . __FUNCTION__ . "5.png";
     $oGraph->done(array('filename' => MAX_PATH . '/tests/' . $filename));
     echo '<img src="' . $filename . '" alt=""/>' . "\n";
     // Prepare the priority graph
     $oCanvas =& Image_Canvas::factory('png', array('width' => 600, 'height' => 600, 'antialias' => false));
     $oGraph =& Image_Graph::factory('graph', $oCanvas);
     if (function_exists('imagettfbbox') && isset($conf['graphs']['ttfName'])) {
         $oFont =& $oGraph->addNew('ttf_font', $conf['graphs']['ttfName']);
         $oFont->setSize(9);
         $oGraph->setFont($oFont);
     }
     $oGraph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Priority Compensation in Fixed Impression Zone: Multi-Ad Complex Scale-Back Test', 12)), Image_Graph::vertical($oPlotarea = Image_Graph::factory('plotarea', array('axis', 'axis')), $oLegend = Image_Graph::factory('legend'), 90), 10));
     $oLegend->setPlotarea($oPlotarea);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_X);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_Y);
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_X);
     $oAxis->setTitle('Operation Intervals');
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
     $oAxis->setTitle('Priority', 'vertical');
     // Ad the data sets to the graph
     foreach ($aAds as $adKey => $aAdData) {
         if ($adKey == 3) {
             $dataSetName = 'oDataSet_Ad_' . $adKey . '_Priority';
             $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
             $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', array($aAdData['priorityFactorColour'], 'transparent'));
             $oPlot->setLineStyle($oLineStyle);
         }
     }
     $oPlotarea->setFillColor('white');
     $filename = "results/" . __CLASS__ . '_' . __FUNCTION__ . "6.png";
     $oGraph->done(array('filename' => MAX_PATH . '/tests/' . $filename));
     echo '<img src="' . $filename . '" alt=""/>' . "\n";
 }
示例#15
0
文件: Charts.php 项目: kduqi/corebos
 /**
  * Creates pie chart image of opportunities by lead_source.
  * param $datax- the sales stage data to display in the x-axis
  * param $datay- the sum of opportunity amounts for each opportunity in each sales stage
  * to display in the y-axis
  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
  * All Rights Reserved..
  * Contributor(s): ______________________________________..
  */
 function pipeline_by_lead_source($legends = array('foo', 'bar'), $user_id = array('1'), $cache_file_name = 'a_file', $refresh = true, $width = 900, $height = 500)
 {
     global $log, $current_user;
     $log->debug("Entering pipeline_by_lead_source(" . $legends . ") method ...");
     global $app_strings, $lang_crm, $current_module_strings, $log, $charset, $tmp_dir;
     global $theme;
     include_once 'Image/Graph.php';
     include_once 'Image/Canvas.php';
     $font = calculate_font_name($lang_crm);
     if (!file_exists($cache_file_name) || !file_exists($cache_file_name . '.map') || $refresh == true) {
         $log =& LoggerManager::getLogger('opportunity charts');
         $log->debug("starting pipeline chart");
         $log->debug("legends is:");
         $log->debug($legends);
         $log->debug("user_id is: ");
         $log->debug($user_id);
         $log->debug("cache_file_name is: {$cache_file_name}");
         //Now do the db queries
         //query for opportunity data that matches $legends and $user
         $where = "";
         //build the where clause for the query that matches $datax
         $count = count($legends);
         if ($count > 0) {
             $where .= " leadsource in ( ";
             $ls_i = 0;
             foreach ($legends as $key => $value) {
                 if ($ls_i != 0) {
                     $where .= ", ";
                 }
                 $where .= "'" . addslashes($key) . "'";
                 $ls_i++;
             }
             $where .= ")";
         }
         $opp = new Potentials();
         $opp_list = $opp->get_full_list("vtiger_potential.amount DESC, vtiger_potential.closingdate DESC", $where);
         //build pipeline by lead source data
         $total = 0;
         $count = array();
         $sum = array();
         if (isset($opp_list)) {
             foreach ($opp_list as $record) {
                 if (!isset($sum[$record->column_fields['leadsource']])) {
                     $sum[$record->column_fields['leadsource']] = 0;
                 }
                 if (isset($record->column_fields['amount']) && isset($record->column_fields['leadsource'])) {
                     // Strip all non numbers from this string.
                     $amount = CurrencyField::convertFromMasterCurrency(preg_replace('/[^0-9]/', '', floor($record->column_fields['amount'])), $current_user->conv_rate);
                     $sum[$record->column_fields['leadsource']] = $sum[$record->column_fields['leadsource']] + $amount / 1000;
                     if (isset($count[$record->column_fields['leadsource']])) {
                         $count[$record->column_fields['leadsource']]++;
                     } else {
                         $count[$record->column_fields['leadsource']] = 1;
                     }
                     $total = $total + $amount / 1000;
                 }
             }
         }
         $visible_legends = array();
         $data = array();
         $aTargets = array();
         $aAlts = array();
         foreach ($legends as $lead_source_key => $lead_source_translation) {
             if (isset($sum[$lead_source_key])) {
                 array_push($data, $sum[$lead_source_key]);
                 if ($lead_source_key != '') {
                     array_push($visible_legends, $lead_source_translation);
                 } else {
                     // put none in if the vtiger_field is blank.
                     array_push($visible_legends, $current_module_strings['NTC_NO_LEGENDS']);
                 }
                 $cvid = getCvIdOfAll("Potentials");
                 array_push($aTargets, "index.php?module=Potentials&action=ListView&leadsource=" . urlencode($lead_source_key) . "&query=true&type=dbrd&viewname=" . $cvid);
                 array_push($aAlts, $count[$lead_source_key] . " " . $current_module_strings['LBL_OPPS_IN_LEAD_SOURCE'] . " {$lead_source_translation}\t");
             }
         }
         $log->debug("sum is:");
         $log->debug($sum);
         $log->debug("count is:");
         $log->debug($count);
         $log->debug("total is: {$total}");
         if ($total == 0) {
             $log->debug("Exiting pipeline_by_lead_source method ...");
             return $current_module_strings['ERR_NO_OPPS'];
         }
         if ($theme == "blue") {
             $font_color = "#212473";
         } else {
             $font_color = "#000000";
         }
         $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true));
         $imagemap = $canvas->getImageMap();
         $graph =& Image_Graph::factory('graph', $canvas);
         $font =& $graph->addNew('font', calculate_font_name($lang_crm));
         // set the font size to 11 pixels
         $font->setSize(8);
         $font->setColor($font_color);
         $graph->setFont($font);
         // create the plotarea layout
         $title =& Image_Graph::factory('title', array('Test', 10));
         $plotarea =& Image_Graph::factory('plotarea', array('category', 'axis'));
         $footer =& Image_Graph::factory('title', array('Footer', 8));
         $graph->add(Image_Graph::vertical($title, Image_Graph::vertical($plotarea, $footer, 90), 5));
         // Generate colours
         $colors = color_generator(count($visible_legends), '#33CCFF', '#3322FF');
         $index = 0;
         $dataset =& Image_Graph::factory('dataset');
         $fills =& Image_Graph::factory('Image_Graph_Fill_Array');
         foreach ($visible_legends as $legend) {
             $dataset->addPoint($legend, $data[$index], array('url' => $aTargets[$index], 'alt' => $aAlts[$index]));
             $fills->addColor($colors[$index]);
             $log->debug('point =' . $legend . ',' . $data[$index]);
             $index++;
         }
         // create the pie chart and associate the filling colours
         $gbplot =& $plotarea->addNew('pie', $dataset);
         $plotarea->hideAxis();
         $gbplot->setFillStyle($fills);
         // Setup title
         $titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'] . $current_user->currency_symbol . $total . $app_strings['LBL_THOUSANDS_SYMBOL'];
         //$titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'].$current_user->currency_symbol.$total;
         $title->setText($titlestr);
         // format the data values
         $valueproc =& Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', $current_user->currency_symbol . "%d");
         // set markers
         $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y);
         $marker->setDataPreprocessor($valueproc);
         $marker->setFillColor('#FFFFFF');
         $marker->setBorderColor($font_color);
         $marker->setFontColor($font_color);
         $marker->setFontSize(8);
         $pointingMarker =& $graph->addNew('Image_Graph_Marker_Pointing_Angular', array(20, &$marker));
         $gbplot->setMarker($pointingMarker);
         // set legend
         $legend_box =& $plotarea->addNew('legend');
         $legend_box->setPadding(array('top' => 20, 'bottom' => 0, 'left' => 0, 'right' => 0));
         $legend_box->setFillColor('#F5F5F5');
         $legend_box->showShadow();
         $subtitle = $current_module_strings['LBL_OPP_SIZE'] . $current_user->currency_symbol . $current_module_strings['LBL_OPP_SIZE_VALUE'];
         $footer->setText($subtitle);
         $footer->setAlignment(IMAGE_GRAPH_ALIGN_TOP_LEFT);
         $imgMap = $graph->done(array('tohtml' => true, 'border' => 0, 'filename' => $cache_file_name, 'filepath' => './', 'urlpath' => ''));
         //$imgMap = htmlspecialchars($output);
         save_image_map($cache_file_name . '.map', $imgMap);
     } else {
         $imgMap_fp = fopen($cache_file_name . '.map', "rb");
         $imgMap = fread($imgMap_fp, filesize($cache_file_name . '.map'));
         fclose($imgMap_fp);
     }
     $fileModTime = filemtime($cache_file_name . '.map');
     $return = "\n{$imgMap}";
     $log->debug("Exiting pipeline_by_lead_source method ...");
     return $return;
 }
/** Function to render the Horizontal Graph
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 */
function vertical_graph($referdata, $refer_code, $width, $height, $left, $right, $top, $bottom, $title, $target_val, $cache_file_name, $html_image_name)
{
    global $log, $root_directory, $lang_crm, $theme, $app_strings;
    //We'll be getting the values in the form of a string separated by commas
    $datay = explode("::", $referdata);
    // The datay values
    $datax = explode("::", $refer_code);
    // The datax values
    // The links values are given as string in the encoded form, here we are decoding it
    $target_val = urldecode($target_val);
    $target = explode("::", $target_val);
    $alts = array();
    $temp = array();
    for ($i = 0; $i < count($datax); $i++) {
        if ($app_strings[$datax[$i]] != '') {
            //HomePage Dashboard Strings i18nized - ahmed
            $name = $app_strings[$datax[$i]];
        } else {
            $name = $datax[$i];
        }
        $pos = substr_count($name, " ");
        $alts[] = htmlentities($name) . "=%d";
        //If the datax value of a string is greater, adding '\n' to it so that it'll cme inh 2nd line
        if (strlen($name) >= 15) {
            $name = substr($name, 0, 15);
        }
        if ($pos >= 2) {
            $val = explode(" ", $name);
            $n = count($val) - 1;
            $x = "";
            for ($j = 0; $j < count($val); $j++) {
                if ($j != $n) {
                    $x .= " " . $val[$j];
                } else {
                    $x .= "@#" . $val[$j];
                }
            }
            $name = $x;
        }
        $name = str_replace("@#", "\n", $name);
        $temp[] = $name;
    }
    $datax = $temp;
    //datay is the values
    //datax is the status
    // Set the basic parameters of the graph
    $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true));
    $imagemap = $canvas->getImageMap();
    $graph =& Image_Graph::factory('graph', $canvas);
    $font =& $graph->addNew('font', calculate_font_name($lang_crm));
    // set the font size to 12
    $font->setSize(8);
    if ($theme == "blue") {
        $font_color = "#212473";
    } else {
        $font_color = "#000000";
    }
    $font->setColor($font_color);
    $graph->setFont($font);
    $titlestr =& Image_Graph::factory('title', array($title, 10));
    $plotarea =& Image_Graph::factory('plotarea', array('axis', 'axis', 'vertical'));
    $graph->add(Image_Graph::vertical($titlestr, $plotarea, 5));
    // Now create a bar plot
    $max = 0;
    $xlabels = array();
    $dataset =& Image_Graph::factory('dataset');
    if ($theme == 'woodspice') {
        $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED, '#804000', 'white'));
    } elseif ($theme == 'bluelagoon') {
        $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED, 'blue', 'white'));
    } elseif ($theme == 'softed') {
        $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED, 'blue', 'white'));
    } else {
        $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED, 'black', 'white'));
    }
    for ($i = 0; $i < count($datay); $i++) {
        $x = 1 + 2 * $i;
        if ($datay[$i] >= $max) {
            $max = $datay[$i];
        }
        $dataset->addPoint($x, $datay[$i], array('url' => $target[$i], 'alt' => $alts[$i]));
        // build the xaxis label array to allow intermediate ticks
        $xlabels[$x] = $datax[$i];
        $xlabels[$x + 1] = '';
    }
    //$bplot = new BarPlot($datay);
    $bplot =& $plotarea->addNew('bar', $dataset);
    $bplot->setFillStyle($fill);
    //You can change the width of the bars if you like
    $bplot->setBarWidth(50 / count($datax), "%");
    $bplot->setPadding(array('top' => 20));
    $bplot->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'white', 'white')));
    // Setup X-axis
    $xaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    $yaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $yaxis->setFontSize(10);
    // set grid
    $gridY =& $plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y);
    $gridY->setLineColor('#FFFFFF@0.5');
    $gridY2 =& $plotarea->addNew('bar_grid', null, IMAGE_GRAPH_AXIS_Y);
    $gridY2->setFillColor('#FFFFFF@0.2');
    // Add some grace to y-axis so the bars doesn't go
    // all the way to the end of the plot area
    if ($max <= 10) {
        $yaxis->forceMaximum(round($max * 1.1 + 1.5));
    } elseif ($max > 10 && $max <= 100) {
        $yaxis->forceMaximum(round($max * 1.1 + 1.5));
    } elseif ($max > 100 && $max <= 1000) {
        $yaxis->forceMaximum(round($max * 1.1 + 10.5));
    } else {
        $yaxis->forceMaximum(round($max * 1.1 + 100.5));
    }
    $ticks = get_tickspacing(round($max * 1.1 + 2.0));
    // First make the labels look right
    $yaxis->setLabelInterval($ticks[0]);
    $yaxis->setTickOptions(5, 0);
    $yaxis->setLabelInterval($ticks[1], 2);
    $yaxis->setTickOptions(2, 0, 2);
    // Create the xaxis labels
    $array_data =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array', array($xlabels));
    // Then fix the tick marks
    $xaxis->setDataPreprocessor($array_data);
    $xaxis->forceMinimum(0);
    $xaxis->forceMaximum(2 * count($datay));
    $xaxis->setFontAngle('vertical');
    $xaxis->setLabelInterval(1);
    $xaxis->setTickOptions(0, 0);
    $xaxis->setLabelInterval(2, 2);
    $xaxis->setTickOptions(5, 0, 2);
    // set markers
    $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y);
    $marker->setFillColor('000000@0.0');
    $marker->setBorderColor('000000@0.0');
    $marker->setFontSize(10);
    // shift markers 10 pix right
    $marker_pointing =& $graph->addNew('Image_Graph_Marker_Pointing', array(0, -10, &$marker));
    $marker_pointing->setLineColor('000000@0.0');
    $bplot->setMarker($marker_pointing);
    //Getting the graph in the form of html page
    $img = $graph->done(array('tohtml' => true, 'border' => 0, 'filename' => $cache_file_name, 'filepath' => '', 'urlpath' => ''));
    save_image_map($cache_file_name . '.map', $img);
    return $img;
}
示例#17
0
 * Usage example for Image_Graph.
 * 
 * Main purpose: 
 * Demonstrate SWF canvas
 * 
 * Other: 
 * None specific
 * 
 * $Id$
 * 
 * @package Image_Graph
 * @author Jesper Veggerby <*****@*****.**>
 */
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
示例#18
0
 public static function getPieChart($xaxisData, $yaxisData, $title = '', $width = '', $height = '', $charttype = 'vertical', $cachedFileName = false, $target = false, $color = '')
 {
     global $log, $lang_crm, $default_charset;
     require_once 'include/utils/utils.php';
     require_once 'include/utils/GraphUtils.php';
     include_once 'Image/Graph.php';
     include_once 'Image/Canvas.php';
     if ($cachedFileName === false) {
         $cache_file_name = 'cache/images/pie_chart_' . time() . '.png';
     } else {
         $cache_file_name = $cachedFileName;
     }
     if (empty($width)) {
         $width = '500';
     }
     if (empty($height)) {
         $height = '400';
     }
     if ($target === false) {
         $target = array();
     }
     $alts = array();
     $temp = array();
     for ($i = 0; $i < count($xaxisData); $i++) {
         $name = html_entity_decode($xaxisData[$i], ENT_QUOTES, $default_charset);
         $pos = substr_count($name, " ");
         $alts[] = $name;
         //If the datax value of a string is greater, adding '\n' to it so that it'll come in 2nd line
         if (strlen($name) >= 14) {
             $name = substr($name, 0, 34);
         }
         if ($pos >= 2) {
             $val = explode(" ", $name);
             $n = count($val) - 1;
             $x = "";
             for ($j = 0; $j < count($val); $j++) {
                 if ($j != $n) {
                     $x .= " " . $val[$j];
                 } else {
                     $x .= "@#" . $val[$j];
                 }
             }
             $name = $x;
         }
         $name = str_replace("@#", "\n", $name);
         $temp[] = $name;
     }
     $xaxisData = $temp;
     $width = $width + $width / 5;
     $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true));
     $imagemap = $canvas->getImageMap();
     $graph =& Image_Graph::factory('graph', $canvas);
     $font =& $graph->addNew('font', calculate_font_name($lang_crm));
     $font->setSize(8);
     $font->setColor($color);
     $graph->setFont($font);
     // create the plotarea layout
     $title =& Image_Graph::factory('title', array($title, 10));
     $plotarea =& Image_Graph::factory('plotarea', array('category', 'axis'));
     $graph->add(Image_Graph::vertical($title, $plotarea, 5));
     // To create unique lables we need to keep track of lable name and its count
     $uniquex = array();
     // Generate colours
     $colors = color_generator(count($yaxisData), '#33DDFF', '#3322FF');
     $dataset =& Image_Graph::factory('dataset');
     $fills =& Image_Graph::factory('Image_Graph_Fill_Array');
     $sum = 0;
     $pcvalues = array();
     for ($i = 0; $i < count($yaxisData); $i++) {
         $sum += $yaxisData[$i];
     }
     for ($i = 0; $i < count($yaxisData); $i++) {
         // To have unique names even in case of duplicates let us add the id
         $datalabel = $xaxisData[$i];
         $xaxisData_appearance = $uniquex[$xaxisData[$i]];
         if ($xaxisData_appearance == null) {
             $uniquex[$xaxisData[$i]] = 1;
         } else {
             $datalabel = $xaxisData[$i] . ' [' . $xaxisData_appearance . ']';
             $uniquex[$xaxisData[$i]] = $xaxisData_appearance + 1;
         }
         $dataset->addPoint($datalabel, $yaxisData[$i], array('url' => $target[$i], 'alt' => $alts[$i] . '=' . sprintf('%0.1f%%', 100 * $yaxisData[$i] / $sum)));
         $pcvalues[$yaxisData[$i]] = sprintf('%0.1f%%', 100 * $yaxisData[$i] / $sum);
         $fills->addColor($colors[$i]);
     }
     if ($sum == 0) {
         return null;
     }
     // create the pie chart and associate the filling colours
     $gbplot =& $plotarea->addNew('pie', $dataset);
     $plotarea->setPadding(array('top' => 0, 'bottom' => 0, 'left' => 0, 'right' => $width / 20));
     $plotarea->hideAxis();
     $gbplot->setFillStyle($fills);
     // format the data values
     $marker_array =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array', array($pcvalues));
     // set markers
     $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y);
     $marker->setDataPreprocessor($marker_array);
     $marker->setFillColor('#FFFFFF');
     $marker->setBorderColor($color);
     $marker->setFontColor($color);
     $marker->setFontSize(8);
     $pointingMarker =& $graph->addNew('Image_Graph_Marker_Pointing_Angular', array(20, &$marker));
     $gbplot->setMarker($pointingMarker);
     $legend_box =& $plotarea->addNew('legend');
     $legend_box->setPadding(array('top' => 20, 'bottom' => 0, 'left' => 0, 'right' => 0));
     $legend_box->setFillColor('#F5F5F5');
     $legend_box->showShadow();
     $img = $graph->done(array('tohtml' => true, 'border' => 0, 'filename' => $cache_file_name, 'filepath' => '', 'urlpath' => ''));
     return $img;
 }
示例#19
0
 /**
  * Get a canvas specific HTML tag.
  *
  * This method implicitly saves the canvas to the filename in the
  * filesystem path specified and parses it as URL specified by URL path
  *
  * Parameter array:
  * 'filename': string
  * 'filepath': string Path to the file on the file system. Remember the final slash
  * 'urlpath': string Path to the file available through an URL. Remember the final slash
  * 'width': int The width in pixels
  * 'height': int The height in pixels
  */
 function toHtml($params)
 {
     parent::toHtml($params);
     return '<embed src="' . $params['urlpath'] . $params['filename'] . '" width=' . $params['width'] . ' height=' . $params['height'] . ' type="image/svg+xml">';
 }
示例#20
0
文件: SWF.php 项目: roojs/pear
 /**
  * Get an SWF specific HTML tag
  *
  * This method implicitly saves the canvas to the filename in the
  * filesystem path specified and parses it as URL specified by URL path
  *
  * Parameter array:
  * 'filename' : string
  * 'filepath' : string Path to the file on the file system. Remember the final slash
  * 'urlpath'  : string Path to the file available through an URL. Remember the final slash
  * 'width'    : int The width in pixels
  * 'height'   : int The height in pixels
  * 'quality'  : Flash quality
  * 'scale'    : Scale
  * 'menu'     : Whether to display the Flash menu on mouse right-click
  *
  * @param array $params Parameter array
  *
  * @return string HTML-output
  */
 function toHtml($params)
 {
     parent::toHtml($params);
     return '<object data="' . $params['urlpath'] . $params['filename'] . '" type="application/x-shockwave-flash" width="' . $params['width'] . '" height="' . $params['height'] . '">
                 <param name="movie" value="' . $params['urlpath'] . $params['filename'] . '">
                 <param name="quality" value="' . $params['quality'] . '">
                 <param name="scale" value="' . $params['scale'] . '">
                 <param name="menu" value="' . $params['menu'] . '">
             </object>';
 }
示例#21
0
 * 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 <*****@*****.**>
 * @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));
示例#22
0
 function display($grouping_criteria = Null, $grouping_aggregate = Null, &$formatter)
 {
     $this->formatter =& $formatter;
     $this->formatter->setLevel($this);
     $this->grouping_criteria = $grouping_criteria;
     $this->grouping_aggregate = $grouping_aggregate;
     $this->group_level = false;
     if (count($this->lev_items) > 0) {
         $this->group_level = true;
     }
     set_include_path(get_include_path() . PATH_SEPARATOR . PATH_INCLUDES . "pear");
     include_once 'Image/Graph.php';
     include_once 'Image/Canvas.php';
     $this->canvas =& Image_Canvas::factory('png', array('width' => $this->lev_setting["width"], 'height' => $this->lev_setting["height"], 'antialias' => 'native'));
     $this->graph =& Image_Graph::factory('graph', $this->canvas);
     $this->plotarea =& $this->graph->addNew('plotarea', array('Image_Graph_Axis_Category', 'Image_Graph_Axis', $this->lev_setting['direction']));
     $this->plotarea->setFillColor('black@0.1');
     #$this->plotarea->showShadow();
     $AxisX =& $this->plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
     $AxisY =& $this->plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
     $AxisX->setFontAngle($this->lev_setting["x_label_angle"]);
     $AxisY->setFontAngle($this->lev_setting["y_label_angle"]);
     foreach ($this->dataset as $dset) {
         $SQL_criteria = '';
         if ($dset['SQL_criteria'] != '') {
             $SQL_criteria = $this->addToFilter($SQL_criteria, $dset['SQL_criteria']);
         }
         #echo "C1: ".$SQL_criteria."<BR>";
         if ($this->lev_setting['SQL_criteria'] != '') {
             $SQL_criteria = $this->addToFilter($SQL_criteria, $this->lev_setting['SQL_criteria']);
         }
         #echo "C2: ".$SQL_criteria."<BR>";
         if (count($this->grouping_criteria) > 0) {
             foreach ($this->grouping_criteria as $key => $value) {
                 $SQL_criteria = $this->addToFilter($SQL_criteria, "{$key} = {$value}", $this->grouping_aggregate[$key]);
             }
         }
         #echo "C3: ".$SQL_criteria."<BR>";
         $this->SQL_filtered = $this->shuffleSQL($dset["SQL_select"] . $SQL_criteria . " " . $dset["SQL_order"]);
         if (defined('REPORT_DEBUG')) {
             echo "<br>The SQL_filtered is: " . $this->SQL_filtered . "<br>";
         }
         $db =& DB();
         $result = $db->Execute($this->SQL_filtered);
         if (!$result) {
             echo "SQL: " . $this->SQL_filtered . "<br>" . $db->ErrorMsg();
             exit;
         }
         $num_rows = $result->RecordCount();
         if ($num_rows == 0) {
             return;
         }
         $Dataset =& Image_Graph::factory('dataset');
         while (!$result->EOF) {
             $Dataset->addPoint($result->fields[0], $result->fields[1]);
             $result->MoveNext();
         }
         $Plot =& $this->plotarea->addNew($this->lev_setting["type"], &$Dataset);
     }
     $file = tempnam($this->formatter->output_path . "/", "s");
     @unlink($file);
     $file .= ".png";
     $this->graph->done(array('filename' => $file));
     # add to output
     $this->formatter->insertImage($file, $this->lev_setting["width"], $this->lev_setting["height"]);
     #intersperse and whatnot
     if ($this->group_level === true) {
         $this->formatter->endTable();
     }
     if ($this->group_level === true) {
         $this->intersperse($this->grouping_criteria, $this->grouping_aggregate);
     }
 }
示例#23
0
 /**
  * Get a canvas specific HTML tag.
  * 
  * This method implicitly saves the canvas to the filename in the 
  * filesystem path specified and parses it as URL specified by URL path
  * 
  * Parameter array:
  * 'filename': string
  * 'filepath': string Path to the file on the file system. Remember the final slash
  * 'urlpath': string Path to the file available through an URL. Remember the final slash
  * 'title': string The url title
  */
 function toHtml($params)
 {
     parent::toHtml($params);
     return '<a href="' . $params['urlpath'] . $params['filename'] . '">' . $params['title'] . '</a>';
 }
示例#24
0
 public function createImage($x, $y)
 {
     $this->_image = Image_Canvas::factory($this->_type, array('width' => $x, 'height' => $y, 'antialias' => 'driver'));
 }
示例#25
0
/** Function to render the Horizontal Graph */
function pie_chart($referdata, $refer_code, $width, $height, $left, $right, $top, $bottom, $title, $target_val, $cache_file_name, $html_image_name)
{
    global $log, $root_directory, $lang_crm, $theme;
    //We'll be getting the values in the form of a string separated by commas
    $datay = explode("::", $referdata);
    // The datay values
    $datax = explode("::", $refer_code);
    // The datax values
    $target_val = urldecode($target_val);
    $target = explode("::", $target_val);
    $alts = array();
    $temp = array();
    for ($i = 0; $i < count($datax); $i++) {
        $name = $datax[$i];
        $pos = substr_count($name, " ");
        $alts[] = htmlentities($name) . "=%d";
        //If the datax value of a string is greater, adding '\n' to it so that it'll come in 2nd line
        if (strlen($name) >= 14) {
            $name = substr($name, 0, 34);
        }
        if ($pos >= 2) {
            $val = explode(" ", $name);
            $n = count($val) - 1;
            $x = "";
            for ($j = 0; $j < count($val); $j++) {
                if ($j != $n) {
                    $x .= " " . $val[$j];
                } else {
                    $x .= "@#" . $val[$j];
                }
            }
            $name = $x;
        }
        $name = str_replace("@#", "\n", $name);
        $temp[] = $name;
    }
    $datax = $temp;
    if ($theme == "blue") {
        $font_color = "#212473";
    } else {
        $font_color = "#000000";
    }
    $width = $width + 140;
    $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true));
    $imagemap = $canvas->getImageMap();
    $graph =& Image_Graph::factory('graph', $canvas);
    $font =& $graph->addNew('font', calculate_font_name($lang_crm));
    // set the font size to 11 pixels
    $font->setSize(8);
    $font->setColor($font_color);
    $graph->setFont($font);
    // create the plotarea layout
    $title =& Image_Graph::factory('title', array($title, 10));
    $plotarea =& Image_Graph::factory('plotarea', array('category', 'axis'));
    $footer =& Image_Graph::factory('title', array('Footer', 8));
    $legend_box =& Image_Graph::factory('legend');
    $graph->add(Image_Graph::vertical($title, $plotarea, 5));
    // To create unique lables we need to keep track of lable name and its count
    $uniquex = array();
    // Generate colours
    $colors = color_generator(count($datay), '#33DDFF', '#3322FF');
    $dataset =& Image_Graph::factory('dataset');
    $fills =& Image_Graph::factory('Image_Graph_Fill_Array');
    $sum = 0;
    for ($i = 0; $i < count($datay); $i++) {
        if (isset($_REQUEST['display_view']) && $_REQUEST['display_view'] == 'MATRIX') {
            $datax[$i] = trim($datax[$i]);
            if (strlen($datax[$i]) <= 10) {
                $datax[$i] = $datax[$i];
            } else {
                $datax[$i] = substr($datax[$i], 0, 10) . "..";
            }
        }
        // To have unique names even in case of duplicates let us add the id
        $datalabel = $datax[$i];
        $datax_appearance = $uniquex[$datax[$i]];
        if ($datax_appearance == null) {
            $uniquex[$datax[$i]] = 1;
        } else {
            $datalabel = $datax[$i] . ' [' . $datax_appearance . ']';
            $uniquex[$datax[$i]] = $datax_appearance + 1;
        }
        $dataset->addPoint($datalabel, $datay[$i], array('url' => $target[$i], 'alt' => $alts[$i]));
        $sum += $datay[$i];
        $fills->addColor($colors[$i]);
    }
    // create an array with % values
    $pcvalues = array();
    for ($i = 0; $i < count($datay); $i++) {
        $pcvalues[$datay[$i]] = sprintf('%0.1f%%', 100 * $datay[$i] / $sum);
    }
    // create the pie chart and associate the filling colours
    $gbplot =& $plotarea->addNew('pie', $dataset);
    $plotarea->setPadding(array('top' => 20, 'bottom' => 0, 'left' => 0, 'right' => 50));
    $plotarea->hideAxis();
    $gbplot->setFillStyle($fills);
    // format the data values
    $marker_array =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array', array($pcvalues));
    // set markers
    $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y);
    $marker->setDataPreprocessor($marker_array);
    $marker->setFillColor('#FFFFFF');
    $marker->setBorderColor($font_color);
    $marker->setFontColor($font_color);
    $marker->setFontSize(8);
    $pointingMarker =& $graph->addNew('Image_Graph_Marker_Pointing_Angular', array(20, &$marker));
    $gbplot->setMarker($pointingMarker);
    // set legend
    $legend_box =& $plotarea->addNew('legend');
    $legend_box->setPadding(array('top' => 20, 'bottom' => 0, 'left' => 0, 'right' => 0));
    $legend_box->setFillColor('#F5F5F5');
    $legend_box->showShadow();
    $img = $graph->done(array('tohtml' => true, 'border' => 0, 'filename' => $cache_file_name, 'filepath' => '', 'urlpath' => ''));
    save_image_map($cache_file_name . '.map', $img);
    return $img;
}
 /**
  * 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);
         }
         $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'];
             $oAd->pastRequiredImpressions = $aAdData['impressions'];
             $oAd->pastRequestedImpressions = $aAdData['impressions'];
             $oAd->pastActualImpressions = $aDelivered[$adKey];
             $oAd->pastAdZonePriorityFactor = $result['ads'][$adKey]['priority_factor'];
             $oAd->pastZoneTrafficFraction = $result['ads'][$adKey]['past_zone_traffic_fraction'];
             $oZone->addAdvert($oAd);
         }
         $result = $oPriorityCompensation->compensatedPriorities($oZone);
     }
     // Prepare the graph
     $oCanvas =& Image_Canvas::factory('png', array('width' => 600, 'height' => 480, 'antialias' => false));
     $oGraph =& Image_Graph::factory('graph', $oCanvas);
     if (function_exists('imagettfbbox') && isset($conf['graphs']['ttfName'])) {
         $oFont =& $oGraph->addNew('ttf_font', $conf['graphs']['ttfName']);
         $oFont->setSize(9);
         $oGraph->setFont($oFont);
     }
     $oGraph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Priority Compensation in Fixed Impression Zone', 12)), Image_Graph::vertical($oPlotarea = Image_Graph::factory('plotarea', array('axis', 'axis_log')), $oLegend = Image_Graph::factory('legend'), 80), 10));
     $oLegend->setPlotarea($oPlotarea);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_X);
     $oGridLines =& $oPlotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_Y);
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_X);
     $oAxis->setTitle('Operation Intervals');
     $oAxis =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
     $oAxis->setTitle('Impressions', 'vertical');
     $counter = 1;
     $aAxisLabels = array();
     while ($counter < $maxZoneImpressions) {
         $counter *= 10;
         $aAxisLabels[] = $counter;
     }
     $oAxis->setLabelInterval($aAxisLabels);
     // Ad the data sets to the graph
     foreach ($aAds as $adKey => $aAdData) {
         $dataSetName = 'oDataSet_Ad' . $adKey . '_RequiredImpressions';
         $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
         $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dashed', array($aAdData['colour'], 'transparent'));
         $oPlot->setLineStyle($oLineStyle);
         $dataSetName = 'oDataSet_Ad' . $adKey . '_AvailableImpressions';
         $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
         $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dotted', array($aAdData['colour'], 'transparent'));
         $oPlot->setLineStyle($oLineStyle);
         $dataSetName = 'oDataSet_Ad' . $adKey . '_ActualImpressions';
         $oPlot =& $oPlotarea->addNew('line', ${$dataSetName});
         $oPlot->setLineColor($aAdData['colour']);
     }
     $oPlot =& $oPlotarea->addNew('line', $oDataSetBestError);
     $oLineStyle =& Image_Graph::factory('Image_Graph_Line_Dotted', array('magenta', 'transparent'));
     $oPlot->setLineStyle($oLineStyle);
     $oPlot =& $oPlotarea->addNew('line', $oDataSetTotalError);
     $oPlot->setLineColor('magenta');
     $oPlotarea->setFillColor('white');
     $filename = "results/" . __CLASS__ . '_' . __FUNCTION__ . ".png";
     $oGraph->done(array('filename' => MAX_PATH . '/tests/' . $filename));
     echo '<img src="' . $filename . '" alt="" />' . "\n";
 }
示例#27
0
 /**
  * The final "child" implementation of the parental abstract method,
  * to produce a graph of the data for delivery statistics.
  *
  * @param array $aGraphFilterArray Filter array ...?
  * @return string Complete link ...?
  */
 function showGraph($aGraphFilterArray)
 {
     global $conf, $GraphFile;
     if (!extension_loaded('gd')) {
         // GD isn't enabled in php install
         return 'noGD';
     }
     if (isset($this->aStatsData)) {
         // Put sum_clicks on right axis only when there are
         $aTempGraph = array_flip($aGraphFilterArray);
         if (isset($aTempGraph['sum_clicks']) && !isset($aTempGraph['sum_ctr'])) {
             $aClickKey = $aTempGraph['sum_clicks'];
         } else {
             $aClickKey = false;
         }
         /**
          * stat display fonfiguration array to determine how the data is visually displayed on the graph
          * field line:  if set to Image_Graph_Plot_Bar, then it will display as a Bar. Otherwise it will be a line (can be dotted, dashed or solid)
          * field params: set the color of the line
          * field axis:  determine whether data is connected with left-hand axis (1) or righthand-axis (2)
          */
         $aFieldStyle = array('sum_requests' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#33cc00', 'transpartent'), 'axis' => '1'), 'sum_views' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#006699', 'transparent'), 'axis' => '1'), 'sum_clicks' => array('line' => 'Image_Graph_Plot_Bar', 'params' => array('#333333', 'transparent'), 'axis' => '1', 'background' => 'white@0.3'), 'sum_ctr' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('cadetblue', 'transparent'), 'axis' => '2', 'background' => 'white@0.3'), 'sum_conversions' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#hh00hh', 'transparent'), 'axis' => '1'), 'sum_conversions_pending' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#cccccc', 'transparent'), 'axis' => '1'), 'sum_sr_views' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#0000cc', 'transparent'), 'axis' => '2', 'background' => 'white@0.3'), 'sum_sr_clicks' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#cc0000', 'transparent'), 'axis' => '2', 'background' => 'white@0.3'), 'sum_revenue' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#120024', 'transparent'), 'axis' => '1'), 'sum_cost' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#123456', 'transparent'), 'axis' => '1'), 'sum_bv' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#654321', 'transparent'), 'axis' => '1'), 'sum_revcpc' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#666666', 'transparent'), 'axis' => '1'), 'sum_costcpc' => array('line' => 'Image_Graph_Line_Solid', 'params' => array('#343434', 'transparent'), 'axis' => '1'));
         if ($aClickKey) {
             $aFieldStyle[$aGraphFilterArray[$aClickKey]]['axis'] = '2';
         }
         if (function_exists("imagejpeg")) {
             $imageFormat = 'jpg';
         }
         if (function_exists("imagepng")) {
             $imageFormat = 'png';
         }
         // Create the graph
         $oCanvas =& Image_Canvas::factory($imageFormat, array('width' => 800, 'height' => 400, 'usemap' => true));
         $oImagemap = $oCanvas->getImageMap();
         $oGraph =& Image_Graph::factory('graph', $oCanvas);
         if (function_exists('ImageTTFBBox')) {
             // Add a TrueType font
             $Font =& $oGraph->addNew('ttf_font', 'arial.ttf');
             // Set the font size to 11 pixels
             $Font->setSize(8);
             $Font->setColor('#444444');
             $oGraph->setFont($Font);
         }
         $oPlotarea =& $oGraph->addNew('plotarea');
         // Set gradient background
         $Fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'lightgrey', 'white'));
         $oPlotarea->setFillStyle($Fill);
         // Aet grid for graph
         $Grid =& $oPlotarea->addNew('bar_grid', null, IMAGE_GRAPH_AXIS_Y);
         $Grid->setFillColor('gray@0.2');
         // Creat a fake object to be able to add description to second Y Axis
         $Dataset2 =& Image_Graph::factory('random', array(0, 0, 100));
         $PlotA =& $oPlotarea->addNew('Image_Graph_Plot_Area', $Dataset2, IMAGE_GRAPH_AXIS_Y_SECONDARY);
         $PlotA->setTitle($strStatsArea);
         $AxisY =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
         $AxisY->forceMinimum(0.1);
         $AxisYsecondary =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY);
         $AxisY->setTitle('Value #', 'vertical');
         if ($aClickKey) {
             $AxisYsecondary->setTitle($this->aColumns[$aGraphFilterArray[$aClickKey]], 'vertical2');
             if (count($aTempGraph) < 3) {
                 $AxisY->setTitle($this->aColumns[$aGraphFilterArray[0]], 'vertical');
             }
         } else {
             $AxisYsecondary->setTitle('Value %', 'vertical2');
         }
         foreach ($aGraphFilterArray as $k) {
             $Dataset[$k] =& Image_Graph::factory('dataset');
             foreach ($this->aStatsData as $key => $record) {
                 // Split the date ($key) into days and year, and place the year on the second line
                 $patterns = array('/(19|20)(\\d{2})-(\\d{1,2})-(\\d{1,2})/');
                 $replace = array('\\4-\\3--\\1\\2');
                 $key = preg_replace($patterns, $replace, $key);
                 $key = preg_split('/--/', $key);
                 if ($aFieldStyle[$k]['axis'] == 'X') {
                     $Dataset[$k]->addPoint($key[0] . "\n" . $key[1], $record[$k], IMAGE_GRAPH_AXIS_X);
                 } else {
                     if ($k == 'sum_ctr') {
                         $record[$k] *= 100;
                     }
                     $Dataset[$k]->addPoint($key[0] . "\n" . $key[1], $record[$k], IMAGE_GRAPH_AXIS_Y_SECONDARY);
                 }
                 $Dataset[$k]->setName($this->aColumns[$k]);
             }
             if ($aFieldStyle[$k]['axis'] == '1') {
                 if ($aFieldStyle[$k]['line'] == 'Image_Graph_Plot_Bar') {
                     $Plot[$k] =& $oPlotarea->addNew('bar', array(&$Dataset[$k]));
                     $Plot[$k]->setFillColor($aFieldStyle[$k]['background']);
                     $LineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', $aFieldStyle[$k]['params']);
                     $Plot[$k]->setLineStyle($LineStyle);
                 } else {
                     $Plot[$k] =& $oPlotarea->addNew('smooth_line', array(&$Dataset[$k]));
                     $Plot[$k]->setFillColor($aFieldStyle[$k]['params'][0] . "@0.1");
                     $LineStyle =& Image_Graph::factory($aFieldStyle[$k]['line'], $aFieldStyle[$k]['params']);
                     $Plot[$k]->setLineStyle($LineStyle);
                 }
             } else {
                 $Plot[$k] =& $oPlotarea->addNew('area', array(&$Dataset[$k]), IMAGE_GRAPH_AXIS_Y_SECONDARY);
                 $Plot[$k]->setFillColor($aFieldStyle[$k]['background']);
                 $LineStyle =& Image_Graph::factory('Image_Graph_Line_Solid', $aFieldStyle[$k]['params']);
                 $Plot[$k]->setLineStyle($LineStyle);
                 foreach ($Dataset[$k]->_data as $id => $val) {
                     // To determine the max value of the 2nd y axis
                     if (is_numeric($val['Y']) && (!isset($maxY2val) || $val['Y'] > $maxY2val)) {
                         $maxY2val = $val['Y'];
                     }
                 }
             }
         }
         $maxY2val = $maxY2val + 5;
         $AxisYsecondary->forceMaximum($maxY2val);
         $oLegend =& $oPlotarea->addNew('legend');
         $oLegend->setFillColor('white@0.7');
         $oLegend->setFontSize(8);
         $oLegend->showShadow();
         $AxisX =& $oPlotarea->getAxis(IMAGE_GRAPH_AXIS_X);
         $oGraph->setPadding(10);
         $oGraph->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED, 'white', '#eeeeee')));
         // Output the Graph
         $tmpGraphFile = 'cache_' . md5(microtime() . rand(1, 1000)) . '.jpg';
         $oGraph->done();
         return $oGraph;
     }
 }
示例#28
0
 * 
 * Main purpose: 
 * PDF canvas
 * 
 * Other: 
 * Datapreprocessor, Axis markers
 * 
 * $Id$
 * 
 * @package Image_Graph
 * @author Jesper Veggerby <*****@*****.**>
 */
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);
示例#29
0
文件: png.php 项目: hbustun/agilebill
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
 * This is a visual test case, testing canvas fundamental canvas functionality.
 *
 * PHP versions 4 and 5
 *
 * LICENSE: This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This library is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * 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 <*****@*****.**>
 * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
 * @version    CVS: $Id: png.php,v 1.2 2005/08/03 21:17:48 nosey Exp $
 * @link       http://pear.php.net/pepr/pepr-proposal-show.php?id=212
 */
// SPECIFY HERE WHERE A TRUETYPE FONT CAN BE FOUND
$testFont = 'c:/windows/fonts/Arial.ttf';
require_once 'Image/Canvas.php';
$canvas =& Image_Canvas::factory('png', array('width' => 600, 'height' => 600));
require_once './canvas_body.php';
示例#30
0
 * Usage example for Image_Graph.
 * 
 * Main purpose: 
 * PDF canvas
 * 
 * Other: 
 * Datapreprocessor, Axis markers
 * 
 * $Id$
 * 
 * @package Image_Graph
 * @author Jesper Veggerby <*****@*****.**>
 */
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();