Exemplo n.º 1
7
/**
 * Draws a rectangle on the provided chart
 *
 * @param  pChart   $chart        The chart to draw on
 * @param  int      $x1           Leftmost x value
 * @param  int      $y1           Topmost y value
 * @param  int      $x2           Rightmost x value
 * @param  int      $y2           Topmost y value
 * @param  array    $color_array  The colors to use
 * @param  boolean  $filled       Whether to fill the area
 */
function draw_rectangle(&$chart, $x1, $y1, $x2, $y2, $color_array, $filled = true)
{
    if ($filled) {
        $chart->drawFilledRectangle($x1, $y1, $x2, $y2, $color_array['r'], $color_array['g'], $color_array['b']);
    } else {
        $chart->drawRectangle($x1, $y1, $x2, $y2, $color_array['r'], $color_array['g'], $color_array['b']);
    }
}
/**
 * Генерация графика
 * @param DataSet $DataSet
 * @param String $GraphTitle
 * @param String $safeToFile
 */
function createGraphToFile($DataSet, $GraphTitle, $safeToFile, $scaleFormat)
{
    // Rotrate
    $rotate = 30;
    // Initialise the graph
    $GraphImage = new pChart(594, 344);
    $GraphImage->setDateFormat($scaleFormat);
    // $GraphImage->loadColorPalette(DIR_FONT.'/tones-3.txt');
    $GraphImage->setFontProperties(DIR_FONT . "/segoepr.ttf", 8);
    $GraphImage->setGraphArea(80, 50, 580, 300);
    $GraphImage->drawFilledRectangle(3, 3, 590, 340, 240, 240, 240);
    $GraphImage->drawRectangle(0, 0, 593, 343, 230, 230, 230);
    $GraphImage->drawGraphArea(255, 255, 255, TRUE);
    $GraphImage->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, $rotate, 0, FALSE);
    $GraphImage->drawGrid(4, TRUE, 230, 230, 230, 50);
    // Draw the 0 line
    $GraphImage->setFontProperties(DIR_FONT . "/segoepr.ttf", 6);
    $GraphImage->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
    // Просто пунктирная линия
    // Draw the cubic curve graph
    $GraphImage->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
    // Draw the line graph
    //$GraphImage->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
    $GraphImage->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255);
    // Finish the graph
    $GraphImage->setFontProperties(DIR_FONT . "/segoepr.ttf", 12);
    $GraphImage->drawTitle(60, 32, $GraphTitle, 50, 50, 50, 600);
    //$GraphImage->Render(DIR_CACHE . './' . $safeToFile . '.png');
    $GraphImage->Stroke();
}
Exemplo n.º 3
0
/**
*
*  Generate a chart for a question
*  @param int $iQuestionID      ID of the question
*  @param int $iSurveyID        ID of the survey
*  @param mixed $type           Type of the chart to be created - null produces bar chart, any other value produces pie chart
*  @param array $lbl            An array containing the labels for the chart items
*  @param mixed $gdata          An array containing the percentages for the chart items
*  @param mixed $grawdata       An array containing the raw count for the chart items
*  @param mixed $cache          An object containing [Hashkey] and [CacheFolder]
*  @param string $sQuestionType The question type
*  @return                Name
*/
function createChart($iQuestionID, $iSurveyID, $type = null, $lbl, $gdata, $grawdata, $cache, $oLanguage, $sQuestionType)
{
    /* This is a lazy solution to bug #6389. A better solution would be to find out how
       the "T" gets passed to this function from the statistics.js file in the first place! */
    if (substr($iSurveyID, 0, 1) == "T") {
        $iSurveyID = substr($iSurveyID, 1);
    }
    static $bErrorGenerate = false;
    if ($bErrorGenerate) {
        return false;
    }
    $rootdir = Yii::app()->getConfig("rootdir");
    $homedir = Yii::app()->getConfig("homedir");
    $homeurl = Yii::app()->getConfig("homeurl");
    $admintheme = Yii::app()->getConfig("admintheme");
    $scriptname = Yii::app()->getConfig("scriptname");
    $chartfontfile = Yii::app()->getConfig("chartfontfile");
    $chartfontsize = Yii::app()->getConfig("chartfontsize");
    $alternatechartfontfile = Yii::app()->getConfig("alternatechartfontfile");
    $language = $oLanguage->langcode;
    $cachefilename = "";
    /* Set the fonts for the chart */
    if ($chartfontfile == 'auto') {
        // Tested with ar,be,el,fa,hu,he,is,lt,mt,sr, and en (english)
        // Not working for hi, si, zh, th, ko, ja : see $config['alternatechartfontfile'] to add some specific language font
        $chartfontfile = 'DejaVuSans.ttf';
        if (array_key_exists($language, $alternatechartfontfile)) {
            $neededfontfile = $alternatechartfontfile[$language];
            if (is_file($rootdir . "/fonts/" . $neededfontfile)) {
                $chartfontfile = $neededfontfile;
            } else {
                Yii::app()->setFlashMessage(sprintf(gT('The fonts file %s was not found in <limesurvey root folder>/fonts directory. Please, see the txt file for your language in fonts directory to generate the charts.'), $neededfontfile), 'error');
                $bErrorGenerate = true;
                // Don't do a graph again.
                return false;
            }
        }
    }
    if (count($lbl) > 72) {
        $DataSet = array(1 => array(1 => 1));
        if ($cache->IsInCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet) && Yii::app()->getConfig('debug') < 2) {
            $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet));
        } else {
            $graph = new pChart(690, 200);
            $graph->loadColorPalette($homedir . DIRECTORY_SEPARATOR . 'styles' . DIRECTORY_SEPARATOR . $admintheme . DIRECTORY_SEPARATOR . 'limesurvey.pal');
            $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
            $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
            $graph->drawTitle(0, 0, gT('Sorry, but this question has too many answer options to be shown properly in a graph.', 'unescaped'), 30, 30, 30, 690, 200);
            $cache->WriteToCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet, $graph);
            $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet));
            unset($graph);
        }
        return $cachefilename;
    }
    if (array_sum($gdata) == 0) {
        $DataSet = array(1 => array(1 => 1));
        if ($cache->IsInCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet) && Yii::app()->getConfig('debug') < 2) {
            $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet));
        } else {
            $graph = new pChart(690, 200);
            $graph->loadColorPalette($homedir . DIRECTORY_SEPARATOR . 'styles' . DIRECTORY_SEPARATOR . $admintheme . DIRECTORY_SEPARATOR . 'limesurvey.pal');
            $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
            $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
            $graph->drawTitle(0, 0, gT('Sorry, but this question has no responses yet so a graph cannot be shown.', 'unescaped'), 30, 30, 30, 690, 200);
            $cache->WriteToCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet, $graph);
            $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet));
            unset($graph);
        }
        return $cachefilename;
    }
    if (array_sum($gdata) > 0) {
        $graph = "";
        $p1 = "";
        $i = 0;
        foreach ($gdata as $data) {
            if ($data != 0) {
                $i++;
            }
        }
        /* Totatllines is the number of entries to show in the key and we need to reduce the font
           and increase the size of the chart if there are lots of them (ie more than 15) */
        $totallines = $i;
        if ($totallines > 15) {
            $gheight = 320 + 6.7 * ($totallines - 15);
            $fontsize = 7;
            $legendtop = 0.01;
            $setcentrey = 0.5 / ($gheight / 320);
        } else {
            $gheight = 320;
            $fontsize = 8;
            $legendtop = 0.07000000000000001;
            $setcentrey = 0.5;
        }
        if (!$type) {
            $DataSet = new pData();
            $counter = 0;
            $maxyvalue = 0;
            foreach ($grawdata as $datapoint) {
                $DataSet->AddPoint(array($datapoint), "Serie{$counter}");
                $DataSet->AddSerie("Serie{$counter}");
                $counter++;
                if ($datapoint > $maxyvalue) {
                    $maxyvalue = $datapoint;
                }
            }
            if ($maxyvalue < 10) {
                ++$maxyvalue;
            }
            if ($language == 'ar') {
                if (!class_exists('I18N_Arabic_Glyphs', false)) {
                    $Arabic = new I18N_Arabic('Glyphs');
                } else {
                    $Arabic = new I18N_Arabic_Glyphs();
                }
                foreach ($lbl as $kkey => $kval) {
                    if (preg_match("^[A-Za-z]^", $kkey)) {
                        //auto detect if english
                        $lblout[] = $kkey . ' (' . $kval . ')';
                    } else {
                        $lblout[] = $Arabic->utf8Glyphs($kkey . ' )' . $kval . '(');
                    }
                }
            } elseif (getLanguageRTL($language)) {
                foreach ($lbl as $kkey => $kval) {
                    $lblout[] = UTF8Strrev($kkey . ' )' . $kval . '(');
                }
            } else {
                foreach ($lbl as $kkey => $kval) {
                    $lblout[] = $kkey . ' (' . $kval . ')';
                }
            }
            $counter = 0;
            foreach ($lblout as $sLabelName) {
                $DataSet->SetSerieName(html_entity_decode($sLabelName, null, 'UTF-8'), "Serie{$counter}");
                $counter++;
            }
            if ($cache->IsInCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData()) && Yii::app()->getConfig('debug') < 2) {
                $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData()));
            } else {
                $graph = new pChart(1, 1);
                $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
                $legendsize = $graph->getLegendBoxSize($DataSet->GetDataDescription());
                if ($legendsize[1] < 320) {
                    $gheight = 420;
                } else {
                    $gheight = $legendsize[1] + 100;
                }
                $graph = new pChart(690 + $legendsize[0], $gheight);
                $graph->drawFilledRectangle(0, 0, 690 + $legendsize[0], $gheight, 254, 254, 254, false);
                $graph->loadColorPalette($homedir . DIRECTORY_SEPARATOR . 'styles' . DIRECTORY_SEPARATOR . $admintheme . DIRECTORY_SEPARATOR . 'limesurvey.pal');
                $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
                $graph->setGraphArea(50, 30, 500, $gheight - 60);
                $graph->drawFilledRoundedRectangle(7, 7, 523 + $legendsize[0], $gheight - 7, 5, 254, 255, 254);
                $graph->drawRoundedRectangle(5, 5, 525 + $legendsize[0], $gheight - 5, 5, 230, 230, 230);
                $graph->drawGraphArea(254, 254, 254, TRUE);
                $graph->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 90, 0, TRUE, 5, false);
                $graph->drawGrid(4, TRUE, 230, 230, 230, 50);
                // Draw the 0 line
                $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
                $graph->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
                // Draw the bar graph
                $graph->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), FALSE);
                //$Test->setLabel($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie4","1","Important point!");
                // Finish the graph
                $graph->setFontProperties($rootdir . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . $chartfontfile, $chartfontsize);
                $graph->drawLegend(510, 30, $DataSet->GetDataDescription(), 250, 250, 250);
                $cache->WriteToCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData(), $graph);
                $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData()));
                unset($graph);
            }
        } else {
            // this block is to remove the items with value == 0
            // and an inelegant way to remove comments from List with Comments questions
            $i = 0;
            $j = 0;
            $labelTmp = array();
            while (isset($gdata[$i])) {
                $aHelperArray = array_keys($lbl);
                if ($gdata[$i] == 0 || $sQuestionType == "O" && substr($aHelperArray[$i], 0, strlen($oLanguage->gT("Comments"))) == $oLanguage->gT("Comments")) {
                    array_splice($gdata, $i, 1);
                } else {
                    $i++;
                    $labelTmp = $labelTmp + array_slice($lbl, $j, 1, true);
                    // Preserve numeric keys for the labels!
                }
                $j++;
            }
            $lbl = $labelTmp;
            if ($language == 'ar') {
                if (!class_exists('I18N_Arabic_Glyphs', false)) {
                    $Arabic = new I18N_Arabic('Glyphs');
                } else {
                    $Arabic = new I18N_Arabic_Glyphs();
                }
                foreach ($lbl as $kkey => $kval) {
                    if (preg_match("^[A-Za-z]^", $kkey)) {
                        //auto detect if english
                        $lblout[] = $kkey . ' (' . $kval . ')';
                    } else {
                        $lblout[] = $Arabic->utf8Glyphs($kkey . ' )' . $kval . '(');
                    }
                }
            } elseif (getLanguageRTL($language)) {
                foreach ($lbl as $kkey => $kval) {
                    $lblout[] = UTF8Strrev(html_entity_decode($kkey, null, 'UTF-8') . ' )' . $kval . '(');
                }
            } else {
                foreach ($lbl as $kkey => $kval) {
                    $lblout[] = html_entity_decode($kkey, null, 'UTF-8') . ' (' . $kval . ')';
                }
            }
            //create new 3D pie chart
            $DataSet = new pData();
            $DataSet->AddPoint($gdata, "Serie1");
            $DataSet->AddPoint($lblout, "Serie2");
            $DataSet->AddAllSeries();
            $DataSet->SetAbsciseLabelSerie("Serie2");
            if ($cache->IsInCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData()) && Yii::app()->getConfig('debug') < 2) {
                $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData()));
            } else {
                $gheight = ceil($gheight);
                $graph = new pChart(690, $gheight);
                $graph->drawFilledRectangle(0, 0, 690, $gheight, 254, 254, 254, false);
                $graph->loadColorPalette($homedir . '/styles/' . $admintheme . '/limesurvey.pal');
                $graph->drawFilledRoundedRectangle(7, 7, 687, $gheight - 3, 5, 254, 255, 254);
                $graph->drawRoundedRectangle(5, 5, 689, $gheight - 1, 5, 230, 230, 230);
                // Draw the pie chart
                $graph->setFontProperties($rootdir . "/fonts/" . $chartfontfile, $chartfontsize);
                $graph->drawPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 225, round($gheight / 2), 170, PIE_PERCENTAGE, TRUE, 50, 20, 5);
                $graph->setFontProperties($rootdir . "/fonts/" . $chartfontfile, $chartfontsize);
                $graph->drawPieLegend(430, 12, $DataSet->GetData(), $DataSet->GetDataDescription(), 250, 250, 250);
                $cache->WriteToCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData(), $graph);
                $cachefilename = basename($cache->GetFileFromCache("graph" . $iSurveyID . $language . $iQuestionID, $DataSet->GetData()));
                unset($graph);
            }
        }
        //end else -> pie charts
    }
    return $cachefilename;
}
Exemplo n.º 4
0
 /**
  * Creates the object and prepares it for rendering.
  * Does all the calculation like borders, margins, paddings ....
  *
  * @return void
  */
 private function preGraphCreation()
 {
     // Initialize the graph
     $this->objChart = new pChart($this->intWidth, $this->intHeight);
     //set the color palette to be used
     foreach ($this->arrDefaultColorPalette as $intKey => $strCurrentColor) {
         $arrCurColor = hex2rgb($strCurrentColor);
         $this->objChart->setColorPalette($intKey, $arrCurColor[0], $arrCurColor[1], $arrCurColor[2]);
     }
     //calculate all needed params, draw that funky shit
     //the outer bounding and pane - rounded and with sharp corners
     $arrBackgroundColor = hex2rgb($this->strBackgroundColor);
     if ($this->bitRoundedCorners) {
         $this->objChart->drawFilledRoundedRectangle(2, 2, $this->intWidth - 3, $this->intHeight - 3, 5, $arrBackgroundColor[0], $arrBackgroundColor[1], $arrBackgroundColor[2]);
         $arrOuterBack = hex2rgb($this->strOuterFrameColor);
         $this->objChart->drawRoundedRectangle(0, 0, $this->intWidth - 1, $this->intHeight - 1, 5, $arrOuterBack[0], $arrOuterBack[1], $arrOuterBack[2]);
     } else {
         $this->objChart->drawFilledRectangle(0, 0, $this->intWidth, $this->intHeight, $arrBackgroundColor[0], $arrBackgroundColor[1], $arrBackgroundColor[2]);
     }
     //the graph area - x and or y-axis label present?
     if ($this->bitRenderLegend) {
         $intRightMargin = 10;
     } else {
         $intRightMargin = 20;
     }
     $intTopMargin = 15;
     $intBottomMargin = 30;
     $intLeftMargin = 40;
     $intLegendWidth = 0;
     if ($this->bitRenderLegend) {
         $intLegendWidth = 120;
     }
     $intWidth = $this->intWidth - $intRightMargin - $intLegendWidth;
     $intHeight = $this->intHeight - $intBottomMargin;
     $intLeftStart = $intLeftMargin;
     $intTopStart = $intTopMargin;
     if ($this->strYAxisTitle != "") {
         $intLeftStart += 15;
         //$intWidth -= 15; //TODO: why not needed?
     }
     if ($this->strXAxisTitle != "") {
         $intHeight -= 15;
     }
     if ($this->strGraphTitle != "") {
         //$intHeight -= 12; //TODO: why not needed???
         $intTopStart += 12;
     }
     if ($this->intCurrentGraphMode != $this->GRAPH_TYPE_PIE) {
         $this->objChart->setGraphArea($intLeftStart, $intTopStart, $intWidth, $intHeight);
         $arrPaneBackground = hex2rgb($this->strGraphBackgroundColor);
         $this->objChart->drawGraphArea($arrPaneBackground[0], $arrPaneBackground[1], $arrPaneBackground[2], true);
     }
     $arrFontColors = hex2rgb($this->strFontColor);
     $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 8);
     //set up the axis-titles
     if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR || $this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR || $this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) {
         if ($this->strXAxisTitle != "") {
             $this->objDataset->SetXAxisName($this->strXAxisTitle);
         }
         if ($this->strYAxisTitle != "") {
             $this->objDataset->SetYAxisName($this->strYAxisTitle);
         }
     }
     //the x- and y axis, in- / exclusive margins
     if ($this->bitAdditionalDatasetAdded && $this->bitScaleFromAdditionalDataset) {
         $this->objChart->drawScale($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription(), SCALE_START0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true);
     } else {
         if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR) {
             $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_START0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true);
         } else {
             if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR) {
                 $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_ADDALLSTART0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true);
             } else {
                 if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) {
                     $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_NORMAL, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, false);
                 }
             }
         }
     }
     //the background grid
     if ($this->intCurrentGraphMode != $this->GRAPH_TYPE_PIE) {
         $arrGridColor = hex2rgb($this->strGridColor);
         $this->objChart->drawGrid(4, true, $arrGridColor[0], $arrGridColor[1], $arrGridColor[2], 50);
     }
     if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) {
         // Draw the line graph
         $this->objChart->drawLineGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription());
         //dots in line
         $this->objChart->drawPlotGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 3, 2, 255, 255, 255);
     } else {
         if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR) {
             //the zero-line
             $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 6);
             $this->objChart->drawBarGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), TRUE);
             $this->objChart->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
             //if given, render the line-plots on top
             if ($this->bitAdditionalDatasetAdded) {
                 //the line itself
                 $this->objChart->drawLineGraph($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription());
                 //the dots
                 $this->objChart->drawPlotGraph($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription(), 3, 2, 255, 255, 255);
             }
         } else {
             if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR) {
                 //the zero-line
                 $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 6);
                 $this->objChart->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
                 $this->objChart->drawStackedBarGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 75);
             } else {
                 if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_PIE) {
                     $this->objChart->drawPieGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), ceil($this->intWidth / 2) - 20, ceil($this->intHeight / 2), ceil($intHeight / 2) + 20, PIE_PERCENTAGE, TRUE, 50, 20, 5);
                 }
             }
         }
     }
     //render values?
     if (count($this->arrValueSeriesToRender) > 0) {
         $this->objChart->writeValues($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), $this->arrValueSeriesToRender);
     }
     // Finish the graph
     $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 7);
     //set up the legend
     if ($this->bitRenderLegend) {
         if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_PIE) {
             $this->objChart->drawPieLegend($this->intWidth - $intLegendWidth - $intRightMargin + 10 - $this->intLegendAdditionalMargin, $intTopStart, $this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 255, 255, 255);
         } else {
             $arrLegend = $this->objDataset->GetDataDescription();
             //merge legends
             if ($this->bitAdditionalDatasetAdded) {
                 $arrAdditionalLegend = $this->objAdditionalDataset->GetDataDescription();
                 foreach ($arrAdditionalLegend["Description"] as $strKey => $strName) {
                     $arrLegend["Description"][$strKey] = $strName;
                 }
             }
             $this->objChart->drawLegend($this->intWidth - $intLegendWidth - $intRightMargin + 10 - $this->intLegendAdditionalMargin, $intTopStart, $arrLegend, 255, 255, 255);
         }
     }
     //draw the title
     if ($this->strGraphTitle != "") {
         $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 10);
         $this->objChart->drawTitle(0, $intTopMargin, $this->strGraphTitle, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], $this->intWidth, 10);
     }
 }
Exemplo n.º 5
0
            $cmR = $caR;
            $cmG = $caG;
            $cmB = $caB;
        }
    }
    // limita draw
    if ($realVol < $metrYmin) {
        $realVol = $metrYmin;
    }
    if ($realVol > $metrYmax) {
        $realVol = $metrYmax;
    }
    // Y pos of Value
    $yVal = $metrYmax - ($metrYmax - $realVol) / 2;
    $Test->drawFilledRoundedRectangle($bodyXmin, $bodyYmin, $bodyXmax, $metrYmax, 8, $cmR, $cmG, $cmB);
    $Test->drawFilledRectangle($bodyXmin, $bodyYmin + 30, $bodyXmax, $bodyYmax - 10, 100, 100, 100, FALSE, 100);
    // body
    // Current value
    $Test->setFontProperties("./pChart/Fonts/tahoma.ttf", 12);
    $Test->drawTextBox($bodyXmin, $bodyYmin + 15, $bodyXmax, $bodyYmin + 20, "{$currentValue}" . "{$unit}", 0, 245, 245, 245, ALIGN_CENTER, FALSE, -1, -1, -1, 100);
    // Draw label
    $Test->setFontProperties("./pChart/Fonts/tahoma.ttf", 8);
    $Test->drawTextBox($bodyXmin, $bodyYmax - 15, $bodyXmax, $bodyYmax - 7, "{$label}", 0, 255, 255, 255, ALIGN_CENTER, FALSE, -1, -1, -1, 100);
    //end of smartStick1
    //---------------------------- sticker1a
} elseif ($objtype == "sticker1a") {
    // Settings
    $wid = 100;
    $hei = 100;
    // light/black
    if ($black == 1) {
Exemplo n.º 6
0
 $metrDiap = $metrYmax - $metrYmin;
 $metrCenter = $metrDiap / 2;
 $s0Ymin = $bodyYmin + 2;
 $s0Ymax = $bodyYmax - 2;
 $s0Xmin = 2;
 $s0Xmax = $bodyXmax - 3;
 $s1Xmin = 2;
 $s1Xmax = 30;
 $s2Xmin = 29;
 $s2Xmax = 60;
 $s3Xmin = 59;
 $s3Xmax = $bodyXmax - 3;
 $Test = new pChart($wid, $hei);
 $Test->setGraphArea(0, 0, $wid, $hei);
 $Test->drawBackground($cbg, $cbg, $cbg);
 $Test->drawFilledRectangle($bodyXmin, $bodyYmin, $bodyXmax, $bodyYmax, 160, 160, 160, FALSE, 100);
 $Test->drawFilledRectangle($s1Xmin, $s0Ymin, $s3Xmax, $s0Ymax, 220, 220, 220, FALSE, 100);
 $tt0 = timeConvert("00:00") - 3600;
 $tt9 = timeConvert("23:59") - 3600 + 59;
 $ttd = $tt9 - $tt0;
 $ttn = time();
 $tt1 = $ttn - $tt0;
 $ttp = $ttd / $width;
 $ttx = $tt1 / $ttp;
 if ($ttn - $tt0 > 86400) {
     $ttx = $ttx - $width;
 }
 $d1on_ = timeConvert("00:00") - 3600;
 $d1off_ = timeConvert("07:00") - 3600;
 $d2on_ = timeConvert("07:00") - 3600;
 $d2off_ = timeConvert("10:00") - 3600;
Exemplo n.º 7
0
 /**
  * Initializes the chart, sets the properties
  */
 public function initializeChart()
 {
     global $wgPChart4mwFontPath;
     // Retrieve the parameters for the chart
     $args = $this->chartArgs;
     // Create a chart object
     $pChart = new pChart($args["sizeX"], $args["sizeY"]);
     // Draw background colors. If needed, a gradient should be drawn
     if ($args["bgtype"] == "normal") {
         $pChart->drawFilledRectangle(0, 0, $args["sizeX"], $args["sizeY"], $args["bgcolor"][0], $args["bgcolor"][1], $args["bgcolor"][2]);
     } else {
         $pChart->drawGraphAreaGradient($args["bgcolor"][0], $args["bgcolor"][1], $args["bgcolor"][2], 50, TARGET_BACKGROUND);
     }
     // Set default font properties
     $pChart->setFontProperties($wgPChart4mwFontPath . "/" . $args["textfont"], $args["textsize"]);
     // Define the graph area, by computing the margins, legend size, title size etc.
     $pChart = $this->setGraphArea($pChart);
     if ($args["graphbgtype"] == "normal") {
         $pChart->drawGraphArea($args["graphbgcolor"][0], $args["graphbgcolor"][1], $args["graphbgcolor"][2]);
     } elseif ($args["graphbgtype"] == "gradient") {
         $pChart->drawGraphAreaGradient($args["graphbgcolor"][0], $args["graphbgcolor"][1], $args["graphbgcolor"][2], 50);
     }
     $this->pChart = $pChart;
     if (!$this->empty) {
         $this->drawScaleAndGrid();
         $this->setColorPalette();
     }
     return $this->pChart;
 }