/** 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; }
public static function getBarChart($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'; $barwidth = '70'; if ($cachedFileName === false) { $cache_file_name = 'cache/images/bar_chart_' . time() . '.png'; } else { $cache_file_name = $cachedFileName; } if (empty($width)) { $width = '400'; } if (empty($height)) { $height = '300'; } if ($target === false) { $target = array(); } if (empty($color)) { $color = 'black'; } $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 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("@#", " ", $name); $temp[] = html_entity_decode($name, ENT_QUOTES, $default_charset); } $xaxisData = $temp; // 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)); $font->setSize(8); $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', $charttype)); $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 ($charttype == 'horizontal') { $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED, $color, 'white')); } else { $fill =& Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED, $color, 'white')); } for ($i = 0; $i < count($yaxisData); $i++) { $x = 1 + $i; if ($yaxisData[$i] >= $max) { $max = $yaxisData[$i]; } $dataset->addPoint($x, $yaxisData[$i], array('url' => $target[$i], 'alt' => $alts[$i] . '=' . $yaxisData[$i])); $xlabels[$x] = $xaxisData[$i]; // To have unique names even in case of duplicates let us add the id $xaxisData_appearance = $uniquex[$xaxisData[$i]]; if ($xaxisData_appearance == null) { $uniquex[$xaxisData[$i]] = 1; } else { $xlabels[$x] = $xaxisData[$i] . ' [' . $xaxisData_appearance . ']'; $uniquex[$xaxisData[$i]] = $xaxisData_appearance + 1; } } $bplot =& $plotarea->addNew('bar', $dataset); $bplot->setFillStyle($fill); //You can change the width of the bars if you like if (!empty($xaxisData)) { $bplot->setBarWidth($barwidth / count($xaxisData), "%"); } //$bplot->setPadding(array('top'=>10)); $bplot->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL, 'white', 'white'))); $xaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X); $yaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $yaxis->setFontSize(8); $xaxis->setFontSize(8); if ($charttype == 'horizontal') { // Invert X-axis and put Y-axis at bottom $xaxis->setInverted(false); $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 if ($charttype == 'horizontal') { $yaxis->setFontAngle('vertical'); } $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.5); $xaxis->forceMaximum(0.5 + count($yaxisData)); if ($charttype == 'vertical') { $xaxis->setFontAngle('vertical'); } $xaxis->setLabelInterval(1); $xaxis->setTickOptions(0, 0); $xaxis->setLabelInterval(2, 2); // set markers if ($width > 400 && $height > 400) { $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y); $marker->setFillColor('000000@0.0'); $marker->setBorderColor('000000@0.0'); $marker->setFontSize(8); // shift markers 20 pix right if ($charttype == 'horizontal') { $marker_pointing =& $graph->addNew('Image_Graph_Marker_Pointing', array(10, 0, &$marker)); } else { $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' => '')); return $img; }
/** * Creates opportunity pipeline image as a horizontal accumlated bar graph for multiple vtiger_users. * param $datax- the sales stage data to display in the x-axis * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. * All Rights Reserved.. * Contributor(s): ______________________________________.. */ function pipeline_by_sales_stage($datax = array('foo', 'bar'), $date_start = '2071-10-15', $date_end = '2071-10-15', $user_id = array('1'), $cache_file_name = 'a_file', $refresh = false, $width = 900, $height = 500) { global $log, $current_user; $log->debug("Entering pipeline_by_sales_stage(" . $datax . "," . $date_start . "," . $date_end . "," . $user_id . "," . $cache_file_name . "," . $refresh . ") method ..."); global $app_strings, $lang_crm, $current_module_strings, $charset, $tmp_dir; global $theme; include_once 'Image/Graph.php'; include_once 'Image/Canvas.php'; $log =& LoggerManager::getLogger('opportunity charts'); // 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); //$log->debug("graph object created"); // add a TrueType font //$font =& $graph->addNew('font', calculate_font_name($lang_crm)); $font =& $graph->addNew('font', calculate_font_name($lang_crm)); // set the font size to 11 pixels $font->setSize(8); $graph->setFont($font); $title =& Image_Graph::factory('title', array('Test', 10)); $plotarea =& Image_Graph::factory('plotarea', array('axis', 'axis', 'horizontal')); $footer =& Image_Graph::factory('title', array('Footer', 8)); $graph->add(Image_Graph::vertical($title, Image_Graph::vertical($plotarea, $footer, 90), 5)); $log->debug("graph object created"); if (!file_exists($cache_file_name) || !file_exists($cache_file_name . '.map') || $refresh == true) { $log->debug("starting pipeline chart"); $log->debug("datax is:"); $log->debug($datax); $log->debug("user_id is: "); $log->debug($user_id); $log->debug("cache_file_name is: {$cache_file_name}"); $where = ""; //build the where clause for the query that matches $datax $count = count($datax); if ($count > 0) { $where .= " sales_stage in ( "; $ss_i = 0; foreach ($datax as $key => $value) { if ($ss_i != 0) { $where .= ", "; } $where .= "'" . addslashes($key) . "'"; $ss_i++; } $where .= ")"; } $date = new DateTimeField($date_start); $endDate = new DateTimeField($date_end); //build the where clause for the query that matches $date_start and $date_end $where .= " AND closingdate >= '{$date_start}' AND closingdate <= '{$date_end}'"; $subtitle = $current_module_strings['LBL_DATE_RANGE'] . " " . $date->getDisplayDate() . " " . $current_module_strings['LBL_DATE_RANGE_TO'] . " " . $endDate->getDisplayDate() . "\n"; //Now do the db queries //query for opportunity data that matches $datax and $user $opp = new Potentials(); $opp_list = $opp->get_full_list("vtiger_potential.amount DESC, vtiger_potential.closingdate DESC", $where); //build pipeline by sales stage data $total = 0; $count = array(); $sum = array(); if (isset($opp_list)) { foreach ($opp_list as $record) { if (!isset($sum[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']])) { $sum[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']] = 0; } if (isset($record->column_fields['amount']) && in_array($record->column_fields['assigned_user_id'], $user_id)) { // 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['sales_stage']][$record->column_fields['assigned_user_id']] = $sum[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']] + $amount; if (isset($count[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']])) { $count[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']]++; } else { $count[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']] = 1; } $total = $total + $amount / 1000; } } } $legend = array(); $datay = array(); $aTargets = array(); $aAlts = array(); foreach ($datax as $stage_key => $stage_translation) { foreach ($user_id as $the_id) { $the_user = getEntityName('Users', $the_id); $the_user = $the_user[$the_id]; if (!isset($datay[$the_id])) { $datay[$the_id] = array(); } if (!isset($aAlts[$the_id])) { $aAlts[$the_id] = array(); } if (!isset($aTargets[$the_id])) { $aTargets[$the_id] = array(); } if (isset($sum[$stage_key][$the_id])) { array_push($datay[$the_id], $sum[$stage_key][$the_id] / 1000); array_push($aAlts[$the_id], $the_user . ' - ' . $count[$stage_key][$the_id] . " " . $current_module_strings['LBL_OPPS_IN_STAGE'] . " {$stage_translation}"); } else { array_push($datay[$the_id], 0); array_push($aAlts[$the_id], ""); } $cvid = getCvIdOfAll("Potentials"); array_push($aTargets[$the_id], "index.php?module=Potentials&action=ListView&sales_stage=" . urlencode($stage_key) . "&closingdate_start=" . urlencode($date_start) . "&closingdate_end=" . urlencode($date_end) . "&query=true&type=dbrd&owner=" . $the_user . "&viewname=" . $cvid); } array_push($legend, $stage_translation); } $log->debug("datay is:"); $log->debug($datay); $log->debug("aAlts is:"); $log->debug($aAlts); $log->debug("aTargets is:"); $log->debug($aTargets); $log->debug("sum is:"); $log->debug($sum); $log->debug("count is:"); $log->debug($count); //now build the bar plots for each user across the sales stages $colors = color_generator(count($user_id), '#D50100', '#002222'); $index = 0; $datasets = array(); $xlabels = array(); $fills =& Image_Graph::factory('Image_Graph_Fill_Array'); foreach ($user_id as $the_id) { // Now create a bar pot $datasets[$index] =& Image_Graph::factory('dataset'); foreach ($datay[$the_id] as $i => $y) { $x = 1 + 2 * $i; $datasets[$index]->addPoint($x, $y, array('url' => $aTargets[$the_id][$i], 'alt' => $aAlts[$the_id][$i])); } // Set fill colors for bars $fills->addColor($colors[$index]); $index++; } for ($i = 0; $i < count($legend); $i++) { $x = 1 + 2 * $i; $xlabels[$x] = $legend[$i]; $xlabels[$x + 1] = ''; } // compute maximum value because of grace jpGraph parameter not supported $maximum = 0; foreach ($legend as $legendidx => $legend_text) { $legendsum = 0; foreach ($user_id as $the_id) { $legendsum += $datay[$the_id][$legendidx]; } if ($legendsum > $maximum) { $maximum = $legendsum; } } // Create the grouped bar plot $gbplot =& $plotarea->addNew('bar', array($datasets, 'stacked')); $gbplot->setFillStyle($fills); //You can change the width of the bars if you like $gbplot->setBarWidth(50 / count($legend), "%"); // Set white margin color $graph->setBackgroundColor('#F5F5F5'); // Use a box around the plot area $gbplot->setBorderColor('black'); // Use a gradient to fill the plot area $gbplot->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL, 'white', '#E5E5E5'))); if ($theme == "blue") { $font_color = "#212473"; } else { $font_color = "#000000"; } $font->setColor($font_color); // 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); // Create the xaxis labels $array_data =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array', array($xlabels)); // Setup X-axis $xaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X); $xaxis->setDataPreprocessor($array_data); $xaxis->forceMinimum(0); $xaxis->forceMaximum(2 * count($legend)); $xaxis->setLabelInterval(1); $xaxis->setTickOptions(0, 0); $xaxis->setLabelInterval(2, 2); $xaxis->setTickOptions(5, 0, 2); $xaxis->setInverted(true); // Setup Y-axis $yaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $yaxis->setFontSize(8); $yaxis->setAxisIntersection('max'); // Add some grace to y-axis so the bars doesn't go // all the way to the end of the plot area $yaxis->forceMaximum($maximum * 1.1); $ticks = get_tickspacing($maximum); // set grid $gridY =& $plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y); $gridY->setLineColor('#E5E5E5@0.5'); // First make the labels look right $valueproc =& Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', $current_user->currency_symbol . "%d"); $yaxis->setDataPreprocessor($valueproc); $yaxis->setLabelInterval($ticks[0]); $yaxis->setTickOptions(-5, 0); $yaxis->setLabelInterval($ticks[1], 2); $yaxis->setTickOptions(-2, 0, 2); // eliminate zero values $gbplot->setDataSelector(Image_Graph::factory('Image_Graph_DataSelector_NoZeros')); // set markers $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y); $marker->setDataPreprocessor($valueproc); $marker->setFillColor('000000@0.0'); $marker->setBorderColor('000000@0.0'); $marker->setFontColor('white'); $marker->setFontSize(8); $gbplot->setMarker($marker); // Finally setup the title $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_RIGHT); // .. and stroke the graph $imgMap = $graph->done(array('tohtml' => true, 'border' => 0, 'filename' => $cache_file_name, 'filepath' => './', 'urlpath' => '')); //$imgMap = $graph->GetHTMLImageMap('pipeline'); 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_sales_stage 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; }