Beispiel #1
-1
 function cartesianChart($type, $x, $y, $w, $h, $imgname = '', $config = array())
 {
     $w -= 4;
     $h -= 4;
     $settings = array('FontName' => 'tahoma.ttf', 'FontSize' => 8, 'LegendFontSize' => 8, 'LegendFontName' => 'tahoma.ttf', 'Logo' => '', 'LogoTransparency' => 20, 'XAxisFormat' => 'number', 'XAxisUnit' => '', 'YAxisFormat' => 'number', 'YAxisUnit' => '', 'XLogo' => 0, 'YLogo' => 0, 'Xlabel' => 'x label', 'XAngle' => 0, 'Ylabel' => 'y label', 'Legend' => '', 'Textbox' => '', 'TextboxFontSize' => 8, 'TextboxFontName' => 'tahoma.ttf', 'ImgR' => 132, 'ImgG' => 173, 'ImgB' => 131, 'Decay' => 80, 'BGR' => 163, 'BGG' => 203, 'BGB' => 167, 'Decay2' => 80, 'Filled' => '', 'DataR' => 191, 'DataG' => 120, 'DataB' => 71, 'LBR' => 226, 'LBG' => 228, 'LBB' => 230, 'LR' => 0, 'LG' => 0, 'LB' => 0);
     // Get the custom settings
     if (is_array($config)) {
         foreach ($config as $key => $val) {
             $settings[$key] = $val;
         }
     }
     $DataSet = new pData();
     $DataSet->AddPoint($y, "Serie1");
     $DataSet->AddPoint($x, "Serie2");
     $DataSet->AddAllSeries();
     $DataSet->RemoveSerie("Serie2");
     $DataSet->SetAbsciseLabelSerie("Serie2");
     $DataSet->SetSerieName($settings['Legend'], "Serie1");
     $DataSet->SetYAxisName($settings['Ylabel']);
     $DataSet->SetXAxisName($settings['Xlabel']);
     $DataSet->SetXAxisFormat($settings['XAxisFormat']);
     if (strlen($settings['XAxisUnit'])) {
         $DataSet->SetXAxisUnit($settings['XAxisUnit']);
     }
     if (strlen($settings['YAxisUnit'])) {
         $DataSet->SetYAxisUnit($settings['YAxisUnit']);
     }
     $DataSet->SetYAxisFormat($settings['YAxisFormat']);
     // Initialise the graph
     $Test = new pChart($w, $h);
     $Test->drawGraphAreaGradient($settings['ImgR'], $settings['ImgG'], $settings['ImgB'], $settings['Decay'], TARGET_BACKGROUND);
     $FontSize = $settings['FontSize'];
     $FontName = $this->_ext_path . "/fonts/" . $settings['FontName'];
     $Test->setFontProperties($FontName, $FontSize);
     //Calc Textbox Height
     if (strlen($settings['Textbox'])) {
         $TextboxFontSize = $settings['TextboxFontSize'];
         $TextboxFontName = $this->_ext_path . "/fonts/" . $settings['TextboxFontName'];
         $Position = imageftbbox($TextboxFontSize, 0, $TextboxFontName, $settings['Textbox']);
         $TextboxHeight = $Position[1] - $Position[7] + 8;
     } else {
         $TextboxHeight = 0;
     }
     // Maximize The graph area
     //on Y axis
     if ($settings['XAxisFormat'] == 'time') {
         $xdata = "99:99:99";
         $Position = imageftbbox($FontSize, 0, $FontName, $xdata);
         $WXmax = $Position[2] - $Position[0];
         $TextHeightX = $Position[1] - $Position[7];
     } elseif ($settings['XAxisFormat'] == 'date') {
         $xdata = "99/99/9999";
         $Position = imageftbbox($FontSize, 0, $FontName, $xdata);
         $WXmax = $Position[2] - $Position[0];
         $TextHeightX = $Position[1] - $Position[7];
     } else {
         $WXmax = 0;
         foreach ($x as $xdata) {
             $xdata .= $settings['XAxisUnit'];
             $Position = imageftbbox($FontSize, 0, $FontName, $xdata);
             $TextWidth = $Position[2] - $Position[0];
             $TextHeightX = $Position[1] - $Position[7];
             $WXmax = $TextWidth > $WXmax ? $TextWidth : $WXmax;
         }
     }
     if ($settings['XAngle'] > 0) {
         $sin = abs(sin(deg2rad($settings['XAngle'])));
         $cos = abs(cos(deg2rad($settings['XAngle'])));
         $HXmax = $WXmax * $sin + $TextHeightX * $cos;
     } else {
         $HXmax = $TextHeightX;
     }
     //on Y axis...
     if ($settings['YAxisFormat'] == 'time') {
         $ydata = "99:99:99";
         $Position = imageftbbox($FontSize, 0, $FontName, $ydata);
         $WYmax = $Position[2] - $Position[0];
         $TextHeightY = $Position[1] - $Position[7];
     } elseif ($settings['YAxisFormat'] == 'date') {
         $ydata = "99/99/9999";
         $Position = imageftbbox($FontSize, 0, $FontName, $ydata);
         $WYmax = $Position[2] - $Position[0];
         $TextHeightY = $Position[1] - $Position[7];
     } else {
         $WYmax = 0;
         foreach ($y as $ydata) {
             $ydata .= $settings['YAxisUnit'];
             //echo $ydata."<br>";
             $Position = imageftbbox($FontSize, 0, $FontName, $ydata);
             $TextWidth = $Position[2] - $Position[0];
             $TextHeightY = $Position[1] - $Position[7];
             $WYmax = $TextWidth > $WYmax ? $TextWidth : $WYmax;
         }
     }
     $Test->setGraphArea($WYmax + $TextHeightY + 35, 20, $w - 25, $h - $HXmax - $TextHeightX - $TextboxHeight - 20);
     //$Test->setGraphArea(60,20,$w-25,($settings['XAngle']==0)?$h-70:$h-100);
     $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALL, 213, 217, 221, TRUE, $settings['XAngle'], 0, TRUE);
     $Test->drawGraphAreaGradient($settings['BGR'], $settings['BGG'], $settings['BGB'], $settings['Decay2']);
     $Test->drawGrid(4, TRUE, 230, 230, 230, 20);
     // This will put the picture "logo.png" with transparency
     if (strlen($settings['Logo'])) {
         $XLogo = $WYmax + $TextHeightY + 35 + $settings['XLogo'];
         $YLogo = 20 + $settings['XLogo'];
         $logo = $settings['Logo'];
         //Fing extension of logo : png,gif or jpg
         if ($this->_findexts($logo) == "png") {
             echo "png!";
             $Test->drawFromPNG($logo, $XLogo, $YLogo, $settings['LogoTransparency']);
         } elseif ($this->_findexts($logo) == "gif") {
             echo "gif!";
             $Test->drawFromGIF($logo, $XLogo, $YLogo, $settings['LogoTransparency']);
         } elseif ($this->_findexts($logo) == "jpg") {
             echo "jpg";
             $Test->drawFromJPG($logo, $XLogo, $YLogo, $settings['LogoTransparency']);
         }
     }
     $Test->setColorPalette(0, $settings['DataR'], $settings['DataG'], $settings['DataB']);
     if ($type == "bar") {
         // Draw the bar chart
         $Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 70);
     } elseif ($type == "line") {
         $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
         $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 0, -1, -1, -1, TRUE);
     } elseif ($type == "cubic") {
         $Test->setShadowProperties(3, 3, 0, 0, 0, 30, 4);
         $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
         $Test->clearShadow();
         if ($settings['Filled'] == 'yes') {
             $Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 30);
         }
         $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 0, -1, -1, -1, TRUE);
     }
     // Draw the textbox
     if (strlen($settings['Textbox'])) {
         $Test->setFontProperties($TextboxFontName, $TextboxFontSize);
         $Test->drawTextBox(0, $h - $TextboxHeight, $w, $h, $settings['Textbox'], 0, 255, 255, 255, ALIGN_CENTER, TRUE, 0, 0, 0, 30);
     }
     // Draw the legend
     if (strlen($settings['Legend'])) {
         $LegendFontSize = $settings['LegendFontSize'];
         $LegendFontName = $this->_ext_path . "/fonts/" . $settings['LegendFontName'];
         $Position = imageftbbox($LegendFontSize, 0, $LegendFontName, $settings['Legend']);
         $LegendW = $Position[2] - $Position[0] + 40;
         $Test->setFontProperties($LegendFontName, $LegendFontSize);
         $Test->drawLegend($w - $LegendW, 10, $DataSet->GetDataDescription(), $settings['LBR'], $settings['LBG'], $settings['LBB'], 52, 58, 82, $settings['LR'], $settings['LG'], $settings['LB'], TRUE);
     }
     // Render the picture
     $Test->addBorder(2);
     if (strlen($imgname)) {
         //custom image name
         $imgname = $this->_img_path . "/" . $imgname;
     } else {
         $this->obj->load->helper('string');
         $imgname = $this->_img_path . "/{$type}-" . random_string('alnum', 16) . ".png";
     }
     $Test->Render($imgname);
     return array("name" => '/' . $imgname, "w" => $w + 4, "h" => $h + 4);
 }