$h = 400; if ($reportChart['type'] == 'BarChart') { $w = $reportChart['subGroups'] > $w / 100 ? $w + ($reportChart['subGroups'] - $w / 100) * 50 : $w; } if ($reportChart['type'] == 'LineChart') { $w = $reportChart['subGroups'] > $w / 100 ? $w + ($reportChart['subGroups'] - $w / 100) * 50 : $w; } if ($reportChart['type'] == 'StackChart') { $w = $reportChart['subGroups'] > $w / 100 ? $w + ($reportChart['subGroups'] - $w / 100) * 50 : $w; } if ($reportChart['type'] == 'HorizontalChart') { $h = $reportChart['subGroups'] > $h / 100 ? $h + ($reportChart['subGroups'] - $h / 100) * 50 : $h; } $chart = new ReportsDashletChart($fileId); $w = $isDashlet ? '100%' : $w . "px"; $html5Chart[] = array("html" => $chart->display("", "", $reportChart['file'], $chartTypeHtml5, "100%", $h), "id" => $fileId, "dimensions" => array("width" => $w, "height" => $h)); echo 'SUGAR.util.doWhen("((SUGAR && SUGAR.mySugar && SUGAR.mySugar.sugarCharts) || SUGAR.loadChart || document.getElementById(\'showHideChartButton\') != null) && typeof(loadSugarChart) != undefined", function() { var css = new Array(); var chartConfig = new Array(); css["gridLineColor"] = "#cccccc"; css["font-family"] = "Arial"; css["color"] = "#000000"; ' . $chartOrientation . ' chartConfig["' . $chartParamType . '"] = "' . $chartComplex . '"; chartConfig["tip"] = "name"; chartConfig["chartType"] = "' . $chartType . '"; chartConfig["imageExportType"] = "png"; loadCustomChartForReports = function(){ loadSugarChart("' . $fileId . '","' . $tmpFilesDir . $fileId . '.js",css,chartConfig); };
public static function getCrmChartHtml($reportId, $chartEngine, $returnData, $urlChart, $chartInfo, $current_language, $theme, $isStoredReport, $isDashlet) { global $sugar_config; $fixedReportId = str_replace("-", "", $reportId); $asolReportsResizableNVD3Charts = isset($sugar_config['asolReportsResizableNVD3Charts']) && $sugar_config['asolReportsResizableNVD3Charts']; $tmpFilesDir = "modules/asol_Reports/tmpReportFiles/"; if ($isStoredReport && $returnData) { $tmpFilesDir .= 'storedReports/'; } $chartHtml = ""; if ($chartEngine == "flash") { //FLASH foreach ($urlChart as $key => $value) { $chartHtml .= ' var chartSubGroupsValues = document.getElementById("chartSubGroupsValues").value; var groupsCountValues = chartSubGroupsValues.split(","); var flashvars = {}; flashvars.inputFile = "' . $value . '"; flashvars.swfLocation = "include/SugarCharts/swf/"; '; if (file_exists("themes/default/images/sugarColors.xml")) { $chartHtml .= 'flashvars.inputColorScheme = "themes/default/images/sugarColors.xml";'; } else { $chartHtml .= 'flashvars.inputColorScheme = "themes/' . $theme . '/images/sugarColors.xml";'; } $chartHtml .= 'flashvars.c = "1";'; if (file_exists("cache/themes/Sugar/css/chart.css")) { $chartHtml .= 'flashvars.inputStyleSheet = "themes/default/css/chart.css";'; } else { $chartHtml .= 'flashvars.inputStyleSheet = "themes/' . $theme . '/css/chart.css";'; } $chartHtml .= 'flashvars.inputLanguage = "modules/asol_Reports/language/chart_strings.' . $current_language . '.lang.xml";'; $chartHtml .= 'var defaultWidth = 600;'; $chartHtml .= 'var defaultHeight = 450;'; if ($isDashlet) { $chartHtml .= 'defaultWidth = "100%";'; } else { if ($chartInfo[$key]['type'] == 'bar') { $chartHtml .= 'defaultWidth = (groupsCountValues[' . $key . '] > defaultWidth/100) ? defaultWidth + ((( groupsCountValues[' . $key . '] ) -(defaultWidth/100))*65) : defaultWidth;'; } if ($chartInfo[$key]['type'] == 'line') { $chartHtml .= 'defaultWidth = (groupsCountValues[' . $key . '] > defaultWidth/100) ? defaultWidth + ((( groupsCountValues[' . $key . '] ) -(defaultWidth/100))*85) : defaultWidth;'; } if ($chartInfo[$key]['type'] == 'stack') { $chartHtml .= 'defaultWidth = (groupsCountValues[' . $key . '] > defaultWidth/100) ? defaultWidth + ((( groupsCountValues[' . $key . '] ) -(defaultWidth/100))*85) : defaultWidth;'; } if ($chartInfo[$key]['type'] == 'horizontal') { $chartHtml .= 'defaultHeight = (groupsCountValues[' . $key . '] > defaultHeight/100) ? defaultHeight + ((( groupsCountValues[' . $key . '] ) -(defaultHeight/100))*25) : defaultHeight;'; } } $chartHtml .= 'flashvars.myWidth = defaultWidth;'; $chartHtml .= 'flashvars.myHeight = defaultHeight;'; $chartHtml .= ' var params = {}; params.quality = "high"; params.wmode = "transparent"; params.menu = "false"; params.allowscriptaccess = "always"; var attributes = {}; '; $chartHtml .= 'swfobject.embedSWF("include/SugarCharts/swf/ASOLchart.swf", "ASOLflash_' . $fixedReportId . '_' . $key . '", defaultWidth, defaultHeight, "10.0.0", "", flashvars, params, attributes);'; } $chartArray = array("chartHtml" => $chartHtml); } else { if ($chartEngine == "html5") { //HTML5 $html5Chart = array(); foreach ($urlChart as $key => $value) { $fileIdArray = explode("/", $value); $fileIdArray2 = explode(".", $fileIdArray[count($fileIdArray) - 1]); $fileId = $fileIdArray2[0]; $chartType = $chartInfo[$key]['type'] == 'PieChart' ? "pieChart" : "barChart"; $chartParamType = $chartInfo[$key]['type'] == 'PieChart' ? "pieType" : "barType"; $chartComplex = in_array($chartInfo[$key]['type'], array('StackChart', 'HorizontalChart', 'LineChart')) ? "stacked" : "basic"; if ($chartInfo[$key]['type'] == 'HorizontalChart') { $chartOrientation = 'chartConfig["orientation"] = "horizontal";'; } else { if ($chartInfo[$key]['type'] == 'StackChart') { $chartOrientation = 'chartConfig["orientation"] = "vertical";'; } else { $chartOrientation = ''; } } if ($returnData) { if ($chartInfo[$key]['type'] == 'PieChart') { $chartTypeHtml5 = "pie chart"; } if ($chartInfo[$key]['type'] == 'BarChart') { $chartTypeHtml5 = "bar chart"; } if ($chartInfo[$key]['type'] == 'StackChart') { $chartTypeHtml5 = "stacked group by chart"; } if ($chartInfo[$key]['type'] == 'HorizontalChart') { $chartTypeHtml5 = "horizontal group by chart"; } if ($chartInfo[$key]['type'] == 'LineChart') { $chartTypeHtml5 = "line chart"; } if ($chartInfo[$key]['type'] == 'FunnelChart') { $chartTypeHtml5 = "funnel chart 3D"; } $chart = new ReportsDashletChart($fileId); $w = 600; $h = 400; if ($isDashlet) { $w = '100%'; } else { if ($chartInfo[$key]['type'] == 'BarChart') { $w = $chartInfo[$key]['subgroups'] > $w / 100 ? $w + ($chartInfo[$key]['subgroups'] - $w / 100) * 50 : $w; } if ($chartInfo[$key]['type'] == 'LineChart') { $w = $chartInfo[$key]['subgroups'] > $w / 100 ? $w + ($chartInfo[$key]['subgroups'] - $w / 100) * 50 : $w; } if ($chartInfo[$key]['type'] == 'StackChart') { $w = $chartInfo[$key]['subgroups'] > $w / 100 ? $w + ($chartInfo[$key]['subgroups'] - $w / 100) * 50 : $w; } if ($chartInfo[$key]['type'] == 'HorizontalChart') { $h = $chartInfo[$key]['subgroups'] > $h / 100 ? $h + ($chartInfo[$key]['subgroups'] - $h / 100) * 50 : $h; } $w .= 'px'; } $html5Chart[] = array("html" => $chart->display("", "", $value, $chartTypeHtml5, "100%", $h), "id" => $fileId, "dimensions" => array("width" => $w, "height" => $h)); } $chartHtml .= ' function generateHtml5Chart_' . $fixedReportId . '_' . $key . '() { var css = new Array(); var chartConfig = new Array(); css["gridLineColor"] = "#cccccc"; css["font-family"] = "Arial"; css["color"] = "#000000"; ' . $chartOrientation . ' chartConfig["' . $chartParamType . '"] = "' . $chartComplex . '"; chartConfig["tip"] = "name"; chartConfig["chartType"] = "' . $chartType . '"; chartConfig["imageExportType"] = "png"; loadCustomChartForReports = function(){ loadSugarChart("' . $fileId . '","' . $tmpFilesDir . $fileId . '.js",css,chartConfig); }; loadCustomChartForReports(); } if(typeof window.SUGAR.util.doWhen == \'function\') { SUGAR.util.doWhen("((SUGAR && SUGAR.mySugar && SUGAR.mySugar.sugarCharts) || SUGAR.loadChart || document.getElementById(\'showHideChartButton\') != null) && typeof(loadSugarChart) != undefined", function(){ generateHtml5Chart_' . $fixedReportId . '_' . $key . '(); } ); } else { $(document).ready(function() { generateHtml5Chart_' . $fixedReportId . '_' . $key . '(); }); }'; } $chartArray = array("chartHtml" => $chartHtml, "returnedCharts" => $html5Chart); } else { if ($chartEngine == "nvd3") { //NVD3 $nvd3Chart = array(); foreach ($urlChart as $key => $value) { if ($returnData) { $w = 600; $h = 400; if ($isDashlet) { $w = '100%'; } else { if (in_array($chartInfo[$key]['type'], array('BarChart', 'LineChart', 'ScatterChart', 'StackChart', 'AreaChart', 'BubbleChart'))) { $w = $chartInfo[$key]['subgroups'] > $w / 100 ? $w + ($chartInfo[$key]['subgroups'] - $w / 100) * 25 : $w; } if ($chartInfo[$key]['type'] == 'HorizontalChart') { $h = $chartInfo[$key]['subgroups'] > $h / 100 ? $h + ($chartInfo[$key]['subgroups'] - $h / 100) * 20 : $h; } $w .= 'px'; } $nvd3Chart[] = array("html" => "<h4 id='ASOLnvd3Title_" . $fixedReportId . "_" . $key . "'></h4>", "dimensions" => array("width" => $w, "height" => $h)); } $chartHtml .= ' function generateNvd3Chart_' . $fixedReportId . '_' . $key . '() { ' . file_get_contents($value) . ' } try { if(typeof window.SUGAR.util.doWhen == \'function\') { SUGAR.util.doWhen(function(){ return (typeof $ != \'undefined\')}, function(){ generateNvd3Chart_' . $fixedReportId . '_' . $key . '(); }); } else { $(document).ready(function() { generateNvd3Chart_' . $fixedReportId . '_' . $key . '(); }); }'; if (!$isDashlet && $asolReportsResizableNVD3Charts) { $chartHtml .= '$("#ASOLnvd3_' . $fixedReportId . '_' . $key . '").resizable({ alsoResize: "#ASOLsvg_' . $fixedReportId . '_' . $key . '" });'; } $chartHtml .= ' } catch(err) { console.log("Cannot Load AlineaSolReport [' . $reportId . ']"); } '; } $chartArray = array("chartHtml" => $chartHtml, "returnedCharts" => $nvd3Chart); } } } return $chartArray; }