[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/modules/Dashboard/ -> vertical_bargraph.php (source)

   1  <?php
   2  
   3  /*********************************************************************************
   4  ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
   5   * ("License"); You may not use this file except in compliance with the License
   6   * The Original Code is:  vtiger CRM Open Source
   7   * The Initial Developer of the Original Code is vtiger.
   8   * Portions created by vtiger are Copyright (C) vtiger.
   9   * All Rights Reserved.
  10  *
  11   ********************************************************************************/
  12  
  13  require_once ('config.php');
  14  require_once ('include/utils/GraphUtils.php');
  15  include_once  ('Image/Graph.php');
  16  include_once  ('Image/Canvas.php');
  17  
  18  //$tmp_dir=$root_directory."cache/images/";
  19  
  20  /** Function to render the Horizontal Graph
  21          * Portions created by vtiger are Copyright (C) vtiger.
  22          * All Rights Reserved.
  23          * Contributor(s): ______________________________________..
  24   */
  25  function vertical_graph($referdata,$refer_code,$width,$height,$left,$right,$top,$bottom,$title,$target_val,$cache_file_name,$html_image_name)
  26  {
  27  
  28      global $log,$root_directory,$lang_crm,$theme,$app_strings;
  29  //We'll be getting the values in the form of a string separated by commas
  30      $datay=explode("::",$referdata); // The datay values  
  31      $datax=explode("::",$refer_code); // The datax values  
  32  
  33  // The links values are given as string in the encoded form, here we are decoding it
  34      $target_val=urldecode($target_val);
  35      $target=explode("::",$target_val);
  36  
  37      $alts=array();
  38      $temp=array();
  39      for($i=0;$i<count($datax);$i++)
  40      {
  41          if($app_strings[$datax[$i]] != '') //HomePage Dashboard Strings i18nized - ahmed
  42              $name=$app_strings[$datax[$i]];
  43          else
  44              $name=$datax[$i];
  45          $pos = substr_count($name," ");
  46          $alts[]=$name."=%d";
  47  //If the daatx value of a string is greater, adding '\n' to it so that it'll cme inh 2nd line
  48           if(strlen($name)>=15)
  49                          $name=substr($name, 0, 15);
  50          if($pos>=2)
  51          {
  52              $val=explode(" ",$name);
  53              $n=count($val)-1;
  54  
  55              $x="";
  56              for($j=0;$j<count($val);$j++)
  57              {
  58                  if($j != $n)
  59                  {
  60                      $x  .=" ". $val[$j];
  61                  }
  62                  else
  63                  {
  64                      $x .= "@#".$val[$j];
  65                  }
  66              }
  67              $name = $x;
  68          }
  69          $name=str_replace("@#", "\n",$name);
  70          $temp[]=$name; 
  71      }
  72      $datax=$temp;
  73  
  74      //datay is the values
  75      //datax is the status
  76  
  77      // Set the basic parameters of the graph
  78      $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true));
  79      $imagemap = $canvas->getImageMap();
  80      $graph =& Image_Graph::factory('graph', $canvas);
  81      $font =& $graph->addNew('font', calculate_font_name($lang_crm));
  82      // set the font size to 12
  83      $font->setSize(8);
  84  
  85      if($theme == "blue")
  86      {
  87          $font_color = "#212473";
  88      }
  89      else
  90      {
  91          $font_color = "#000000";
  92      }
  93      $font->setColor($font_color);
  94          
  95      $graph->setFont($font);
  96      $titlestr =& Image_Graph::factory('title', array($title,10));
  97         $plotarea =& Image_Graph::factory('plotarea',array(
  98                  'axis',
  99                  'axis',
 100                  'vertical'
 101                  ));
 102      $graph->add(
 103          Image_Graph::vertical($titlestr,
 104              $plotarea,
 105          5
 106           )
 107      );   
 108  
 109  
 110      // Now create a bar plot
 111      $max=0;
 112      $xlabels = array();
 113      $dataset = & Image_Graph::factory('dataset');
 114      $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED, 'blue', 'white'));
 115      for($i=0;$i<count($datay); $i++)
 116      {
 117          $x=1+2*$i;
 118          if($datay[$i]>=$max) $max=$datay[$i];
 119          $dataset->addPoint(
 120                      $x,
 121                      $datay[$i],
 122                      array(
 123                          'url' => $target[$i],
 124                          'alt' => $alts[$i]
 125                      )
 126          );
 127          // build the xaxis label array to allow intermediate ticks
 128          $xlabels[$x] = $datax[$i];
 129          $xlabels[$x+1] = '';
 130      }
 131  
 132  
 133      //$bplot = new BarPlot($datay);
 134      $bplot = & $plotarea->addNew('bar', $dataset);
 135      $bplot->setFillStyle($fill);
 136  
 137      //You can change the width of the bars if you like
 138      $bplot->setBarWidth(50/count($datax),"%");
 139      $bplot->setPadding(array('top'=>20));
 140  
 141      $bplot->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'white', '#E5E5E5')));
 142  
 143      // Setup X-axis
 144      $xaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
 145      $yaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
 146      $yaxis->setFontSize(10);
 147              
 148      // set grid
 149      $gridY =& $plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y);
 150      $gridY->setLineColor('#E5E5E5@0.5');
 151      $gridY2 =& $plotarea->addNew('bar_grid', null, IMAGE_GRAPH_AXIS_Y); 
 152      $gridY2->setFillColor('#66CDAA@0.2'); 
 153  
 154  
 155      // Add some grace to y-axis so the bars doesn't go
 156      // all the way to the end of the plot area
 157      $yaxis->forceMaximum(round(($max * 1.1) + 0.5));
 158      $ticks = get_tickspacing($max);
 159  
 160      // First make the labels look right
 161      $yaxis->setLabelInterval($ticks[0]);
 162      $yaxis->setTickOptions(5,0);
 163      $yaxis->setLabelInterval($ticks[1],2);
 164      $yaxis->setTickOptions(2,0,2);
 165      
 166      // Create the xaxis labels
 167      $array_data =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array', 
 168          array($xlabels) 
 169      ); 
 170  
 171      // Then fix the tick marks
 172      $xaxis->setDataPreprocessor($array_data);
 173      $xaxis->forceMinimum(0);
 174      $xaxis->forceMaximum(2*count($datay));
 175      $xaxis->setFontAngle('vertical');
 176      $xaxis->setLabelInterval(1);
 177      $xaxis->setTickOptions(0,0);
 178      $xaxis->setLabelInterval(2,2);
 179      $xaxis->setTickOptions(5,0,2);
 180              
 181      // set markers
 182      $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y);
 183      $marker->setFillColor('000000@0.0');
 184      $marker->setBorderColor('000000@0.0');
 185      $marker->setFontSize(10);
 186      // shift markers 10 pix right
 187      $marker_pointing =& $graph->addNew('Image_Graph_Marker_Pointing', array(0,-10,& $marker));
 188      $marker_pointing->setLineColor('000000@0.0');
 189      $bplot->setMarker($marker_pointing);
 190  
 191  
 192      //Getting the graph in the form of html page    
 193      $img = $graph->done(
 194                              array(
 195                                      'tohtml' => true,
 196                                      'border' => 0,
 197                                      'filename' => $cache_file_name,
 198                                      'filepath' => '',
 199                                      'urlpath' => ''
 200                                  ));
 201      save_image_map($cache_file_name.'.map', $img);
 202  
 203      return $img;
 204  }
 205  
 206  ?>


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