From f47995c40c6bebebe5dc1a66913008069eb32b58 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 3 Apr 2011 09:14:04 +0100 Subject: [PATCH] Get charts and write images to disk (thanks Google) & fixed one chart title. --- src/WriteDayOfWeekData.php | 13 +++++++++++-- src/WriteHourOfDayData.php | 12 +++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/WriteDayOfWeekData.php b/src/WriteDayOfWeekData.php index 36237b0..a1a7e66 100644 --- a/src/WriteDayOfWeekData.php +++ b/src/WriteDayOfWeekData.php @@ -35,16 +35,25 @@ public function write() { $data[$item->getDateTimeAs('D')]++; } - if (true) { + if (isset($this->configData['graphfile']) && $this->configData['graphfile']) { $maxCommits = max($data); $dataArray = $labelArray = array(); foreach($data as $day=>$commits) { $dataArray[] = intval($commits / $maxCommits * 100); $labelArray[] = $day; } - $url = 'http://chart.apis.google.com/chart?cht=bvg&chtt=Hour+Of+Day&chs=220x300&chxt=x&chxl=0:|'.implode('|',$labelArray).'&chd=t:'.implode(',',$dataArray); + $url = 'http://chart.apis.google.com/chart?cht=bvg&chtt=Day+Of+Week&chs=220x300&chxt=x&chxl=0:|'.implode('|',$labelArray).'&chd=t:'.implode(',',$dataArray); print "URL: $url \n\n"; + + $ch = curl_init($url); + $fp = fopen($this->configData['graphfile'], "w"); + curl_setopt($ch, CURLOPT_FILE, $fp); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_exec($ch); + curl_close($ch); + fclose($fp); + } if (isset($this->configData['file']) && $this->configData['file']) { diff --git a/src/WriteHourOfDayData.php b/src/WriteHourOfDayData.php index f141cf3..32072cf 100644 --- a/src/WriteHourOfDayData.php +++ b/src/WriteHourOfDayData.php @@ -28,7 +28,7 @@ public function write() { $data[intval($item->getDateTimeAs('G'))]++; } - if (true) { + if (isset($this->configData['graphfile']) && $this->configData['graphfile']) { $maxCommits = max($data); $dataArray = $labelArray = array(); foreach($data as $day=>$commits) { @@ -38,6 +38,16 @@ public function write() { $url = 'http://chart.apis.google.com/chart?cht=bvg&chtt=Hour+Of+Day&chs=700x400&chbh=18&chxt=x&chxl=0:|'.implode('|',$labelArray).'&chd=t:'.implode(',',$dataArray); print "URL: $url \n\n"; + + $ch = curl_init($url); + $fp = fopen($this->configData['graphfile'], "w"); + curl_setopt($ch, CURLOPT_FILE, $fp); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_exec($ch); + curl_close($ch); + fclose($fp); + + } if (isset($this->configData['file']) && $this->configData['file']) {