PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/scielolog/GraphVisitsMonthAllYears.php

https://github.com/robertatakenaka/Web
PHP | 99 lines | 80 code | 19 blank | 0 comment | 7 complexity | c1a78f290e60c51f3cf177e47888408b MD5 | raw file
  1. <?php
  2. include_once ("classLogDatabaseQueryArticleMonthYear.php");
  3. include_once ("jpgraph/jpgraph.php");
  4. include_once ("jpgraph/jpgraph_log.php");
  5. include_once ("jpgraph/jpgraph_bar.php");
  6. define ("LOGDEF", "../scielo.def");
  7. class PlotVisitsMonthAllYears
  8. {
  9. var $_data = "";
  10. var $_legend = "";
  11. var $_months = Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
  12. function _setValues($pid)
  13. {
  14. $log = new LogDatabaseQueryArticleMonthYear (LOGDEF);
  15. $log->SetPid ($pid);
  16. if ( ! ($result = $log->executeQuery()) )
  17. {
  18. echo "Error: " . $log->getMySQLError();
  19. $log->destroy ();
  20. exit;
  21. }
  22. $date = $log->getInitDate();
  23. if ($date) $iniYear = substr ($date, 0, 4);
  24. $date = $log->getLastDate();
  25. if ($date) $finYear = substr ($date, 0, 4);
  26. $count = 0;
  27. for ($year = $iniYear; $year <= $finYear; $year++)
  28. {
  29. $this->_legend [$count] = $year;
  30. $this->_data [$count++] = Array (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  31. }
  32. for ($i = 0; $i < mysql_num_rows ($result); $i++)
  33. {
  34. $row = mysql_fetch_array ($result);
  35. $index = $row["year"] - $iniYear;
  36. $imonth = $row["month"] - 1;
  37. $this->_data [$index][$imonth] += $row["total"];
  38. }
  39. $log->destroy ();
  40. }
  41. function plot($pid)
  42. {
  43. $this->_setValues ($pid);
  44. $graph = new Graph(600,400);
  45. $graph->img->SetMargin(60,95,40,40);
  46. $graph->SetShadow();
  47. $graph->SetScale("textlog");
  48. $colors = Array ("hotpink", "green", "blue", "gold", "blueviolet", "deepskyblue", "brown", "cadetblue", "darksalmon", "cornflowerblue", "darkslateblue", "limegreen", "yellow", "navy", "slategray");
  49. srand (1);
  50. for ($i = 0; $i < sizeof($this->_data); $i++)
  51. {
  52. $bplot[$i] = new BarPlot($this->_data[$i]);
  53. if ($i < sizeof($colors))
  54. {
  55. $color = $colors[$i];
  56. }
  57. else
  58. {
  59. $r = rand(0, 255);
  60. $g = rand(0, 255);
  61. $b = rand(0, 255);
  62. $color = Array ( $r, $g, $b);
  63. }
  64. $bplot[$i]->SetFillColor ($color);
  65. $bplot[$i]->SetLegend ($this->_legend[$i]);
  66. }
  67. $gbplot = new GroupBarPlot($bplot);
  68. $graph->Add($gbplot);
  69. $graph->title->Set ("# of Visited Articles per Month (log scale)");
  70. $graph->title->SetFont (FONT2_BOLD);
  71. $graph->xaxis->SetTickLabels ($this->_months);
  72. $graph->ygrid->Show(true,true);
  73. $graph->xaxis->SetFont (FONT1_BOLD);
  74. $graph->yaxis->SetFont (FONT1_BOLD);
  75. $graph->Stroke();
  76. }
  77. }
  78. $plot = new PlotVisitsMonthAllYears ($year);
  79. $plot->plot ($pid);
  80. ?>