diff --git a/library/Graphique/Graphique.lib.php b/library/Graphique/Graphique.lib.php new file mode 100644 index 000000000..ca0192219 --- /dev/null +++ b/library/Graphique/Graphique.lib.php @@ -0,0 +1,246 @@ +pathToImageCache = $pathImageCache; + } + + protected function chechIfExists($nom) + { + if(file_exists($this->pathToImageCache.$nom)) + return (true); + return (false); + } + + /** + * Permet de connaitre les valeur par default pour les différents graphique. + * Enter description here ... + */ + protected function getDefault() + { + /** + * Paramétres par default Graphique XY + **/ + $default = new stdClass(); + $default->XY->width = 350; + $default->XY->height = 250; + $default->XY->setPlotArea = array(55, 10, 280, 200); + $default->XY->yAxisWidth = 2; + $default->XY->xAxisWidth = 2; + $default->XY->legendeParams = array(50, 10, false, "times.ttf", 9); + $default->XY->colorLegende = 0xff0000; + $default->XY->setLabelStep = 10; + + /** + * Paramétres par default Graphique PieChart + **/ + $default->PieChart->width = 660; + $default->PieChart->height = 243; + $default->PieChart->title->police = "timesbi.ttf"; + $default->PieChart->title->size = 15; + $default->PieChart->Xround = round($default->PieChart->width / 2); + $default->PieChart->Yround = round($default->PieChart->height / 2); + $default->PieChart->radius = 90; + $default->PieChart->setRoundedCorners = 5; + $default->PieChart->setLineColor = array(SameAsMainColor, 0x000000); + $default->PieChart->setStartAngle = 135; + $default->PieChart->setLabelFormat = "<*block,valign=absmiddle*>{label} <*font=".$default->PieChart->title->police.",size=0*>({percent|0}%)"; + $default->PieChart->set3D = 20; + $default->PieChart->getHTMLImageMap = array("", "", "name='{label}' title='{label}
{value|0} K.Euros' class='detailsgraphique'"); + $default->PieChart->makeSession = "chart1"; + + /** + * Paramétres par default Graphique FinanceChart + **/ + $default->financeChart->width = 640; + $default->financeChart->title = "Graphique financié"; + $default->financeChart->addSlowStochastic = array(75, 14, 3, 0x006060, 0x606000); + $default->financeChart->addMainChart = 240; + $default->financeChart->addSimpleMovingAvg = array(array(10, 0x663300), array(20, 0x9900ff)); + $default->financeChart->addCandleStick = array(array(0x00ff00, 0xff000)); + $default->financeChart->addDonchianChannel = array(array(20, 0x9999ff, 0xc06666ff)); + $default->financeChart->addVolBars = array(array(75, 0x99ff99, 0xff9999, 0x808080)); + $default->financeChart->addMACD = array(array(75, 26, 12, 9, 0x0000ff, 0xff00ff, 0x008000)); + $default->financeChart->getHTMLImageMap = array("", "", "name='' title='{value|0} K.Euros' class='detailsgraphique'"); + + + + return ($default); + } + + public function getValueDefault($type) + { + print_r(self::getDefault()->$type); + } + + /** + * $parametres->nom = le nom final de l'image exemple : "552152365-C-actif.png" + * $parametres->width = la largeur de l'image. + * $parametres->height = la hauteur de l'image. + * $parametres->plotArea = "exemple" : array(55, 10, 280, 200) doit être un tableau. + * $parametres->TitleY = array("Keuros"); Les titre sur les coté du graphique. + * $parametres->TitleX = array("Années"); Les titres sur les coté du graphique. + * $parametres->yAxisWidth = 2; + * $parametres->xAxisWidth = 2; + * $parametres->legendeParams = array(50, 10, false, "times.ttf", 9); les paramètres des legendes doit être un tableau ! + * $parametres->colorLegende = la couleur du texte de la legende, 0xff0000 par default. + * $parametres->LineLayer = array("Entreprise", "Secteur"); + * - les legendes des courbes du graphique. + * - (sachant que chaque legende est assigner a un tableau de valeur). + * - Le tableau des datas doit être dans le meme ordre que l'ordre des titres ! IMPORTANT ! + * $parametres->setLabelStep = 10 par default. + * $parametres->labelsY = Les labels en Y exemple les dates (2008, 2004, 2003, 2002, 2001); + * $parametres->labelsX = Les labels en X exemple les chiffre (20K, 30K, 50K) + * - En laissant vide ces champs le système les créras automatiquement. + * + * @param stdClass $parametres + * @param bool $default + */ + public function GraphiqueLineXY($parametres, $default = false) + { + $i = 0; + if(!self::chechIfExists($parametres->nom)) { + $chart = new XYChart(((!$default)?$parametres->width:self::getDefault()->XY->width), + ((!$default)?$parametres->height:self::getDefault()->XY->height)); + $chart->setPlotArea(((!$default)?$parametres->setPlotArea[0]:self::getDefault()->XY->setPlotArea[0]), + ((!$default)?$parametres->setPlotArea[1]:self::getDefault()->XY->setPlotArea[1]), + ((!$default)?$parametres->setPlotArea[2]:self::getDefault()->XY->setPlotArea[2]), + ((!$default)?$parametres->setPlotArea[3]:self::getDefault()->XY->setPlotArea[3])); + foreach ($parametres->TitlesY as $titleY) $chart->yAxis->setTitle($titleY); + foreach ($parametres->TitlesX as $titleX) $chart->xAxis->setTitle($titleX); + $chart->yAxis->setWidth(((!$default)?$parametres->yAxisWidth:self::getDefault()->XY->yAxisWidth)); + $chart->xAxis->setWidth(((!$default)?$parametres->xAxisWidth:self::getDefault()->XY->xAxisWidth)); + $legendObj = $chart->addLegend(((!$default)?$parametres->legendeParams[0]:self::getDefault()->XY->legendeParams[0]), + ((!$default)?$parametres->legendeParams[1]:self::getDefault()->XY->legendeParams[1]), + ((!$default)?$parametres->legendeParams[2]:self::getDefault()->XY->legendeParams[2]), + ((!$default)?$parametres->legendeParams[3]:self::getDefault()->XY->legendeParams[3])); + $legendObj->setBackground(Transparent); + foreach ($parametres->LineLayer as $lineLayer) {$chart->addLineLayer($parametres->datas[$i], + ((isset($parametres->colorLegende->$lineLayer))?$parametres->colorLegende->$lineLayer:self::getDefault()->XY->colorLegende), + $lineLayer);$i++;} + $chart->yAxis->setLabels($parametres->labelsY); + $chart->yAxis->setLabelStep(((!$default)?$parametres->setLabelStep:self::getDefault()->XY->setLabelStep)); + $chart->xAxis->setLabels($parametres->labelsX); + $chart->makeChart($this->pathToImageCache.$parametres->nom); + } + return ($this->pathToImageCache.$parametres->nom); + } + + /** + * $parametres->nom = le nom final de l'image exemple : "552152365-C-actif.png" + * $parametres->width = largeur de l'image du graphique + * $parametres->height = la hauteur de l'images du graphique + * $parametres->title->texte = le texte de l'image du graphique ex : actif pour la période de... + * $parametres->title->police = la police utilisé ex : timesbi.ttf + * $parametres->title->size = la taille de la police pour le titre du graphique + * $parametres->setPieSize = array(round(width/2), round(height/2), radius); + * - La largeur / 2 arrondie + * - La hauteur divisé par 2 arrondie + * - Le radius. ex: (90) + * $parametres->setRoundedCorners = une valeur ex : 5 + * $parametres->setLineColor = array(SameAsMainColor, 0x000000). + * $parametres->setStartAngle = 135 (angle du camanbert par default). + * $parametres->setLabelFormat = "html..." le code de formatage de la ligne + * - exemple : <*block,valign=absmiddle*>{label} <*font=timesbi.ttf,size=0*> + * $parametres->setData = array($data, $labels) les données et les labels correspondants. + * $parametres->set3D = 20 (permet de definir la profondeur 3d.). + * $parametres->makeSession = "chart1" les nom de la session. + * $parametres->getHTMLImageMap = array("", "", "name='{label}' title='{label}
{value|0} K.Euros' class='detailsgraphique'"); + * - Les parametres pour les area comment formater chaque tootltip. + * + * Cette méthode retourne une stdClass() avec les parametres imageMap et chartID. + * + * @param stdClass $parametres + * @param bool $default + */ + public function GraphiquePieChart($parametres, $default = false) + { + $return = new stdClass(); + $pieChart = new PieChart(((!$default)?$parametres->width:self::getDefault()->PieChart->width), + ((!$default)?$parametres->height:self::getDefault()->PieChart->height)); + $pieChart->addTitle($parametres->title->texte, + (!$default)?$parametres->title->police:self::getDefault()->PieChart->title->police, + (!$default)?$parametres->title->size:self::getDefault()->PieChart->title->size); + $pieChart->setPieSize((!$default)?$parametres->Xround:self::getDefault()->PieChart->Xround, + (!$default)?$parametres->Yround:self::getDefault()->PieChart->Yround, + (!$default)?$parametres->radius:self::getDefault()->PieChart->radius); + $pieChart->setLabelLayout(SideLayout); + $style = $pieChart->setLabelStyle(); + $style->setBackground(SameAsMainColor, Transparent, softLighting()); + $style->setRoundedCorners((!$default)?$parametres->setRoundedCorners:self::getDefault()->PieChart->setRoundedCorners); + $pieChart->setLineColor((!$default)?$parametres->setLineColor[0]:self::getDefault()->PieChart->setLineColor[0], + (!$default)?$parametres->setLineColor[1]:self::getDefault()->PieChart->setLineColor[1]); + $pieChart->setStartAngle((!$default)?$parametres->setStartAngle:self::getDefault()->PieChart->setStartAngle); + $pieChart->setLabelFormat((!$default)?$parametres->setLabelFormat:self::getDefault()->PieChart->setLabelFormat); + $pieChart->setData($parametres->datas, $parametres->labels); + $pieChart->set3D((!$default)?$parametres->set3D:self::getDefault()->PieChart->set3D); + $makeSession = (!$default)?$parametres->makeSession:self::getDefault()->PieChart->makeSession; + $return->chartID = $pieChart->makeSession($makeSession); + $return->imageMap = $pieChart->getHTMLImageMap((!$default)?$parametres->getHTMLImageMap[0]:self::getDefault()->PieChart->getHTMLImageMap[0], + (!$default)?$parametres->getHTMLImageMap[1]:self::getDefault()->PieChart->getHTMLImageMap[1], + (!$default)?$parametres->getHTMLImageMap[2]:self::getDefault()->PieChart->getHTMLImageMap[2]); + $pieChart->makeChart($this->pathToImageCache.$parametres->nom); + return ($return); + } + + /** + * $parametres->nom = le nom final de l'image exemple : "552152365-C-actif.png" + * $parametres->width = largeur de l'image du graphique + * $parametres->title = titre du graphique + * $parametres->timeStamps = $timeStamps; + * $parametres->highData = les données les plus hautes pour l'action + * $parametres->lowData = les données les plus basses pour l'action + * $parametres->openData = l'ouverture des données + * $parametres->closeData = les fermeture des données. + * $parametres->volData = $volData; + * $parametres->extraDays = $extraDays; + * $parametres->addMainChart = $addMainChart; ex : 5 + * $parametres->addSlowStochastic = array(75, 14, 3, 0x006060, 0x606000); + * $parametres->addSimpleMovingAvg = array(array(10, 0x663300), array(20, 0x9900ff)); + * $parametres->addCandleStick = array(array(0x00ff00, 0xff000)); + * $parametres->addDonchianChannel = array(array(20, 0x9999ff, 0xc06666ff)); + * $parametres->addVolBars = array(array(75, 0x99ff99, 0xff9999, 0x808080)); + * $parametres->addMACD = array(array(75, 26, 12, 9, 0x0000ff, 0xff00ff, 0x008000)); + * $parametres->makeSession = nom dans le session ID unique (sert pour le mappage des areas); + * + * Cette méthode retourne une stdClass() avec les parametres imageMap et chartIDRL. + * + * @param stdClass $parametres + * @param bool $default + */ + public function GraphiqueFinance($parametres, $default = false) + { + $return = new stdClass(); + $financeChart = new FinanceChart((!$default)?$parametres->width:self::getDefault()->financeChart->width); + $financeChart->addTitle((!$default)?$parametres->title:self::getDefault()->financeChart->title); + $financeChart->setData($parametres->timeStamps, $parametres->highData, $parametres->lowData, + $parametres->openData, $parametres->closeData, $parametres->volData, $parametres->extraDays); + $financeChart->addSlowStochastic((!$default)?$parametres->addSlowStochastic[0]:self::getDefault()->financeChart->addSlowStochastic[0], + (!$default)?$parametres->addSlowStochastic[1]:self::getDefault()->financeChart->addSlowStochastic[1], + (!$default)?$parametres->addSlowStochastic[2]:self::getDefault()->financeChart->addSlowStochastic[2], + (!$default)?$parametres->addSlowStochastic[3]:self::getDefault()->financeChart->addSlowStochastic[3], + (!$default)?$parametres->addSlowStochastic[4]:self::getDefault()->financeChart->addSlowStochastic[4]); + $financeChart->addMainChart((!$default)?$parametres->financeChart->addMainChart:self::getDefault()->financeChart->addMainChart); + foreach ((!$default)?$parametres->addSimpleMovingAvg:self::getDefault()->financeChart->addSimpleMovingAvg as $addSimpleMovingAvg) + $financeChart->addSimpleMovingAvg($addSimpleMovingAvg[0], $addSimpleMovingAvg[1]); + foreach ((!$default)?$parametres->addCandleStick:self::getDefault()->financeChart->addCandleStick as $addCandleStick) + $financeChart->addCandleStick($addCandleStick[0], $addCandleStick[1]); + foreach ((!$default)?$parametres->addDonchianChannel:self::getDefault()->financeChart->addDonchianChannel as $addDonchianChannel) + $financeChart->addDonchianChannel($addDonchianChannel[0], $addDonchianChannel[1], $addDonchianChannel[2]); + foreach ((!$default)?$parametres->addVolBars:self::getDefault()->financeChart->addVolBars as $addVolBars) + $financeChart->addVolBars($addVolBars[0], $addVolBars[1], $addVolBars[2], $addVolBars[3]); + foreach ((!$default)?$parametres->addMACD:self::getDefault()->financeChart->addMACD as $addMACD) + $financeChart->addMACD($addMACD[0], $addMACD[1], $addMACD[2], $addMACD[3], $addMACD[4], $addMACD[5],$addMACD[6]); + $makeSession = (!$default)?$parametres->makeSession:self::getDefault()->financeChart->makeSession; + $return->chartID = $financeChart->makeSession($makeSession); + $return->imageMap = $financeChart->getHTMLImageMap((!$default)?$parametres->getHTMLImageMap[0]:self::getDefault()->financeChart->getHTMLImageMap[0], + (!$default)?$parametres->getHTMLImageMap[1]:self::getDefault()->financeChart->getHTMLImageMap[1], + (!$default)?$parametres->getHTMLImageMap[2]:self::getDefault()->financeChart->getHTMLImageMap[2]); + $financeChart->makeChart($this->pathToImageCache.$parametres->nom); + return ($return); + } +} \ No newline at end of file